Bump version to 24.04.3.4
[LibreOffice.git] / svx / source / sdr / attribute / sdrtextattribute.cxx
blob5c9ecb34ede2f6155d050fcb3a2efdbc18f39677
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <sdr/attribute/sdrtextattribute.hxx>
22 #include <sdr/attribute/sdrformtextattribute.hxx>
23 #include <svx/svdotext.hxx>
24 #include <editeng/outlobj.hxx>
25 #include <svx/sdr/properties/properties.hxx>
28 namespace drawinglayer::attribute
30 class ImpSdrTextAttribute
32 public:
33 // all-text attributes. The SdrText itself and a copy
34 // of the OPO
35 const SdrText* mpSdrText;
36 std::shared_ptr<OutlinerParaObject> mxOutlinerParaObject;
38 // Set when it's a FormText; contains all FormText attributes
39 SdrFormTextAttribute maSdrFormTextAttribute;
41 // text distances
42 sal_Int32 maTextLeftDistance;
43 sal_Int32 maTextUpperDistance;
44 sal_Int32 maTextRightDistance;
45 sal_Int32 maTextLowerDistance;
47 // #i101556# use versioning from text attributes to detect changes
48 sal_uInt32 maPropertiesVersion;
50 // text alignments
51 SdrTextHorzAdjust maSdrTextHorzAdjust;
52 SdrTextVertAdjust maSdrTextVertAdjust;
54 bool mbContour : 1;
55 bool mbFitToSize : 1;
56 bool mbAutoFit : 1;
57 bool mbHideContour : 1;
58 bool mbBlink : 1;
59 bool mbScroll : 1;
60 bool mbInEditMode : 1;
61 bool mbFixedCellHeight : 1;
62 bool mbWrongSpell : 1;
64 bool mbChainable : 1;
67 public:
68 ImpSdrTextAttribute(
69 const SdrText* pSdrText,
70 const OutlinerParaObject& rOutlinerParaObject,
71 XFormTextStyle eFormTextStyle,
72 sal_Int32 aTextLeftDistance,
73 sal_Int32 aTextUpperDistance,
74 sal_Int32 aTextRightDistance,
75 sal_Int32 aTextLowerDistance,
76 SdrTextHorzAdjust aSdrTextHorzAdjust,
77 SdrTextVertAdjust aSdrTextVertAdjust,
78 bool bContour,
79 bool bFitToSize,
80 bool bAutoFit,
81 bool bHideContour,
82 bool bBlink,
83 bool bScroll,
84 bool bInEditMode,
85 bool bFixedCellHeight,
86 bool bWrongSpell,
87 bool bChainable)
88 : mpSdrText(pSdrText),
89 mxOutlinerParaObject(std::make_shared<OutlinerParaObject>(rOutlinerParaObject)),
90 maTextLeftDistance(aTextLeftDistance),
91 maTextUpperDistance(aTextUpperDistance),
92 maTextRightDistance(aTextRightDistance),
93 maTextLowerDistance(aTextLowerDistance),
94 maPropertiesVersion(0),
95 maSdrTextHorzAdjust(aSdrTextHorzAdjust),
96 maSdrTextVertAdjust(aSdrTextVertAdjust),
97 mbContour(bContour),
98 mbFitToSize(bFitToSize),
99 mbAutoFit(bAutoFit),
100 mbHideContour(bHideContour),
101 mbBlink(bBlink),
102 mbScroll(bScroll),
103 mbInEditMode(bInEditMode),
104 mbFixedCellHeight(bFixedCellHeight),
105 mbWrongSpell(bWrongSpell),
106 mbChainable(bChainable)
108 if(!pSdrText)
109 return;
111 if(XFormTextStyle::NONE != eFormTextStyle)
113 // text on path. Create FormText attribute
114 const SfxItemSet& rSet = pSdrText->GetItemSet();
115 maSdrFormTextAttribute = SdrFormTextAttribute(rSet);
118 // #i101556# init with version number to detect changes of single text
119 // attribute and/or style sheets in primitive data without having to
120 // copy that data locally (which would be better from principle)
121 maPropertiesVersion = pSdrText->GetObject().GetProperties().getVersion();
124 ImpSdrTextAttribute()
125 : mpSdrText(nullptr),
126 maTextLeftDistance(0),
127 maTextUpperDistance(0),
128 maTextRightDistance(0),
129 maTextLowerDistance(0),
130 maPropertiesVersion(0),
131 maSdrTextHorzAdjust(SDRTEXTHORZADJUST_LEFT),
132 maSdrTextVertAdjust(SDRTEXTVERTADJUST_TOP),
133 mbContour(false),
134 mbFitToSize(false),
135 mbAutoFit(false),
136 mbHideContour(false),
137 mbBlink(false),
138 mbScroll(false),
139 mbInEditMode(false),
140 mbFixedCellHeight(false),
141 mbWrongSpell(false),
142 mbChainable(false)
146 // data read access
147 const SdrText& getSdrText() const
149 assert(mpSdrText && "Access to text of default version of ImpSdrTextAttribute (!)");
150 return *mpSdrText;
153 const OutlinerParaObject& getOutlinerParaObject() const
155 assert(mxOutlinerParaObject && "Access to OutlinerParaObject of default version of ImpSdrTextAttribute (!)");
156 return *mxOutlinerParaObject;
159 bool isContour() const { return mbContour; }
160 bool isFitToSize() const { return mbFitToSize; }
161 bool isAutoFit() const { return mbAutoFit; }
162 bool isHideContour() const { return mbHideContour; }
163 bool isBlink() const { return mbBlink; }
164 bool isScroll() const { return mbScroll; }
165 bool isInEditMode() const { return mbInEditMode; }
166 bool isFixedCellHeight() const { return mbFixedCellHeight; }
167 bool isChainable() const { return mbChainable; }
168 const SdrFormTextAttribute& getSdrFormTextAttribute() const { return maSdrFormTextAttribute; }
169 sal_Int32 getTextLeftDistance() const { return maTextLeftDistance; }
170 sal_Int32 getTextUpperDistance() const { return maTextUpperDistance; }
171 sal_Int32 getTextRightDistance() const { return maTextRightDistance; }
172 sal_Int32 getTextLowerDistance() const { return maTextLowerDistance; }
173 SdrTextHorzAdjust getSdrTextHorzAdjust() const { return maSdrTextHorzAdjust; }
174 SdrTextVertAdjust getSdrTextVertAdjust() const { return maSdrTextVertAdjust; }
176 // compare operator
177 bool operator==(const ImpSdrTextAttribute& rCandidate) const
179 if (mxOutlinerParaObject.get() != rCandidate.mxOutlinerParaObject.get())
181 if (mxOutlinerParaObject && rCandidate.mxOutlinerParaObject)
183 // compares OPO and it's contents, but traditionally not the RedLining
184 // which is not seen as model, but as temporary information
185 if(getOutlinerParaObject() != rCandidate.getOutlinerParaObject())
187 return false;
190 // #i102062# for primitive visualisation, the WrongList (SpellChecking)
191 // is important, too, so use isWrongListEqual since there is no WrongList
192 // comparison in the regular OutlinerParaObject compare (since it's
193 // not-persistent data)
194 if(!(getOutlinerParaObject().isWrongListEqual(rCandidate.getOutlinerParaObject())))
196 return false;
199 else
201 // only one is zero; not equal
202 return false;
206 return (
207 getSdrFormTextAttribute() == rCandidate.getSdrFormTextAttribute()
208 && getTextLeftDistance() == rCandidate.getTextLeftDistance()
209 && getTextUpperDistance() == rCandidate.getTextUpperDistance()
210 && getTextRightDistance() == rCandidate.getTextRightDistance()
211 && getTextLowerDistance() == rCandidate.getTextLowerDistance()
212 && maPropertiesVersion == rCandidate.maPropertiesVersion
214 && getSdrTextHorzAdjust() == rCandidate.getSdrTextHorzAdjust()
215 && getSdrTextVertAdjust() == rCandidate.getSdrTextVertAdjust()
217 && isContour() == rCandidate.isContour()
218 && isFitToSize() == rCandidate.isFitToSize()
219 && isAutoFit() == rCandidate.isAutoFit()
220 && isHideContour() == rCandidate.isHideContour()
221 && isBlink() == rCandidate.isBlink()
222 && isScroll() == rCandidate.isScroll()
223 && isInEditMode() == rCandidate.isInEditMode()
224 && isFixedCellHeight() == rCandidate.isFixedCellHeight()
225 && mbWrongSpell == rCandidate.mbWrongSpell );
229 namespace
231 SdrTextAttribute::ImplType& theGlobalDefault()
233 static SdrTextAttribute::ImplType SINGLETON;
234 return SINGLETON;
238 SdrTextAttribute::SdrTextAttribute(
239 const SdrText& rSdrText,
240 const OutlinerParaObject& rOutlinerParaObject,
241 XFormTextStyle eFormTextStyle,
242 sal_Int32 aTextLeftDistance,
243 sal_Int32 aTextUpperDistance,
244 sal_Int32 aTextRightDistance,
245 sal_Int32 aTextLowerDistance,
246 SdrTextHorzAdjust aSdrTextHorzAdjust,
247 SdrTextVertAdjust aSdrTextVertAdjust,
248 bool bContour,
249 bool bFitToSize,
250 bool bAutoFit,
251 bool bHideContour,
252 bool bBlink,
253 bool bScroll,
254 bool bInEditMode,
255 bool bFixedCellHeight,
256 bool bWrongSpell,
257 bool bChainable)
258 : mpSdrTextAttribute(
259 ImpSdrTextAttribute(
260 &rSdrText, rOutlinerParaObject, eFormTextStyle, aTextLeftDistance,
261 aTextUpperDistance, aTextRightDistance, aTextLowerDistance,
262 aSdrTextHorzAdjust, aSdrTextVertAdjust, bContour, bFitToSize, bAutoFit,
263 bHideContour, bBlink, bScroll, bInEditMode, bFixedCellHeight, bWrongSpell,
264 bChainable))
268 SdrTextAttribute::SdrTextAttribute()
269 : mpSdrTextAttribute(theGlobalDefault())
273 SdrTextAttribute::SdrTextAttribute(const SdrTextAttribute& rCandidate)
274 : mpSdrTextAttribute(rCandidate.mpSdrTextAttribute)
278 SdrTextAttribute::SdrTextAttribute(SdrTextAttribute&& rCandidate) noexcept
279 : mpSdrTextAttribute(std::move(rCandidate.mpSdrTextAttribute))
283 SdrTextAttribute::~SdrTextAttribute()
287 bool SdrTextAttribute::isDefault() const
289 return mpSdrTextAttribute.same_object(theGlobalDefault());
292 SdrTextAttribute& SdrTextAttribute::operator=(const SdrTextAttribute& rCandidate)
294 mpSdrTextAttribute = rCandidate.mpSdrTextAttribute;
295 return *this;
298 SdrTextAttribute& SdrTextAttribute::operator=(SdrTextAttribute&& rCandidate) noexcept
300 mpSdrTextAttribute = std::move(rCandidate.mpSdrTextAttribute);
301 return *this;
304 bool SdrTextAttribute::operator==(const SdrTextAttribute& rCandidate) const
306 // tdf#87509 default attr is always != non-default attr, even with same values
307 if(rCandidate.isDefault() != isDefault())
308 return false;
310 return rCandidate.mpSdrTextAttribute == mpSdrTextAttribute;
313 const SdrText& SdrTextAttribute::getSdrText() const
315 return mpSdrTextAttribute->getSdrText();
318 const OutlinerParaObject& SdrTextAttribute::getOutlinerParaObject() const
320 return mpSdrTextAttribute->getOutlinerParaObject();
323 bool SdrTextAttribute::isContour() const
325 return mpSdrTextAttribute->isContour();
328 bool SdrTextAttribute::isFitToSize() const
330 return mpSdrTextAttribute->isFitToSize();
333 bool SdrTextAttribute::isAutoFit() const
335 return mpSdrTextAttribute->isAutoFit();
338 bool SdrTextAttribute::isHideContour() const
340 return mpSdrTextAttribute->isHideContour();
343 bool SdrTextAttribute::isBlink() const
345 return mpSdrTextAttribute->isBlink();
348 bool SdrTextAttribute::isScroll() const
350 return mpSdrTextAttribute->isScroll();
353 bool SdrTextAttribute::isInEditMode() const
355 return mpSdrTextAttribute->isInEditMode();
358 bool SdrTextAttribute::isChainable() const
360 return mpSdrTextAttribute->isChainable();
364 bool SdrTextAttribute::isFixedCellHeight() const
366 return mpSdrTextAttribute->isFixedCellHeight();
369 const SdrFormTextAttribute& SdrTextAttribute::getSdrFormTextAttribute() const
371 return mpSdrTextAttribute->getSdrFormTextAttribute();
374 sal_Int32 SdrTextAttribute::getTextLeftDistance() const
376 return mpSdrTextAttribute->getTextLeftDistance();
379 sal_Int32 SdrTextAttribute::getTextUpperDistance() const
381 return mpSdrTextAttribute->getTextUpperDistance();
384 sal_Int32 SdrTextAttribute::getTextRightDistance() const
386 return mpSdrTextAttribute->getTextRightDistance();
389 sal_Int32 SdrTextAttribute::getTextLowerDistance() const
391 return mpSdrTextAttribute->getTextLowerDistance();
394 SdrTextHorzAdjust SdrTextAttribute::getSdrTextHorzAdjust() const
396 return mpSdrTextAttribute->getSdrTextHorzAdjust();
399 SdrTextVertAdjust SdrTextAttribute::getSdrTextVertAdjust() const
401 return mpSdrTextAttribute->getSdrTextVertAdjust();
404 void SdrTextAttribute::getBlinkTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList) const
406 if(isBlink())
408 getSdrText().GetObject().impGetBlinkTextTiming(rAnimList);
412 void SdrTextAttribute::getScrollTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList, double fFrameLength, double fTextLength) const
414 if(isScroll())
416 getSdrText().GetObject().impGetScrollTextTiming(rAnimList, fFrameLength, fTextLength);
420 } // end of namespace
422 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */