merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / docnode / ndnotxt.cxx
blob4b94c1bf12fd3eb1034a21bd5f375dc418e4d970
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ndnotxt.cxx,v $
10 * $Revision: 1.13.214.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <tools/poly.hxx>
37 #include <svtools/stritem.hxx>
38 #include <svx/contdlg.hxx>
39 #include <vcl/svapp.hxx>
40 #include <docary.hxx>
41 #include <doc.hxx>
42 #include <fmtcol.hxx>
43 #include <ndnotxt.hxx>
44 #include <ndgrf.hxx>
45 #include <ndole.hxx>
46 #include <ndindex.hxx>
47 #include <hints.hxx> // fuer SwFmtChg
48 #include <istyleaccess.hxx>
49 #include <SwStyleNameMapper.hxx>
51 // --> OD 2009-07-13 #i73249#
52 #include <frmfmt.hxx>
53 // <--
55 SwNoTxtNode::SwNoTxtNode( const SwNodeIndex & rWhere,
56 const BYTE nNdType,
57 SwGrfFmtColl *pGrfColl,
58 SwAttrSet* pAutoAttr ) :
59 SwCntntNode( rWhere, nNdType, pGrfColl ),
60 pContour( 0 ),
61 bAutomaticContour( FALSE ),
62 bContourMapModeValid( TRUE ),
63 bPixelContour( FALSE )
65 // soll eine Harte-Attributierung gesetzt werden?
66 if( pAutoAttr )
67 SetAttr( *pAutoAttr );
71 SwNoTxtNode::~SwNoTxtNode()
73 delete pContour;
77 // erzeugt fuer alle Ableitungen einen AttrSet mit Bereichen
78 // fuer Frame- und Grafik-Attributen
79 void SwNoTxtNode::NewAttrSet( SwAttrPool& rPool )
81 ASSERT( !mpAttrSet.get(), "AttrSet ist doch gesetzt" );
82 SwAttrSet aNewAttrSet( rPool, aNoTxtNodeSetRange );
84 // put names of parent style and conditional style:
85 const SwFmtColl* pFmtColl = GetFmtColl();
86 String sVal;
87 SwStyleNameMapper::FillProgName( pFmtColl->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
88 SfxStringItem aFmtColl( RES_FRMATR_STYLE_NAME, sVal );
89 aNewAttrSet.Put( aFmtColl );
91 aNewAttrSet.SetParent( &GetFmtColl()->GetAttrSet() );
92 mpAttrSet = GetDoc()->GetIStyleAccess().getAutomaticStyle( aNewAttrSet, IStyleAccess::AUTO_STYLE_NOTXT );
95 // Dummies fuer das Laden/Speichern von persistenten Daten
96 // bei Grafiken und OLE-Objekten
99 BOOL SwNoTxtNode::RestorePersistentData()
101 return TRUE;
105 BOOL SwNoTxtNode::SavePersistentData()
107 return TRUE;
111 void SwNoTxtNode::SetContour( const PolyPolygon *pPoly, BOOL bAutomatic )
113 delete pContour;
114 if ( pPoly )
115 pContour = new PolyPolygon( *pPoly );
116 else
117 pContour = 0;
118 bAutomaticContour = bAutomatic;
119 bContourMapModeValid = TRUE;
120 bPixelContour = FALSE;
124 void SwNoTxtNode::CreateContour()
126 ASSERT( !pContour, "Contour available." );
127 pContour = new PolyPolygon(SvxContourDlg::CreateAutoContour(GetGraphic()));
128 bAutomaticContour = TRUE;
129 bContourMapModeValid = TRUE;
130 bPixelContour = FALSE;
133 const PolyPolygon *SwNoTxtNode::HasContour() const
135 if( !bContourMapModeValid )
137 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
138 BOOL bPixelGrf = aGrfMap.GetMapUnit() == MAP_PIXEL;
139 const MapMode aContourMap( bPixelGrf ? MAP_PIXEL : MAP_100TH_MM );
140 if( bPixelGrf ? !bPixelContour : aGrfMap != aContourMap )
142 ASSERT( !bPixelGrf || aGrfMap == aContourMap,
143 "scale factor for pixel unsupported" );
144 OutputDevice* pOutDev =
145 (bPixelGrf || bPixelContour) ? Application::GetDefaultDevice()
146 : 0;
147 USHORT nPolyCount = pContour->Count();
148 for( USHORT j=0; j<nPolyCount; j++ )
150 Polygon& rPoly = (*pContour)[j];
152 USHORT nCount = rPoly.GetSize();
153 for( USHORT i=0 ; i<nCount; i++ )
155 if( bPixelGrf )
156 rPoly[i] = pOutDev->LogicToPixel( rPoly[i],
157 aContourMap );
158 else if( bPixelContour )
159 rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap );
160 else
161 rPoly[i] = OutputDevice::LogicToLogic( rPoly[i],
162 aContourMap,
163 aGrfMap );
167 ((SwNoTxtNode *)this)->bContourMapModeValid = TRUE;
168 ((SwNoTxtNode *)this)->bPixelContour = FALSE;
171 return pContour;
174 void SwNoTxtNode::GetContour( PolyPolygon &rPoly ) const
176 ASSERT( pContour, "Contour not available." );
177 rPoly = *HasContour();
180 void SwNoTxtNode::SetContourAPI( const PolyPolygon *pPoly )
182 delete pContour;
183 if ( pPoly )
184 pContour = new PolyPolygon( *pPoly );
185 else
186 pContour = 0;
187 bContourMapModeValid = FALSE;
190 BOOL SwNoTxtNode::GetContourAPI( PolyPolygon &rContour ) const
192 if( !pContour )
193 return FALSE;
195 rContour = *pContour;
196 if( bContourMapModeValid )
198 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
199 const MapMode aContourMap( MAP_100TH_MM );
200 ASSERT( aGrfMap.GetMapUnit() != MAP_PIXEL ||
201 aGrfMap == MapMode( MAP_PIXEL ),
202 "scale factor for pixel unsupported" );
203 if( aGrfMap.GetMapUnit() != MAP_PIXEL &&
204 aGrfMap != aContourMap )
206 USHORT nPolyCount = rContour.Count();
207 for( USHORT j=0; j<nPolyCount; j++ )
209 Polygon& rPoly = (*pContour)[j];
211 USHORT nCount = rPoly.GetSize();
212 for( USHORT i=0 ; i<nCount; i++ )
214 rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap,
215 aContourMap );
221 return TRUE;
224 BOOL SwNoTxtNode::IsPixelContour() const
226 BOOL bRet;
227 if( bContourMapModeValid )
229 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
230 bRet = aGrfMap.GetMapUnit() == MAP_PIXEL;
232 else
234 bRet = bPixelContour;
237 return bRet;
241 Graphic SwNoTxtNode::GetGraphic() const
243 Graphic aRet;
244 if ( GetGrfNode() )
246 ((SwGrfNode*)this)->SwapIn( TRUE );
247 aRet = ((SwGrfNode*)this)->GetGrf();
249 else
251 ASSERT( GetOLENode(), "new type of Node?" );
252 aRet = *((SwOLENode*)this)->SwOLENode::GetGraphic();
254 return aRet;
257 // --> OD 2009-07-14 #i73249#
258 void SwNoTxtNode::SetTitle( const String& rTitle, bool bBroadcast )
260 // Title attribute of <SdrObject> replaces own AlternateText attribute
261 SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
262 ASSERT( pFlyFmt,
263 "<SwNoTxtNode::SetTitle(..)> - missing <SwFlyFrmFmt> instance" );
264 if ( !pFlyFmt )
266 return;
269 pFlyFmt->SetObjTitle( rTitle, bBroadcast );
272 const String SwNoTxtNode::GetTitle() const
274 const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
275 ASSERT( pFlyFmt,
276 "<SwNoTxtNode::GetTitle(..)> - missing <SwFlyFrmFmt> instance" );
277 if ( !pFlyFmt )
279 return aEmptyStr;
282 return pFlyFmt->GetObjTitle();
285 void SwNoTxtNode::SetDescription( const String& rDescription, bool bBroadcast )
287 SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
288 ASSERT( pFlyFmt,
289 "<SwNoTxtNode::SetDescription(..)> - missing <SwFlyFrmFmt> instance" );
290 if ( !pFlyFmt )
292 return;
295 pFlyFmt->SetObjDescription( rDescription, bBroadcast );
298 const String SwNoTxtNode::GetDescription() const
300 const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
301 ASSERT( pFlyFmt,
302 "<SwNoTxtNode::GetDescription(..)> - missing <SwFlyFrmFmt> instance" );
303 if ( !pFlyFmt )
305 return aEmptyStr;
308 return pFlyFmt->GetObjDescription();
310 // <--