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>
43 #include <ndnotxt.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#
55 SwNoTxtNode::SwNoTxtNode( const SwNodeIndex
& rWhere
,
57 SwGrfFmtColl
*pGrfColl
,
58 SwAttrSet
* pAutoAttr
) :
59 SwCntntNode( rWhere
, nNdType
, pGrfColl
),
61 bAutomaticContour( FALSE
),
62 bContourMapModeValid( TRUE
),
63 bPixelContour( FALSE
)
65 // soll eine Harte-Attributierung gesetzt werden?
67 SetAttr( *pAutoAttr
);
71 SwNoTxtNode::~SwNoTxtNode()
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();
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()
105 BOOL
SwNoTxtNode::SavePersistentData()
111 void SwNoTxtNode::SetContour( const PolyPolygon
*pPoly
, BOOL bAutomatic
)
115 pContour
= new PolyPolygon( *pPoly
);
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()
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
++ )
156 rPoly
[i
] = pOutDev
->LogicToPixel( rPoly
[i
],
158 else if( bPixelContour
)
159 rPoly
[i
] = pOutDev
->PixelToLogic( rPoly
[i
], aGrfMap
);
161 rPoly
[i
] = OutputDevice::LogicToLogic( rPoly
[i
],
167 ((SwNoTxtNode
*)this)->bContourMapModeValid
= TRUE
;
168 ((SwNoTxtNode
*)this)->bPixelContour
= FALSE
;
174 void SwNoTxtNode::GetContour( PolyPolygon
&rPoly
) const
176 ASSERT( pContour
, "Contour not available." );
177 rPoly
= *HasContour();
180 void SwNoTxtNode::SetContourAPI( const PolyPolygon
*pPoly
)
184 pContour
= new PolyPolygon( *pPoly
);
187 bContourMapModeValid
= FALSE
;
190 BOOL
SwNoTxtNode::GetContourAPI( PolyPolygon
&rContour
) const
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
,
224 BOOL
SwNoTxtNode::IsPixelContour() const
227 if( bContourMapModeValid
)
229 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
230 bRet
= aGrfMap
.GetMapUnit() == MAP_PIXEL
;
234 bRet
= bPixelContour
;
241 Graphic
SwNoTxtNode::GetGraphic() const
246 ((SwGrfNode
*)this)->SwapIn( TRUE
);
247 aRet
= ((SwGrfNode
*)this)->GetGrf();
251 ASSERT( GetOLENode(), "new type of Node?" );
252 aRet
= *((SwOLENode
*)this)->SwOLENode::GetGraphic();
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());
263 "<SwNoTxtNode::SetTitle(..)> - missing <SwFlyFrmFmt> instance" );
269 pFlyFmt
->SetObjTitle( rTitle
, bBroadcast
);
272 const String
SwNoTxtNode::GetTitle() const
274 const SwFlyFrmFmt
* pFlyFmt
= dynamic_cast<const SwFlyFrmFmt
*>(GetFlyFmt());
276 "<SwNoTxtNode::GetTitle(..)> - missing <SwFlyFrmFmt> instance" );
282 return pFlyFmt
->GetObjTitle();
285 void SwNoTxtNode::SetDescription( const String
& rDescription
, bool bBroadcast
)
287 SwFlyFrmFmt
* pFlyFmt
= dynamic_cast<SwFlyFrmFmt
*>(GetFlyFmt());
289 "<SwNoTxtNode::SetDescription(..)> - missing <SwFlyFrmFmt> instance" );
295 pFlyFmt
->SetObjDescription( rDescription
, bBroadcast
);
298 const String
SwNoTxtNode::GetDescription() const
300 const SwFlyFrmFmt
* pFlyFmt
= dynamic_cast<const SwFlyFrmFmt
*>(GetFlyFmt());
302 "<SwNoTxtNode::GetDescription(..)> - missing <SwFlyFrmFmt> instance" );
308 return pFlyFmt
->GetObjDescription();