xref: /AOO41X/main/svx/source/sdr/attribute/sdrtextattribute.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_svx.hxx"
25 
26 #include <svx/sdr/attribute/sdrtextattribute.hxx>
27 #include <svx/sdr/attribute/sdrformtextattribute.hxx>
28 #include <svx/svdotext.hxx>
29 #include <editeng/outlobj.hxx>
30 #include <editeng/editobj.hxx>
31 #include <editeng/flditem.hxx>
32 #include <svx/sdr/properties/properties.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace drawinglayer
37 {
38     namespace attribute
39     {
40         class ImpSdrTextAttribute
41         {
42         public:
43             // refcounter
44             sal_uInt32                          mnRefCount;
45 
46             // all-text attributes. The SdrText itself and a copy
47             // of te OPO
48             const SdrText*                      mpSdrText;
49             const OutlinerParaObject*           mpOutlinerParaObject;
50 
51             // Set when it's a FormText; contains all FormText attributes
52             SdrFormTextAttribute                maSdrFormTextAttribute;
53 
54             // text distances
55             sal_Int32                           maTextLeftDistance;
56             sal_Int32                           maTextUpperDistance;
57             sal_Int32                           maTextRightDistance;
58             sal_Int32                           maTextLowerDistance;
59 
60             // #i101556# use versioning from text attributes to detect changes
61             sal_uInt32                          maPropertiesVersion;
62 
63             // text alignments
64             SdrTextHorzAdjust                   maSdrTextHorzAdjust;
65             SdrTextVertAdjust                   maSdrTextVertAdjust;
66 
67             // bitfield
68             unsigned                            mbContour : 1;
69             unsigned                            mbFitToSize : 1;
70             unsigned                            mbHideContour : 1;
71             unsigned                            mbBlink : 1;
72             unsigned                            mbScroll : 1;
73             unsigned                            mbInEditMode : 1;
74             unsigned                            mbFixedCellHeight : 1;
75             unsigned                            mbWrongSpell : 1;
76 
77         public:
ImpSdrTextAttribute(const SdrText * pSdrText,const OutlinerParaObject & rOutlinerParaObject,XFormTextStyle eFormTextStyle,sal_Int32 aTextLeftDistance,sal_Int32 aTextUpperDistance,sal_Int32 aTextRightDistance,sal_Int32 aTextLowerDistance,SdrTextHorzAdjust aSdrTextHorzAdjust,SdrTextVertAdjust aSdrTextVertAdjust,bool bContour,bool bFitToSize,bool bHideContour,bool bBlink,bool bScroll,bool bInEditMode,bool bFixedCellHeight,bool bWrongSpell)78             ImpSdrTextAttribute(
79                 const SdrText* pSdrText,
80                 const OutlinerParaObject& rOutlinerParaObject,
81                 XFormTextStyle eFormTextStyle,
82                 sal_Int32 aTextLeftDistance,
83                 sal_Int32 aTextUpperDistance,
84                 sal_Int32 aTextRightDistance,
85                 sal_Int32 aTextLowerDistance,
86                 SdrTextHorzAdjust aSdrTextHorzAdjust,
87                 SdrTextVertAdjust aSdrTextVertAdjust,
88                 bool bContour,
89                 bool bFitToSize,
90                 bool bHideContour,
91                 bool bBlink,
92                 bool bScroll,
93                 bool bInEditMode,
94                 bool bFixedCellHeight,
95                 bool bWrongSpell)
96             :   mnRefCount(0),
97                 mpSdrText(pSdrText),
98                 mpOutlinerParaObject(new OutlinerParaObject(rOutlinerParaObject)),
99                 maSdrFormTextAttribute(),
100                 maTextLeftDistance(aTextLeftDistance),
101                 maTextUpperDistance(aTextUpperDistance),
102                 maTextRightDistance(aTextRightDistance),
103                 maTextLowerDistance(aTextLowerDistance),
104                 maPropertiesVersion(0),
105                 maSdrTextHorzAdjust(aSdrTextHorzAdjust),
106                 maSdrTextVertAdjust(aSdrTextVertAdjust),
107                 mbContour(bContour),
108                 mbFitToSize(bFitToSize),
109                 mbHideContour(bHideContour),
110                 mbBlink(bBlink),
111                 mbScroll(bScroll),
112                 mbInEditMode(bInEditMode),
113                 mbFixedCellHeight(bFixedCellHeight),
114                 mbWrongSpell(bWrongSpell)
115             {
116                 if(pSdrText)
117                 {
118                     if(XFT_NONE != eFormTextStyle)
119                     {
120                         // text on path. Create FormText attribute
121                         const SfxItemSet& rSet = pSdrText->GetItemSet();
122                         maSdrFormTextAttribute = SdrFormTextAttribute(rSet);
123                     }
124 
125                     // #i101556# init with version number to detect changes of single text
126                     // attribute and/or style sheets in primitive data without having to
127                     // copy that data locally (which would be better from principle)
128                     maPropertiesVersion = pSdrText->GetObject().GetProperties().getVersion();
129                 }
130             }
131 
ImpSdrTextAttribute()132             ImpSdrTextAttribute()
133             :   mnRefCount(0),
134                 mpSdrText(0),
135                 mpOutlinerParaObject(0),
136                 maSdrFormTextAttribute(),
137                 maTextLeftDistance(0),
138                 maTextUpperDistance(0),
139                 maTextRightDistance(0),
140                 maTextLowerDistance(0),
141                 maPropertiesVersion(0),
142                 maSdrTextHorzAdjust(SDRTEXTHORZADJUST_LEFT),
143                 maSdrTextVertAdjust(SDRTEXTVERTADJUST_TOP),
144                 mbContour(false),
145                 mbFitToSize(false),
146                 mbHideContour(false),
147                 mbBlink(false),
148                 mbScroll(false),
149                 mbInEditMode(false),
150                 mbFixedCellHeight(false),
151                 mbWrongSpell(false)
152             {
153             }
154 
~ImpSdrTextAttribute()155             ~ImpSdrTextAttribute()
156             {
157                 if(mpOutlinerParaObject)
158                 {
159                     delete mpOutlinerParaObject;
160                 }
161             }
162 
163             // data read access
getSdrText() const164             const SdrText& getSdrText() const
165             {
166                 OSL_ENSURE(mpSdrText, "Access to text of default version of ImpSdrTextAttribute (!)");
167                 return *mpSdrText;
168             }
getOutlinerParaObject() const169             const OutlinerParaObject& getOutlinerParaObject() const
170             {
171                 OSL_ENSURE(mpOutlinerParaObject, "Access to OutlinerParaObject of default version of ImpSdrTextAttribute (!)");
172                 return *mpOutlinerParaObject;
173             }
isContour() const174             bool isContour() const { return mbContour; }
isFitToSize() const175             bool isFitToSize() const { return mbFitToSize; }
isHideContour() const176             bool isHideContour() const { return mbHideContour; }
isBlink() const177             bool isBlink() const { return mbBlink; }
isScroll() const178             bool isScroll() const { return mbScroll; }
isInEditMode() const179             bool isInEditMode() const { return mbInEditMode; }
isFixedCellHeight() const180             bool isFixedCellHeight() const { return mbFixedCellHeight; }
isWrongSpell() const181             bool isWrongSpell() const { return mbWrongSpell; }
getSdrFormTextAttribute() const182             const SdrFormTextAttribute& getSdrFormTextAttribute() const { return maSdrFormTextAttribute; }
getTextLeftDistance() const183             sal_Int32 getTextLeftDistance() const { return maTextLeftDistance; }
getTextUpperDistance() const184             sal_Int32 getTextUpperDistance() const { return maTextUpperDistance; }
getTextRightDistance() const185             sal_Int32 getTextRightDistance() const { return maTextRightDistance; }
getTextLowerDistance() const186             sal_Int32 getTextLowerDistance() const { return maTextLowerDistance; }
getPropertiesVersion() const187             sal_uInt32 getPropertiesVersion() const { return maPropertiesVersion; }
getSdrTextHorzAdjust() const188             SdrTextHorzAdjust getSdrTextHorzAdjust() const { return maSdrTextHorzAdjust; }
getSdrTextVertAdjust() const189             SdrTextVertAdjust getSdrTextVertAdjust() const { return maSdrTextVertAdjust; }
190 
191             // compare operator
operator ==(const ImpSdrTextAttribute & rCandidate) const192             bool operator==(const ImpSdrTextAttribute& rCandidate) const
193             {
194                 if(mpOutlinerParaObject != rCandidate.mpOutlinerParaObject)
195                 {
196                     if(mpOutlinerParaObject && rCandidate.mpOutlinerParaObject)
197                     {
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()))
201                         {
202                             return false;
203                         }
204 
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())))
210                         {
211                             return false;
212                         }
213                     }
214                     else
215                     {
216                         // only one is zero; not equal
217                         return false;
218                     }
219                 }
220 
221                 return (
222                        getSdrFormTextAttribute() == rCandidate.getSdrFormTextAttribute()
223                     && getTextLeftDistance() == rCandidate.getTextLeftDistance()
224                     && getTextUpperDistance() == rCandidate.getTextUpperDistance()
225                     && getTextRightDistance() == rCandidate.getTextRightDistance()
226                     && getTextLowerDistance() == rCandidate.getTextLowerDistance()
227                     && getPropertiesVersion() == rCandidate.getPropertiesVersion()
228 
229                     && getSdrTextHorzAdjust() == rCandidate.getSdrTextHorzAdjust()
230                     && getSdrTextVertAdjust() == rCandidate.getSdrTextVertAdjust()
231 
232                     && isContour() == rCandidate.isContour()
233                     && isFitToSize() == rCandidate.isFitToSize()
234                     && isHideContour() == rCandidate.isHideContour()
235                     && isBlink() == rCandidate.isBlink()
236                     && isScroll() == rCandidate.isScroll()
237                     && isInEditMode() == rCandidate.isInEditMode()
238                     && isFixedCellHeight() == rCandidate.isFixedCellHeight()
239                     && isWrongSpell() == rCandidate.isWrongSpell());
240             }
241 
get_global_default()242             static ImpSdrTextAttribute* get_global_default()
243             {
244                 static ImpSdrTextAttribute* pDefault = 0;
245 
246                 if(!pDefault)
247                 {
248                     // use default constructor
249                     pDefault = new ImpSdrTextAttribute();
250 
251                     // never delete; start with RefCount 1, not 0
252                     pDefault->mnRefCount++;
253                 }
254 
255                 return pDefault;
256             }
257         };
258 
SdrTextAttribute(const SdrText & rSdrText,const OutlinerParaObject & rOutlinerParaObject,XFormTextStyle eFormTextStyle,sal_Int32 aTextLeftDistance,sal_Int32 aTextUpperDistance,sal_Int32 aTextRightDistance,sal_Int32 aTextLowerDistance,SdrTextHorzAdjust aSdrTextHorzAdjust,SdrTextVertAdjust aSdrTextVertAdjust,bool bContour,bool bFitToSize,bool bHideContour,bool bBlink,bool bScroll,bool bInEditMode,bool bFixedCellHeight,bool bWrongSpell)259         SdrTextAttribute::SdrTextAttribute(
260             const SdrText& rSdrText,
261             const OutlinerParaObject& rOutlinerParaObject,
262             XFormTextStyle eFormTextStyle,
263             sal_Int32 aTextLeftDistance,
264             sal_Int32 aTextUpperDistance,
265             sal_Int32 aTextRightDistance,
266             sal_Int32 aTextLowerDistance,
267             SdrTextHorzAdjust aSdrTextHorzAdjust,
268             SdrTextVertAdjust aSdrTextVertAdjust,
269             bool bContour,
270             bool bFitToSize,
271             bool bHideContour,
272             bool bBlink,
273             bool bScroll,
274             bool bInEditMode,
275             bool bFixedCellHeight,
276             bool bWrongSpell)
277         :   mpSdrTextAttribute(new ImpSdrTextAttribute(
278                 &rSdrText, rOutlinerParaObject, eFormTextStyle, aTextLeftDistance, aTextUpperDistance,
279                 aTextRightDistance, aTextLowerDistance, aSdrTextHorzAdjust, aSdrTextVertAdjust, bContour,
280                 bFitToSize, bHideContour, bBlink, bScroll, bInEditMode, bFixedCellHeight, bWrongSpell))
281         {
282         }
283 
SdrTextAttribute()284         SdrTextAttribute::SdrTextAttribute()
285         :   mpSdrTextAttribute(ImpSdrTextAttribute::get_global_default())
286         {
287             mpSdrTextAttribute->mnRefCount++;
288         }
289 
SdrTextAttribute(const SdrTextAttribute & rCandidate)290         SdrTextAttribute::SdrTextAttribute(const SdrTextAttribute& rCandidate)
291         :   mpSdrTextAttribute(rCandidate.mpSdrTextAttribute)
292         {
293             mpSdrTextAttribute->mnRefCount++;
294         }
295 
~SdrTextAttribute()296         SdrTextAttribute::~SdrTextAttribute()
297         {
298             if(mpSdrTextAttribute->mnRefCount)
299             {
300                 mpSdrTextAttribute->mnRefCount--;
301             }
302             else
303             {
304                 delete mpSdrTextAttribute;
305             }
306         }
307 
isDefault() const308         bool SdrTextAttribute::isDefault() const
309         {
310             return mpSdrTextAttribute == ImpSdrTextAttribute::get_global_default();
311         }
312 
operator =(const SdrTextAttribute & rCandidate)313         SdrTextAttribute& SdrTextAttribute::operator=(const SdrTextAttribute& rCandidate)
314         {
315             if(rCandidate.mpSdrTextAttribute != mpSdrTextAttribute)
316             {
317                 if(mpSdrTextAttribute->mnRefCount)
318                 {
319                     mpSdrTextAttribute->mnRefCount--;
320                 }
321                 else
322                 {
323                     delete mpSdrTextAttribute;
324                 }
325 
326                 mpSdrTextAttribute = rCandidate.mpSdrTextAttribute;
327                 mpSdrTextAttribute->mnRefCount++;
328             }
329 
330             return *this;
331         }
332 
operator ==(const SdrTextAttribute & rCandidate) const333         bool SdrTextAttribute::operator==(const SdrTextAttribute& rCandidate) const
334         {
335             if(rCandidate.mpSdrTextAttribute == mpSdrTextAttribute)
336             {
337                 return true;
338             }
339 
340             if(rCandidate.isDefault() != isDefault())
341             {
342                 return false;
343             }
344 
345             return (*rCandidate.mpSdrTextAttribute == *mpSdrTextAttribute);
346         }
347 
getSdrText() const348         const SdrText& SdrTextAttribute::getSdrText() const
349         {
350             return mpSdrTextAttribute->getSdrText();
351         }
352 
getOutlinerParaObject() const353         const OutlinerParaObject& SdrTextAttribute::getOutlinerParaObject() const
354         {
355             return mpSdrTextAttribute->getOutlinerParaObject();
356         }
357 
isContour() const358         bool SdrTextAttribute::isContour() const
359         {
360             return mpSdrTextAttribute->isContour();
361         }
362 
isFitToSize() const363         bool SdrTextAttribute::isFitToSize() const
364         {
365             return mpSdrTextAttribute->isFitToSize();
366         }
367 
isHideContour() const368         bool SdrTextAttribute::isHideContour() const
369         {
370             return mpSdrTextAttribute->isHideContour();
371         }
372 
isBlink() const373         bool SdrTextAttribute::isBlink() const
374         {
375             return mpSdrTextAttribute->isBlink();
376         }
377 
isScroll() const378         bool SdrTextAttribute::isScroll() const
379         {
380             return mpSdrTextAttribute->isScroll();
381         }
382 
isInEditMode() const383         bool SdrTextAttribute::isInEditMode() const
384         {
385             return mpSdrTextAttribute->isInEditMode();
386         }
387 
isFixedCellHeight() const388         bool SdrTextAttribute::isFixedCellHeight() const
389         {
390             return mpSdrTextAttribute->isFixedCellHeight();
391         }
392 
isWrongSpell() const393         bool SdrTextAttribute::isWrongSpell() const
394         {
395             return mpSdrTextAttribute->isWrongSpell();
396         }
397 
getSdrFormTextAttribute() const398         const SdrFormTextAttribute& SdrTextAttribute::getSdrFormTextAttribute() const
399         {
400             return mpSdrTextAttribute->getSdrFormTextAttribute();
401         }
402 
getTextLeftDistance() const403         sal_Int32 SdrTextAttribute::getTextLeftDistance() const
404         {
405             return mpSdrTextAttribute->getTextLeftDistance();
406         }
407 
getTextUpperDistance() const408         sal_Int32 SdrTextAttribute::getTextUpperDistance() const
409         {
410             return mpSdrTextAttribute->getTextUpperDistance();
411         }
412 
getTextRightDistance() const413         sal_Int32 SdrTextAttribute::getTextRightDistance() const
414         {
415             return mpSdrTextAttribute->getTextRightDistance();
416         }
417 
getTextLowerDistance() const418         sal_Int32 SdrTextAttribute::getTextLowerDistance() const
419         {
420             return mpSdrTextAttribute->getTextLowerDistance();
421         }
422 
getPropertiesVersion() const423         sal_uInt32 SdrTextAttribute::getPropertiesVersion() const
424         {
425             return mpSdrTextAttribute->getPropertiesVersion();
426         }
427 
getSdrTextHorzAdjust() const428         SdrTextHorzAdjust SdrTextAttribute::getSdrTextHorzAdjust() const
429         {
430             return mpSdrTextAttribute->getSdrTextHorzAdjust();
431         }
432 
getSdrTextVertAdjust() const433         SdrTextVertAdjust SdrTextAttribute::getSdrTextVertAdjust() const
434         {
435             return mpSdrTextAttribute->getSdrTextVertAdjust();
436         }
437 
getBlinkTextTiming(drawinglayer::animation::AnimationEntryList & rAnimList) const438         void SdrTextAttribute::getBlinkTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList) const
439         {
440             if(isBlink())
441             {
442                 getSdrText().GetObject().impGetBlinkTextTiming(rAnimList);
443             }
444         }
445 
getScrollTextTiming(drawinglayer::animation::AnimationEntryList & rAnimList,double fFrameLength,double fTextLength) const446         void SdrTextAttribute::getScrollTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList, double fFrameLength, double fTextLength) const
447         {
448             if(isScroll())
449             {
450                 getSdrText().GetObject().impGetScrollTextTiming(rAnimList, fFrameLength, fTextLength);
451             }
452         }
453     } // end of namespace attribute
454 } // end of namespace drawinglayer
455 
456 //////////////////////////////////////////////////////////////////////////////
457 // eof
458