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 <osl/diagnose.h>
22#include <tools/poly.hxx>
23#include <svl/stritem.hxx>
24#include <svx/contdlg.hxx>
25#include <vcl/svapp.hxx>
26#include <doc.hxx>
27#include <fmtcol.hxx>
28#include <ndnotxt.hxx>
29#include <ndgrf.hxx>
30#include <ndole.hxx>
31#include <ndindex.hxx>
32#include <istyleaccess.hxx>
33#include <SwStyleNameMapper.hxx>
34
35#include <frmfmt.hxx>
36
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 )
45{
46 // Should this set a hard attribute?
47 if( pAutoAttr )
48 SetAttr( *pAutoAttr );
49}
50
52{
53}
54
58{
59 OSL_ENSURE( !mpAttrSet, "AttrSet is already set" );
60 SwAttrSet aNewAttrSet( rPool, aNoTextNodeSetRange );
61
62 // put names of parent style and conditional style:
63 const SwFormatColl* pFormatColl = GetFormatColl();
64 OUString sVal;
66 SfxStringItem aFormatColl( RES_FRMATR_STYLE_NAME, sVal );
67 aNewAttrSet.Put( aFormatColl );
68
69 aNewAttrSet.SetParent( &GetFormatColl()->GetAttrSet() );
71}
72
76{
77 return true;
78}
79
81{
82 return true;
83}
84
85void SwNoTextNode::SetContour( const tools::PolyPolygon *pPoly, bool bAutomatic )
86{
87 if ( pPoly )
88 m_pContour = *pPoly;
89 else
90 m_pContour.reset();
91 m_bAutomaticContour = bAutomatic;
93 m_bPixelContour = false;
94}
95
97{
98 OSL_ENSURE( !m_pContour, "Contour available." );
100 m_bAutomaticContour = true;
102 m_bPixelContour = false;
103}
104
106{
108 {
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 )
113 {
114 double nGrfDPIx = 0.0;
115 double nGrfDPIy = 0.0;
116 {
117 if ( !bPixelGrf && m_bPixelContour )
118 {
120 nGrfDPIx = aDPI.getWidth();
121 nGrfDPIy = aDPI.getHeight();
122 }
123 }
124 OSL_ENSURE( !bPixelGrf || aGrfMap == aContourMap,
125 "scale factor for pixel unsupported" );
126 OutputDevice* pOutDev =
128 : nullptr;
129 sal_uInt16 nPolyCount = m_pContour->Count();
130 for( sal_uInt16 j=0; j<nPolyCount; j++ )
131 {
132 tools::Polygon& rPoly = (*m_pContour)[j];
133
134 sal_uInt16 nCount = rPoly.GetSize();
135 for( sal_uInt16 i=0 ; i<nCount; i++ )
136 {
137 if( bPixelGrf )
138 rPoly[i] = pOutDev->LogicToPixel( rPoly[i],
139 aContourMap );
140 else if( m_bPixelContour )
141 {
142 rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap );
143
144 if ( nGrfDPIx != 0 && nGrfDPIy != 0 )
145 {
146 rPoly[i] = Point( rPoly[i].getX() * pOutDev->GetDPIX() / nGrfDPIx,
147 rPoly[i].getY() * pOutDev->GetDPIY() / nGrfDPIy );
148 }
149 }
150 else
151 rPoly[i] = OutputDevice::LogicToLogic( rPoly[i],
152 aContourMap,
153 aGrfMap );
154 }
155 }
156 }
158 m_bPixelContour = false;
159 }
160
161 return m_pContour ? &*m_pContour : nullptr;
162}
163
165{
166 OSL_ENSURE( m_pContour, "Contour not available." );
167 rPoly = *HasContour();
168}
169
171{
172 if ( pPoly )
173 m_pContour = *pPoly;
174 else
175 m_pContour.reset();
177}
178
180{
181 if( !m_pContour )
182 return false;
183
184 rContour = *m_pContour;
186 {
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 )
194 {
195 sal_uInt16 nPolyCount = rContour.Count();
196 for( sal_uInt16 j=0; j<nPolyCount; j++ )
197 {
198 tools::Polygon& rPoly = rContour[j];
199
200 sal_uInt16 nCount = rPoly.GetSize();
201 for( sal_uInt16 i=0 ; i<nCount; i++ )
202 {
203 rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap,
204 aContourMap );
205 }
206 }
207 }
208 }
209
210 return true;
211}
212
214{
215 bool bRet;
217 {
218 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
219 bRet = aGrfMap.GetMapUnit() == MapUnit::MapPixel;
220 }
221 else
222 {
223 bRet = m_bPixelContour;
224 }
225
226 return bRet;
227}
228
230{
231 Graphic aRet;
232 if ( GetGrfNode() )
233 {
234 aRet = static_cast<const SwGrfNode*>(this)->GetGrf(true);
235 }
236 else
237 {
238 OSL_ENSURE( GetOLENode(), "new type of Node?" );
239 aRet = *const_cast<SwOLENode*>(static_cast<const SwOLENode*>(this))->SwOLENode::GetGraphic();
240 }
241 return aRet;
242}
243
244// #i73249#
245void SwNoTextNode::SetTitle( const OUString& rTitle )
246{
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" );
250 if ( !pFlyFormat )
251 {
252 return;
253 }
254
255 pFlyFormat->SetObjTitle( rTitle );
256}
257
259{
260 const SwFlyFrameFormat* pFlyFormat = dynamic_cast<const SwFlyFrameFormat*>(GetFlyFormat());
261 OSL_ENSURE( pFlyFormat, "<SwNoTextNode::GetTitle(..)> - missing <SwFlyFrameFormat> instance" );
262 if ( !pFlyFormat )
263 {
264 return OUString();
265 }
266
267 return pFlyFormat->GetObjTitle();
268}
269
270void SwNoTextNode::SetDescription( const OUString& rDescription )
271{
272 SwFlyFrameFormat* pFlyFormat = dynamic_cast<SwFlyFrameFormat*>(GetFlyFormat());
273 OSL_ENSURE( pFlyFormat, "<SwNoTextNode::SetDescription(..)> - missing <SwFlyFrameFormat> instance" );
274 if ( !pFlyFormat )
275 {
276 return;
277 }
278
279 pFlyFormat->SetObjDescription( rDescription );
280}
281
283{
284 const SwFlyFrameFormat* pFlyFormat = dynamic_cast<const SwFlyFrameFormat*>(GetFlyFormat());
285 OSL_ENSURE( pFlyFormat, "<SwNoTextNode::GetDescription(..)> - missing <SwFlyFrameFormat> instance" );
286 if ( !pFlyFormat )
287 {
288 return OUString();
289 }
290
291 return pFlyFormat->GetObjDescription();
292}
293
294/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
basegfx::B2DSize GetPPI() const
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
MapUnit GetMapUnit() const
SAL_DLLPRIVATE sal_Int32 GetDPIX() const
SAL_DLLPRIVATE sal_Int32 GetDPIY() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
void SetParent(const SfxItemSet *pNew)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
static tools::PolyPolygon CreateAutoContour(const Graphic &rGraphic, const tools::Rectangle *pRect=nullptr)
SwFormatColl * GetFormatColl() const
Definition: node.hxx:497
std::shared_ptr< const SfxItemSet > mpAttrSet
Attribute-set for all auto attributes of a ContentNode.
Definition: node.hxx:413
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1601
IStyleAccess & GetIStyleAccess()
Definition: doc.hxx:765
void SetObjDescription(const OUString &rDescription, bool bBroadcast=false)
Definition: atrfrm.cxx:3233
OUString GetObjDescription() const
Definition: atrfrm.cxx:3252
OUString GetObjTitle() const
Definition: atrfrm.cxx:3209
void SetObjTitle(const OUString &rTitle, bool bBroadcast=false)
Definition: atrfrm.cxx:3190
const OUString & GetName() const
Definition: format.hxx:131
SwNoTextNode(const SwNoTextNode &)=delete
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
Definition: ndnotxt.cxx:85
OUString GetDescription() const
Definition: ndnotxt.cxx:282
bool m_bAutomaticContour
Definition: ndnotxt.hxx:35
void GetContour(tools::PolyPolygon &rPoly) const
Definition: ndnotxt.cxx:164
void SetContourAPI(const tools::PolyPolygon *pPoly)
Definition: ndnotxt.cxx:170
bool m_bPixelContour
Definition: ndnotxt.hxx:39
virtual bool SavePersistentData()
Definition: ndnotxt.cxx:80
virtual bool RestorePersistentData()
Dummies for loading/saving of persistent data when working with graphics and OLE objects.
Definition: ndnotxt.cxx:75
OUString GetTitle() const
Definition: ndnotxt.cxx:258
bool GetContourAPI(tools::PolyPolygon &rPoly) const
Definition: ndnotxt.cxx:179
const tools::PolyPolygon * HasContour() const
Definition: ndnotxt.cxx:105
virtual ~SwNoTextNode() override
Definition: ndnotxt.cxx:51
void SetTitle(const OUString &rTitle)
Definition: ndnotxt.cxx:245
std::optional< tools::PolyPolygon > m_pContour
Definition: ndnotxt.hxx:34
bool IsPixelContour() const
Definition: ndnotxt.cxx:213
Graphic GetGraphic() const
Definition: ndnotxt.cxx:229
void CreateContour()
Definition: ndnotxt.cxx:96
bool m_bContourMapModeValid
Definition: ndnotxt.hxx:36
virtual void NewAttrSet(SwAttrPool &) override
Creates an AttrSet for all derivations with ranges for frame- and graphics-attributes.
Definition: ndnotxt.cxx:57
void SetDescription(const OUString &rDescription)
Definition: ndnotxt.cxx:270
Base class of the Writer document model elements.
Definition: node.hxx:98
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:739
SwGrfNode * GetGrfNode()
Definition: ndgrf.hxx:154
SwDoc & GetDoc()
Definition: node.hxx:233
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:165
static void FillProgName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
TYPE getWidth() const
TYPE getHeight() const
sal_uInt16 Count() const
sal_uInt16 GetSize() const
int nCount
constexpr TypedWhichId< SfxStringItem > RES_FRMATR_STYLE_NAME(127)
WhichRangesContainer const aNoTextNodeSetRange(svl::Items< RES_FRMATR_BEGIN, RES_FRMATR_END-1, RES_GRFATR_BEGIN, RES_GRFATR_END-1, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
int i
SwNodeType
Definition: ndtyp.hxx:28