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