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