LibreOffice Module sw (master)  1
ndnotxt.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <hintids.hxx>
21 #include <tools/poly.hxx>
22 #include <tools/fract.hxx>
23 #include <svl/stritem.hxx>
24 #include <svx/contdlg.hxx>
25 #include <vcl/svapp.hxx>
26 #include <docary.hxx>
27 #include <doc.hxx>
28 #include <fmtcol.hxx>
29 #include <ndnotxt.hxx>
30 #include <ndgrf.hxx>
31 #include <ndole.hxx>
32 #include <ndindex.hxx>
33 #include <hints.hxx>
34 #include <istyleaccess.hxx>
35 #include <SwStyleNameMapper.hxx>
36 
37 #include <frmfmt.hxx>
38 
40  const SwNodeType nNdType,
41  SwGrfFormatColl *pGrfColl,
42  SwAttrSet const * pAutoAttr ) :
43  SwContentNode( rWhere, nNdType, pGrfColl ),
44  m_bAutomaticContour( false ),
45  m_bContourMapModeValid( true ),
46  m_bPixelContour( false )
47 {
48  // Should this set a hard attribute?
49  if( pAutoAttr )
50  SetAttr( *pAutoAttr );
51 }
52 
54 {
55 }
56 
60 {
61  OSL_ENSURE( !mpAttrSet.get(), "AttrSet is already set" );
62  SwAttrSet aNewAttrSet( rPool, aNoTextNodeSetRange );
63 
64  // put names of parent style and conditional style:
65  const SwFormatColl* pFormatColl = GetFormatColl();
66  OUString sVal;
68  SfxStringItem aFormatColl( RES_FRMATR_STYLE_NAME, sVal );
69  aNewAttrSet.Put( aFormatColl );
70 
71  aNewAttrSet.SetParent( &GetFormatColl()->GetAttrSet() );
73 }
74 
78 {
79  return true;
80 }
81 
83 {
84  return true;
85 }
86 
87 void SwNoTextNode::SetContour( const tools::PolyPolygon *pPoly, bool bAutomatic )
88 {
89  if ( pPoly )
90  m_pContour.reset( new tools::PolyPolygon( *pPoly ) );
91  else
92  m_pContour.reset();
93  m_bAutomaticContour = bAutomatic;
95  m_bPixelContour = false;
96 }
97 
99 {
100  OSL_ENSURE( !m_pContour, "Contour available." );
102  m_bAutomaticContour = true;
103  m_bContourMapModeValid = true;
104  m_bPixelContour = false;
105 }
106 
108 {
110  {
111  const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
112  bool bPixelGrf = aGrfMap.GetMapUnit() == MapUnit::MapPixel;
113  const MapMode aContourMap( bPixelGrf ? MapUnit::MapPixel : MapUnit::Map100thMM );
114  if( bPixelGrf ? !m_bPixelContour : aGrfMap != aContourMap )
115  {
116  double nGrfDPIx = 0.0;
117  double nGrfDPIy = 0.0;
118  {
119  if ( !bPixelGrf && m_bPixelContour )
120  {
122  nGrfDPIx = aDPI.getX();
123  nGrfDPIy = aDPI.getY();
124  }
125  }
126  OSL_ENSURE( !bPixelGrf || aGrfMap == aContourMap,
127  "scale factor for pixel unsupported" );
128  OutputDevice* pOutDev =
130  : nullptr;
131  sal_uInt16 nPolyCount = m_pContour->Count();
132  for( sal_uInt16 j=0; j<nPolyCount; j++ )
133  {
134  tools::Polygon& rPoly = (*m_pContour)[j];
135 
136  sal_uInt16 nCount = rPoly.GetSize();
137  for( sal_uInt16 i=0 ; i<nCount; i++ )
138  {
139  if( bPixelGrf )
140  rPoly[i] = pOutDev->LogicToPixel( rPoly[i],
141  aContourMap );
142  else if( m_bPixelContour )
143  {
144  rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap );
145 
146  if ( nGrfDPIx != 0 && nGrfDPIy != 0 )
147  {
148  rPoly[i] = Point( rPoly[i].getX() * pOutDev->GetDPIX() / nGrfDPIx,
149  rPoly[i].getY() * pOutDev->GetDPIY() / nGrfDPIy );
150  }
151  }
152  else
153  rPoly[i] = OutputDevice::LogicToLogic( rPoly[i],
154  aContourMap,
155  aGrfMap );
156  }
157  }
158  }
159  const_cast<SwNoTextNode *>(this)->m_bContourMapModeValid = true;
160  const_cast<SwNoTextNode *>(this)->m_bPixelContour = false;
161  }
162 
163  return m_pContour.get();
164 }
165 
167 {
168  OSL_ENSURE( m_pContour, "Contour not available." );
169  rPoly = *HasContour();
170 }
171 
173 {
174  if ( pPoly )
175  m_pContour.reset( new tools::PolyPolygon( *pPoly ) );
176  else
177  m_pContour.reset();
178  m_bContourMapModeValid = false;
179 }
180 
182 {
183  if( !m_pContour )
184  return false;
185 
186  rContour = *m_pContour;
188  {
189  const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
190  const MapMode aContourMap( MapUnit::Map100thMM );
191  OSL_ENSURE( aGrfMap.GetMapUnit() != MapUnit::MapPixel ||
192  aGrfMap == MapMode( MapUnit::MapPixel ),
193  "scale factor for pixel unsupported" );
194  if( aGrfMap.GetMapUnit() != MapUnit::MapPixel &&
195  aGrfMap != aContourMap )
196  {
197  sal_uInt16 nPolyCount = rContour.Count();
198  for( sal_uInt16 j=0; j<nPolyCount; j++ )
199  {
200  tools::Polygon& rPoly = rContour[j];
201 
202  sal_uInt16 nCount = rPoly.GetSize();
203  for( sal_uInt16 i=0 ; i<nCount; i++ )
204  {
205  rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap,
206  aContourMap );
207  }
208  }
209  }
210  }
211 
212  return true;
213 }
214 
216 {
217  bool bRet;
219  {
220  const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
221  bRet = aGrfMap.GetMapUnit() == MapUnit::MapPixel;
222  }
223  else
224  {
225  bRet = m_bPixelContour;
226  }
227 
228  return bRet;
229 }
230 
232 {
233  Graphic aRet;
234  if ( GetGrfNode() )
235  {
236  aRet = static_cast<const SwGrfNode*>(this)->GetGrf(true);
237  }
238  else
239  {
240  OSL_ENSURE( GetOLENode(), "new type of Node?" );
241  aRet = *const_cast<SwOLENode*>(static_cast<const SwOLENode*>(this))->SwOLENode::GetGraphic();
242  }
243  return aRet;
244 }
245 
246 // #i73249#
247 void SwNoTextNode::SetTitle( const OUString& rTitle )
248 {
249  // Title attribute of <SdrObject> replaces own AlternateText attribute
250  SwFlyFrameFormat* pFlyFormat = dynamic_cast<SwFlyFrameFormat*>(GetFlyFormat());
251  OSL_ENSURE( pFlyFormat, "<SwNoTextNode::SetTitle(..)> - missing <SwFlyFrameFormat> instance" );
252  if ( !pFlyFormat )
253  {
254  return;
255  }
256 
257  pFlyFormat->SetObjTitle( rTitle );
258 }
259 
260 OUString SwNoTextNode::GetTitle() const
261 {
262  const SwFlyFrameFormat* pFlyFormat = dynamic_cast<const SwFlyFrameFormat*>(GetFlyFormat());
263  OSL_ENSURE( pFlyFormat, "<SwNoTextNode::GetTitle(..)> - missing <SwFlyFrameFormat> instance" );
264  if ( !pFlyFormat )
265  {
266  return OUString();
267  }
268 
269  return pFlyFormat->GetObjTitle();
270 }
271 
272 void SwNoTextNode::SetDescription( const OUString& rDescription )
273 {
274  SwFlyFrameFormat* pFlyFormat = dynamic_cast<SwFlyFrameFormat*>(GetFlyFormat());
275  OSL_ENSURE( pFlyFormat, "<SwNoTextNode::SetDescription(..)> - missing <SwFlyFrameFormat> instance" );
276  if ( !pFlyFormat )
277  {
278  return;
279  }
280 
281  pFlyFormat->SetObjDescription( rDescription );
282 }
283 
285 {
286  const SwFlyFrameFormat* pFlyFormat = dynamic_cast<const SwFlyFrameFormat*>(GetFlyFormat());
287  OSL_ENSURE( pFlyFormat, "<SwNoTextNode::GetDescription(..)> - missing <SwFlyFrameFormat> instance" );
288  if ( !pFlyFormat )
289  {
290  return OUString();
291  }
292 
293  return pFlyFormat->GetObjDescription();
294 }
295 
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 Count() const
Graphic GetGraphic() const
Definition: ndnotxt.cxx:231
void SetDescription(const OUString &rDescription)
Definition: ndnotxt.cxx:272
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
OUString GetObjDescription() const
Definition: atrfrm.cxx:3138
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:157
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetTitle(const OUString &rTitle)
Definition: ndnotxt.cxx:247
double getX() const
double getY() const
bool IsPixelContour() const
Definition: ndnotxt.cxx:215
sal_uInt16 const aNoTextNodeSetRange[]
Definition: init.cxx:191
const tools::PolyPolygon * HasContour() const
Definition: ndnotxt.cxx:107
bool m_bAutomaticContour
Definition: ndnotxt.hxx:36
static OutputDevice * GetDefaultDevice()
void CreateContour()
Definition: ndnotxt.cxx:98
static tools::PolyPolygon CreateAutoContour(const Graphic &rGraphic, const tools::Rectangle *pRect=nullptr)
const OUString & GetName() const
Definition: format.hxx:111
SwNoTextNode(const SwNoTextNode &)=delete
bool GetContourAPI(tools::PolyPolygon &rPoly) const
Definition: ndnotxt.cxx:181
OUString GetObjTitle() const
Definition: atrfrm.cxx:3101
virtual void NewAttrSet(SwAttrPool &) override
Creates an AttrSet for all derivations with ranges for frame- and graphics-attributes.
Definition: ndnotxt.cxx:59
std::shared_ptr< const SfxItemSet > mpAttrSet
Attribute-set for all auto attributes of a ContentNode.
Definition: node.hxx:368
SwNodeType
Definition: ndtyp.hxx:28
bool m_bPixelContour
Definition: ndnotxt.hxx:40
void SetContourAPI(const tools::PolyPolygon *pPoly)
Definition: ndnotxt.cxx:172
bool m_bContourMapModeValid
Definition: ndnotxt.hxx:37
int i
SwDoc * GetDoc()
Definition: node.hxx:702
virtual ~SwNoTextNode() override
Definition: ndnotxt.cxx:53
sal_uInt16 GetSize() const
Marks a node in the document model.
Definition: ndindex.hxx:31
MapUnit GetMapUnit() const
OUString GetDescription() const
Definition: ndnotxt.cxx:284
void GetContour(tools::PolyPolygon &rPoly) const
Definition: ndnotxt.cxx:166
virtual bool RestorePersistentData()
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndnotxt.cxx:77
virtual bool SavePersistentData()
Definition: ndnotxt.cxx:82
basegfx::B2DSize GetPPI() const
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
std::unique_ptr< tools::PolyPolygon > m_pContour
Definition: ndnotxt.hxx:35
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1471
OUString GetTitle() const
Definition: ndnotxt.cxx:260
static void FillProgName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
SwFormatColl * GetFormatColl() const
Definition: node.hxx:447
void SetObjTitle(const OUString &rTitle, bool bBroadcast=false)
Definition: atrfrm.cxx:3078
SwGrfNode * GetGrfNode()
Definition: ndgrf.hxx:155
IStyleAccess & GetIStyleAccess()
Definition: doc.hxx:751
SAL_DLLPRIVATE sal_Int32 GetDPIY() const
void SetObjDescription(const OUString &rDescription, bool bBroadcast=false)
Definition: atrfrm.cxx:3115
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:710
#define RES_FRMATR_STYLE_NAME
Definition: hintids.hxx:232
SAL_DLLPRIVATE sal_Int32 GetDPIX() const
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
Definition: ndnotxt.cxx:87