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>
38 SwNoTextNode::SwNoTextNode( SwNode
& rWhere
,
39 const SwNodeType nNdType
,
40 SwGrfFormatColl
*pGrfColl
,
41 SwAttrSet
const * pAutoAttr
) :
42 SwContentNode( rWhere
, nNdType
, pGrfColl
),
43 m_bAutomaticContour( false ),
44 m_bContourMapModeValid( true ),
45 m_bPixelContour( false )
47 // Should this set a hard attribute?
49 SetAttr( *pAutoAttr
);
52 SwNoTextNode::~SwNoTextNode()
56 /// Creates an AttrSet for all derivations with ranges for frame-
57 /// and graphics-attributes.
58 void SwNoTextNode::NewAttrSet( SwAttrPool
& rPool
)
60 OSL_ENSURE( !mpAttrSet
, "AttrSet is already set" );
61 SwAttrSet
aNewAttrSet( rPool
, aNoTextNodeSetRange
);
63 // put names of parent style and conditional style:
64 const SwFormatColl
* pFormatColl
= GetFormatColl();
66 SwStyleNameMapper::FillProgName( pFormatColl
->GetName(), sVal
, SwGetPoolIdFromName::TxtColl
);
67 SfxStringItem
aFormatColl( RES_FRMATR_STYLE_NAME
, sVal
.toString() );
68 aNewAttrSet
.Put( aFormatColl
);
70 aNewAttrSet
.SetParent( &GetFormatColl()->GetAttrSet() );
71 mpAttrSet
= GetDoc().GetIStyleAccess().getAutomaticStyle( aNewAttrSet
, IStyleAccess::AUTO_STYLE_NOTXT
);
74 /// Dummies for loading/saving of persistent data
75 /// when working with graphics and OLE objects
76 bool SwNoTextNode::RestorePersistentData()
81 bool SwNoTextNode::SavePersistentData()
86 void SwNoTextNode::SetContour( const tools::PolyPolygon
*pPoly
, bool bAutomatic
)
92 m_bAutomaticContour
= bAutomatic
;
93 m_bContourMapModeValid
= true;
94 m_bPixelContour
= false;
97 void SwNoTextNode::CreateContour()
99 OSL_ENSURE( !m_pContour
, "Contour available." );
100 m_pContour
= SvxContourDlg::CreateAutoContour(GetGraphic());
101 m_bAutomaticContour
= true;
102 m_bContourMapModeValid
= true;
103 m_bPixelContour
= false;
106 const tools::PolyPolygon
*SwNoTextNode::HasContour() const
108 if( !m_bContourMapModeValid
)
110 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
111 bool bPixelGrf
= aGrfMap
.GetMapUnit() == MapUnit::MapPixel
;
112 const MapMode
aContourMap( bPixelGrf
? MapUnit::MapPixel
: MapUnit::Map100thMM
);
113 if( bPixelGrf
? !m_bPixelContour
: aGrfMap
!= aContourMap
)
115 double nGrfDPIx
= 0.0;
116 double nGrfDPIy
= 0.0;
118 if ( !bPixelGrf
&& m_bPixelContour
)
120 basegfx::B2DSize aDPI
= GetGraphic().GetPPI();
121 nGrfDPIx
= aDPI
.getWidth();
122 nGrfDPIy
= aDPI
.getHeight();
125 OSL_ENSURE( !bPixelGrf
|| aGrfMap
== aContourMap
,
126 "scale factor for pixel unsupported" );
127 OutputDevice
* pOutDev
=
128 (bPixelGrf
|| m_bPixelContour
) ? Application::GetDefaultDevice()
131 for ( auto& rPoly
: *m_pContour
)
133 sal_uInt16 nCount
= rPoly
.GetSize();
134 for( sal_uInt16 i
=0 ; i
<nCount
; i
++ )
137 rPoly
[i
] = pOutDev
->LogicToPixel( rPoly
[i
],
139 else if( m_bPixelContour
)
141 rPoly
[i
] = pOutDev
->PixelToLogic( rPoly
[i
], aGrfMap
);
143 if ( nGrfDPIx
!= 0 && nGrfDPIy
!= 0 )
145 rPoly
[i
] = Point( rPoly
[i
].getX() * pOutDev
->GetDPIX() / nGrfDPIx
,
146 rPoly
[i
].getY() * pOutDev
->GetDPIY() / nGrfDPIy
);
150 rPoly
[i
] = OutputDevice::LogicToLogic( rPoly
[i
],
156 m_bContourMapModeValid
= true;
157 m_bPixelContour
= false;
160 return m_pContour
? &*m_pContour
: nullptr;
163 void SwNoTextNode::GetContour( tools::PolyPolygon
&rPoly
) const
165 OSL_ENSURE( m_pContour
, "Contour not available." );
166 rPoly
= *HasContour();
169 void SwNoTextNode::SetContourAPI( const tools::PolyPolygon
*pPoly
)
175 m_bContourMapModeValid
= false;
178 bool SwNoTextNode::GetContourAPI( tools::PolyPolygon
&rContour
) const
183 rContour
= *m_pContour
;
184 if( m_bContourMapModeValid
)
186 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
187 const MapMode
aContourMap( MapUnit::Map100thMM
);
188 OSL_ENSURE( aGrfMap
.GetMapUnit() != MapUnit::MapPixel
||
189 aGrfMap
== MapMode( MapUnit::MapPixel
),
190 "scale factor for pixel unsupported" );
191 if( aGrfMap
.GetMapUnit() != MapUnit::MapPixel
&&
192 aGrfMap
!= aContourMap
)
194 for( auto& rPoly
: rContour
)
196 sal_uInt16 nCount
= rPoly
.GetSize();
197 for( sal_uInt16 i
=0 ; i
<nCount
; i
++ )
199 rPoly
[i
] = OutputDevice::LogicToLogic( rPoly
[i
], aGrfMap
,
209 bool SwNoTextNode::IsPixelContour() const
212 if( m_bContourMapModeValid
)
214 const MapMode
aGrfMap( GetGraphic().GetPrefMapMode() );
215 bRet
= aGrfMap
.GetMapUnit() == MapUnit::MapPixel
;
219 bRet
= m_bPixelContour
;
225 Graphic
SwNoTextNode::GetGraphic() const
230 aRet
= static_cast<const SwGrfNode
*>(this)->GetGrf(true);
234 OSL_ENSURE( GetOLENode(), "new type of Node?" );
235 if (const Graphic
* pGraphic
= const_cast<SwOLENode
*>(static_cast<const SwOLENode
*>(this))->SwOLENode::GetGraphic())
242 void SwNoTextNode::SetTitle( const OUString
& rTitle
)
244 // Title attribute of <SdrObject> replaces own AlternateText attribute
245 SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<SwFlyFrameFormat
*>(GetFlyFormat());
246 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::SetTitle(..)> - missing <SwFlyFrameFormat> instance" );
252 pFlyFormat
->SetObjTitle( rTitle
);
255 OUString
SwNoTextNode::GetTitle() const
257 const SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<const SwFlyFrameFormat
*>(GetFlyFormat());
258 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::GetTitle(..)> - missing <SwFlyFrameFormat> instance" );
264 return pFlyFormat
->GetObjTitle();
267 void SwNoTextNode::SetDescription( const OUString
& rDescription
)
269 SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<SwFlyFrameFormat
*>(GetFlyFormat());
270 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::SetDescription(..)> - missing <SwFlyFrameFormat> instance" );
276 pFlyFormat
->SetObjDescription( rDescription
);
279 OUString
SwNoTextNode::GetDescription() const
281 const SwFlyFrameFormat
* pFlyFormat
= dynamic_cast<const SwFlyFrameFormat
*>(GetFlyFormat());
282 OSL_ENSURE( pFlyFormat
, "<SwNoTextNode::GetDescription(..)> - missing <SwFlyFrameFormat> instance" );
288 return pFlyFormat
->GetObjDescription();
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */