Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : : #include <tools/poly.hxx>
31 : : #include <svl/stritem.hxx>
32 : : #include <svx/contdlg.hxx>
33 : : #include <vcl/svapp.hxx>
34 : : #include <docary.hxx>
35 : : #include <doc.hxx>
36 : : #include <fmtcol.hxx>
37 : : #include <ndnotxt.hxx>
38 : : #include <ndgrf.hxx>
39 : : #include <ndole.hxx>
40 : : #include <ndindex.hxx>
41 : : #include <hints.hxx>
42 : : #include <istyleaccess.hxx>
43 : : #include <SwStyleNameMapper.hxx>
44 : :
45 : : #include <frmfmt.hxx> // #i73249#
46 : :
47 : 526 : SwNoTxtNode::SwNoTxtNode( const SwNodeIndex & rWhere,
48 : : const sal_uInt8 nNdType,
49 : : SwGrfFmtColl *pGrfColl,
50 : : SwAttrSet* pAutoAttr ) :
51 : : SwCntntNode( rWhere, nNdType, pGrfColl ),
52 : : pContour( 0 ),
53 : : bAutomaticContour( sal_False ),
54 : : bContourMapModeValid( sal_True ),
55 : 526 : bPixelContour( sal_False )
56 : : {
57 : : // Should this set a hard attribute?
58 [ + + ]: 526 : if( pAutoAttr )
59 [ + - ]: 3 : SetAttr( *pAutoAttr );
60 : 526 : }
61 : :
62 : 436 : SwNoTxtNode::~SwNoTxtNode()
63 : : {
64 [ - + ][ # # ]: 436 : delete pContour;
65 [ - + ]: 436 : }
66 : :
67 : : /// Creates an AttrSet for all derivations with ranges for frame-
68 : : /// and graphics-attributes.
69 : 89 : void SwNoTxtNode::NewAttrSet( SwAttrPool& rPool )
70 : : {
71 : : OSL_ENSURE( !mpAttrSet.get(), "AttrSet is already set" );
72 [ + - ]: 89 : SwAttrSet aNewAttrSet( rPool, aNoTxtNodeSetRange );
73 : :
74 : : // put names of parent style and conditional style:
75 : 89 : const SwFmtColl* pFmtColl = GetFmtColl();
76 [ + - ]: 89 : String sVal;
77 [ + - ]: 89 : SwStyleNameMapper::FillProgName( pFmtColl->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
78 [ + - ]: 89 : SfxStringItem aFmtColl( RES_FRMATR_STYLE_NAME, sVal );
79 [ + - ]: 89 : aNewAttrSet.Put( aFmtColl );
80 : :
81 : 89 : aNewAttrSet.SetParent( &GetFmtColl()->GetAttrSet() );
82 [ + - ][ + - ]: 89 : mpAttrSet = GetDoc()->GetIStyleAccess().getAutomaticStyle( aNewAttrSet, IStyleAccess::AUTO_STYLE_NOTXT );
[ + - ][ + - ]
[ + - ][ + - ]
83 : 89 : }
84 : :
85 : : /// Dummies for loading/saving of persistent data
86 : : /// when working with graphics and OLE objects
87 : 0 : sal_Bool SwNoTxtNode::RestorePersistentData()
88 : : {
89 : 0 : return sal_True;
90 : : }
91 : :
92 : 0 : sal_Bool SwNoTxtNode::SavePersistentData()
93 : : {
94 : 0 : return sal_True;
95 : : }
96 : :
97 : 20 : void SwNoTxtNode::SetContour( const PolyPolygon *pPoly, sal_Bool bAutomatic )
98 : : {
99 [ - + ]: 20 : delete pContour;
100 [ - + ]: 20 : if ( pPoly )
101 [ # # ]: 0 : pContour = new PolyPolygon( *pPoly );
102 : : else
103 : 20 : pContour = 0;
104 : 20 : bAutomaticContour = bAutomatic;
105 : 20 : bContourMapModeValid = sal_True;
106 : 20 : bPixelContour = sal_False;
107 : 20 : }
108 : :
109 : 0 : void SwNoTxtNode::CreateContour()
110 : : {
111 : : OSL_ENSURE( !pContour, "Contour available." );
112 [ # # ][ # # ]: 0 : pContour = new PolyPolygon(SvxContourDlg::CreateAutoContour(GetGraphic()));
113 : 0 : bAutomaticContour = sal_True;
114 : 0 : bContourMapModeValid = sal_True;
115 : 0 : bPixelContour = sal_False;
116 : 0 : }
117 : :
118 : 25 : const PolyPolygon *SwNoTxtNode::HasContour() const
119 : : {
120 [ - + ]: 25 : if( !bContourMapModeValid )
121 : : {
122 [ # # ][ # # ]: 0 : const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
[ # # ]
123 : 0 : sal_Bool bPixelGrf = aGrfMap.GetMapUnit() == MAP_PIXEL;
124 [ # # ][ # # ]: 0 : const MapMode aContourMap( bPixelGrf ? MAP_PIXEL : MAP_100TH_MM );
125 [ # # ][ # # ]: 0 : if( bPixelGrf ? !bPixelContour : aGrfMap != aContourMap )
[ # # ]
126 : : {
127 : : // #i102238#
128 : 0 : double nGrfDPIx = 0.0;
129 : 0 : double nGrfDPIy = 0.0;
130 : : {
131 [ # # ][ # # ]: 0 : if ( !bPixelGrf && bPixelContour )
132 : : {
133 [ # # ][ # # ]: 0 : const Size aGrfPixelSize( GetGraphic().GetSizePixel() );
[ # # ]
134 [ # # ][ # # ]: 0 : const Size aGrfPrefMapModeSize( GetGraphic().GetPrefSize() );
[ # # ]
135 [ # # ]: 0 : if ( aGrfMap.GetMapUnit() == MAP_INCH )
136 : : {
137 [ # # ]: 0 : nGrfDPIx = aGrfPixelSize.Width() / ( (double)aGrfMap.GetScaleX() * aGrfPrefMapModeSize.Width() );
138 [ # # ]: 0 : nGrfDPIy = aGrfPixelSize.Height() / ( (double)aGrfMap.GetScaleY() * aGrfPrefMapModeSize.Height() );
139 : : }
140 : : else
141 : : {
142 : : const Size aGrf1000thInchSize =
143 : : OutputDevice::LogicToLogic( aGrfPrefMapModeSize,
144 [ # # ][ # # ]: 0 : aGrfMap, MAP_1000TH_INCH );
[ # # ]
145 : 0 : nGrfDPIx = 1000.0 * aGrfPixelSize.Width() / aGrf1000thInchSize.Width();
146 : 0 : nGrfDPIy = 1000.0 * aGrfPixelSize.Height() / aGrf1000thInchSize.Height();
147 : : }
148 : : }
149 : : }
150 : : OSL_ENSURE( !bPixelGrf || aGrfMap == aContourMap,
151 : : "scale factor for pixel unsupported" );
152 : : OutputDevice* pOutDev =
153 : : (bPixelGrf || bPixelContour) ? Application::GetDefaultDevice()
154 [ # # ][ # # ]: 0 : : 0;
[ # # ]
155 [ # # ]: 0 : sal_uInt16 nPolyCount = pContour->Count();
156 [ # # ]: 0 : for( sal_uInt16 j=0; j<nPolyCount; j++ )
157 : : {
158 [ # # ]: 0 : Polygon& rPoly = (*pContour)[j];
159 : :
160 [ # # ]: 0 : sal_uInt16 nCount = rPoly.GetSize();
161 [ # # ]: 0 : for( sal_uInt16 i=0 ; i<nCount; i++ )
162 : : {
163 [ # # ]: 0 : if( bPixelGrf )
164 [ # # ][ # # ]: 0 : rPoly[i] = pOutDev->LogicToPixel( rPoly[i],
165 [ # # ]: 0 : aContourMap );
166 [ # # ]: 0 : else if( bPixelContour )
167 : : {
168 [ # # ][ # # ]: 0 : rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap );
[ # # ]
169 : : // #i102238#
170 [ # # ][ # # ]: 0 : if ( nGrfDPIx != 0 && nGrfDPIy != 0 )
171 : : {
172 [ # # # # ]: 0 : rPoly[i] = Point( rPoly[i].X() * pOutDev->ImplGetDPIX() / nGrfDPIx,
173 [ # # ]: 0 : rPoly[i].Y() * pOutDev->ImplGetDPIY() / nGrfDPIy );
174 : : }
175 : : }
176 : : else
177 [ # # ][ # # ]: 0 : rPoly[i] = OutputDevice::LogicToLogic( rPoly[i],
178 : : aContourMap,
179 [ # # ]: 0 : aGrfMap );
180 : : }
181 : : }
182 : : }
183 : 0 : ((SwNoTxtNode *)this)->bContourMapModeValid = sal_True;
184 [ # # ][ # # ]: 0 : ((SwNoTxtNode *)this)->bPixelContour = sal_False;
185 : : }
186 : :
187 : 25 : return pContour;
188 : : }
189 : :
190 : 0 : void SwNoTxtNode::GetContour( PolyPolygon &rPoly ) const
191 : : {
192 : : OSL_ENSURE( pContour, "Contour not available." );
193 : 0 : rPoly = *HasContour();
194 : 0 : }
195 : :
196 : 0 : void SwNoTxtNode::SetContourAPI( const PolyPolygon *pPoly )
197 : : {
198 [ # # ]: 0 : delete pContour;
199 [ # # ]: 0 : if ( pPoly )
200 [ # # ]: 0 : pContour = new PolyPolygon( *pPoly );
201 : : else
202 : 0 : pContour = 0;
203 : 0 : bContourMapModeValid = sal_False;
204 : 0 : }
205 : :
206 : 2 : sal_Bool SwNoTxtNode::GetContourAPI( PolyPolygon &rContour ) const
207 : : {
208 [ + - ]: 2 : if( !pContour )
209 : 2 : return sal_False;
210 : :
211 : 0 : rContour = *pContour;
212 [ # # ]: 0 : if( bContourMapModeValid )
213 : : {
214 [ # # ][ # # ]: 0 : const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
[ # # ]
215 [ # # ]: 0 : const MapMode aContourMap( MAP_100TH_MM );
216 : : OSL_ENSURE( aGrfMap.GetMapUnit() != MAP_PIXEL ||
217 : : aGrfMap == MapMode( MAP_PIXEL ),
218 : : "scale factor for pixel unsupported" );
219 [ # # ][ # # ]: 0 : if( aGrfMap.GetMapUnit() != MAP_PIXEL &&
[ # # ]
220 [ # # ]: 0 : aGrfMap != aContourMap )
221 : : {
222 [ # # ]: 0 : sal_uInt16 nPolyCount = rContour.Count();
223 [ # # ]: 0 : for( sal_uInt16 j=0; j<nPolyCount; j++ )
224 : : {
225 : : // --> OD #i102238# - use the right <PolyPolygon> instance
226 [ # # ]: 0 : Polygon& rPoly = rContour[j];
227 : : // <--
228 : :
229 [ # # ]: 0 : sal_uInt16 nCount = rPoly.GetSize();
230 [ # # ]: 0 : for( sal_uInt16 i=0 ; i<nCount; i++ )
231 : : {
232 [ # # ][ # # ]: 0 : rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap,
233 [ # # ]: 0 : aContourMap );
234 : : }
235 : : }
236 [ # # ][ # # ]: 0 : }
237 : : }
238 : :
239 : 2 : return sal_True;
240 : : }
241 : :
242 : 0 : sal_Bool SwNoTxtNode::IsPixelContour() const
243 : : {
244 : : sal_Bool bRet;
245 [ # # ]: 0 : if( bContourMapModeValid )
246 : : {
247 [ # # ][ # # ]: 0 : const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
[ # # ]
248 [ # # ]: 0 : bRet = aGrfMap.GetMapUnit() == MAP_PIXEL;
249 : : }
250 : : else
251 : : {
252 : 0 : bRet = bPixelContour;
253 : : }
254 : :
255 : 0 : return bRet;
256 : : }
257 : :
258 : 16 : Graphic SwNoTxtNode::GetGraphic() const
259 : : {
260 : 16 : Graphic aRet;
261 [ + - ]: 16 : if ( GetGrfNode() )
262 : : {
263 [ + - ]: 16 : ((SwGrfNode*)this)->SwapIn( sal_True );
264 [ + - ][ + - ]: 16 : aRet = ((SwGrfNode*)this)->GetGrf();
265 : : }
266 : : else
267 : : {
268 : : OSL_ENSURE( GetOLENode(), "new type of Node?" );
269 [ # # ][ # # ]: 0 : aRet = *((SwOLENode*)this)->SwOLENode::GetGraphic();
270 : : }
271 : 16 : return aRet;
272 : : }
273 : :
274 : : // #i73249#
275 : 3 : void SwNoTxtNode::SetTitle( const String& rTitle, bool bBroadcast )
276 : : {
277 : : // Title attribute of <SdrObject> replaces own AlternateText attribute
278 [ - + ]: 3 : SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
279 : : OSL_ENSURE( pFlyFmt,
280 : : "<SwNoTxtNode::SetTitle(..)> - missing <SwFlyFrmFmt> instance" );
281 [ - + ]: 3 : if ( !pFlyFmt )
282 : : {
283 : 3 : return;
284 : : }
285 : :
286 : 3 : pFlyFmt->SetObjTitle( rTitle, bBroadcast );
287 : : }
288 : :
289 : 39 : const String SwNoTxtNode::GetTitle() const
290 : : {
291 [ - + ]: 39 : const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
292 : : OSL_ENSURE( pFlyFmt,
293 : : "<SwNoTxtNode::GetTitle(..)> - missing <SwFlyFrmFmt> instance" );
294 [ - + ]: 39 : if ( !pFlyFmt )
295 : : {
296 : 0 : return aEmptyStr;
297 : : }
298 : :
299 : 39 : return pFlyFmt->GetObjTitle();
300 : : }
301 : :
302 : 3 : void SwNoTxtNode::SetDescription( const String& rDescription, bool bBroadcast )
303 : : {
304 [ - + ]: 3 : SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
305 : : OSL_ENSURE( pFlyFmt,
306 : : "<SwNoTxtNode::SetDescription(..)> - missing <SwFlyFrmFmt> instance" );
307 [ - + ]: 3 : if ( !pFlyFmt )
308 : : {
309 : 3 : return;
310 : : }
311 : :
312 : 3 : pFlyFmt->SetObjDescription( rDescription, bBroadcast );
313 : : }
314 : :
315 : 5 : const String SwNoTxtNode::GetDescription() const
316 : : {
317 [ - + ]: 5 : const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
318 : : OSL_ENSURE( pFlyFmt,
319 : : "<SwNoTxtNode::GetDescription(..)> - missing <SwFlyFrmFmt> instance" );
320 [ - + ]: 5 : if ( !pFlyFmt )
321 : : {
322 : 0 : return aEmptyStr;
323 : : }
324 : :
325 : 5 : return pFlyFmt->GetObjDescription();
326 : : }
327 : :
328 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|