Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svx/sdr/attribute/sdrtextattribute.hxx>
31 : : #include <svx/sdr/attribute/sdrformtextattribute.hxx>
32 : : #include <svx/svdotext.hxx>
33 : : #include <editeng/outlobj.hxx>
34 : : #include <editeng/editobj.hxx>
35 : : #include <editeng/flditem.hxx>
36 : : #include <svx/sdr/properties/properties.hxx>
37 : :
38 : : //////////////////////////////////////////////////////////////////////////////
39 : :
40 : : namespace drawinglayer
41 : : {
42 : : namespace attribute
43 : : {
44 : : class ImpSdrTextAttribute
45 : : {
46 : : public:
47 : : // refcounter
48 : : sal_uInt32 mnRefCount;
49 : :
50 : : // all-text attributes. The SdrText itself and a copy
51 : : // of te OPO
52 : : const SdrText* mpSdrText;
53 : : const OutlinerParaObject* mpOutlinerParaObject;
54 : :
55 : : // Set when it's a FormText; contains all FormText attributes
56 : : SdrFormTextAttribute maSdrFormTextAttribute;
57 : :
58 : : // text distances
59 : : sal_Int32 maTextLeftDistance;
60 : : sal_Int32 maTextUpperDistance;
61 : : sal_Int32 maTextRightDistance;
62 : : sal_Int32 maTextLowerDistance;
63 : :
64 : : // #i101556# use versioning from text attributes to detect changes
65 : : sal_uInt32 maPropertiesVersion;
66 : :
67 : : // text alignments
68 : : SdrTextHorzAdjust maSdrTextHorzAdjust;
69 : : SdrTextVertAdjust maSdrTextVertAdjust;
70 : :
71 : : // bitfield
72 : : unsigned mbContour : 1;
73 : : unsigned mbFitToSize : 1;
74 : : unsigned mbAutoFit : 1;
75 : : unsigned mbHideContour : 1;
76 : : unsigned mbBlink : 1;
77 : : unsigned mbScroll : 1;
78 : : unsigned mbInEditMode : 1;
79 : : unsigned mbFixedCellHeight : 1;
80 : : unsigned mbWrongSpell : 1;
81 : :
82 : : public:
83 : 28367 : ImpSdrTextAttribute(
84 : : const SdrText* pSdrText,
85 : : const OutlinerParaObject& rOutlinerParaObject,
86 : : XFormTextStyle eFormTextStyle,
87 : : sal_Int32 aTextLeftDistance,
88 : : sal_Int32 aTextUpperDistance,
89 : : sal_Int32 aTextRightDistance,
90 : : sal_Int32 aTextLowerDistance,
91 : : SdrTextHorzAdjust aSdrTextHorzAdjust,
92 : : SdrTextVertAdjust aSdrTextVertAdjust,
93 : : bool bContour,
94 : : bool bFitToSize,
95 : : bool bAutoFit,
96 : : bool bHideContour,
97 : : bool bBlink,
98 : : bool bScroll,
99 : : bool bInEditMode,
100 : : bool bFixedCellHeight,
101 : : bool bWrongSpell)
102 : : : mnRefCount(0),
103 : : mpSdrText(pSdrText),
104 [ + - ]: 28367 : mpOutlinerParaObject(new OutlinerParaObject(rOutlinerParaObject)),
105 : : maSdrFormTextAttribute(),
106 : : maTextLeftDistance(aTextLeftDistance),
107 : : maTextUpperDistance(aTextUpperDistance),
108 : : maTextRightDistance(aTextRightDistance),
109 : : maTextLowerDistance(aTextLowerDistance),
110 : : maPropertiesVersion(0),
111 : : maSdrTextHorzAdjust(aSdrTextHorzAdjust),
112 : : maSdrTextVertAdjust(aSdrTextVertAdjust),
113 : : mbContour(bContour),
114 : : mbFitToSize(bFitToSize),
115 : : mbAutoFit(bAutoFit),
116 : : mbHideContour(bHideContour),
117 : : mbBlink(bBlink),
118 : : mbScroll(bScroll),
119 : : mbInEditMode(bInEditMode),
120 : : mbFixedCellHeight(bFixedCellHeight),
121 : 56734 : mbWrongSpell(bWrongSpell)
122 : : {
123 [ + - ]: 28367 : if(pSdrText)
124 : : {
125 [ - + ]: 28367 : if(XFT_NONE != eFormTextStyle)
126 : : {
127 : : // text on path. Create FormText attribute
128 [ # # ]: 0 : const SfxItemSet& rSet = pSdrText->GetItemSet();
129 [ # # ][ # # ]: 0 : maSdrFormTextAttribute = SdrFormTextAttribute(rSet);
[ # # ]
130 : : }
131 : :
132 : : // #i101556# init with version number to detect changes of single text
133 : : // attribute and/or style sheets in primitive data without having to
134 : : // copy that data locally (which would be better from principle)
135 [ + - ][ + - ]: 28367 : maPropertiesVersion = pSdrText->GetObject().GetProperties().getVersion();
136 : : }
137 : 28367 : }
138 : :
139 : 47 : ImpSdrTextAttribute()
140 : : : mnRefCount(0),
141 : : mpSdrText(0),
142 : : mpOutlinerParaObject(0),
143 : : maSdrFormTextAttribute(),
144 : : maTextLeftDistance(0),
145 : : maTextUpperDistance(0),
146 : : maTextRightDistance(0),
147 : : maTextLowerDistance(0),
148 : : maPropertiesVersion(0),
149 : : maSdrTextHorzAdjust(SDRTEXTHORZADJUST_LEFT),
150 : : maSdrTextVertAdjust(SDRTEXTVERTADJUST_TOP),
151 : : mbContour(false),
152 : : mbFitToSize(false),
153 : : mbAutoFit(false),
154 : : mbHideContour(false),
155 : : mbBlink(false),
156 : : mbScroll(false),
157 : : mbInEditMode(false),
158 : : mbFixedCellHeight(false),
159 : 47 : mbWrongSpell(false)
160 : : {
161 : 47 : }
162 : :
163 : 28367 : ~ImpSdrTextAttribute()
164 : 28367 : {
165 [ + - ]: 28367 : if(mpOutlinerParaObject)
166 : : {
167 [ + - ][ + - ]: 28367 : delete mpOutlinerParaObject;
168 : : }
169 : 28367 : }
170 : :
171 : : // data read access
172 : 13465 : const SdrText& getSdrText() const
173 : : {
174 : : OSL_ENSURE(mpSdrText, "Access to text of default version of ImpSdrTextAttribute (!)");
175 : 13465 : return *mpSdrText;
176 : : }
177 : 76663 : const OutlinerParaObject& getOutlinerParaObject() const
178 : : {
179 : : OSL_ENSURE(mpOutlinerParaObject, "Access to OutlinerParaObject of default version of ImpSdrTextAttribute (!)");
180 : 76663 : return *mpOutlinerParaObject;
181 : : }
182 : 43721 : bool isContour() const { return mbContour; }
183 : 43721 : bool isFitToSize() const { return mbFitToSize; }
184 : 43721 : bool isAutoFit() const { return mbAutoFit; }
185 : 30256 : bool isHideContour() const { return mbHideContour; }
186 : 43721 : bool isBlink() const { return mbBlink; }
187 : 57157 : bool isScroll() const { return mbScroll; }
188 : 43721 : bool isInEditMode() const { return mbInEditMode; }
189 : 43692 : bool isFixedCellHeight() const { return mbFixedCellHeight; }
190 : 30256 : bool isWrongSpell() const { return mbWrongSpell; }
191 : 127099 : const SdrFormTextAttribute& getSdrFormTextAttribute() const { return maSdrFormTextAttribute; }
192 : 43721 : sal_Int32 getTextLeftDistance() const { return maTextLeftDistance; }
193 : 43721 : sal_Int32 getTextUpperDistance() const { return maTextUpperDistance; }
194 : 43721 : sal_Int32 getTextRightDistance() const { return maTextRightDistance; }
195 : 43721 : sal_Int32 getTextLowerDistance() const { return maTextLowerDistance; }
196 : 30256 : sal_uInt32 getPropertiesVersion() const { return maPropertiesVersion; }
197 : 43692 : SdrTextHorzAdjust getSdrTextHorzAdjust() const { return maSdrTextHorzAdjust; }
198 : 43692 : SdrTextVertAdjust getSdrTextVertAdjust() const { return maSdrTextVertAdjust; }
199 : :
200 : : // compare operator
201 : 16471 : bool operator==(const ImpSdrTextAttribute& rCandidate) const
202 : : {
203 [ + - ]: 16471 : if(mpOutlinerParaObject != rCandidate.mpOutlinerParaObject)
204 : : {
205 [ + - ][ + - ]: 16471 : if(mpOutlinerParaObject && rCandidate.mpOutlinerParaObject)
206 : : {
207 : : // compares OPO and it's contents, but traditionally not the RedLining
208 : : // which is not seen as model, but as temporary information
209 [ + + ]: 16471 : if(!(getOutlinerParaObject() == rCandidate.getOutlinerParaObject()))
210 : : {
211 : 1343 : return false;
212 : : }
213 : :
214 : : // #i102062# for primitive visualisation, the WrongList (SpellChecking)
215 : : // is important, too, so use isWrongListEqual since there is no WrongList
216 : : // comparison in the regular OutlinerParaObject compare (since it's
217 : : // not-persistent data)
218 [ - + ]: 15128 : if(!(getOutlinerParaObject().isWrongListEqual(rCandidate.getOutlinerParaObject())))
219 : : {
220 : 0 : return false;
221 : : }
222 : : }
223 : : else
224 : : {
225 : : // only one is zero; not equal
226 : 15128 : return false;
227 : : }
228 : : }
229 : :
230 : : return (
231 : 15128 : getSdrFormTextAttribute() == rCandidate.getSdrFormTextAttribute()
232 : 15128 : && getTextLeftDistance() == rCandidate.getTextLeftDistance()
233 : 15128 : && getTextUpperDistance() == rCandidate.getTextUpperDistance()
234 : 15128 : && getTextRightDistance() == rCandidate.getTextRightDistance()
235 : 15128 : && getTextLowerDistance() == rCandidate.getTextLowerDistance()
236 : 15128 : && getPropertiesVersion() == rCandidate.getPropertiesVersion()
237 : :
238 : 15128 : && getSdrTextHorzAdjust() == rCandidate.getSdrTextHorzAdjust()
239 : 15128 : && getSdrTextVertAdjust() == rCandidate.getSdrTextVertAdjust()
240 : :
241 : 15128 : && isContour() == rCandidate.isContour()
242 : 15128 : && isFitToSize() == rCandidate.isFitToSize()
243 : 15128 : && isAutoFit() == rCandidate.isAutoFit()
244 : 15128 : && isHideContour() == rCandidate.isHideContour()
245 : 15128 : && isBlink() == rCandidate.isBlink()
246 : 15128 : && isScroll() == rCandidate.isScroll()
247 : 15128 : && isInEditMode() == rCandidate.isInEditMode()
248 : 15128 : && isFixedCellHeight() == rCandidate.isFixedCellHeight()
249 [ + + ][ + - : 243391 : && isWrongSpell() == rCandidate.isWrongSpell());
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - +
- ]
250 : : }
251 : :
252 : 260907 : static ImpSdrTextAttribute* get_global_default()
253 : : {
254 : : static ImpSdrTextAttribute* pDefault = 0;
255 : :
256 [ + + ]: 260907 : if(!pDefault)
257 : : {
258 : : // use default constructor
259 [ + - ]: 47 : pDefault = new ImpSdrTextAttribute();
260 : :
261 : : // never delete; start with RefCount 1, not 0
262 : 47 : pDefault->mnRefCount++;
263 : : }
264 : :
265 : 260907 : return pDefault;
266 : : }
267 : : };
268 : :
269 : 28367 : SdrTextAttribute::SdrTextAttribute(
270 : : const SdrText& rSdrText,
271 : : const OutlinerParaObject& rOutlinerParaObject,
272 : : XFormTextStyle eFormTextStyle,
273 : : sal_Int32 aTextLeftDistance,
274 : : sal_Int32 aTextUpperDistance,
275 : : sal_Int32 aTextRightDistance,
276 : : sal_Int32 aTextLowerDistance,
277 : : SdrTextHorzAdjust aSdrTextHorzAdjust,
278 : : SdrTextVertAdjust aSdrTextVertAdjust,
279 : : bool bContour,
280 : : bool bFitToSize,
281 : : bool bAutoFit,
282 : : bool bHideContour,
283 : : bool bBlink,
284 : : bool bScroll,
285 : : bool bInEditMode,
286 : : bool bFixedCellHeight,
287 : : bool bWrongSpell)
288 : : : mpSdrTextAttribute(new ImpSdrTextAttribute(
289 : : &rSdrText, rOutlinerParaObject, eFormTextStyle, aTextLeftDistance, aTextUpperDistance,
290 : : aTextRightDistance, aTextLowerDistance, aSdrTextHorzAdjust, aSdrTextVertAdjust, bContour,
291 [ + - ]: 28367 : bFitToSize, bAutoFit, bHideContour, bBlink, bScroll, bInEditMode, bFixedCellHeight, bWrongSpell))
292 : : {
293 : 28367 : }
294 : :
295 : 149613 : SdrTextAttribute::SdrTextAttribute()
296 : 149613 : : mpSdrTextAttribute(ImpSdrTextAttribute::get_global_default())
297 : : {
298 : 149613 : mpSdrTextAttribute->mnRefCount++;
299 : 149613 : }
300 : :
301 : 156503 : SdrTextAttribute::SdrTextAttribute(const SdrTextAttribute& rCandidate)
302 : 156503 : : mpSdrTextAttribute(rCandidate.mpSdrTextAttribute)
303 : : {
304 : 156503 : mpSdrTextAttribute->mnRefCount++;
305 : 156503 : }
306 : :
307 : 334483 : SdrTextAttribute::~SdrTextAttribute()
308 : : {
309 [ + + ]: 334483 : if(mpSdrTextAttribute->mnRefCount)
310 : : {
311 : 306116 : mpSdrTextAttribute->mnRefCount--;
312 : : }
313 : : else
314 : : {
315 [ + - ]: 28367 : delete mpSdrTextAttribute;
316 : : }
317 : 334483 : }
318 : :
319 : 111294 : bool SdrTextAttribute::isDefault() const
320 : : {
321 : 111294 : return mpSdrTextAttribute == ImpSdrTextAttribute::get_global_default();
322 : : }
323 : :
324 : 83687 : SdrTextAttribute& SdrTextAttribute::operator=(const SdrTextAttribute& rCandidate)
325 : : {
326 [ + + ]: 83687 : if(rCandidate.mpSdrTextAttribute != mpSdrTextAttribute)
327 : : {
328 [ + - ]: 28367 : if(mpSdrTextAttribute->mnRefCount)
329 : : {
330 : 28367 : mpSdrTextAttribute->mnRefCount--;
331 : : }
332 : : else
333 : : {
334 [ # # ]: 0 : delete mpSdrTextAttribute;
335 : : }
336 : :
337 : 28367 : mpSdrTextAttribute = rCandidate.mpSdrTextAttribute;
338 : 28367 : mpSdrTextAttribute->mnRefCount++;
339 : : }
340 : :
341 : 83687 : return *this;
342 : : }
343 : :
344 : 54892 : bool SdrTextAttribute::operator==(const SdrTextAttribute& rCandidate) const
345 : : {
346 [ + + ]: 54892 : if(rCandidate.mpSdrTextAttribute == mpSdrTextAttribute)
347 : : {
348 : 38355 : return true;
349 : : }
350 : :
351 [ + + ]: 16537 : if(rCandidate.isDefault() != isDefault())
352 : : {
353 : 66 : return false;
354 : : }
355 : :
356 : 54892 : return (*rCandidate.mpSdrTextAttribute == *mpSdrTextAttribute);
357 : : }
358 : :
359 : 13465 : const SdrText& SdrTextAttribute::getSdrText() const
360 : : {
361 : 13465 : return mpSdrTextAttribute->getSdrText();
362 : : }
363 : :
364 : 13465 : const OutlinerParaObject& SdrTextAttribute::getOutlinerParaObject() const
365 : : {
366 : 13465 : return mpSdrTextAttribute->getOutlinerParaObject();
367 : : }
368 : :
369 : 13465 : bool SdrTextAttribute::isContour() const
370 : : {
371 : 13465 : return mpSdrTextAttribute->isContour();
372 : : }
373 : :
374 : 13465 : bool SdrTextAttribute::isFitToSize() const
375 : : {
376 : 13465 : return mpSdrTextAttribute->isFitToSize();
377 : : }
378 : :
379 : 13465 : bool SdrTextAttribute::isAutoFit() const
380 : : {
381 : 13465 : return mpSdrTextAttribute->isAutoFit();
382 : : }
383 : :
384 : 0 : bool SdrTextAttribute::isHideContour() const
385 : : {
386 : 0 : return mpSdrTextAttribute->isHideContour();
387 : : }
388 : :
389 : 13465 : bool SdrTextAttribute::isBlink() const
390 : : {
391 : 13465 : return mpSdrTextAttribute->isBlink();
392 : : }
393 : :
394 : 26901 : bool SdrTextAttribute::isScroll() const
395 : : {
396 : 26901 : return mpSdrTextAttribute->isScroll();
397 : : }
398 : :
399 : 13465 : bool SdrTextAttribute::isInEditMode() const
400 : : {
401 : 13465 : return mpSdrTextAttribute->isInEditMode();
402 : : }
403 : :
404 : 13436 : bool SdrTextAttribute::isFixedCellHeight() const
405 : : {
406 : 13436 : return mpSdrTextAttribute->isFixedCellHeight();
407 : : }
408 : :
409 : 96843 : const SdrFormTextAttribute& SdrTextAttribute::getSdrFormTextAttribute() const
410 : : {
411 : 96843 : return mpSdrTextAttribute->getSdrFormTextAttribute();
412 : : }
413 : :
414 : 13465 : sal_Int32 SdrTextAttribute::getTextLeftDistance() const
415 : : {
416 : 13465 : return mpSdrTextAttribute->getTextLeftDistance();
417 : : }
418 : :
419 : 13465 : sal_Int32 SdrTextAttribute::getTextUpperDistance() const
420 : : {
421 : 13465 : return mpSdrTextAttribute->getTextUpperDistance();
422 : : }
423 : :
424 : 13465 : sal_Int32 SdrTextAttribute::getTextRightDistance() const
425 : : {
426 : 13465 : return mpSdrTextAttribute->getTextRightDistance();
427 : : }
428 : :
429 : 13465 : sal_Int32 SdrTextAttribute::getTextLowerDistance() const
430 : : {
431 : 13465 : return mpSdrTextAttribute->getTextLowerDistance();
432 : : }
433 : :
434 : 13436 : SdrTextHorzAdjust SdrTextAttribute::getSdrTextHorzAdjust() const
435 : : {
436 : 13436 : return mpSdrTextAttribute->getSdrTextHorzAdjust();
437 : : }
438 : :
439 : 13436 : SdrTextVertAdjust SdrTextAttribute::getSdrTextVertAdjust() const
440 : : {
441 : 13436 : return mpSdrTextAttribute->getSdrTextVertAdjust();
442 : : }
443 : :
444 : 0 : void SdrTextAttribute::getBlinkTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList) const
445 : : {
446 [ # # ]: 0 : if(isBlink())
447 : : {
448 : 0 : getSdrText().GetObject().impGetBlinkTextTiming(rAnimList);
449 : : }
450 : 0 : }
451 : :
452 : 0 : void SdrTextAttribute::getScrollTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList, double fFrameLength, double fTextLength) const
453 : : {
454 [ # # ]: 0 : if(isScroll())
455 : : {
456 : 0 : getSdrText().GetObject().impGetScrollTextTiming(rAnimList, fFrameLength, fTextLength);
457 : : }
458 : 0 : }
459 : : } // end of namespace attribute
460 : : } // end of namespace drawinglayer
461 : :
462 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|