1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrtextprimitive2d.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrtextprimitive2d.hxx>
34 #include <svx/svdotext.hxx>
35 #include <basegfx/color/bcolor.hxx>
36 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
37 #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
38 #include <svx/outlobj.hxx>
39 #include <svx/editobj.hxx>
40 #include <svx/flditem.hxx>
41 #include <drawinglayer/geometry/viewinformation2d.hxx>
43 #include <svx/svdpage.hxx>
44 #include <svx/svdmodel.hxx>
45 #include <svx/svdoutl.hxx>
46 #include <com/sun/star/beans/XPropertySet.hpp>
48 //////////////////////////////////////////////////////////////////////////////
50 using namespace com::sun::star
;
52 //////////////////////////////////////////////////////////////////////////////
56 sal_Int16
getPageNumber(const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
)
59 uno::Reference
< beans::XPropertySet
> xSet(rxDrawPage
, uno::UNO_QUERY
);
65 const uno::Any
aNumber(xSet
->getPropertyValue(::rtl::OUString::createFromAscii("Number")));
68 catch(const uno::Exception
&)
77 sal_Int16
getPageCount(const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
)
80 SdrPage
* pPage
= GetSdrPageFromXDrawPage(rxDrawPage
);
82 if(pPage
&& pPage
->GetModel())
84 const sal_uInt16
nPageCount(pPage
->GetModel()->GetPageCount());
85 nRetval
= ((sal_Int16
)nPageCount
- 1) / 2;
90 } // end of anonymous namespace
92 //////////////////////////////////////////////////////////////////////////////
94 namespace drawinglayer
98 // support for XTEXT_PAINTSHAPE_BEGIN/XTEXT_PAINTSHAPE_END Metafile comments
99 // for slideshow. This uses TextHierarchyBlockPrimitive2D to mark a text block.
100 // ATM there is only one text block per SdrObject, this may get more in the future
101 Primitive2DSequence
SdrTextPrimitive2D::encapsulateWithTextHierarchyBlockPrimitive2D(const Primitive2DSequence
& rCandidate
) const
103 Primitive2DReference
xReference(new TextHierarchyBlockPrimitive2D(rCandidate
));
104 Primitive2DSequence
xRetval(&xReference
, 1);
109 SdrTextPrimitive2D::SdrTextPrimitive2D(
110 const SdrText
* pSdrText
,
111 const OutlinerParaObject
& rOutlinerParaObject
)
113 mrSdrText(const_cast< SdrText
* >(pSdrText
)),
114 maOutlinerParaObject(rOutlinerParaObject
),
115 mxLastVisualizingPage(),
118 maLastTextBackgroundColor(),
119 mbLastSpellCheck(false),
120 mbContainsPageField(false),
121 mbContainsPageCountField(false),
122 mbContainsOtherFields(false)
124 const EditTextObject
& rETO
= maOutlinerParaObject
.GetTextObject();
126 mbContainsPageField
= rETO
.HasField(SvxPageField::StaticType());
127 mbContainsPageCountField
= rETO
.HasField(SvxPagesField::StaticType());
128 mbContainsOtherFields
= rETO
.HasField(SvxHeaderField::StaticType())
129 || rETO
.HasField(SvxFooterField::StaticType())
130 || rETO
.HasField(SvxDateTimeField::StaticType())
131 || rETO
.HasField(SvxAuthorField::StaticType());
134 bool SdrTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
136 if(BasePrimitive2D::operator==(rPrimitive
))
138 const SdrTextPrimitive2D
& rCompare
= (SdrTextPrimitive2D
&)rPrimitive
;
140 return (getOutlinerParaObject() == rCompare
.getOutlinerParaObject());
146 Primitive2DSequence
SdrTextPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
148 const bool bCurrentSpellCheck(getSdrText()
149 ? getSdrText()->GetObject().impCheckSpellCheckForDecomposeTextPrimitive()
151 uno::Reference
< drawing::XDrawPage
> xCurrentlyVisualizingPage
;
152 bool bCurrentlyVisualizingPageIsSet(false);
153 Color aNewTextBackgroundColor
;
154 bool bNewTextBackgroundColorIsSet(false);
155 sal_Int16
nCurrentlyValidPageNumber(0);
156 sal_Int16
nCurrentlyValidPageCount(0);
158 if(getLocalDecomposition().hasElements())
160 bool bDoDelete(getLastSpellCheck() != bCurrentSpellCheck
);
162 // check visualized page
163 if(!bDoDelete
&& (mbContainsPageField
|| mbContainsPageCountField
|| mbContainsOtherFields
))
165 // get visualized page and remember
166 xCurrentlyVisualizingPage
= rViewInformation
.getVisualizedPage();
167 bCurrentlyVisualizingPageIsSet
= true;
169 if(xCurrentlyVisualizingPage
!= mxLastVisualizingPage
)
174 // #i98870# check visualized PageNumber
175 if(!bDoDelete
&& mbContainsPageField
)
177 nCurrentlyValidPageNumber
= getPageNumber(xCurrentlyVisualizingPage
);
179 if(nCurrentlyValidPageNumber
!= mnLastPageNumber
)
185 // #i98870# check visualized PageCount, too
186 if(!bDoDelete
&& mbContainsPageCountField
)
188 nCurrentlyValidPageCount
= getPageCount(xCurrentlyVisualizingPage
);
190 if(nCurrentlyValidPageCount
!= mnLastPageCount
)
197 // #i101443# check change of TextBackgroundolor
198 if(!bDoDelete
&& getSdrText() && getSdrText()->GetModel())
200 SdrOutliner
& rDrawOutliner
= getSdrText()->GetModel()->GetDrawOutliner(0);
201 aNewTextBackgroundColor
= rDrawOutliner
.GetBackgroundColor();
202 bNewTextBackgroundColorIsSet
= true;
204 if(aNewTextBackgroundColor
!= maLastTextBackgroundColor
)
212 const_cast< SdrTextPrimitive2D
* >(this)->setLocalDecomposition(Primitive2DSequence());
216 if(!getLocalDecomposition().hasElements())
218 if(!bCurrentlyVisualizingPageIsSet
&& mbContainsPageField
)
220 xCurrentlyVisualizingPage
= rViewInformation
.getVisualizedPage();
223 if(!nCurrentlyValidPageNumber
&& mbContainsPageField
)
225 nCurrentlyValidPageNumber
= getPageNumber(xCurrentlyVisualizingPage
);
228 if(!nCurrentlyValidPageCount
&& mbContainsPageCountField
)
230 nCurrentlyValidPageCount
= getPageCount(xCurrentlyVisualizingPage
);
233 if(!bNewTextBackgroundColorIsSet
&& getSdrText() && getSdrText()->GetModel())
235 SdrOutliner
& rDrawOutliner
= getSdrText()->GetModel()->GetDrawOutliner(0);
236 aNewTextBackgroundColor
= rDrawOutliner
.GetBackgroundColor();
239 const_cast< SdrTextPrimitive2D
* >(this)->setLastSpellCheck(bCurrentSpellCheck
);
240 const_cast< SdrTextPrimitive2D
* >(this)->mxLastVisualizingPage
= xCurrentlyVisualizingPage
;
241 const_cast< SdrTextPrimitive2D
* >(this)->mnLastPageNumber
= nCurrentlyValidPageNumber
;
242 const_cast< SdrTextPrimitive2D
* >(this)->mnLastPageCount
= nCurrentlyValidPageCount
;
243 const_cast< SdrTextPrimitive2D
* >(this)->maLastTextBackgroundColor
= aNewTextBackgroundColor
;
247 return BasePrimitive2D::get2DDecomposition(rViewInformation
);
249 } // end of namespace primitive2d
250 } // end of namespace drawinglayer
252 //////////////////////////////////////////////////////////////////////////////
254 namespace drawinglayer
256 namespace primitive2d
258 Primitive2DSequence
SdrContourTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
260 Primitive2DSequence aRetval
;
261 const bool bCurrentSpellCheck(getSdrText()
262 ? getSdrText()->GetObject().impDecomposeContourTextPrimitive(aRetval
, *this, aViewInformation
)
265 if(getLastSpellCheck() != bCurrentSpellCheck
)
267 // remember last spell check state; this is part of the decomposition source data definition
268 const_cast< SdrContourTextPrimitive2D
* >(this)->setLastSpellCheck(bCurrentSpellCheck
);
271 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
274 SdrContourTextPrimitive2D::SdrContourTextPrimitive2D(
275 const SdrText
* pSdrText
,
276 const OutlinerParaObject
& rOutlinerParaObject
,
277 const basegfx::B2DPolyPolygon
& rUnitPolyPolygon
,
278 const basegfx::B2DHomMatrix
& rObjectTransform
)
279 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
280 maUnitPolyPolygon(rUnitPolyPolygon
),
281 maObjectTransform(rObjectTransform
)
285 bool SdrContourTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
287 if(SdrTextPrimitive2D::operator==(rPrimitive
))
289 const SdrContourTextPrimitive2D
& rCompare
= (SdrContourTextPrimitive2D
&)rPrimitive
;
291 return (getUnitPolyPolygon() == rCompare
.getUnitPolyPolygon()
292 && getObjectTransform() == rCompare
.getObjectTransform());
298 SdrTextPrimitive2D
* SdrContourTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
300 return new SdrContourTextPrimitive2D(
302 getOutlinerParaObject(),
303 getUnitPolyPolygon(),
304 rTransform
* getObjectTransform());
308 ImplPrimitrive2DIDBlock(SdrContourTextPrimitive2D
, PRIMITIVE2D_ID_SDRCONTOURTEXTPRIMITIVE2D
)
310 } // end of namespace primitive2d
311 } // end of namespace drawinglayer
313 //////////////////////////////////////////////////////////////////////////////
315 namespace drawinglayer
317 namespace primitive2d
319 Primitive2DSequence
SdrPathTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
321 Primitive2DSequence aRetval
;
322 const bool bCurrentSpellCheck(getSdrText()
323 ? getSdrText()->GetObject().impDecomposePathTextPrimitive(aRetval
, *this, aViewInformation
)
326 if(getLastSpellCheck() != bCurrentSpellCheck
)
328 // remember last spell check state; this is part of the decomposition source data definition
329 const_cast< SdrPathTextPrimitive2D
* >(this)->setLastSpellCheck(bCurrentSpellCheck
);
332 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
335 SdrPathTextPrimitive2D::SdrPathTextPrimitive2D(
336 const SdrText
* pSdrText
,
337 const OutlinerParaObject
& rOutlinerParaObject
,
338 const basegfx::B2DPolyPolygon
& rPathPolyPolygon
,
339 const attribute::SdrFormTextAttribute
& rSdrFormTextAttribute
)
340 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
341 maPathPolyPolygon(rPathPolyPolygon
),
342 maSdrFormTextAttribute(rSdrFormTextAttribute
)
346 bool SdrPathTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
348 if(SdrTextPrimitive2D::operator==(rPrimitive
))
350 const SdrPathTextPrimitive2D
& rCompare
= (SdrPathTextPrimitive2D
&)rPrimitive
;
352 return (getPathPolyPolygon() == rCompare
.getPathPolyPolygon()
353 && getSdrFormTextAttribute() == rCompare
.getSdrFormTextAttribute());
359 SdrTextPrimitive2D
* SdrPathTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
361 basegfx::B2DPolyPolygon
aNewPolyPolygon(getPathPolyPolygon());
362 aNewPolyPolygon
.transform(rTransform
);
364 return new SdrPathTextPrimitive2D(
366 getOutlinerParaObject(),
368 getSdrFormTextAttribute());
372 ImplPrimitrive2DIDBlock(SdrPathTextPrimitive2D
, PRIMITIVE2D_ID_SDRPATHTEXTPRIMITIVE2D
)
374 } // end of namespace primitive2d
375 } // end of namespace drawinglayer
377 //////////////////////////////////////////////////////////////////////////////
379 namespace drawinglayer
381 namespace primitive2d
383 Primitive2DSequence
SdrBlockTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
385 Primitive2DSequence aRetval
;
386 const bool bCurrentSpellCheck(getSdrText()
387 ? getSdrText()->GetObject().impDecomposeBlockTextPrimitive(aRetval
, *this, aViewInformation
)
390 if(getLastSpellCheck() != bCurrentSpellCheck
)
392 // remember last spell check state; this is part of the decomposition source data definition
393 const_cast< SdrBlockTextPrimitive2D
* >(this)->setLastSpellCheck(bCurrentSpellCheck
);
396 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
399 SdrBlockTextPrimitive2D::SdrBlockTextPrimitive2D(
400 const SdrText
* pSdrText
,
401 const OutlinerParaObject
& rOutlinerParaObject
,
402 const basegfx::B2DHomMatrix
& rTextRangeTransform
,
406 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
407 maTextRangeTransform(rTextRangeTransform
),
408 mbUnlimitedPage(bUnlimitedPage
),
409 mbCellText(bCellText
),
410 mbWordWrap(bWordWrap
)
414 bool SdrBlockTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
416 if(SdrTextPrimitive2D::operator==(rPrimitive
))
418 const SdrBlockTextPrimitive2D
& rCompare
= (SdrBlockTextPrimitive2D
&)rPrimitive
;
420 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
421 && getUnlimitedPage() == rCompare
.getUnlimitedPage()
422 && getCellText() == rCompare
.getCellText()
423 && getWordWrap() == rCompare
.getWordWrap());
429 SdrTextPrimitive2D
* SdrBlockTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
431 return new SdrBlockTextPrimitive2D(
433 getOutlinerParaObject(),
434 rTransform
* getTextRangeTransform(),
441 ImplPrimitrive2DIDBlock(SdrBlockTextPrimitive2D
, PRIMITIVE2D_ID_SDRBLOCKTEXTPRIMITIVE2D
)
443 } // end of namespace primitive2d
444 } // end of namespace drawinglayer
446 //////////////////////////////////////////////////////////////////////////////
448 namespace drawinglayer
450 namespace primitive2d
452 Primitive2DSequence
SdrAutoFitTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
454 Primitive2DSequence aRetval
;
455 const bool bCurrentSpellCheck(getSdrText()->GetObject().impDecomposeAutoFitTextPrimitive(aRetval
, *this, aViewInformation
));
457 if(getLastSpellCheck() != bCurrentSpellCheck
)
459 // remember last spell check state; this is part of the decomposition source data definition
460 const_cast< SdrAutoFitTextPrimitive2D
* >(this)->setLastSpellCheck(bCurrentSpellCheck
);
463 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
466 SdrAutoFitTextPrimitive2D::SdrAutoFitTextPrimitive2D(
467 const SdrText
* pSdrText
,
468 const OutlinerParaObject
& rParaObj
,
469 const ::basegfx::B2DHomMatrix
& rTextRangeTransform
,
471 : SdrTextPrimitive2D(pSdrText
, rParaObj
),
472 maTextRangeTransform(rTextRangeTransform
),
473 mbWordWrap(bWordWrap
)
477 bool SdrAutoFitTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
479 if(SdrTextPrimitive2D::operator==(rPrimitive
))
481 const SdrBlockTextPrimitive2D
& rCompare
= (SdrBlockTextPrimitive2D
&)rPrimitive
;
483 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
484 && getWordWrap() == rCompare
.getWordWrap());
490 SdrTextPrimitive2D
* SdrAutoFitTextPrimitive2D::createTransformedClone(const ::basegfx::B2DHomMatrix
& rTransform
) const
492 return new SdrAutoFitTextPrimitive2D(getSdrText(), getOutlinerParaObject(), rTransform
* getTextRangeTransform(), getWordWrap());
496 ImplPrimitrive2DIDBlock(SdrAutoFitTextPrimitive2D
, PRIMITIVE2D_ID_SDRAUTOFITTEXTPRIMITIVE2D
)
498 } // end of namespace primitive2d
499 } // end of namespace drawinglayer
501 //////////////////////////////////////////////////////////////////////////////
503 namespace drawinglayer
505 namespace primitive2d
507 Primitive2DSequence
SdrStretchTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
509 Primitive2DSequence aRetval
;
510 const bool bCurrentSpellCheck(getSdrText()
511 ? getSdrText()->GetObject().impDecomposeStretchTextPrimitive(aRetval
, *this, aViewInformation
)
514 if(getLastSpellCheck() != bCurrentSpellCheck
)
516 // remember last spell check state; this is part of the decomposition source data definition
517 const_cast< SdrStretchTextPrimitive2D
* >(this)->setLastSpellCheck(bCurrentSpellCheck
);
520 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
523 SdrStretchTextPrimitive2D::SdrStretchTextPrimitive2D(
524 const SdrText
* pSdrText
,
525 const OutlinerParaObject
& rOutlinerParaObject
,
526 const basegfx::B2DHomMatrix
& rTextRangeTransform
)
527 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
528 maTextRangeTransform(rTextRangeTransform
)
532 bool SdrStretchTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
534 if(SdrTextPrimitive2D::operator==(rPrimitive
))
536 const SdrStretchTextPrimitive2D
& rCompare
= (SdrStretchTextPrimitive2D
&)rPrimitive
;
538 return (getTextRangeTransform() == rCompare
.getTextRangeTransform());
544 SdrTextPrimitive2D
* SdrStretchTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
546 return new SdrStretchTextPrimitive2D(
548 getOutlinerParaObject(),
549 rTransform
* getTextRangeTransform());
553 ImplPrimitrive2DIDBlock(SdrStretchTextPrimitive2D
, PRIMITIVE2D_ID_SDRSTRETCHTEXTPRIMITIVE2D
)
555 } // end of namespace primitive2d
556 } // end of namespace drawinglayer
558 //////////////////////////////////////////////////////////////////////////////