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 .
21 #include <svx/sdr/attribute/sdrtextattribute.hxx>
22 #include <svx/sdr/attribute/sdrformtextattribute.hxx>
23 #include <svx/svdotext.hxx>
24 #include <editeng/outlobj.hxx>
25 #include <editeng/editobj.hxx>
26 #include <editeng/flditem.hxx>
27 #include <svx/sdr/properties/properties.hxx>
29 //////////////////////////////////////////////////////////////////////////////
31 namespace drawinglayer
35 class ImpSdrTextAttribute
39 sal_uInt32 mnRefCount
;
41 // all-text attributes. The SdrText itself and a copy
43 const SdrText
* mpSdrText
;
44 const OutlinerParaObject
* mpOutlinerParaObject
;
46 // Set when it's a FormText; contains all FormText attributes
47 SdrFormTextAttribute maSdrFormTextAttribute
;
50 sal_Int32 maTextLeftDistance
;
51 sal_Int32 maTextUpperDistance
;
52 sal_Int32 maTextRightDistance
;
53 sal_Int32 maTextLowerDistance
;
55 // #i101556# use versioning from text attributes to detect changes
56 sal_uInt32 maPropertiesVersion
;
59 SdrTextHorzAdjust maSdrTextHorzAdjust
;
60 SdrTextVertAdjust maSdrTextVertAdjust
;
63 unsigned mbContour
: 1;
64 unsigned mbFitToSize
: 1;
65 unsigned mbAutoFit
: 1;
66 unsigned mbHideContour
: 1;
68 unsigned mbScroll
: 1;
69 unsigned mbInEditMode
: 1;
70 unsigned mbFixedCellHeight
: 1;
71 unsigned mbWrongSpell
: 1;
75 const SdrText
* pSdrText
,
76 const OutlinerParaObject
& rOutlinerParaObject
,
77 XFormTextStyle eFormTextStyle
,
78 sal_Int32 aTextLeftDistance
,
79 sal_Int32 aTextUpperDistance
,
80 sal_Int32 aTextRightDistance
,
81 sal_Int32 aTextLowerDistance
,
82 SdrTextHorzAdjust aSdrTextHorzAdjust
,
83 SdrTextVertAdjust aSdrTextVertAdjust
,
91 bool bFixedCellHeight
,
95 mpOutlinerParaObject(new OutlinerParaObject(rOutlinerParaObject
)),
96 maSdrFormTextAttribute(),
97 maTextLeftDistance(aTextLeftDistance
),
98 maTextUpperDistance(aTextUpperDistance
),
99 maTextRightDistance(aTextRightDistance
),
100 maTextLowerDistance(aTextLowerDistance
),
101 maPropertiesVersion(0),
102 maSdrTextHorzAdjust(aSdrTextHorzAdjust
),
103 maSdrTextVertAdjust(aSdrTextVertAdjust
),
105 mbFitToSize(bFitToSize
),
107 mbHideContour(bHideContour
),
110 mbInEditMode(bInEditMode
),
111 mbFixedCellHeight(bFixedCellHeight
),
112 mbWrongSpell(bWrongSpell
)
116 if(XFT_NONE
!= eFormTextStyle
)
118 // text on path. Create FormText attribute
119 const SfxItemSet
& rSet
= pSdrText
->GetItemSet();
120 maSdrFormTextAttribute
= SdrFormTextAttribute(rSet
);
123 // #i101556# init with version number to detect changes of single text
124 // attribute and/or style sheets in primitive data without having to
125 // copy that data locally (which would be better from principle)
126 maPropertiesVersion
= pSdrText
->GetObject().GetProperties().getVersion();
130 ImpSdrTextAttribute()
133 mpOutlinerParaObject(0),
134 maSdrFormTextAttribute(),
135 maTextLeftDistance(0),
136 maTextUpperDistance(0),
137 maTextRightDistance(0),
138 maTextLowerDistance(0),
139 maPropertiesVersion(0),
140 maSdrTextHorzAdjust(SDRTEXTHORZADJUST_LEFT
),
141 maSdrTextVertAdjust(SDRTEXTVERTADJUST_TOP
),
145 mbHideContour(false),
149 mbFixedCellHeight(false),
154 ~ImpSdrTextAttribute()
156 if(mpOutlinerParaObject
)
158 delete mpOutlinerParaObject
;
163 const SdrText
& getSdrText() const
165 OSL_ENSURE(mpSdrText
, "Access to text of default version of ImpSdrTextAttribute (!)");
168 const OutlinerParaObject
& getOutlinerParaObject() const
170 OSL_ENSURE(mpOutlinerParaObject
, "Access to OutlinerParaObject of default version of ImpSdrTextAttribute (!)");
171 return *mpOutlinerParaObject
;
173 bool isContour() const { return mbContour
; }
174 bool isFitToSize() const { return mbFitToSize
; }
175 bool isAutoFit() const { return mbAutoFit
; }
176 bool isHideContour() const { return mbHideContour
; }
177 bool isBlink() const { return mbBlink
; }
178 bool isScroll() const { return mbScroll
; }
179 bool isInEditMode() const { return mbInEditMode
; }
180 bool isFixedCellHeight() const { return mbFixedCellHeight
; }
181 bool isWrongSpell() const { return mbWrongSpell
; }
182 const SdrFormTextAttribute
& getSdrFormTextAttribute() const { return maSdrFormTextAttribute
; }
183 sal_Int32
getTextLeftDistance() const { return maTextLeftDistance
; }
184 sal_Int32
getTextUpperDistance() const { return maTextUpperDistance
; }
185 sal_Int32
getTextRightDistance() const { return maTextRightDistance
; }
186 sal_Int32
getTextLowerDistance() const { return maTextLowerDistance
; }
187 sal_uInt32
getPropertiesVersion() const { return maPropertiesVersion
; }
188 SdrTextHorzAdjust
getSdrTextHorzAdjust() const { return maSdrTextHorzAdjust
; }
189 SdrTextVertAdjust
getSdrTextVertAdjust() const { return maSdrTextVertAdjust
; }
192 bool operator==(const ImpSdrTextAttribute
& rCandidate
) const
194 if(mpOutlinerParaObject
!= rCandidate
.mpOutlinerParaObject
)
196 if(mpOutlinerParaObject
&& rCandidate
.mpOutlinerParaObject
)
198 // compares OPO and it's contents, but traditionally not the RedLining
199 // which is not seen as model, but as temporary information
200 if(!(getOutlinerParaObject() == rCandidate
.getOutlinerParaObject()))
205 // #i102062# for primitive visualisation, the WrongList (SpellChecking)
206 // is important, too, so use isWrongListEqual since there is no WrongList
207 // comparison in the regular OutlinerParaObject compare (since it's
208 // not-persistent data)
209 if(!(getOutlinerParaObject().isWrongListEqual(rCandidate
.getOutlinerParaObject())))
216 // only one is zero; not equal
222 getSdrFormTextAttribute() == rCandidate
.getSdrFormTextAttribute()
223 && getTextLeftDistance() == rCandidate
.getTextLeftDistance()
224 && getTextUpperDistance() == rCandidate
.getTextUpperDistance()
225 && getTextRightDistance() == rCandidate
.getTextRightDistance()
226 && getTextLowerDistance() == rCandidate
.getTextLowerDistance()
227 && getPropertiesVersion() == rCandidate
.getPropertiesVersion()
229 && getSdrTextHorzAdjust() == rCandidate
.getSdrTextHorzAdjust()
230 && getSdrTextVertAdjust() == rCandidate
.getSdrTextVertAdjust()
232 && isContour() == rCandidate
.isContour()
233 && isFitToSize() == rCandidate
.isFitToSize()
234 && isAutoFit() == rCandidate
.isAutoFit()
235 && isHideContour() == rCandidate
.isHideContour()
236 && isBlink() == rCandidate
.isBlink()
237 && isScroll() == rCandidate
.isScroll()
238 && isInEditMode() == rCandidate
.isInEditMode()
239 && isFixedCellHeight() == rCandidate
.isFixedCellHeight()
240 && isWrongSpell() == rCandidate
.isWrongSpell());
243 static ImpSdrTextAttribute
* get_global_default()
245 static ImpSdrTextAttribute
* pDefault
= 0;
249 // use default constructor
250 pDefault
= new ImpSdrTextAttribute();
252 // never delete; start with RefCount 1, not 0
253 pDefault
->mnRefCount
++;
260 SdrTextAttribute::SdrTextAttribute(
261 const SdrText
& rSdrText
,
262 const OutlinerParaObject
& rOutlinerParaObject
,
263 XFormTextStyle eFormTextStyle
,
264 sal_Int32 aTextLeftDistance
,
265 sal_Int32 aTextUpperDistance
,
266 sal_Int32 aTextRightDistance
,
267 sal_Int32 aTextLowerDistance
,
268 SdrTextHorzAdjust aSdrTextHorzAdjust
,
269 SdrTextVertAdjust aSdrTextVertAdjust
,
277 bool bFixedCellHeight
,
279 : mpSdrTextAttribute(new ImpSdrTextAttribute(
280 &rSdrText
, rOutlinerParaObject
, eFormTextStyle
, aTextLeftDistance
, aTextUpperDistance
,
281 aTextRightDistance
, aTextLowerDistance
, aSdrTextHorzAdjust
, aSdrTextVertAdjust
, bContour
,
282 bFitToSize
, bAutoFit
, bHideContour
, bBlink
, bScroll
, bInEditMode
, bFixedCellHeight
, bWrongSpell
))
286 SdrTextAttribute::SdrTextAttribute()
287 : mpSdrTextAttribute(ImpSdrTextAttribute::get_global_default())
289 mpSdrTextAttribute
->mnRefCount
++;
292 SdrTextAttribute::SdrTextAttribute(const SdrTextAttribute
& rCandidate
)
293 : mpSdrTextAttribute(rCandidate
.mpSdrTextAttribute
)
295 mpSdrTextAttribute
->mnRefCount
++;
298 SdrTextAttribute::~SdrTextAttribute()
300 if(mpSdrTextAttribute
->mnRefCount
)
302 mpSdrTextAttribute
->mnRefCount
--;
306 delete mpSdrTextAttribute
;
310 bool SdrTextAttribute::isDefault() const
312 return mpSdrTextAttribute
== ImpSdrTextAttribute::get_global_default();
315 SdrTextAttribute
& SdrTextAttribute::operator=(const SdrTextAttribute
& rCandidate
)
317 if(rCandidate
.mpSdrTextAttribute
!= mpSdrTextAttribute
)
319 if(mpSdrTextAttribute
->mnRefCount
)
321 mpSdrTextAttribute
->mnRefCount
--;
325 delete mpSdrTextAttribute
;
328 mpSdrTextAttribute
= rCandidate
.mpSdrTextAttribute
;
329 mpSdrTextAttribute
->mnRefCount
++;
335 bool SdrTextAttribute::operator==(const SdrTextAttribute
& rCandidate
) const
337 if(rCandidate
.mpSdrTextAttribute
== mpSdrTextAttribute
)
342 if(rCandidate
.isDefault() != isDefault())
347 return (*rCandidate
.mpSdrTextAttribute
== *mpSdrTextAttribute
);
350 const SdrText
& SdrTextAttribute::getSdrText() const
352 return mpSdrTextAttribute
->getSdrText();
355 const OutlinerParaObject
& SdrTextAttribute::getOutlinerParaObject() const
357 return mpSdrTextAttribute
->getOutlinerParaObject();
360 bool SdrTextAttribute::isContour() const
362 return mpSdrTextAttribute
->isContour();
365 bool SdrTextAttribute::isFitToSize() const
367 return mpSdrTextAttribute
->isFitToSize();
370 bool SdrTextAttribute::isAutoFit() const
372 return mpSdrTextAttribute
->isAutoFit();
375 bool SdrTextAttribute::isHideContour() const
377 return mpSdrTextAttribute
->isHideContour();
380 bool SdrTextAttribute::isBlink() const
382 return mpSdrTextAttribute
->isBlink();
385 bool SdrTextAttribute::isScroll() const
387 return mpSdrTextAttribute
->isScroll();
390 bool SdrTextAttribute::isInEditMode() const
392 return mpSdrTextAttribute
->isInEditMode();
395 bool SdrTextAttribute::isFixedCellHeight() const
397 return mpSdrTextAttribute
->isFixedCellHeight();
400 const SdrFormTextAttribute
& SdrTextAttribute::getSdrFormTextAttribute() const
402 return mpSdrTextAttribute
->getSdrFormTextAttribute();
405 sal_Int32
SdrTextAttribute::getTextLeftDistance() const
407 return mpSdrTextAttribute
->getTextLeftDistance();
410 sal_Int32
SdrTextAttribute::getTextUpperDistance() const
412 return mpSdrTextAttribute
->getTextUpperDistance();
415 sal_Int32
SdrTextAttribute::getTextRightDistance() const
417 return mpSdrTextAttribute
->getTextRightDistance();
420 sal_Int32
SdrTextAttribute::getTextLowerDistance() const
422 return mpSdrTextAttribute
->getTextLowerDistance();
425 SdrTextHorzAdjust
SdrTextAttribute::getSdrTextHorzAdjust() const
427 return mpSdrTextAttribute
->getSdrTextHorzAdjust();
430 SdrTextVertAdjust
SdrTextAttribute::getSdrTextVertAdjust() const
432 return mpSdrTextAttribute
->getSdrTextVertAdjust();
435 void SdrTextAttribute::getBlinkTextTiming(drawinglayer::animation::AnimationEntryList
& rAnimList
) const
439 getSdrText().GetObject().impGetBlinkTextTiming(rAnimList
);
443 void SdrTextAttribute::getScrollTextTiming(drawinglayer::animation::AnimationEntryList
& rAnimList
, double fFrameLength
, double fTextLength
) const
447 getSdrText().GetObject().impGetScrollTextTiming(rAnimList
, fFrameLength
, fTextLength
);
450 } // end of namespace attribute
451 } // end of namespace drawinglayer
453 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */