1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <osl/diagnose.h>
22 #include <tools/poly.hxx>
23 #include <svl/stritem.hxx>
24 #include <svx/contdlg.hxx>
25 #include <vcl/svapp.hxx>
28 #include <ndnotxt.hxx>
31 #include <ndindex.hxx>
32 #include <istyleaccess.hxx>
33 #include <SwStyleNameMapper.hxx>
37 SwNoTextNode::SwNoTextNode( SwNode
& rWhere
,
38 const SwNodeType nNdType
,
39 SwGrfFormatColl
*pGrfColl
,
40 SwAttrSet
const * pAutoAttr
) :
41 SwContentNode( rWhere
, nNdType
, pGrfColl
),
42 m_bAutomaticContour( false ),
43 m_bContourMapModeValid( true ),
44 m_bPixelContour( false )
46 // Should this set a hard attribute?
48 SetAttr( *pAutoAttr
);
51 SwNoTextNode::~SwNoTextNode()
55 /// Creates an AttrSet for all derivations with ranges for frame-
56 /// and graphics-attributes.
57 void SwNoTextNode::NewAttrSet( SwAttrPool
& rPool
)
59 OSL_ENSURE( !mpAttrSet
, "AttrSet is already set" );
60 SwAttrSet
aNewAttrSet( rPool
, aNoTextNodeSetRange
);
62 // put names of parent style and conditional style:
63 const SwFormatColl
* pFormatColl
= GetFormatColl();
65 SwStyleNameMapper::FillProgName( pFormatColl
->GetName(), sVal
, SwGetPoolIdFromName::TxtColl
);
66 SfxStringItem
aFormatColl( RES_FRMATR_STYLE_NAME
, sVal
);
67 aNewAttrSet
.Put( aFormatColl
);
69 aNewAttrSet
.SetParent( &GetFormatColl()->GetAttrSet() );
70 mpAttrSet
= GetDoc().GetIStyleAccess().getAutomaticStyle( aNewAttrSet
, IStyleAccess::AUTO_STYLE_NOTXT
);
73 /// Dummies for loading/saving of persistent data
74 /// when working with graphics and OLE objects
75 bool SwNoTextNode::RestorePersistentData()
80 bool SwNoTextNode::SavePersistentData()
85 void SwNoTextNode::SetContour( const tools::PolyPolygon
*pPoly
, bool bAutomatic
)
91 m_bAutomaticContour
= bAutomatic
;
92 m_bContourMapModeValid
= true;
93 m_bPixelContour
= false;
96 void SwNoTextNode::CreateContour()
98 OSL_ENSURE( !m_pContour
, "Contour available." );
99 m_pContour
= SvxContourDlg::CreateAutoContour(GetGraphic());
100 m_bAutomaticContour
= true;
101 m_bContourMapModeValid
= true;
102 m_bPixelContour
= false;
105 const tools::PolyPolygon
*SwNoTextNode::HasContour() const
107 if( !m_bContourMapModeValid
)
109 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
110 bool bPixelGrf
= aGrfMap
.GetMapUnit() == MapUnit::MapPixel
;
111 const MapMode
aContourMap( bPixelGrf
? MapUnit::MapPixel
: MapUnit::Map100thMM
);
112 if( bPixelGrf
? !m_bPixelContour
: aGrfMap
!= aContourMap
)
114 double nGrfDPIx
= 0.0;
115 double nGrfDPIy
= 0.0;
117 if ( !bPixelGrf
&& m_bPixelContour
)
119 basegfx::B2DSize aDPI
= GetGraphic().GetPPI();
120 nGrfDPIx
= aDPI
.getWidth();
121 nGrfDPIy
= aDPI
.getHeight();
124 OSL_ENSURE( !bPixelGrf
|| aGrfMap
== aContourMap
,
125 "scale factor for pixel unsupported" );
126 OutputDevice
* pOutDev
=
127 (bPixelGrf
|| m_bPixelContour
) ? Application::GetDefaultDevice()
129 sal_uInt16 nPolyCount
= m_pContour
->Count();
130 for( sal_uInt16 j
=0; j
<nPolyCount
; j
++ )
132 tools::Polygon
& rPoly
= (*m_pContour
)[j
];
134 sal_uInt16 nCount
= rPoly
.GetSize();
135 for( sal_uInt16 i
=0 ; i
<nCount
; i
++ )
138 rPoly
[i
] = pOutDev
->LogicToPixel( rPoly
[i
],
140 else if( m_bPixelContour
)
142 rPoly
[i
] = pOutDev
->PixelToLogic( rPoly
[i
], aGrfMap
);
144 if ( nGrfDPIx
!= 0 && nGrfDPIy
!= 0 )
146 rPoly
[i
] = Point( rPoly
[i
].getX() * pOutDev
->GetDPIX() / nGrfDPIx
,
147 rPoly
[i
].getY() * pOutDev
->GetDPIY() / nGrfDPIy
);
151 rPoly
[i
] = OutputDevice::LogicToLogic( rPoly
[i
],
157 m_bContourMapModeValid
= true;
158 m_bPixelContour
= false;
161 return m_pContour
? &*m_pContour
: nullptr;
164 void SwNoTextNode::GetContour( tools::PolyPolygon
&rPoly
) const
166 OSL_ENSURE( m_pContour
, "Contour not available." );
167 rPoly
= *HasContour();
170 void SwNoTextNode::SetContourAPI( const tools::PolyPolygon
*pPoly
)
176 m_bContourMapModeValid
= false;
179 bool SwNoTextNode::GetContourAPI( tools::PolyPolygon
&rContour
) const
184 rContour
= *m_pContour
;
185 if( m_bContourMapModeValid
)
187 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
188 const MapMode
aContourMap( MapUnit::Map100thMM
);
189 OSL_ENSURE( aGrfMap
.GetMapUnit() != MapUnit::MapPixel
||
190 aGrfMap
== MapMode( MapUnit::MapPixel
),
191 "scale factor for pixel unsupported" );
192 if( aGrfMap
.GetMapUnit() != MapUnit::MapPixel
&&
193 aGrfMap
!= aContourMap
)
195 sal_uInt16 nPolyCount
= rContour
.Count();
196 for( sal_uInt16 j
=0; j
<nPolyCount
; j
++ )
198 tools::Polygon
& rPoly
= rContour
[j
];
200 sal_uInt16 nCount
= rPoly
.GetSize();
201 for( sal_uInt16 i
=0 ; i
<nCount
; i
++ )
203 rPoly
[i
] = OutputDevice::LogicToLogic( rPoly
[i
], aGrfMap
,
213 bool SwNoTextNode::IsPixelContour() const
216 if( m_bContourMapModeValid
)
218 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
219 bRet
= aGrfMap
.GetMapUnit() == MapUnit::MapPixel
;
223 bRet
= m_bPixelContour
;
229 Graphic
SwNoTextNode::GetGraphic() const
234 aRet
= static_cast<const SwGrfNode
*>(this)->GetGrf(true);
238 OSL_ENSURE( GetOLENode(), "new type of Node?" );
239 aRet
= *const_cast<SwOLENode
*>(static_cast<const SwOLENode
*>(this))->SwOLENode::GetGraphic();
245 void SwNoTextNode::SetTitle( const OUString
& rTitle
)
247 // Title attribute of <SdrObject> replaces own AlternateText attribute
248 SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<SwFlyFrameFormat
*>(GetFlyFormat());
249 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::SetTitle(..)> - missing <SwFlyFrameFormat> instance" );
255 pFlyFormat
->SetObjTitle( rTitle
);
258 OUString
SwNoTextNode::GetTitle() const
260 const SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<const SwFlyFrameFormat
*>(GetFlyFormat());
261 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::GetTitle(..)> - missing <SwFlyFrameFormat> instance" );
267 return pFlyFormat
->GetObjTitle();
270 void SwNoTextNode::SetDescription( const OUString
& rDescription
)
272 SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<SwFlyFrameFormat
*>(GetFlyFormat());
273 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::SetDescription(..)> - missing <SwFlyFrameFormat> instance" );
279 pFlyFormat
->SetObjDescription( rDescription
);
282 OUString
SwNoTextNode::GetDescription() const
284 const SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<const SwFlyFrameFormat
*>(GetFlyFormat());
285 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::GetDescription(..)> - missing <SwFlyFrameFormat> instance" );
291 return pFlyFormat
->GetObjDescription();
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */