xref: /trunk/main/sw/source/core/docnode/ndnotxt.cxx (revision 51d7d8e8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <hintids.hxx>
29 #include <tools/poly.hxx>
30 #include <svl/stritem.hxx>
31 #include <svx/contdlg.hxx>
32 #include <vcl/svapp.hxx>
33 #include <docary.hxx>
34 #include <doc.hxx>
35 #include <fmtcol.hxx>
36 #include <ndnotxt.hxx>
37 #include <ndgrf.hxx>
38 #include <ndole.hxx>
39 #include <ndindex.hxx>
40 #include <hints.hxx>			// fuer SwFmtChg
41 #include <istyleaccess.hxx>
42 #include <SwStyleNameMapper.hxx>
43 
44 // --> OD 2009-07-13 #i73249#
45 #include <frmfmt.hxx>
46 // <--
47 
SwNoTxtNode(const SwNodeIndex & rWhere,const sal_uInt8 nNdType,SwGrfFmtColl * pGrfColl,SwAttrSet * pAutoAttr)48 SwNoTxtNode::SwNoTxtNode( const SwNodeIndex & rWhere,
49 				  const sal_uInt8 nNdType,
50 				  SwGrfFmtColl *pGrfColl,
51 				  SwAttrSet* pAutoAttr ) :
52 	SwCntntNode( rWhere, nNdType, pGrfColl ),
53     pContour( 0 ),
54     bAutomaticContour( sal_False ),
55 	bContourMapModeValid( sal_True ),
56 	bPixelContour( sal_False )
57 {
58 	// soll eine Harte-Attributierung gesetzt werden?
59 	if( pAutoAttr )
60 		SetAttr( *pAutoAttr );
61 }
62 
63 
~SwNoTxtNode()64 SwNoTxtNode::~SwNoTxtNode()
65 {
66 	delete pContour;
67 }
68 
69 
70 // erzeugt fuer alle Ableitungen einen AttrSet mit Bereichen
71 // fuer Frame- und Grafik-Attributen
NewAttrSet(SwAttrPool & rPool)72 void SwNoTxtNode::NewAttrSet( SwAttrPool& rPool )
73 {
74     ASSERT( !mpAttrSet.get(), "AttrSet ist doch gesetzt" );
75     SwAttrSet aNewAttrSet( rPool, aNoTxtNodeSetRange );
76 
77     // put names of parent style and conditional style:
78     const SwFmtColl* pFmtColl = GetFmtColl();
79     String sVal;
80     SwStyleNameMapper::FillProgName( pFmtColl->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
81     SfxStringItem aFmtColl( RES_FRMATR_STYLE_NAME, sVal );
82     aNewAttrSet.Put( aFmtColl );
83 
84     aNewAttrSet.SetParent( &GetFmtColl()->GetAttrSet() );
85     mpAttrSet = GetDoc()->GetIStyleAccess().getAutomaticStyle( aNewAttrSet, IStyleAccess::AUTO_STYLE_NOTXT );
86 }
87 
88 // Dummies fuer das Laden/Speichern von persistenten Daten
89 // bei Grafiken und OLE-Objekten
90 
91 
RestorePersistentData()92 sal_Bool SwNoTxtNode::RestorePersistentData()
93 {
94 	return sal_True;
95 }
96 
97 
SavePersistentData()98 sal_Bool SwNoTxtNode::SavePersistentData()
99 {
100 	return sal_True;
101 }
102 
103 
SetContour(const PolyPolygon * pPoly,sal_Bool bAutomatic)104 void SwNoTxtNode::SetContour( const PolyPolygon *pPoly, sal_Bool bAutomatic )
105 {
106 	delete pContour;
107 	if ( pPoly )
108 		pContour = new PolyPolygon( *pPoly );
109 	else
110 		pContour = 0;
111     bAutomaticContour = bAutomatic;
112 	bContourMapModeValid = sal_True;
113 	bPixelContour = sal_False;
114 }
115 
116 
CreateContour()117 void SwNoTxtNode::CreateContour()
118 {
119 	ASSERT( !pContour, "Contour available." );
120     pContour = new PolyPolygon(SvxContourDlg::CreateAutoContour(GetGraphic()));
121     bAutomaticContour = sal_True;
122 	bContourMapModeValid = sal_True;
123 	bPixelContour = sal_False;
124 }
125 
HasContour() const126 const PolyPolygon *SwNoTxtNode::HasContour() const
127 {
128 	if( !bContourMapModeValid )
129 	{
130 		const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
131 		sal_Bool bPixelGrf = aGrfMap.GetMapUnit() == MAP_PIXEL;
132 		const MapMode aContourMap( bPixelGrf ? MAP_PIXEL : MAP_100TH_MM );
133 		if( bPixelGrf ? !bPixelContour : aGrfMap != aContourMap )
134 		{
135             // --> OD #i102238#
136             double nGrfDPIx = 0.0;
137             double nGrfDPIy = 0.0;
138             {
139                 if ( !bPixelGrf && bPixelContour )
140                 {
141                     const Size aGrfPixelSize( GetGraphic().GetSizePixel() );
142                     const Size aGrfPrefMapModeSize( GetGraphic().GetPrefSize() );
143                     if ( aGrfMap.GetMapUnit() == MAP_INCH )
144                     {
145                         nGrfDPIx = aGrfPixelSize.Width() / ( (double)aGrfMap.GetScaleX() * aGrfPrefMapModeSize.Width() );
146                         nGrfDPIy = aGrfPixelSize.Height() / ( (double)aGrfMap.GetScaleY() * aGrfPrefMapModeSize.Height() );
147                     }
148                     else
149                     {
150                         const Size aGrf1000thInchSize =
151                             OutputDevice::LogicToLogic( aGrfPrefMapModeSize,
152                                                         aGrfMap, MAP_1000TH_INCH );
153                         nGrfDPIx = 1000.0 * aGrfPixelSize.Width() / aGrf1000thInchSize.Width();
154                         nGrfDPIy = 1000.0 * aGrfPixelSize.Height() / aGrf1000thInchSize.Height();
155                     }
156                 }
157             }
158             // <--
159 			ASSERT( !bPixelGrf || aGrfMap == aContourMap,
160 					"scale factor for pixel unsupported" );
161 			OutputDevice* pOutDev =
162 				(bPixelGrf || bPixelContour) ? Application::GetDefaultDevice()
163 											 : 0;
164 			sal_uInt16 nPolyCount = pContour->Count();
165 			for( sal_uInt16 j=0; j<nPolyCount; j++ )
166 			{
167 				Polygon& rPoly = (*pContour)[j];
168 
169 				sal_uInt16 nCount = rPoly.GetSize();
170 				for( sal_uInt16 i=0 ; i<nCount; i++ )
171 				{
172 					if( bPixelGrf )
173 						rPoly[i] = pOutDev->LogicToPixel( rPoly[i],
174 														  aContourMap );
175 					else if( bPixelContour )
176                     {
177 						rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap );
178                         // --> OD #i102238#
179                         if ( nGrfDPIx != 0 && nGrfDPIy != 0 )
180                         {
181                             rPoly[i] = Point( rPoly[i].X() * pOutDev->ImplGetDPIX() / nGrfDPIx,
182                                               rPoly[i].Y() * pOutDev->ImplGetDPIY() / nGrfDPIy );
183                         }
184                         // <--
185                     }
186 					else
187 						rPoly[i] = OutputDevice::LogicToLogic( rPoly[i],
188 														  	   aContourMap,
189 														  	   aGrfMap );
190 				}
191 			}
192 		}
193 		((SwNoTxtNode *)this)->bContourMapModeValid = sal_True;
194 		((SwNoTxtNode *)this)->bPixelContour = sal_False;
195 	}
196 
197 	return pContour;
198 }
199 
GetContour(PolyPolygon & rPoly) const200 void SwNoTxtNode::GetContour( PolyPolygon &rPoly ) const
201 {
202 	ASSERT( pContour, "Contour not available." );
203 	rPoly = *HasContour();
204 }
205 
SetContourAPI(const PolyPolygon * pPoly)206 void SwNoTxtNode::SetContourAPI( const PolyPolygon *pPoly )
207 {
208 	delete pContour;
209 	if ( pPoly )
210 		pContour = new PolyPolygon( *pPoly );
211 	else
212 		pContour = 0;
213 	bContourMapModeValid = sal_False;
214 }
215 
GetContourAPI(PolyPolygon & rContour) const216 sal_Bool SwNoTxtNode::GetContourAPI( PolyPolygon &rContour ) const
217 {
218 	if( !pContour )
219 		return sal_False;
220 
221 	rContour = *pContour;
222 	if( bContourMapModeValid )
223 	{
224 		const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
225 		const MapMode aContourMap( MAP_100TH_MM );
226 		ASSERT( aGrfMap.GetMapUnit() != MAP_PIXEL ||
227 				aGrfMap == MapMode( MAP_PIXEL ),
228 					"scale factor for pixel unsupported" );
229 		if( aGrfMap.GetMapUnit() != MAP_PIXEL &&
230 			aGrfMap != aContourMap )
231 		{
232 			sal_uInt16 nPolyCount = rContour.Count();
233 			for( sal_uInt16 j=0; j<nPolyCount; j++ )
234 			{
235                 // --> OD #i102238# - use the right <PolyPolygon> instance
236                 Polygon& rPoly = rContour[j];
237                 // <--
238 
239 				sal_uInt16 nCount = rPoly.GetSize();
240 				for( sal_uInt16 i=0 ; i<nCount; i++ )
241 				{
242 					rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap,
243 														   aContourMap );
244 				}
245 			}
246 		}
247 	}
248 
249 	return sal_True;
250 }
251 
IsPixelContour() const252 sal_Bool SwNoTxtNode::IsPixelContour() const
253 {
254 	sal_Bool bRet;
255 	if( bContourMapModeValid )
256 	{
257 		const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
258 		bRet = aGrfMap.GetMapUnit() == MAP_PIXEL;
259 	}
260 	else
261 	{
262 		bRet = bPixelContour;
263 	}
264 
265 	return bRet;
266 }
267 
268 
GetGraphic() const269 Graphic SwNoTxtNode::GetGraphic() const
270 {
271 	Graphic aRet;
272 	if ( GetGrfNode() )
273 	{
274 		((SwGrfNode*)this)->SwapIn( sal_True );
275 		aRet = ((SwGrfNode*)this)->GetGrf();
276 	}
277 	else
278 	{
279 		ASSERT( GetOLENode(), "new type of Node?" );
280         aRet = *((SwOLENode*)this)->SwOLENode::GetGraphic();
281 	}
282 	return aRet;
283 }
284 
SetTitle(const String & rTitle,bool bBroadcast)285 void SwNoTxtNode::SetTitle( const String& rTitle, bool bBroadcast )
286 {
287     // Title attribute of <SdrObject> replaces own AlternateText attribute
288     SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
289     ASSERT( pFlyFmt,
290             "<SwNoTxtNode::SetTitle(..)> - missing <SwFlyFrmFmt> instance" );
291     if ( !pFlyFmt )
292     {
293         return;
294     }
295 
296     pFlyFmt->SetObjTitle( rTitle, bBroadcast );
297 }
298 
GetTitle() const299 const String SwNoTxtNode::GetTitle() const
300 {
301     const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
302     ASSERT( pFlyFmt,
303             "<SwNoTxtNode::GetTitle(..)> - missing <SwFlyFrmFmt> instance" );
304     if ( !pFlyFmt )
305     {
306         return aEmptyStr;
307     }
308 
309     return pFlyFmt->GetObjTitle();
310 }
311 
SetDescription(const String & rDescription,bool bBroadcast)312 void SwNoTxtNode::SetDescription( const String& rDescription, bool bBroadcast )
313 {
314     SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
315     ASSERT( pFlyFmt,
316             "<SwNoTxtNode::SetDescription(..)> - missing <SwFlyFrmFmt> instance" );
317     if ( !pFlyFmt )
318     {
319         return;
320     }
321 
322     pFlyFmt->SetObjDescription( rDescription, bBroadcast );
323 }
324 
GetDescription() const325 const String SwNoTxtNode::GetDescription() const
326 {
327     const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
328     ASSERT( pFlyFmt,
329             "<SwNoTxtNode::GetDescription(..)> - missing <SwFlyFrmFmt> instance" );
330     if ( !pFlyFmt )
331     {
332         return aEmptyStr;
333     }
334 
335     return pFlyFmt->GetObjDescription();
336 }
337 // <--
338