fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrtextprimitive2d.cxx
blobc3c3e43473a5c15479e3675d4f2f629bf36d2b49
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 .
20 #include <svx/sdr/primitive2d/sdrtextprimitive2d.hxx>
21 #include <svx/svdotext.hxx>
22 #include <basegfx/color/bcolor.hxx>
23 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
24 #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
25 #include <editeng/outlobj.hxx>
26 #include <editeng/editobj.hxx>
27 #include <editeng/flditem.hxx>
28 #include <drawinglayer/geometry/viewinformation2d.hxx>
29 #include <svx/unoapi.hxx>
30 #include <svx/svdpage.hxx>
31 #include <svx/svdmodel.hxx>
32 #include <svx/svdoutl.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
35 //////////////////////////////////////////////////////////////////////////////
37 using namespace com::sun::star;
39 //////////////////////////////////////////////////////////////////////////////
41 namespace
43 sal_Int16 getPageNumber(const uno::Reference< drawing::XDrawPage >& rxDrawPage)
45 sal_Int16 nRetval(0);
46 uno::Reference< beans::XPropertySet > xSet(rxDrawPage, uno::UNO_QUERY);
48 if (xSet.is())
50 try
52 const uno::Any aNumber(xSet->getPropertyValue(OUString("Number")));
53 aNumber >>= nRetval;
55 catch(const uno::Exception&)
57 OSL_ASSERT(false);
61 return nRetval;
64 sal_Int16 getPageCount(const uno::Reference< drawing::XDrawPage >& rxDrawPage)
66 sal_Int16 nRetval(0);
67 SdrPage* pPage = GetSdrPageFromXDrawPage(rxDrawPage);
69 if(pPage && pPage->GetModel())
71 if( (pPage->GetPageNum() == 0) && !pPage->IsMasterPage() )
73 // handout page!
74 return pPage->GetModel()->getHandoutPageCount();
76 else
78 const sal_uInt16 nPageCount(pPage->GetModel()->GetPageCount());
79 nRetval = ((sal_Int16)nPageCount - 1) / 2;
83 return nRetval;
85 } // end of anonymous namespace
87 //////////////////////////////////////////////////////////////////////////////
89 namespace drawinglayer
91 namespace primitive2d
93 // support for XTEXT_PAINTSHAPE_BEGIN/XTEXT_PAINTSHAPE_END Metafile comments
94 // for slideshow. This uses TextHierarchyBlockPrimitive2D to mark a text block.
95 // ATM there is only one text block per SdrObject, this may get more in the future
96 Primitive2DSequence SdrTextPrimitive2D::encapsulateWithTextHierarchyBlockPrimitive2D(const Primitive2DSequence& rCandidate) const
98 Primitive2DReference xReference(new TextHierarchyBlockPrimitive2D(rCandidate));
99 Primitive2DSequence xRetval(&xReference, 1);
101 return xRetval;
104 SdrTextPrimitive2D::SdrTextPrimitive2D(
105 const SdrText* pSdrText,
106 const OutlinerParaObject& rOutlinerParaObject)
107 : BufferedDecompositionPrimitive2D(),
108 mrSdrText(const_cast< SdrText* >(pSdrText)),
109 maOutlinerParaObject(rOutlinerParaObject),
110 mxLastVisualizingPage(),
111 mnLastPageNumber(0),
112 mnLastPageCount(0),
113 maLastTextBackgroundColor(),
114 mbContainsPageField(false),
115 mbContainsPageCountField(false),
116 mbContainsOtherFields(false)
118 const EditTextObject& rETO = maOutlinerParaObject.GetTextObject();
120 mbContainsPageField = rETO.HasField(SvxPageField::StaticClassId());
121 mbContainsPageCountField = rETO.HasField(SvxPagesField::StaticClassId());
122 mbContainsOtherFields = rETO.HasField(SvxHeaderField::StaticClassId())
123 || rETO.HasField(SvxFooterField::StaticClassId())
124 || rETO.HasField(SvxDateTimeField::StaticClassId())
125 || rETO.HasField(SvxAuthorField::StaticClassId());
128 bool SdrTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
130 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
132 const SdrTextPrimitive2D& rCompare = (SdrTextPrimitive2D&)rPrimitive;
134 return (
136 // compare OPO and content, but not WrongList
137 getOutlinerParaObject() == rCompare.getOutlinerParaObject()
139 // also compare WrongList (not-persistent data, but visualized)
140 && getOutlinerParaObject().isWrongListEqual(rCompare.getOutlinerParaObject()));
143 return false;
146 Primitive2DSequence SdrTextPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
148 uno::Reference< drawing::XDrawPage > xCurrentlyVisualizingPage;
149 bool bCurrentlyVisualizingPageIsSet(false);
150 Color aNewTextBackgroundColor;
151 bool bNewTextBackgroundColorIsSet(false);
152 sal_Int16 nCurrentlyValidPageNumber(0);
153 sal_Int16 nCurrentlyValidPageCount(0);
155 if(getBuffered2DDecomposition().hasElements())
157 bool bDoDelete(false);
159 // check visualized page
160 if(mbContainsPageField || mbContainsPageCountField || mbContainsOtherFields)
162 // get visualized page and remember
163 xCurrentlyVisualizingPage = rViewInformation.getVisualizedPage();
164 bCurrentlyVisualizingPageIsSet = true;
166 if(xCurrentlyVisualizingPage != mxLastVisualizingPage)
168 bDoDelete = true;
171 // #i98870# check visualized PageNumber
172 if(!bDoDelete && mbContainsPageField)
174 nCurrentlyValidPageNumber = getPageNumber(xCurrentlyVisualizingPage);
176 if(nCurrentlyValidPageNumber != mnLastPageNumber)
178 bDoDelete = true;
182 // #i98870# check visualized PageCount, too
183 if(!bDoDelete && mbContainsPageCountField)
185 nCurrentlyValidPageCount = getPageCount(xCurrentlyVisualizingPage);
187 if(nCurrentlyValidPageCount != mnLastPageCount)
189 bDoDelete = true;
194 // #i101443# check change of TextBackgroundolor
195 if(!bDoDelete && getSdrText() && getSdrText()->GetModel())
197 SdrOutliner& rDrawOutliner = getSdrText()->GetModel()->GetDrawOutliner(0);
198 aNewTextBackgroundColor = rDrawOutliner.GetBackgroundColor();
199 bNewTextBackgroundColorIsSet = true;
201 if(aNewTextBackgroundColor != maLastTextBackgroundColor)
203 bDoDelete = true;
207 if(bDoDelete)
209 const_cast< SdrTextPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
213 if(!getBuffered2DDecomposition().hasElements())
215 if(!bCurrentlyVisualizingPageIsSet && mbContainsPageField)
217 xCurrentlyVisualizingPage = rViewInformation.getVisualizedPage();
220 if(!nCurrentlyValidPageNumber && mbContainsPageField)
222 nCurrentlyValidPageNumber = getPageNumber(xCurrentlyVisualizingPage);
225 if(!nCurrentlyValidPageCount && mbContainsPageCountField)
227 nCurrentlyValidPageCount = getPageCount(xCurrentlyVisualizingPage);
230 if(!bNewTextBackgroundColorIsSet && getSdrText() && getSdrText()->GetModel())
232 SdrOutliner& rDrawOutliner = getSdrText()->GetModel()->GetDrawOutliner(0);
233 aNewTextBackgroundColor = rDrawOutliner.GetBackgroundColor();
236 const_cast< SdrTextPrimitive2D* >(this)->mxLastVisualizingPage = xCurrentlyVisualizingPage;
237 const_cast< SdrTextPrimitive2D* >(this)->mnLastPageNumber = nCurrentlyValidPageNumber;
238 const_cast< SdrTextPrimitive2D* >(this)->mnLastPageCount = nCurrentlyValidPageCount;
239 const_cast< SdrTextPrimitive2D* >(this)->maLastTextBackgroundColor = aNewTextBackgroundColor;
242 // call parent
243 return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
245 } // end of namespace primitive2d
246 } // end of namespace drawinglayer
248 //////////////////////////////////////////////////////////////////////////////
250 namespace drawinglayer
252 namespace primitive2d
254 Primitive2DSequence SdrContourTextPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& aViewInformation) const
256 Primitive2DSequence aRetval;
257 getSdrText()->GetObject().impDecomposeContourTextPrimitive(aRetval, *this, aViewInformation);
259 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval);
262 SdrContourTextPrimitive2D::SdrContourTextPrimitive2D(
263 const SdrText* pSdrText,
264 const OutlinerParaObject& rOutlinerParaObject,
265 const basegfx::B2DPolyPolygon& rUnitPolyPolygon,
266 const basegfx::B2DHomMatrix& rObjectTransform)
267 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
268 maUnitPolyPolygon(rUnitPolyPolygon),
269 maObjectTransform(rObjectTransform)
273 bool SdrContourTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
275 if(SdrTextPrimitive2D::operator==(rPrimitive))
277 const SdrContourTextPrimitive2D& rCompare = (SdrContourTextPrimitive2D&)rPrimitive;
279 return (getUnitPolyPolygon() == rCompare.getUnitPolyPolygon()
280 && getObjectTransform() == rCompare.getObjectTransform());
283 return false;
286 SdrTextPrimitive2D* SdrContourTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
288 return new SdrContourTextPrimitive2D(
289 getSdrText(),
290 getOutlinerParaObject(),
291 getUnitPolyPolygon(),
292 rTransform * getObjectTransform());
295 // provide unique ID
296 ImplPrimitive2DIDBlock(SdrContourTextPrimitive2D, PRIMITIVE2D_ID_SDRCONTOURTEXTPRIMITIVE2D)
298 } // end of namespace primitive2d
299 } // end of namespace drawinglayer
301 //////////////////////////////////////////////////////////////////////////////
303 namespace drawinglayer
305 namespace primitive2d
307 Primitive2DSequence SdrPathTextPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& aViewInformation) const
309 Primitive2DSequence aRetval;
310 getSdrText()->GetObject().impDecomposePathTextPrimitive(aRetval, *this, aViewInformation);
312 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval);
315 SdrPathTextPrimitive2D::SdrPathTextPrimitive2D(
316 const SdrText* pSdrText,
317 const OutlinerParaObject& rOutlinerParaObject,
318 const basegfx::B2DPolyPolygon& rPathPolyPolygon,
319 const attribute::SdrFormTextAttribute& rSdrFormTextAttribute)
320 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
321 maPathPolyPolygon(rPathPolyPolygon),
322 maSdrFormTextAttribute(rSdrFormTextAttribute)
326 bool SdrPathTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
328 if(SdrTextPrimitive2D::operator==(rPrimitive))
330 const SdrPathTextPrimitive2D& rCompare = (SdrPathTextPrimitive2D&)rPrimitive;
332 return (getPathPolyPolygon() == rCompare.getPathPolyPolygon()
333 && getSdrFormTextAttribute() == rCompare.getSdrFormTextAttribute());
336 return false;
339 SdrTextPrimitive2D* SdrPathTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
341 basegfx::B2DPolyPolygon aNewPolyPolygon(getPathPolyPolygon());
342 aNewPolyPolygon.transform(rTransform);
344 return new SdrPathTextPrimitive2D(
345 getSdrText(),
346 getOutlinerParaObject(),
347 aNewPolyPolygon,
348 getSdrFormTextAttribute());
351 // provide unique ID
352 ImplPrimitive2DIDBlock(SdrPathTextPrimitive2D, PRIMITIVE2D_ID_SDRPATHTEXTPRIMITIVE2D)
354 } // end of namespace primitive2d
355 } // end of namespace drawinglayer
357 //////////////////////////////////////////////////////////////////////////////
359 namespace drawinglayer
361 namespace primitive2d
363 Primitive2DSequence SdrBlockTextPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& aViewInformation) const
365 Primitive2DSequence aRetval;
366 getSdrText()->GetObject().impDecomposeBlockTextPrimitive(aRetval, *this, aViewInformation);
368 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval);
371 SdrBlockTextPrimitive2D::SdrBlockTextPrimitive2D(
372 const SdrText* pSdrText,
373 const OutlinerParaObject& rOutlinerParaObject,
374 const basegfx::B2DHomMatrix& rTextRangeTransform,
375 SdrTextHorzAdjust aSdrTextHorzAdjust,
376 SdrTextVertAdjust aSdrTextVertAdjust,
377 bool bFixedCellHeight,
378 bool bUnlimitedPage,
379 bool bCellText,
380 bool bWordWrap,
381 bool bClipOnBounds)
382 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
383 maTextRangeTransform(rTextRangeTransform),
384 maSdrTextHorzAdjust(aSdrTextHorzAdjust),
385 maSdrTextVertAdjust(aSdrTextVertAdjust),
386 mbFixedCellHeight(bFixedCellHeight),
387 mbUnlimitedPage(bUnlimitedPage),
388 mbCellText(bCellText),
389 mbWordWrap(bWordWrap),
390 mbClipOnBounds(bClipOnBounds)
394 bool SdrBlockTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
396 if(SdrTextPrimitive2D::operator==(rPrimitive))
398 const SdrBlockTextPrimitive2D& rCompare = (SdrBlockTextPrimitive2D&)rPrimitive;
400 return (getTextRangeTransform() == rCompare.getTextRangeTransform()
401 && getSdrTextHorzAdjust() == rCompare.getSdrTextHorzAdjust()
402 && getSdrTextVertAdjust() == rCompare.getSdrTextVertAdjust()
403 && isFixedCellHeight() == rCompare.isFixedCellHeight()
404 && getUnlimitedPage() == rCompare.getUnlimitedPage()
405 && getCellText() == rCompare.getCellText()
406 && getWordWrap() == rCompare.getWordWrap()
407 && getClipOnBounds() == rCompare.getClipOnBounds());
410 return false;
413 SdrTextPrimitive2D* SdrBlockTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
415 return new SdrBlockTextPrimitive2D(
416 getSdrText(),
417 getOutlinerParaObject(),
418 rTransform * getTextRangeTransform(),
419 getSdrTextHorzAdjust(),
420 getSdrTextVertAdjust(),
421 isFixedCellHeight(),
422 getUnlimitedPage(),
423 getCellText(),
424 getWordWrap(),
425 getClipOnBounds());
428 // provide unique ID
429 ImplPrimitive2DIDBlock(SdrBlockTextPrimitive2D, PRIMITIVE2D_ID_SDRBLOCKTEXTPRIMITIVE2D)
431 } // end of namespace primitive2d
432 } // end of namespace drawinglayer
434 //////////////////////////////////////////////////////////////////////////////
436 namespace drawinglayer
438 namespace primitive2d
440 Primitive2DSequence SdrAutoFitTextPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& aViewInformation) const
442 Primitive2DSequence aRetval;
443 getSdrText()->GetObject().impDecomposeAutoFitTextPrimitive(aRetval, *this, aViewInformation);
445 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval);
448 SdrAutoFitTextPrimitive2D::SdrAutoFitTextPrimitive2D(
449 const SdrText* pSdrText,
450 const OutlinerParaObject& rParaObj,
451 const ::basegfx::B2DHomMatrix& rTextRangeTransform,
452 bool bWordWrap)
453 : SdrTextPrimitive2D(pSdrText, rParaObj),
454 maTextRangeTransform(rTextRangeTransform),
455 mbWordWrap(bWordWrap)
459 bool SdrAutoFitTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
461 if(SdrTextPrimitive2D::operator==(rPrimitive))
463 const SdrBlockTextPrimitive2D& rCompare = (SdrBlockTextPrimitive2D&)rPrimitive;
465 return (getTextRangeTransform() == rCompare.getTextRangeTransform()
466 && getWordWrap() == rCompare.getWordWrap());
469 return false;
472 SdrTextPrimitive2D* SdrAutoFitTextPrimitive2D::createTransformedClone(const ::basegfx::B2DHomMatrix& rTransform) const
474 return new SdrAutoFitTextPrimitive2D(getSdrText(), getOutlinerParaObject(), rTransform * getTextRangeTransform(), getWordWrap());
477 // provide unique ID
478 ImplPrimitive2DIDBlock(SdrAutoFitTextPrimitive2D, PRIMITIVE2D_ID_SDRAUTOFITTEXTPRIMITIVE2D)
480 } // end of namespace primitive2d
481 } // end of namespace drawinglayer
483 //////////////////////////////////////////////////////////////////////////////
485 namespace drawinglayer
487 namespace primitive2d
489 Primitive2DSequence SdrStretchTextPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& aViewInformation) const
491 Primitive2DSequence aRetval;
492 getSdrText()->GetObject().impDecomposeStretchTextPrimitive(aRetval, *this, aViewInformation);
494 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval);
497 SdrStretchTextPrimitive2D::SdrStretchTextPrimitive2D(
498 const SdrText* pSdrText,
499 const OutlinerParaObject& rOutlinerParaObject,
500 const basegfx::B2DHomMatrix& rTextRangeTransform,
501 bool bFixedCellHeight)
502 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
503 maTextRangeTransform(rTextRangeTransform),
504 mbFixedCellHeight(bFixedCellHeight)
508 bool SdrStretchTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
510 if(SdrTextPrimitive2D::operator==(rPrimitive))
512 const SdrStretchTextPrimitive2D& rCompare = (SdrStretchTextPrimitive2D&)rPrimitive;
514 return (getTextRangeTransform() == rCompare.getTextRangeTransform()
515 && isFixedCellHeight() == rCompare.isFixedCellHeight());
518 return false;
521 SdrTextPrimitive2D* SdrStretchTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
523 return new SdrStretchTextPrimitive2D(
524 getSdrText(),
525 getOutlinerParaObject(),
526 rTransform * getTextRangeTransform(),
527 isFixedCellHeight());
530 // provide unique ID
531 ImplPrimitive2DIDBlock(SdrStretchTextPrimitive2D, PRIMITIVE2D_ID_SDRSTRETCHTEXTPRIMITIVE2D)
533 } // end of namespace primitive2d
534 } // end of namespace drawinglayer
536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */