xref: /AOO41X/main/svx/source/svdraw/svdotext.cxx (revision 9dcd2d78ee6377e8ad1e2e01efd517f26f4562c3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svdotext.hxx>
28 #include "svx/svditext.hxx"
29 #include <svx/svdpagv.hxx>  // fuer Abfrage im Paint, ob das
30 #include <svx/svdview.hxx>  // Objekt gerade editiert wird
31 #include <svx/svdpage.hxx>  // und fuer AnimationHandler (Laufschrift)
32 #include <svx/svdetc.hxx>
33 #include <svx/svdoutl.hxx>
34 #include <svx/svdmodel.hxx>  // OutlinerDefaults
35 #include "svx/svdglob.hxx"  // Stringcache
36 #include "svx/svdstr.hrc"   // Objektname
37 #include <editeng/writingmodeitem.hxx>
38 #include <svx/sdtfchim.hxx>
39 #include <svtools/colorcfg.hxx>
40 #include <editeng/eeitem.hxx>
41 #include <editeng/editstat.hxx>
42 #include <editeng/outlobj.hxx>
43 #include <editeng/editobj.hxx>
44 #include <editeng/outliner.hxx>
45 #include <editeng/fhgtitem.hxx>
46 #include <svl/itempool.hxx>
47 #include <editeng/adjitem.hxx>
48 #include <editeng/flditem.hxx>
49 #include <svx/xftouit.hxx>
50 #include <vcl/salbtype.hxx>     // FRound
51 #include <svx/xflgrit.hxx>
52 #include <svx/svdpool.hxx>
53 #include <svx/xflclit.hxx>
54 #include <svl/style.hxx>
55 #include <editeng/editeng.hxx>
56 #include <svl/itemiter.hxx>
57 #include <svx/sdr/properties/textproperties.hxx>
58 #include <vcl/metaact.hxx>
59 #include <svx/sdr/contact/viewcontactoftextobj.hxx>
60 #include <basegfx/tuple/b2dtuple.hxx>
61 #include <basegfx/matrix/b2dhommatrix.hxx>
62 #include <basegfx/polygon/b2dpolygon.hxx>
63 #include <drawinglayer/geometry/viewinformation2d.hxx>
64 #include <vcl/virdev.hxx>
65 #include <basegfx/matrix/b2dhommatrixtools.hxx>
66 
67 //////////////////////////////////////////////////////////////////////////////
68 
69 using namespace com::sun::star;
70 
71 //////////////////////////////////////////////////////////////////////////////
72 // #104018# replace macros above with type-safe methods
73 inline double ImplTwipsToMM(double fVal) { return (fVal * (127.0 / 72.0)); }
74 inline double ImplMMToTwips(double fVal) { return (fVal * (72.0 / 127.0)); }
75 
76 ////////////////////////////////////////////////////////////////////////////////////////////////////
77 //
78 //  @@@@@@ @@@@@ @@   @@ @@@@@@  @@@@  @@@@@  @@@@@@
79 //    @@   @@    @@@ @@@   @@   @@  @@ @@  @@     @@
80 //    @@   @@     @@@@@    @@   @@  @@ @@  @@     @@
81 //    @@   @@@@    @@@     @@   @@  @@ @@@@@      @@
82 //    @@   @@     @@@@@    @@   @@  @@ @@  @@     @@
83 //    @@   @@    @@@ @@@   @@   @@  @@ @@  @@ @@  @@
84 //    @@   @@@@@ @@   @@   @@    @@@@  @@@@@   @@@@
85 //
86 ////////////////////////////////////////////////////////////////////////////////////////////////////
87 
88 //////////////////////////////////////////////////////////////////////////////
89 // BaseProperties section
90 
91 sdr::properties::BaseProperties* SdrTextObj::CreateObjectSpecificProperties()
92 {
93     return new sdr::properties::TextProperties(*this);
94 }
95 
96 //////////////////////////////////////////////////////////////////////////////
97 // DrawContact section
98 
99 sdr::contact::ViewContact* SdrTextObj::CreateObjectSpecificViewContact()
100 {
101     return new sdr::contact::ViewContactOfTextObj(*this);
102 }
103 
104 //////////////////////////////////////////////////////////////////////////////
105 
106 TYPEINIT1(SdrTextObj,SdrAttrObj);
107 
108 SdrTextObj::SdrTextObj()
109 :   SdrAttrObj(),
110     mpText(NULL),
111     pEdtOutl(NULL),
112     pFormTextBoundRect(NULL),
113     eTextKind(OBJ_TEXT)
114 {
115     bTextSizeDirty=sal_False;
116     bTextFrame=sal_False;
117     bNoShear=sal_False;
118     bNoRotate=sal_False;
119     bNoMirror=sal_False;
120     bDisableAutoWidthOnDragging=sal_False;
121 
122     // #101684#
123     mbInEditMode = sal_False;
124 
125     // #111096#
126     mbTextHidden = sal_False;
127 
128     // #111096#
129     mbTextAnimationAllowed = sal_True;
130 
131     // #108784#
132     maTextEditOffset = Point(0, 0);
133 
134     // #i25616#
135     mbSupportTextIndentingOnLineWidthChange = sal_True;
136 }
137 
138 SdrTextObj::SdrTextObj(const Rectangle& rNewRect)
139 :   SdrAttrObj(),
140     aRect(rNewRect),
141     mpText(NULL),
142     pEdtOutl(NULL),
143     pFormTextBoundRect(NULL)
144 {
145     bTextSizeDirty=sal_False;
146     bTextFrame=sal_False;
147     bNoShear=sal_False;
148     bNoRotate=sal_False;
149     bNoMirror=sal_False;
150     bDisableAutoWidthOnDragging=sal_False;
151     ImpJustifyRect(aRect);
152 
153     // #101684#
154     mbInEditMode = sal_False;
155 
156     // #111096#
157     mbTextHidden = sal_False;
158 
159     // #111096#
160     mbTextAnimationAllowed = sal_True;
161 
162     // #108784#
163     maTextEditOffset = Point(0, 0);
164 
165     // #i25616#
166     mbSupportTextIndentingOnLineWidthChange = sal_True;
167 }
168 
169 SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind)
170 :   SdrAttrObj(),
171     mpText(NULL),
172     pEdtOutl(NULL),
173     pFormTextBoundRect(NULL),
174     eTextKind(eNewTextKind)
175 {
176     bTextSizeDirty=sal_False;
177     bTextFrame=sal_True;
178     bNoShear=sal_True;
179     bNoRotate=sal_False;
180     bNoMirror=sal_True;
181     bDisableAutoWidthOnDragging=sal_False;
182 
183     // #101684#
184     mbInEditMode = sal_False;
185 
186     // #111096#
187     mbTextHidden = sal_False;
188 
189     // #111096#
190     mbTextAnimationAllowed = sal_True;
191 
192     // #108784#
193     maTextEditOffset = Point(0, 0);
194 
195     // #i25616#
196     mbSupportTextIndentingOnLineWidthChange = sal_True;
197 }
198 
199 SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind, const Rectangle& rNewRect)
200 :   SdrAttrObj(),
201     aRect(rNewRect),
202     mpText(NULL),
203     pEdtOutl(NULL),
204     pFormTextBoundRect(NULL),
205     eTextKind(eNewTextKind)
206 {
207     bTextSizeDirty=sal_False;
208     bTextFrame=sal_True;
209     bNoShear=sal_True;
210     bNoRotate=sal_False;
211     bNoMirror=sal_True;
212     bDisableAutoWidthOnDragging=sal_False;
213     ImpJustifyRect(aRect);
214 
215     // #101684#
216     mbInEditMode = sal_False;
217 
218     // #111096#
219     mbTextHidden = sal_False;
220 
221     // #111096#
222     mbTextAnimationAllowed = sal_True;
223 
224     // #108784#
225     maTextEditOffset = Point(0, 0);
226 
227     // #i25616#
228     mbSupportTextIndentingOnLineWidthChange = sal_True;
229 }
230 
231 SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind, const Rectangle& rNewRect, SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat)
232 :   SdrAttrObj(),
233     aRect(rNewRect),
234     mpText(NULL),
235     pEdtOutl(NULL),
236     pFormTextBoundRect(NULL),
237     eTextKind(eNewTextKind)
238 {
239     bTextSizeDirty=sal_False;
240     bTextFrame=sal_True;
241     bNoShear=sal_True;
242     bNoRotate=sal_False;
243     bNoMirror=sal_True;
244     bDisableAutoWidthOnDragging=sal_False;
245     ImpJustifyRect(aRect);
246 
247     NbcSetText(rInput, rBaseURL, eFormat);
248 
249     // #101684#
250     mbInEditMode = sal_False;
251 
252     // #111096#
253     mbTextHidden = sal_False;
254 
255     // #111096#
256     mbTextAnimationAllowed = sal_True;
257 
258     // #108784#
259     maTextEditOffset = Point(0, 0);
260 
261     // #i25616#
262     mbSupportTextIndentingOnLineWidthChange = sal_True;
263 }
264 
265 SdrTextObj::~SdrTextObj()
266 {
267     if( pModel )
268     {
269         SdrOutliner& rOutl = pModel->GetHitTestOutliner();
270         if( rOutl.GetTextObj() == this )
271             rOutl.SetTextObj( NULL );
272     }
273 
274     if(mpText!=NULL)
275         delete mpText;
276 
277     if (pFormTextBoundRect!=NULL)
278         delete pFormTextBoundRect;
279 
280     ImpLinkAbmeldung();
281 }
282 
283 void SdrTextObj::FitFrameToTextSize()
284 {
285     DBG_ASSERT(pModel!=NULL,"SdrTextObj::FitFrameToTextSize(): pModel=NULL!");
286     ImpJustifyRect(aRect);
287 
288     SdrText* pText = getActiveText();
289     if( pText!=NULL && pText->GetOutlinerParaObject() && pModel!=NULL)
290     {
291         SdrOutliner& rOutliner=ImpGetDrawOutliner();
292         rOutliner.SetPaperSize(Size(aRect.Right()-aRect.Left(),aRect.Bottom()-aRect.Top()));
293         rOutliner.SetUpdateMode(sal_True);
294         rOutliner.SetText(*pText->GetOutlinerParaObject());
295         Rectangle aTextRect;
296         Size aNewSize(rOutliner.CalcTextSize());
297         rOutliner.Clear();
298         aNewSize.Width()++; // wegen evtl. Rundungsfehler
299         aNewSize.Width()+=GetTextLeftDistance()+GetTextRightDistance();
300         aNewSize.Height()+=GetTextUpperDistance()+GetTextLowerDistance();
301         Rectangle aNewRect(aRect);
302         aNewRect.SetSize(aNewSize);
303         ImpJustifyRect(aNewRect);
304         if (aNewRect!=aRect) {
305             SetLogicRect(aNewRect);
306         }
307     }
308 }
309 
310 void SdrTextObj::NbcSetText(const XubString& rStr)
311 {
312     SdrOutliner& rOutliner=ImpGetDrawOutliner();
313     rOutliner.SetStyleSheet( 0, GetStyleSheet());
314     //OutputDevice* pRef1=rOutliner.GetRefDevice();
315     rOutliner.SetUpdateMode(sal_True);
316     rOutliner.SetText(rStr,rOutliner.GetParagraph( 0 ));
317     OutlinerParaObject* pNewText=rOutliner.CreateParaObject();
318     Size aSiz(rOutliner.CalcTextSize());
319     //OutputDevice* pRef2=rOutliner.GetRefDevice();
320     rOutliner.Clear();
321     NbcSetOutlinerParaObject(pNewText);
322     aTextSize=aSiz;
323     bTextSizeDirty=sal_False;
324 }
325 
326 void SdrTextObj::SetText(const XubString& rStr)
327 {
328     Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
329     // #110094#-14 SendRepaintBroadcast();
330     NbcSetText(rStr);
331     SetChanged();
332     BroadcastObjectChange();
333     SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
334     //if (GetBoundRect()!=aBoundRect0) {
335     //  SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
336     //}
337 }
338 
339 void SdrTextObj::NbcSetText(SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat)
340 {
341     SdrOutliner& rOutliner=ImpGetDrawOutliner();
342     rOutliner.SetStyleSheet( 0, GetStyleSheet());
343     rOutliner.Read(rInput,rBaseURL,eFormat);
344     OutlinerParaObject* pNewText=rOutliner.CreateParaObject();
345     rOutliner.SetUpdateMode(sal_True);
346     Size aSiz(rOutliner.CalcTextSize());
347     rOutliner.Clear();
348     NbcSetOutlinerParaObject(pNewText);
349     aTextSize=aSiz;
350     bTextSizeDirty=sal_False;
351 }
352 
353 void SdrTextObj::SetText(SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat)
354 {
355     Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
356     // #110094#-14 SendRepaintBroadcast();
357     NbcSetText(rInput,rBaseURL,eFormat);
358     SetChanged();
359     BroadcastObjectChange();
360     SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
361 }
362 
363 const Size& SdrTextObj::GetTextSize() const
364 {
365     if (bTextSizeDirty)
366     {
367         Size aSiz;
368         SdrText* pText = getActiveText();
369         if( pText && pText->GetOutlinerParaObject ())
370         {
371             SdrOutliner& rOutliner=ImpGetDrawOutliner();
372             rOutliner.SetText(*pText->GetOutlinerParaObject());
373             rOutliner.SetUpdateMode(sal_True);
374             aSiz=rOutliner.CalcTextSize();
375             rOutliner.Clear();
376         }
377         // 2x casting auf nonconst
378         ((SdrTextObj*)this)->aTextSize=aSiz;
379         ((SdrTextObj*)this)->bTextSizeDirty=sal_False;
380     }
381     return aTextSize;
382 }
383 
384 FASTBOOL SdrTextObj::IsAutoGrowHeight() const
385 {
386     if(!bTextFrame)
387         return sal_False; // AutoGrow nur bei TextFrames
388 
389     const SfxItemSet& rSet = GetObjectItemSet();
390     sal_Bool bRet = ((SdrTextAutoGrowHeightItem&)(rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT))).GetValue();
391 
392     if(bRet)
393     {
394         SdrTextAniKind eAniKind = ((SdrTextAniKindItem&)(rSet.Get(SDRATTR_TEXT_ANIKIND))).GetValue();
395 
396         if(eAniKind == SDRTEXTANI_SCROLL || eAniKind == SDRTEXTANI_ALTERNATE || eAniKind == SDRTEXTANI_SLIDE)
397         {
398             SdrTextAniDirection eDirection = ((SdrTextAniDirectionItem&)(rSet.Get(SDRATTR_TEXT_ANIDIRECTION))).GetValue();
399 
400             if(eDirection == SDRTEXTANI_UP || eDirection == SDRTEXTANI_DOWN)
401             {
402                 bRet = sal_False;
403             }
404         }
405     }
406     return bRet;
407 }
408 
409 FASTBOOL SdrTextObj::IsAutoGrowWidth() const
410 {
411     if(!bTextFrame)
412         return sal_False; // AutoGrow nur bei TextFrames
413 
414     const SfxItemSet& rSet = GetObjectItemSet();
415     sal_Bool bRet = ((SdrTextAutoGrowHeightItem&)(rSet.Get(SDRATTR_TEXT_AUTOGROWWIDTH))).GetValue();
416 
417     // #101684#
418     sal_Bool bInEditMOde = IsInEditMode();
419 
420     if(!bInEditMOde && bRet)
421     {
422         SdrTextAniKind eAniKind = ((SdrTextAniKindItem&)(rSet.Get(SDRATTR_TEXT_ANIKIND))).GetValue();
423 
424         if(eAniKind == SDRTEXTANI_SCROLL || eAniKind == SDRTEXTANI_ALTERNATE || eAniKind == SDRTEXTANI_SLIDE)
425         {
426             SdrTextAniDirection eDirection = ((SdrTextAniDirectionItem&)(rSet.Get(SDRATTR_TEXT_ANIDIRECTION))).GetValue();
427 
428             if(eDirection == SDRTEXTANI_LEFT || eDirection == SDRTEXTANI_RIGHT)
429             {
430                 bRet = sal_False;
431             }
432         }
433     }
434     return bRet;
435 }
436 
437 SdrTextHorzAdjust SdrTextObj::GetTextHorizontalAdjust() const
438 {
439     return GetTextHorizontalAdjust(GetObjectItemSet());
440 }
441 
442 SdrTextHorzAdjust SdrTextObj::GetTextHorizontalAdjust(const SfxItemSet& rSet) const
443 {
444     if(IsContourTextFrame())
445         return SDRTEXTHORZADJUST_BLOCK;
446 
447     SdrTextHorzAdjust eRet = ((SdrTextHorzAdjustItem&)(rSet.Get(SDRATTR_TEXT_HORZADJUST))).GetValue();
448 
449     // #101684#
450     sal_Bool bInEditMode = IsInEditMode();
451 
452     if(!bInEditMode && eRet == SDRTEXTHORZADJUST_BLOCK)
453     {
454         SdrTextAniKind eAniKind = ((SdrTextAniKindItem&)(rSet.Get(SDRATTR_TEXT_ANIKIND))).GetValue();
455 
456         if(eAniKind == SDRTEXTANI_SCROLL || eAniKind == SDRTEXTANI_ALTERNATE || eAniKind == SDRTEXTANI_SLIDE)
457         {
458             SdrTextAniDirection eDirection = ((SdrTextAniDirectionItem&)(rSet.Get(SDRATTR_TEXT_ANIDIRECTION))).GetValue();
459 
460             if(eDirection == SDRTEXTANI_LEFT || eDirection == SDRTEXTANI_RIGHT)
461             {
462                 eRet = SDRTEXTHORZADJUST_LEFT;
463             }
464         }
465     }
466 
467     return eRet;
468 } // defaults: BLOCK fuer Textrahmen, CENTER fuer beschriftete Grafikobjekte
469 
470 SdrTextVertAdjust SdrTextObj::GetTextVerticalAdjust() const
471 {
472     return GetTextVerticalAdjust(GetObjectItemSet());
473 }
474 
475 SdrTextVertAdjust SdrTextObj::GetTextVerticalAdjust(const SfxItemSet& rSet) const
476 {
477     if(IsContourTextFrame())
478         return SDRTEXTVERTADJUST_TOP;
479 
480     // #103516# Take care for vertical text animation here
481     SdrTextVertAdjust eRet = ((SdrTextVertAdjustItem&)(rSet.Get(SDRATTR_TEXT_VERTADJUST))).GetValue();
482     sal_Bool bInEditMode = IsInEditMode();
483 
484     // #103516# Take care for vertical text animation here
485     if(!bInEditMode && eRet == SDRTEXTVERTADJUST_BLOCK)
486     {
487         SdrTextAniKind eAniKind = ((SdrTextAniKindItem&)(rSet.Get(SDRATTR_TEXT_ANIKIND))).GetValue();
488 
489         if(eAniKind == SDRTEXTANI_SCROLL || eAniKind == SDRTEXTANI_ALTERNATE || eAniKind == SDRTEXTANI_SLIDE)
490         {
491             SdrTextAniDirection eDirection = ((SdrTextAniDirectionItem&)(rSet.Get(SDRATTR_TEXT_ANIDIRECTION))).GetValue();
492 
493             if(eDirection == SDRTEXTANI_LEFT || eDirection == SDRTEXTANI_RIGHT)
494             {
495                 eRet = SDRTEXTVERTADJUST_TOP;
496             }
497         }
498     }
499 
500     return eRet;
501 } // defaults: TOP fuer Textrahmen, CENTER fuer beschriftete Grafikobjekte
502 
503 void SdrTextObj::ImpJustifyRect(Rectangle& rRect) const
504 {
505     if (!rRect.IsEmpty()) {
506         rRect.Justify();
507         if (rRect.Left()==rRect.Right()) rRect.Right()++;
508         if (rRect.Top()==rRect.Bottom()) rRect.Bottom()++;
509     }
510 }
511 
512 void SdrTextObj::ImpCheckShear()
513 {
514     if (bNoShear && aGeo.nShearWink!=0) {
515         aGeo.nShearWink=0;
516         aGeo.nTan=0;
517     }
518 }
519 
520 void SdrTextObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
521 {
522     FASTBOOL bNoTextFrame=!IsTextFrame();
523     rInfo.bResizeFreeAllowed=bNoTextFrame || aGeo.nDrehWink%9000==0;
524     rInfo.bResizePropAllowed=sal_True;
525     rInfo.bRotateFreeAllowed=sal_True;
526     rInfo.bRotate90Allowed  =sal_True;
527     rInfo.bMirrorFreeAllowed=bNoTextFrame;
528     rInfo.bMirror45Allowed  =bNoTextFrame;
529     rInfo.bMirror90Allowed  =bNoTextFrame;
530 
531     // allow transparence
532     rInfo.bTransparenceAllowed = sal_True;
533 
534     // gradient depends on fillstyle
535     XFillStyle eFillStyle = ((XFillStyleItem&)(GetObjectItem(XATTR_FILLSTYLE))).GetValue();
536     rInfo.bGradientAllowed = (eFillStyle == XFILL_GRADIENT);
537     rInfo.bShearAllowed     =bNoTextFrame;
538     rInfo.bEdgeRadiusAllowed=sal_True;
539     FASTBOOL bCanConv=ImpCanConvTextToCurve();
540     rInfo.bCanConvToPath    =bCanConv;
541     rInfo.bCanConvToPoly    =bCanConv;
542     rInfo.bCanConvToPathLineToArea=bCanConv;
543     rInfo.bCanConvToPolyLineToArea=bCanConv;
544     rInfo.bCanConvToContour = (rInfo.bCanConvToPoly || LineGeometryUsageIsNecessary());
545 }
546 
547 sal_uInt16 SdrTextObj::GetObjIdentifier() const
548 {
549     return sal_uInt16(eTextKind);
550 }
551 
552 bool SdrTextObj::HasTextImpl( SdrOutliner* pOutliner )
553 {
554     bool bRet=false;
555     if(pOutliner)
556     {
557         Paragraph* p1stPara=pOutliner->GetParagraph( 0 );
558         sal_uIntPtr nParaAnz=pOutliner->GetParagraphCount();
559         if(p1stPara==NULL)
560             nParaAnz=0;
561 
562         if(nParaAnz==1)
563         {
564             // if it is only one paragraph, check if that paragraph is empty
565             XubString aStr(pOutliner->GetText(p1stPara));
566 
567             if(!aStr.Len())
568                 nParaAnz = 0;
569         }
570 
571         bRet= nParaAnz!=0;
572     }
573     return bRet;
574 }
575 
576 FASTBOOL SdrTextObj::HasEditText() const
577 {
578     return HasTextImpl( pEdtOutl );
579 }
580 
581 void SdrTextObj::SetPage(SdrPage* pNewPage)
582 {
583     FASTBOOL bRemove=pNewPage==NULL && pPage!=NULL;
584     FASTBOOL bInsert=pNewPage!=NULL && pPage==NULL;
585     FASTBOOL bLinked=IsLinkedText();
586 
587     if (bLinked && bRemove) {
588         ImpLinkAbmeldung();
589     }
590 
591     SdrAttrObj::SetPage(pNewPage);
592 
593     if (bLinked && bInsert) {
594         ImpLinkAnmeldung();
595     }
596 }
597 
598 void SdrTextObj::SetModel(SdrModel* pNewModel)
599 {
600     SdrModel* pOldModel=pModel;
601     bool bLinked=IsLinkedText();
602     bool bChg=pNewModel!=pModel;
603 
604     if (bLinked && bChg)
605     {
606         ImpLinkAbmeldung();
607     }
608 
609     SdrAttrObj::SetModel(pNewModel);
610 
611     if( bChg )
612     {
613         if( pNewModel != 0 && pOldModel != 0 )
614             SetTextSizeDirty();
615 
616         sal_Int32 nCount = getTextCount();
617         for( sal_Int32 nText = 0; nText < nCount; nText++ )
618         {
619             SdrText* pText = getText( nText );
620             if( pText )
621                 pText->SetModel( pNewModel );
622         }
623     }
624 
625     if (bLinked && bChg)
626     {
627         ImpLinkAnmeldung();
628     }
629 }
630 
631 FASTBOOL SdrTextObj::NbcSetEckenradius(long nRad)
632 {
633     SetObjectItem(SdrEckenradiusItem(nRad));
634     return sal_True;
635 }
636 
637 FASTBOOL SdrTextObj::NbcSetAutoGrowHeight(bool bAuto)
638 {
639     if(bTextFrame)
640     {
641         SetObjectItem(SdrTextAutoGrowHeightItem(bAuto));
642         return sal_True;
643     }
644     return sal_False;
645 }
646 
647 FASTBOOL SdrTextObj::NbcSetMinTextFrameHeight(long nHgt)
648 {
649     if( bTextFrame && ( !pModel || !pModel->isLocked() ) )          // SJ: #i44922#
650     {
651         SetObjectItem(SdrTextMinFrameHeightItem(nHgt));
652 
653         // #84974# use bDisableAutoWidthOnDragging as
654         // bDisableAutoHeightOnDragging if vertical.
655         if(IsVerticalWriting() && bDisableAutoWidthOnDragging)
656         {
657             bDisableAutoWidthOnDragging = sal_False;
658             SetObjectItem(SdrTextAutoGrowHeightItem(sal_False));
659         }
660 
661         return sal_True;
662     }
663     return sal_False;
664 }
665 
666 FASTBOOL SdrTextObj::NbcSetMaxTextFrameHeight(long nHgt)
667 {
668     if(bTextFrame)
669     {
670         SetObjectItem(SdrTextMaxFrameHeightItem(nHgt));
671         return sal_True;
672     }
673     return sal_False;
674 }
675 
676 FASTBOOL SdrTextObj::NbcSetAutoGrowWidth(bool bAuto)
677 {
678     if(bTextFrame)
679     {
680         SetObjectItem(SdrTextAutoGrowWidthItem(bAuto));
681         return sal_True;
682     }
683     return sal_False;
684 }
685 
686 FASTBOOL SdrTextObj::NbcSetMinTextFrameWidth(long nWdt)
687 {
688     if( bTextFrame && ( !pModel || !pModel->isLocked() ) )          // SJ: #i44922#
689     {
690         SetObjectItem(SdrTextMinFrameWidthItem(nWdt));
691 
692         // #84974# use bDisableAutoWidthOnDragging only
693         // when not vertical.
694         if(!IsVerticalWriting() && bDisableAutoWidthOnDragging)
695         {
696             bDisableAutoWidthOnDragging = sal_False;
697             SetObjectItem(SdrTextAutoGrowWidthItem(sal_False));
698         }
699 
700         return sal_True;
701     }
702     return sal_False;
703 }
704 
705 FASTBOOL SdrTextObj::NbcSetMaxTextFrameWidth(long nWdt)
706 {
707     if(bTextFrame)
708     {
709         SetObjectItem(SdrTextMaxFrameWidthItem(nWdt));
710         return sal_True;
711     }
712     return sal_False;
713 }
714 
715 FASTBOOL SdrTextObj::NbcSetFitToSize(SdrFitToSizeType eFit)
716 {
717     if(bTextFrame)
718     {
719         SetObjectItem(SdrTextFitToSizeTypeItem(eFit));
720         return sal_True;
721     }
722     return sal_False;
723 }
724 
725 void SdrTextObj::ImpSetContourPolygon( SdrOutliner& rOutliner, Rectangle& rAnchorRect, sal_Bool bLineWidth ) const
726 {
727     basegfx::B2DPolyPolygon aXorPolyPolygon(TakeXorPoly());
728     basegfx::B2DPolyPolygon* pContourPolyPolygon = 0L;
729     basegfx::B2DHomMatrix aMatrix(basegfx::tools::createTranslateB2DHomMatrix(
730         -rAnchorRect.Left(), -rAnchorRect.Top()));
731 
732     if(aGeo.nDrehWink)
733     {
734         // Unrotate!
735         aMatrix.rotate(-aGeo.nDrehWink * nPi180);
736     }
737 
738     aXorPolyPolygon.transform(aMatrix);
739 
740     if( bLineWidth )
741     {
742         // Strichstaerke beruecksichtigen
743         // Beim Hittest muss das unterbleiben (Performance!)
744         pContourPolyPolygon = new basegfx::B2DPolyPolygon();
745 
746         // #86258# test if shadow needs to be avoided for TakeContour()
747         const SfxItemSet& rSet = GetObjectItemSet();
748         sal_Bool bShadowOn = ((SdrShadowItem&)(rSet.Get(SDRATTR_SHADOW))).GetValue();
749 
750         // #i33696#
751         // Remember TextObject currently set at the DrawOutliner, it WILL be
752         // replaced during calculating the outline since it uses an own paint
753         // and that one uses the DrawOutliner, too.
754         const SdrTextObj* pLastTextObject = rOutliner.GetTextObj();
755 
756         if(bShadowOn)
757         {
758             // #86258# force shadow off
759             SdrObject* pCopy = Clone();
760             pCopy->SetMergedItem(SdrShadowItem(sal_False));
761             *pContourPolyPolygon = pCopy->TakeContour();
762             SdrObject::Free( pCopy );
763         }
764         else
765         {
766             *pContourPolyPolygon = TakeContour();
767         }
768 
769         // #i33696#
770         // restore remembered text object
771         if(pLastTextObject != rOutliner.GetTextObj())
772         {
773             rOutliner.SetTextObj(pLastTextObject);
774         }
775 
776         pContourPolyPolygon->transform(aMatrix);
777     }
778 
779     rOutliner.SetPolygon(aXorPolyPolygon, pContourPolyPolygon);
780 }
781 
782 void SdrTextObj::TakeUnrotatedSnapRect(Rectangle& rRect) const
783 {
784     rRect=aRect;
785 }
786 
787 void SdrTextObj::TakeTextAnchorRect(Rectangle& rAnchorRect) const
788 {
789     long nLeftDist=GetTextLeftDistance();
790     long nRightDist=GetTextRightDistance();
791     long nUpperDist=GetTextUpperDistance();
792     long nLowerDist=GetTextLowerDistance();
793     Rectangle aAnkRect(aRect); // Rect innerhalb dem geankert wird
794     FASTBOOL bFrame=IsTextFrame();
795     if (!bFrame) {
796         TakeUnrotatedSnapRect(aAnkRect);
797     }
798     Point aRotateRef(aAnkRect.TopLeft());
799     aAnkRect.Left()+=nLeftDist;
800     aAnkRect.Top()+=nUpperDist;
801     aAnkRect.Right()-=nRightDist;
802     aAnkRect.Bottom()-=nLowerDist;
803 
804     // #108816#
805     // Since sizes may be bigger than the object bounds it is necessary to
806     // justify the rect now.
807     ImpJustifyRect(aAnkRect);
808 
809     if (bFrame) {
810         // !!! hier noch etwas verfeinern !!!
811         if (aAnkRect.GetWidth()<2) aAnkRect.Right()=aAnkRect.Left()+1;   // Mindestgroesse 2
812         if (aAnkRect.GetHeight()<2) aAnkRect.Bottom()=aAnkRect.Top()+1;  // Mindestgroesse 2
813     }
814     if (aGeo.nDrehWink!=0) {
815         Point aTmpPt(aAnkRect.TopLeft());
816         RotatePoint(aTmpPt,aRotateRef,aGeo.nSin,aGeo.nCos);
817         aTmpPt-=aAnkRect.TopLeft();
818         aAnkRect.Move(aTmpPt.X(),aTmpPt.Y());
819     }
820     rAnchorRect=aAnkRect;
821 }
822 
823 void SdrTextObj::TakeTextRect( SdrOutliner& rOutliner, Rectangle& rTextRect, FASTBOOL bNoEditText,
824                                Rectangle* pAnchorRect, sal_Bool bLineWidth ) const
825 {
826     Rectangle aAnkRect; // Rect innerhalb dem geankert wird
827     TakeTextAnchorRect(aAnkRect);
828     SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
829     SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
830     SdrTextAniKind      eAniKind=GetTextAniKind();
831     SdrTextAniDirection eAniDirection=GetTextAniDirection();
832 
833     SdrFitToSizeType eFit=GetFitToSize();
834     FASTBOOL bFitToSize=(eFit==SDRTEXTFIT_PROPORTIONAL || eFit==SDRTEXTFIT_ALLLINES);
835     FASTBOOL bContourFrame=IsContourTextFrame();
836 
837     FASTBOOL bFrame=IsTextFrame();
838     sal_uIntPtr nStat0=rOutliner.GetControlWord();
839     Size aNullSize;
840     if (!bContourFrame)
841     {
842         rOutliner.SetControlWord(nStat0|EE_CNTRL_AUTOPAGESIZE);
843         rOutliner.SetMinAutoPaperSize(aNullSize);
844         rOutliner.SetMaxAutoPaperSize(Size(1000000,1000000));
845     }
846 
847     if (!bFitToSize && !bContourFrame)
848     {
849         long nAnkWdt=aAnkRect.GetWidth();
850         long nAnkHgt=aAnkRect.GetHeight();
851         if (bFrame)
852         {
853             long nWdt=nAnkWdt;
854             long nHgt=nAnkHgt;
855 
856             // #101684#
857             sal_Bool bInEditMode = IsInEditMode();
858 
859             if (!bInEditMode && (eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE))
860             {
861                 // Grenzenlose Papiergroesse fuer Laufschrift
862                 if (eAniDirection==SDRTEXTANI_LEFT || eAniDirection==SDRTEXTANI_RIGHT) nWdt=1000000;
863                 if (eAniDirection==SDRTEXTANI_UP || eAniDirection==SDRTEXTANI_DOWN) nHgt=1000000;
864             }
865 
866             // #119885# Do not limit/force height to geometrical frame (vice versa for vertical writing)
867             if(IsVerticalWriting())
868             {
869                 nWdt = 1000000;
870             }
871             else
872             {
873                 nHgt = 1000000;
874             }
875 
876             rOutliner.SetMaxAutoPaperSize(Size(nWdt,nHgt));
877         }
878 
879         // #103516# New try with _BLOCK for hor and ver after completely
880         // supporting full width for vertical text.
881         if(SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
882         {
883             rOutliner.SetMinAutoPaperSize(Size(nAnkWdt, 0));
884         }
885 
886         if(SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting())
887         {
888             rOutliner.SetMinAutoPaperSize(Size(0, nAnkHgt));
889         }
890     }
891 
892     rOutliner.SetPaperSize(aNullSize);
893     if (bContourFrame)
894         ImpSetContourPolygon( rOutliner, aAnkRect, bLineWidth );
895 
896     // put text into the outliner, if available from the edit outliner
897     SdrText* pText = getActiveText();
898     OutlinerParaObject* pOutlinerParaObject = pText ? pText->GetOutlinerParaObject() : 0;
899     OutlinerParaObject* pPara = (pEdtOutl && !bNoEditText) ? pEdtOutl->CreateParaObject() : pOutlinerParaObject;
900 
901     if (pPara)
902     {
903         sal_Bool bHitTest = sal_False;
904         if( pModel )
905             bHitTest = &pModel->GetHitTestOutliner() == &rOutliner;
906 
907         const SdrTextObj* pTestObj = rOutliner.GetTextObj();
908         if( !pTestObj || !bHitTest || pTestObj != this ||
909             pTestObj->GetOutlinerParaObject() != pOutlinerParaObject )
910         {
911             if( bHitTest ) // #i33696# take back fix #i27510#
912             {
913                 rOutliner.SetTextObj( this );
914                 rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
915             }
916 
917             rOutliner.SetUpdateMode(sal_True);
918             rOutliner.SetText(*pPara);
919         }
920     }
921     else
922     {
923         rOutliner.SetTextObj( NULL );
924     }
925 
926     if (pEdtOutl && !bNoEditText && pPara)
927         delete pPara;
928 
929     rOutliner.SetUpdateMode(sal_True);
930     rOutliner.SetControlWord(nStat0);
931 
932     if( pText )
933         pText->CheckPortionInfo(rOutliner);
934 
935     Point aTextPos(aAnkRect.TopLeft());
936     Size aTextSiz(rOutliner.GetPaperSize()); // GetPaperSize() hat etwas Toleranz drauf, oder?
937 
938     // #106653#
939     // For draw objects containing text correct hor/ver alignment if text is bigger
940     // than the object itself. Without that correction, the text would always be
941     // formatted to the left edge (or top edge when vertical) of the draw object.
942     if(!IsTextFrame())
943     {
944         if(aAnkRect.GetWidth() < aTextSiz.Width() && !IsVerticalWriting())
945         {
946             // #110129#
947             // Horizontal case here. Correct only if eHAdj == SDRTEXTHORZADJUST_BLOCK,
948             // else the alignment is wanted.
949             if(SDRTEXTHORZADJUST_BLOCK == eHAdj)
950             {
951                 eHAdj = SDRTEXTHORZADJUST_CENTER;
952             }
953         }
954 
955         if(aAnkRect.GetHeight() < aTextSiz.Height() && IsVerticalWriting())
956         {
957             // #110129#
958             // Vertical case here. Correct only if eHAdj == SDRTEXTVERTADJUST_BLOCK,
959             // else the alignment is wanted.
960             if(SDRTEXTVERTADJUST_BLOCK == eVAdj)
961             {
962                 eVAdj = SDRTEXTVERTADJUST_CENTER;
963             }
964         }
965     }
966 
967     if (eHAdj==SDRTEXTHORZADJUST_CENTER || eHAdj==SDRTEXTHORZADJUST_RIGHT)
968     {
969         long nFreeWdt=aAnkRect.GetWidth()-aTextSiz.Width();
970         if (eHAdj==SDRTEXTHORZADJUST_CENTER)
971             aTextPos.X()+=nFreeWdt/2;
972         if (eHAdj==SDRTEXTHORZADJUST_RIGHT)
973             aTextPos.X()+=nFreeWdt;
974     }
975     if (eVAdj==SDRTEXTVERTADJUST_CENTER || eVAdj==SDRTEXTVERTADJUST_BOTTOM)
976     {
977         long nFreeHgt=aAnkRect.GetHeight()-aTextSiz.Height();
978         if (eVAdj==SDRTEXTVERTADJUST_CENTER)
979             aTextPos.Y()+=nFreeHgt/2;
980         if (eVAdj==SDRTEXTVERTADJUST_BOTTOM)
981             aTextPos.Y()+=nFreeHgt;
982     }
983     if (aGeo.nDrehWink!=0)
984         RotatePoint(aTextPos,aAnkRect.TopLeft(),aGeo.nSin,aGeo.nCos);
985 
986     if (pAnchorRect)
987         *pAnchorRect=aAnkRect;
988 
989     // rTextRect ist bei ContourFrame in einigen Faellen nicht korrekt
990     rTextRect=Rectangle(aTextPos,aTextSiz);
991     if (bContourFrame)
992         rTextRect=aAnkRect;
993 }
994 
995 OutlinerParaObject* SdrTextObj::GetEditOutlinerParaObject() const
996 {
997     OutlinerParaObject* pPara=NULL;
998     if( HasTextImpl( pEdtOutl ) )
999     {
1000         sal_uInt16 nParaAnz = static_cast< sal_uInt16 >( pEdtOutl->GetParagraphCount() );
1001         pPara = pEdtOutl->CreateParaObject(0, nParaAnz);
1002     }
1003     return pPara;
1004 }
1005 
1006 void SdrTextObj::ImpSetCharStretching(SdrOutliner& rOutliner, const Rectangle& rTextRect, const Rectangle& rAnchorRect, Fraction& rFitXKorreg) const
1007 {
1008     OutputDevice* pOut = rOutliner.GetRefDevice();
1009     sal_Bool bNoStretching(sal_False);
1010 
1011     if(pOut && pOut->GetOutDevType() == OUTDEV_PRINTER)
1012     {
1013         // #35762#: Checken ob CharStretching ueberhaupt moeglich
1014         GDIMetaFile* pMtf = pOut->GetConnectMetaFile();
1015         UniString aTestString(sal_Unicode('J'));
1016 
1017         if(pMtf && (!pMtf->IsRecord() || pMtf->IsPause()))
1018             pMtf = NULL;
1019 
1020         if(pMtf)
1021             pMtf->Pause(sal_True);
1022 
1023         Font aFontMerk(pOut->GetFont());
1024         Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_SERIF, LANGUAGE_SYSTEM, DEFAULTFONT_FLAGS_ONLYONE ) );
1025 
1026         aTmpFont.SetSize(Size(0,100));
1027         pOut->SetFont(aTmpFont);
1028         Size aSize1(pOut->GetTextWidth(aTestString), pOut->GetTextHeight());
1029         aTmpFont.SetSize(Size(800,100));
1030         pOut->SetFont(aTmpFont);
1031         Size aSize2(pOut->GetTextWidth(aTestString), pOut->GetTextHeight());
1032         pOut->SetFont(aFontMerk);
1033 
1034         if(pMtf)
1035             pMtf->Pause(sal_False);
1036 
1037         bNoStretching = (aSize1 == aSize2);
1038 
1039 #ifdef WNT
1040         // #35762# Windows vergroessert bei Size(100,500) den Font proportional
1041         // Und das finden wir nicht so schoen.
1042         if(aSize2.Height() >= aSize1.Height() * 2)
1043         {
1044             bNoStretching = sal_True;
1045         }
1046 #endif
1047     }
1048     unsigned nLoopCount=0;
1049     FASTBOOL bNoMoreLoop=sal_False;
1050     long nXDiff0=0x7FFFFFFF;
1051     long nWantWdt=rAnchorRect.Right()-rAnchorRect.Left();
1052     long nIsWdt=rTextRect.Right()-rTextRect.Left();
1053     if (nIsWdt==0) nIsWdt=1;
1054 
1055     long nWantHgt=rAnchorRect.Bottom()-rAnchorRect.Top();
1056     long nIsHgt=rTextRect.Bottom()-rTextRect.Top();
1057     if (nIsHgt==0) nIsHgt=1;
1058 
1059     long nXTolPl=nWantWdt/100; // Toleranz +1%
1060     long nXTolMi=nWantWdt/25;  // Toleranz -4%
1061     long nXKorr =nWantWdt/20;  // Korrekturmasstab 5%
1062 
1063     long nX=(nWantWdt*100) /nIsWdt; // X-Stretching berechnen
1064     long nY=(nWantHgt*100) /nIsHgt; // Y-Stretching berechnen
1065     FASTBOOL bChkX=sal_True;
1066     FASTBOOL bChkY=sal_True;
1067     if (bNoStretching) { // #35762# evtl. nur proportional moeglich
1068         if (nX>nY) { nX=nY; bChkX=sal_False; }
1069         else { nY=nX; bChkY=sal_False; }
1070     }
1071 
1072     while (nLoopCount<5 && !bNoMoreLoop) {
1073         if (nX<0) nX=-nX;
1074         if (nX<1) { nX=1; bNoMoreLoop=sal_True; }
1075         if (nX>65535) { nX=65535; bNoMoreLoop=sal_True; }
1076 
1077         if (nY<0) nY=-nY;
1078         if (nY<1) { nY=1; bNoMoreLoop=sal_True; }
1079         if (nY>65535) { nY=65535; bNoMoreLoop=sal_True; }
1080 
1081         // exception, there is no text yet (horizontal case)
1082         if(nIsWdt <= 1)
1083         {
1084             nX = nY;
1085             bNoMoreLoop = sal_True;
1086         }
1087 
1088         // #87877# exception, there is no text yet (vertical case)
1089         if(nIsHgt <= 1)
1090         {
1091             nY = nX;
1092             bNoMoreLoop = sal_True;
1093         }
1094 
1095         rOutliner.SetGlobalCharStretching((sal_uInt16)nX,(sal_uInt16)nY);
1096         nLoopCount++;
1097         Size aSiz(rOutliner.CalcTextSize());
1098         long nXDiff=aSiz.Width()-nWantWdt;
1099         rFitXKorreg=Fraction(nWantWdt,aSiz.Width());
1100         if (((nXDiff>=nXTolMi || !bChkX) && nXDiff<=nXTolPl) || nXDiff==nXDiff0/*&& Abs(nYDiff)<=nYTol*/) {
1101             bNoMoreLoop=sal_True;
1102         } else {
1103             // Stretchingfaktoren korregieren
1104             long nMul=nWantWdt;
1105             long nDiv=aSiz.Width();
1106             if (Abs(nXDiff)<=2*nXKorr) {
1107                 if (nMul>nDiv) nDiv+=(nMul-nDiv)/2; // und zwar nur um die haelfte des berechneten
1108                 else nMul+=(nDiv-nMul)/2;           // weil die EE ja eh wieder falsch rechnet
1109             }
1110             nX=nX*nMul/nDiv;
1111             if (bNoStretching) nY=nX;
1112         }
1113         nXDiff0=nXDiff;
1114     }
1115 }
1116 
1117 void SdrTextObj::StartTextAnimation(OutputDevice* /*pOutDev*/, const Point& /*rOffset*/, long /*nExtraData*/)
1118 {
1119     // #111096#
1120     // use new text animation
1121     SetTextAnimationAllowed(sal_True);
1122 }
1123 
1124 void SdrTextObj::StopTextAnimation(OutputDevice* /*pOutDev*/, long /*nExtraData*/)
1125 {
1126     // #111096#
1127     // use new text animation
1128     SetTextAnimationAllowed(sal_False);
1129 }
1130 
1131 void SdrTextObj::TakeObjNameSingul(XubString& rName) const
1132 {
1133     XubString aStr;
1134 
1135     switch(eTextKind)
1136     {
1137         case OBJ_OUTLINETEXT:
1138         {
1139             aStr = ImpGetResStr(STR_ObjNameSingulOUTLINETEXT);
1140             break;
1141         }
1142 
1143         case OBJ_TITLETEXT  :
1144         {
1145             aStr = ImpGetResStr(STR_ObjNameSingulTITLETEXT);
1146             break;
1147         }
1148 
1149         default:
1150         {
1151             if(IsLinkedText())
1152                 aStr = ImpGetResStr(STR_ObjNameSingulTEXTLNK);
1153             else
1154                 aStr = ImpGetResStr(STR_ObjNameSingulTEXT);
1155             break;
1156         }
1157     }
1158 
1159     OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
1160     if(pOutlinerParaObject && eTextKind != OBJ_OUTLINETEXT)
1161     {
1162         // Macht bei OUTLINETEXT wohl derzeit noch etwas Probleme
1163         XubString aStr2(pOutlinerParaObject->GetTextObject().GetText(0));
1164         aStr2.EraseLeadingChars();
1165 
1166         // #69446# avoid non expanded text portions in object name
1167         // (second condition is new)
1168         if(aStr2.Len() && aStr2.Search(sal_Unicode(255)) == STRING_NOTFOUND)
1169         {
1170             // #76681# space between ResStr and content text
1171             aStr += sal_Unicode(' ');
1172 
1173             aStr += sal_Unicode('\'');
1174 
1175             if(aStr2.Len() > 10)
1176             {
1177                 aStr2.Erase(8);
1178                 aStr2.AppendAscii("...", 3);
1179             }
1180 
1181             aStr += aStr2;
1182             aStr += sal_Unicode('\'');
1183         }
1184     }
1185 
1186     rName = aStr;
1187 
1188     String aName( GetName() );
1189     if(aName.Len())
1190     {
1191         rName += sal_Unicode(' ');
1192         rName += sal_Unicode('\'');
1193         rName += aName;
1194         rName += sal_Unicode('\'');
1195     }
1196 
1197 }
1198 
1199 void SdrTextObj::TakeObjNamePlural(XubString& rName) const
1200 {
1201     switch (eTextKind) {
1202         case OBJ_OUTLINETEXT: rName=ImpGetResStr(STR_ObjNamePluralOUTLINETEXT); break;
1203         case OBJ_TITLETEXT  : rName=ImpGetResStr(STR_ObjNamePluralTITLETEXT);   break;
1204         default: {
1205             if (IsLinkedText()) {
1206                 rName=ImpGetResStr(STR_ObjNamePluralTEXTLNK);
1207             } else {
1208                 rName=ImpGetResStr(STR_ObjNamePluralTEXT);
1209             }
1210         } break;
1211     } // switch
1212 }
1213 
1214 void SdrTextObj::operator=(const SdrObject& rObj)
1215 {
1216     // call parent
1217     SdrObject::operator=(rObj);
1218 
1219     const SdrTextObj* pTextObj = dynamic_cast< const SdrTextObj* >( &rObj );
1220     if (pTextObj!=NULL)
1221     {
1222         aRect     =pTextObj->aRect;
1223         aGeo      =pTextObj->aGeo;
1224         eTextKind =pTextObj->eTextKind;
1225         bTextFrame=pTextObj->bTextFrame;
1226         aTextSize=pTextObj->aTextSize;
1227         bTextSizeDirty=pTextObj->bTextSizeDirty;
1228 
1229         // #101776# Not all of the necessary parameters were copied yet.
1230         bNoShear = pTextObj->bNoShear;
1231         bNoRotate = pTextObj->bNoRotate;
1232         bNoMirror = pTextObj->bNoMirror;
1233         bDisableAutoWidthOnDragging = pTextObj->bDisableAutoWidthOnDragging;
1234 
1235         OutlinerParaObject* pNewOutlinerParaObject = 0;
1236 
1237         SdrText* pText = getActiveText();
1238 
1239         if( pText && pTextObj->HasText() )
1240         {
1241             const Outliner* pEO=pTextObj->pEdtOutl;
1242             if (pEO!=NULL)
1243             {
1244                 pNewOutlinerParaObject = pEO->CreateParaObject();
1245             }
1246             else
1247             {
1248                 pNewOutlinerParaObject = new OutlinerParaObject(*pTextObj->getActiveText()->GetOutlinerParaObject());
1249             }
1250         }
1251 
1252         mpText->SetOutlinerParaObject( pNewOutlinerParaObject );
1253         ImpSetTextStyleSheetListeners();
1254     }
1255 }
1256 
1257 basegfx::B2DPolyPolygon SdrTextObj::TakeXorPoly() const
1258 {
1259     Polygon aPol(aRect);
1260     if (aGeo.nShearWink!=0) ShearPoly(aPol,aRect.TopLeft(),aGeo.nTan);
1261     if (aGeo.nDrehWink!=0) RotatePoly(aPol,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
1262 
1263     basegfx::B2DPolyPolygon aRetval;
1264     aRetval.append(aPol.getB2DPolygon());
1265     return aRetval;
1266 }
1267 
1268 basegfx::B2DPolyPolygon SdrTextObj::TakeContour() const
1269 {
1270     basegfx::B2DPolyPolygon aRetval(SdrAttrObj::TakeContour());
1271 
1272     // und nun noch ggf. das BoundRect des Textes dazu
1273     if ( pModel && GetOutlinerParaObject() && !IsFontwork() && !IsContourTextFrame() )
1274     {
1275         // #80328# using Clone()-Paint() strategy inside TakeContour() leaves a destroyed
1276         // SdrObject as pointer in DrawOutliner. Set *this again in fetching the outliner
1277         // in every case
1278         SdrOutliner& rOutliner=ImpGetDrawOutliner();
1279 
1280         Rectangle aAnchor2;
1281         Rectangle aR;
1282         TakeTextRect(rOutliner,aR,sal_False,&aAnchor2);
1283         rOutliner.Clear();
1284         SdrFitToSizeType eFit=GetFitToSize();
1285         FASTBOOL bFitToSize=(eFit==SDRTEXTFIT_PROPORTIONAL || eFit==SDRTEXTFIT_ALLLINES);
1286         if (bFitToSize) aR=aAnchor2;
1287         Polygon aPol(aR);
1288         if (aGeo.nDrehWink!=0) RotatePoly(aPol,aR.TopLeft(),aGeo.nSin,aGeo.nCos);
1289 
1290         aRetval.append(aPol.getB2DPolygon());
1291     }
1292 
1293     return aRetval;
1294 }
1295 
1296 void SdrTextObj::RecalcSnapRect()
1297 {
1298     if (aGeo.nDrehWink!=0 || aGeo.nShearWink!=0) {
1299         Polygon aPol(aRect);
1300         if (aGeo.nShearWink!=0) ShearPoly(aPol,aRect.TopLeft(),aGeo.nTan);
1301         if (aGeo.nDrehWink!=0) RotatePoly(aPol,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
1302         maSnapRect=aPol.GetBoundRect();
1303     } else {
1304         maSnapRect=aRect;
1305     }
1306 }
1307 
1308 sal_uInt32 SdrTextObj::GetSnapPointCount() const
1309 {
1310     return 4L;
1311 }
1312 
1313 Point SdrTextObj::GetSnapPoint(sal_uInt32 i) const
1314 {
1315     Point aP;
1316     switch (i) {
1317         case 0: aP=aRect.TopLeft(); break;
1318         case 1: aP=aRect.TopRight(); break;
1319         case 2: aP=aRect.BottomLeft(); break;
1320         case 3: aP=aRect.BottomRight(); break;
1321         default: aP=aRect.Center(); break;
1322     }
1323     if (aGeo.nShearWink!=0) ShearPoint(aP,aRect.TopLeft(),aGeo.nTan);
1324     if (aGeo.nDrehWink!=0) RotatePoint(aP,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
1325     return aP;
1326 }
1327 
1328 void SdrTextObj::ImpCheckMasterCachable()
1329 {
1330     bNotMasterCachable=sal_False;
1331 
1332     OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
1333 
1334     if(!bNotVisibleAsMaster && pOutlinerParaObject && pOutlinerParaObject->IsEditDoc() )
1335     {
1336         const EditTextObject& rText= pOutlinerParaObject->GetTextObject();
1337         bNotMasterCachable=rText.HasField(SvxPageField::StaticType());
1338         if( !bNotMasterCachable )
1339         {
1340             bNotMasterCachable=rText.HasField(SvxHeaderField::StaticType());
1341             if( !bNotMasterCachable )
1342             {
1343                 bNotMasterCachable=rText.HasField(SvxFooterField::StaticType());
1344                 if( !bNotMasterCachable )
1345                 {
1346                     bNotMasterCachable=rText.HasField(SvxDateTimeField::StaticType());
1347                 }
1348             }
1349         }
1350     }
1351 }
1352 
1353 // #101029#: Extracted from ImpGetDrawOutliner()
1354 void SdrTextObj::ImpInitDrawOutliner( SdrOutliner& rOutl ) const
1355 {
1356     rOutl.SetUpdateMode(sal_False);
1357     sal_uInt16 nOutlinerMode = OUTLINERMODE_OUTLINEOBJECT;
1358     if ( !IsOutlText() )
1359         nOutlinerMode = OUTLINERMODE_TEXTOBJECT;
1360     rOutl.Init( nOutlinerMode );
1361 
1362     rOutl.SetGlobalCharStretching(100,100);
1363     sal_uIntPtr nStat=rOutl.GetControlWord();
1364     nStat&=~(EE_CNTRL_STRETCHING|EE_CNTRL_AUTOPAGESIZE);
1365     rOutl.SetControlWord(nStat);
1366     Size aNullSize;
1367     Size aMaxSize(100000,100000);
1368     rOutl.SetMinAutoPaperSize(aNullSize);
1369     rOutl.SetMaxAutoPaperSize(aMaxSize);
1370     rOutl.SetPaperSize(aMaxSize);
1371     rOutl.ClearPolygon();
1372 }
1373 
1374 SdrOutliner& SdrTextObj::ImpGetDrawOutliner() const
1375 {
1376     SdrOutliner& rOutl=pModel->GetDrawOutliner(this);
1377 
1378     // #101029#: Code extracted to ImpInitDrawOutliner()
1379     ImpInitDrawOutliner( rOutl );
1380 
1381     return rOutl;
1382 }
1383 
1384 boost::shared_ptr< SdrOutliner > SdrTextObj::CreateDrawOutliner()
1385 {
1386     boost::shared_ptr< SdrOutliner > xDrawOutliner( pModel->CreateDrawOutliner(this) );
1387     ImpInitDrawOutliner( *(xDrawOutliner.get()) );
1388     return xDrawOutliner;
1389 }
1390 
1391 // #101029#: Extracted from Paint()
1392 void SdrTextObj::ImpSetupDrawOutlinerForPaint( FASTBOOL         bContourFrame,
1393                                                SdrOutliner&     rOutliner,
1394                                                Rectangle&       rTextRect,
1395                                                Rectangle&       rAnchorRect,
1396                                                Rectangle&       rPaintRect,
1397                                                Fraction&        rFitXKorreg ) const
1398 {
1399     if (!bContourFrame)
1400     {
1401         // FitToSize erstmal nicht mit ContourFrame
1402         SdrFitToSizeType eFit=GetFitToSize();
1403         if (eFit==SDRTEXTFIT_PROPORTIONAL || eFit==SDRTEXTFIT_ALLLINES)
1404         {
1405             sal_uIntPtr nStat=rOutliner.GetControlWord();
1406             nStat|=EE_CNTRL_STRETCHING|EE_CNTRL_AUTOPAGESIZE;
1407             rOutliner.SetControlWord(nStat);
1408         }
1409     }
1410     rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
1411     TakeTextRect(rOutliner, rTextRect, sal_False, &rAnchorRect);
1412     rPaintRect = rTextRect;
1413 
1414     if (!bContourFrame)
1415     {
1416         // FitToSize erstmal nicht mit ContourFrame
1417         SdrFitToSizeType eFit=GetFitToSize();
1418         if (eFit==SDRTEXTFIT_PROPORTIONAL || eFit==SDRTEXTFIT_ALLLINES)
1419         {
1420             ImpSetCharStretching(rOutliner,rTextRect,rAnchorRect,rFitXKorreg);
1421             rPaintRect=rAnchorRect;
1422         }
1423     }
1424 }
1425 
1426 void SdrTextObj::SetupOutlinerFormatting( SdrOutliner& rOutl, Rectangle& rPaintRect ) const
1427 {
1428     ImpInitDrawOutliner( rOutl );
1429     UpdateOutlinerFormatting( rOutl, rPaintRect );
1430 }
1431 
1432 void SdrTextObj::UpdateOutlinerFormatting( SdrOutliner& rOutl, Rectangle& rPaintRect ) const
1433 {
1434     Rectangle aTextRect;
1435     Rectangle aAnchorRect;
1436     Fraction aFitXKorreg(1,1);
1437 
1438     FASTBOOL bContourFrame=IsContourTextFrame();
1439 
1440     if( GetModel() )
1441     {
1442         MapMode aMapMode(GetModel()->GetScaleUnit(), Point(0,0),
1443                          GetModel()->GetScaleFraction(),
1444                          GetModel()->GetScaleFraction());
1445         rOutl.SetRefMapMode(aMapMode);
1446     }
1447 
1448     ImpSetupDrawOutlinerForPaint( bContourFrame, rOutl, aTextRect, aAnchorRect, rPaintRect, aFitXKorreg );
1449 }
1450 
1451 ////////////////////////////////////////////////////////////////////////////////////////////////////
1452 
1453 OutlinerParaObject* SdrTextObj::GetOutlinerParaObject() const
1454 {
1455     SdrText* pText = getActiveText();
1456     if( pText )
1457         return pText->GetOutlinerParaObject();
1458     else
1459         return 0;
1460 }
1461 
1462 bool SdrTextObj::HasOutlinerParaObject() const
1463 {
1464     SdrText* pText = getActiveText();
1465     if( pText && pText->GetOutlinerParaObject() )
1466         return true;
1467     return false;
1468 }
1469 
1470 void SdrTextObj::NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject)
1471 {
1472     NbcSetOutlinerParaObjectForText( pTextObject, getActiveText() );
1473 }
1474 
1475 void SdrTextObj::NbcSetOutlinerParaObjectForText( OutlinerParaObject* pTextObject, SdrText* pText )
1476 {
1477     if( pText )
1478         pText->SetOutlinerParaObject( pTextObject );
1479 
1480     if( pText->GetOutlinerParaObject() )
1481     {
1482         SvxWritingModeItem aWritingMode(pText->GetOutlinerParaObject()->IsVertical()
1483             ? com::sun::star::text::WritingMode_TB_RL
1484             : com::sun::star::text::WritingMode_LR_TB,
1485             SDRATTR_TEXTDIRECTION);
1486         GetProperties().SetObjectItemDirect(aWritingMode);
1487     }
1488 
1489     SetTextSizeDirty();
1490     if (IsTextFrame() && (IsAutoGrowHeight() || IsAutoGrowWidth()))
1491     { // Textrahmen anpassen!
1492         NbcAdjustTextFrameWidthAndHeight();
1493     }
1494     if (!IsTextFrame())
1495     {
1496         // Das SnapRect behaelt seine Groesse bei
1497         SetRectsDirty(sal_True);
1498     }
1499 
1500     // always invalidate BoundRect on change
1501     SetBoundRectDirty();
1502     ActionChanged();
1503 
1504     ImpSetTextStyleSheetListeners();
1505     ImpCheckMasterCachable();
1506 }
1507 
1508 void SdrTextObj::NbcReformatText()
1509 {
1510     SdrText* pText = getActiveText();
1511     if( pText && pText->GetOutlinerParaObject() )
1512     {
1513         pText->ReformatText();
1514         if (bTextFrame)
1515         {
1516             NbcAdjustTextFrameWidthAndHeight();
1517         }
1518         else
1519         {
1520             // Das SnapRect behaelt seine Groesse bei
1521             SetBoundRectDirty();
1522             SetRectsDirty(sal_True);
1523         }
1524         SetTextSizeDirty();
1525         ActionChanged();
1526         // FME, AW: i22396
1527         // Necessary here since we have no compare operator at the outliner
1528         // para object which may detect changes regarding the combination
1529         // of outliner para data and configuration (e.g., change of
1530         // formatting of text numerals)
1531         GetViewContact().flushViewObjectContacts(false);
1532     }
1533 }
1534 
1535 void SdrTextObj::ReformatText()
1536 {
1537     if(GetOutlinerParaObject())
1538     {
1539         Rectangle aBoundRect0;
1540         if (pUserCall!=NULL)
1541             aBoundRect0=GetLastBoundRect();
1542 
1543         // #110094#-14 SendRepaintBroadcast();
1544         NbcReformatText();
1545         SetChanged();
1546         BroadcastObjectChange();
1547         SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
1548     }
1549 }
1550 
1551 SdrObjGeoData* SdrTextObj::NewGeoData() const
1552 {
1553     return new SdrTextObjGeoData;
1554 }
1555 
1556 void SdrTextObj::SaveGeoData(SdrObjGeoData& rGeo) const
1557 {
1558     SdrAttrObj::SaveGeoData(rGeo);
1559     SdrTextObjGeoData& rTGeo=(SdrTextObjGeoData&)rGeo;
1560     rTGeo.aRect  =aRect;
1561     rTGeo.aGeo   =aGeo;
1562 }
1563 
1564 void SdrTextObj::RestGeoData(const SdrObjGeoData& rGeo)
1565 { // RectsDirty wird von SdrObject gerufen
1566     SdrAttrObj::RestGeoData(rGeo);
1567     SdrTextObjGeoData& rTGeo=(SdrTextObjGeoData&)rGeo;
1568     aRect  =rTGeo.aRect;
1569     aGeo   =rTGeo.aGeo;
1570     SetTextSizeDirty();
1571 }
1572 
1573 SdrFitToSizeType SdrTextObj::GetFitToSize() const
1574 {
1575     SdrFitToSizeType eType = SDRTEXTFIT_NONE;
1576 
1577     if(!IsAutoGrowWidth())
1578         eType = ((SdrTextFitToSizeTypeItem&)(GetObjectItem(SDRATTR_TEXT_FITTOSIZE))).GetValue();
1579 
1580     return eType;
1581 }
1582 
1583 void SdrTextObj::ForceOutlinerParaObject()
1584 {
1585     SdrText* pText = getActiveText();
1586     if( pText && (pText->GetOutlinerParaObject() == 0) )
1587     {
1588         sal_uInt16 nOutlMode = OUTLINERMODE_TEXTOBJECT;
1589         if( IsTextFrame() && eTextKind == OBJ_OUTLINETEXT )
1590             nOutlMode = OUTLINERMODE_OUTLINEOBJECT;
1591 
1592         pText->ForceOutlinerParaObject( nOutlMode );
1593     }
1594 }
1595 
1596 sal_Bool SdrTextObj::IsVerticalWriting() const
1597 {
1598     // #89459#
1599     if(pEdtOutl)
1600     {
1601         return pEdtOutl->IsVertical();
1602     }
1603 
1604     OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
1605     if(pOutlinerParaObject)
1606     {
1607         return pOutlinerParaObject->IsVertical();
1608     }
1609 
1610     return sal_False;
1611 }
1612 
1613 void SdrTextObj::SetVerticalWriting(sal_Bool bVertical)
1614 {
1615     OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
1616     if( !pOutlinerParaObject && bVertical )
1617     {
1618         // we only need to force a outliner para object if the default of
1619         // horizontal text is changed
1620         ForceOutlinerParaObject();
1621         pOutlinerParaObject = GetOutlinerParaObject();
1622     }
1623 
1624     if( pOutlinerParaObject && (pOutlinerParaObject->IsVertical() != (bool)bVertical) )
1625     {
1626         // get item settings
1627         const SfxItemSet& rSet = GetObjectItemSet();
1628         sal_Bool bAutoGrowWidth = ((SdrTextAutoGrowWidthItem&)rSet.Get(SDRATTR_TEXT_AUTOGROWWIDTH)).GetValue();
1629         sal_Bool bAutoGrowHeight = ((SdrTextAutoGrowHeightItem&)rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
1630 
1631         // #103516# Also exchange hor/ver adjust items
1632         SdrTextHorzAdjust eHorz = ((SdrTextHorzAdjustItem&)(rSet.Get(SDRATTR_TEXT_HORZADJUST))).GetValue();
1633         SdrTextVertAdjust eVert = ((SdrTextVertAdjustItem&)(rSet.Get(SDRATTR_TEXT_VERTADJUST))).GetValue();
1634 
1635         // rescue object size
1636         Rectangle aObjectRect = GetSnapRect();
1637 
1638         // prepare ItemSet to set exchanged width and height items
1639         SfxItemSet aNewSet(*rSet.GetPool(),
1640             SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWHEIGHT,
1641             // #103516# Expanded item ranges to also support hor and ver adjust.
1642             SDRATTR_TEXT_VERTADJUST, SDRATTR_TEXT_VERTADJUST,
1643             SDRATTR_TEXT_AUTOGROWWIDTH, SDRATTR_TEXT_HORZADJUST,
1644             0, 0);
1645 
1646         aNewSet.Put(rSet);
1647         aNewSet.Put(SdrTextAutoGrowWidthItem(bAutoGrowHeight));
1648         aNewSet.Put(SdrTextAutoGrowHeightItem(bAutoGrowWidth));
1649 
1650         // #103516# Exchange horz and vert adjusts
1651         switch(eVert)
1652         {
1653             case SDRTEXTVERTADJUST_TOP: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT)); break;
1654             case SDRTEXTVERTADJUST_CENTER: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER)); break;
1655             case SDRTEXTVERTADJUST_BOTTOM: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_LEFT)); break;
1656             case SDRTEXTVERTADJUST_BLOCK: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_BLOCK)); break;
1657         }
1658         switch(eHorz)
1659         {
1660             case SDRTEXTHORZADJUST_LEFT: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BOTTOM)); break;
1661             case SDRTEXTHORZADJUST_CENTER: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER)); break;
1662             case SDRTEXTHORZADJUST_RIGHT: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP)); break;
1663             case SDRTEXTHORZADJUST_BLOCK: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BLOCK)); break;
1664         }
1665 
1666         SetObjectItemSet(aNewSet);
1667 
1668         pOutlinerParaObject = GetOutlinerParaObject();
1669         if( pOutlinerParaObject )
1670         {
1671             // set ParaObject orientation accordingly
1672             pOutlinerParaObject->SetVertical(bVertical);
1673         }
1674 
1675         // restore object size
1676         SetSnapRect(aObjectRect);
1677     }
1678 }
1679 
1680 ////////////////////////////////////////////////////////////////////////////////////////////////////
1681 //
1682 // transformation interface for StarOfficeAPI. This implements support for
1683 // homogen 3x3 matrices containing the transformation of the SdrObject. At the
1684 // moment it contains a shearX, rotation and translation, but for setting all linear
1685 // transforms like Scale, ShearX, ShearY, Rotate and Translate are supported.
1686 //
1687 ////////////////////////////////////////////////////////////////////////////////////////////////////
1688 // gets base transformation and rectangle of object. If it's an SdrPathObj it fills the PolyPolygon
1689 // with the base geometry and returns TRUE. Otherwise it returns FALSE.
1690 sal_Bool SdrTextObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& /*rPolyPolygon*/) const
1691 {
1692     // get turn and shear
1693     double fRotate = (aGeo.nDrehWink / 100.0) * F_PI180;
1694     double fShearX = (aGeo.nShearWink / 100.0) * F_PI180;
1695 
1696     // get aRect, this is the unrotated snaprect
1697     Rectangle aRectangle(aRect);
1698 
1699     // fill other values
1700     basegfx::B2DTuple aScale(aRectangle.GetWidth(), aRectangle.GetHeight());
1701     basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top());
1702 
1703     // position maybe relative to anchorpos, convert
1704     if( pModel && pModel->IsWriter() )
1705     {
1706         if(GetAnchorPos().X() || GetAnchorPos().Y())
1707         {
1708             aTranslate -= basegfx::B2DTuple(GetAnchorPos().X(), GetAnchorPos().Y());
1709         }
1710     }
1711 
1712     // force MapUnit to 100th mm
1713     const SfxMapUnit eMapUnit(GetObjectMapUnit());
1714     if(eMapUnit != SFX_MAPUNIT_100TH_MM)
1715     {
1716         switch(eMapUnit)
1717         {
1718             case SFX_MAPUNIT_TWIP :
1719             {
1720                 // postion
1721                 aTranslate.setX(ImplTwipsToMM(aTranslate.getX()));
1722                 aTranslate.setY(ImplTwipsToMM(aTranslate.getY()));
1723 
1724                 // size
1725                 aScale.setX(ImplTwipsToMM(aScale.getX()));
1726                 aScale.setY(ImplTwipsToMM(aScale.getY()));
1727 
1728                 break;
1729             }
1730             default:
1731             {
1732                 DBG_ERROR("TRGetBaseGeometry: Missing unit translation to 100th mm!");
1733             }
1734         }
1735     }
1736 
1737     // build matrix
1738     rMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
1739         aScale,
1740         basegfx::fTools::equalZero(fShearX) ? 0.0 : tan(fShearX),
1741         basegfx::fTools::equalZero(fRotate) ? 0.0 : -fRotate,
1742         aTranslate);
1743 
1744     return sal_False;
1745 }
1746 
1747 // sets the base geometry of the object using infos contained in the homogen 3x3 matrix.
1748 // If it's an SdrPathObj it will use the provided geometry information. The Polygon has
1749 // to use (0,0) as upper left and will be scaled to the given size in the matrix.
1750 void SdrTextObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const basegfx::B2DPolyPolygon& /*rPolyPolygon*/)
1751 {
1752     // break up matrix
1753     basegfx::B2DTuple aScale;
1754     basegfx::B2DTuple aTranslate;
1755     double fRotate(0.0);
1756     double fShearX(0.0);
1757     rMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
1758 
1759     // #i75086# Old DrawingLayer (GeoStat and geometry) does not support holding negative scalings
1760     // in X and Y which equal a 180 degree rotation. Recognize it and react accordingly
1761     if(basegfx::fTools::less(aScale.getX(), 0.0) && basegfx::fTools::less(aScale.getY(), 0.0))
1762     {
1763         aScale.setX(fabs(aScale.getX()));
1764         aScale.setY(fabs(aScale.getY()));
1765         fRotate = fmod(fRotate + F_PI, F_2PI);
1766     }
1767 
1768     // reset object shear and rotations
1769     aGeo.nDrehWink = 0;
1770     aGeo.RecalcSinCos();
1771     aGeo.nShearWink = 0;
1772     aGeo.RecalcTan();
1773 
1774     // force metric to pool metric
1775     const SfxMapUnit eMapUnit(GetObjectMapUnit());
1776     if(eMapUnit != SFX_MAPUNIT_100TH_MM)
1777     {
1778         switch(eMapUnit)
1779         {
1780             case SFX_MAPUNIT_TWIP :
1781             {
1782                 // position
1783                 aTranslate.setX(ImplMMToTwips(aTranslate.getX()));
1784                 aTranslate.setY(ImplMMToTwips(aTranslate.getY()));
1785 
1786                 // size
1787                 aScale.setX(ImplMMToTwips(aScale.getX()));
1788                 aScale.setY(ImplMMToTwips(aScale.getY()));
1789 
1790                 break;
1791             }
1792             default:
1793             {
1794                 DBG_ERROR("TRSetBaseGeometry: Missing unit translation to PoolMetric!");
1795             }
1796         }
1797     }
1798 
1799     // if anchor is used, make position relative to it
1800     if( pModel && pModel->IsWriter() )
1801     {
1802         if(GetAnchorPos().X() || GetAnchorPos().Y())
1803         {
1804             aTranslate += basegfx::B2DTuple(GetAnchorPos().X(), GetAnchorPos().Y());
1805         }
1806     }
1807 
1808     // build and set BaseRect (use scale)
1809     Point aPoint = Point();
1810     Size aSize(FRound(aScale.getX()), FRound(aScale.getY()));
1811     Rectangle aBaseRect(aPoint, aSize);
1812     SetSnapRect(aBaseRect);
1813 
1814     // shear?
1815     if(!basegfx::fTools::equalZero(fShearX))
1816     {
1817         GeoStat aGeoStat;
1818         aGeoStat.nShearWink = FRound((atan(fShearX) / F_PI180) * 100.0);
1819         aGeoStat.RecalcTan();
1820         Shear(Point(), aGeoStat.nShearWink, aGeoStat.nTan, sal_False);
1821     }
1822 
1823     // rotation?
1824     if(!basegfx::fTools::equalZero(fRotate))
1825     {
1826         GeoStat aGeoStat;
1827 
1828         // #i78696#
1829         // fRotate is matematically correct, but aGeoStat.nDrehWink is
1830         // mirrored -> mirror value here
1831         aGeoStat.nDrehWink = NormAngle360(FRound(-fRotate / F_PI18000));
1832         aGeoStat.RecalcSinCos();
1833         Rotate(Point(), aGeoStat.nDrehWink, aGeoStat.nSin, aGeoStat.nCos);
1834     }
1835 
1836     // translate?
1837     if(!aTranslate.equalZero())
1838     {
1839         Move(Size(FRound(aTranslate.getX()), FRound(aTranslate.getY())));
1840     }
1841 }
1842 
1843 bool SdrTextObj::IsRealyEdited() const
1844 {
1845     return pEdtOutl && pEdtOutl->IsModified();
1846 }
1847 
1848 /////////////////////////////////////////////////////////////////////////////////////////////////
1849 // moved inlines here form hxx
1850 
1851 long SdrTextObj::GetEckenradius() const
1852 {
1853     return ((SdrEckenradiusItem&)(GetObjectItemSet().Get(SDRATTR_ECKENRADIUS))).GetValue();
1854 }
1855 
1856 long SdrTextObj::GetMinTextFrameHeight() const
1857 {
1858     return ((SdrTextMinFrameHeightItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_MINFRAMEHEIGHT))).GetValue();
1859 }
1860 
1861 long SdrTextObj::GetMaxTextFrameHeight() const
1862 {
1863     return ((SdrTextMaxFrameHeightItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_MAXFRAMEHEIGHT))).GetValue();
1864 }
1865 
1866 long SdrTextObj::GetMinTextFrameWidth() const
1867 {
1868     return ((SdrTextMinFrameWidthItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_MINFRAMEWIDTH))).GetValue();
1869 }
1870 
1871 long SdrTextObj::GetMaxTextFrameWidth() const
1872 {
1873     return ((SdrTextMaxFrameWidthItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_MAXFRAMEWIDTH))).GetValue();
1874 }
1875 
1876 FASTBOOL SdrTextObj::IsFontwork() const
1877 {
1878     return (bTextFrame) ? sal_False // Default ist FALSE
1879         : ((XFormTextStyleItem&)(GetObjectItemSet().Get(XATTR_FORMTXTSTYLE))).GetValue()!=XFT_NONE;
1880 }
1881 
1882 FASTBOOL SdrTextObj::IsHideContour() const
1883 {
1884     return (bTextFrame) ? sal_False // Default ist: Nein, kein HideContour; HideContour nicht bei TextFrames
1885         : ((XFormTextHideFormItem&)(GetObjectItemSet().Get(XATTR_FORMTXTHIDEFORM))).GetValue();
1886 }
1887 
1888 FASTBOOL SdrTextObj::IsContourTextFrame() const
1889 {
1890     return (bTextFrame) ? sal_False // ContourFrame nicht bei normalen TextFrames
1891         : ((SdrTextContourFrameItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_CONTOURFRAME))).GetValue();
1892 }
1893 
1894 long SdrTextObj::GetTextLeftDistance() const
1895 {
1896     return ((SdrTextLeftDistItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_LEFTDIST))).GetValue();
1897 }
1898 
1899 long SdrTextObj::GetTextRightDistance() const
1900 {
1901     return ((SdrTextRightDistItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_RIGHTDIST))).GetValue();
1902 }
1903 
1904 long SdrTextObj::GetTextUpperDistance() const
1905 {
1906     return ((SdrTextUpperDistItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_UPPERDIST))).GetValue();
1907 }
1908 
1909 long SdrTextObj::GetTextLowerDistance() const
1910 {
1911     return ((SdrTextLowerDistItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_LOWERDIST))).GetValue();
1912 }
1913 
1914 SdrTextAniKind SdrTextObj::GetTextAniKind() const
1915 {
1916     return ((SdrTextAniKindItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_ANIKIND))).GetValue();
1917 }
1918 
1919 SdrTextAniDirection SdrTextObj::GetTextAniDirection() const
1920 {
1921     return ((SdrTextAniDirectionItem&)(GetObjectItemSet().Get(SDRATTR_TEXT_ANIDIRECTION))).GetValue();
1922 }
1923 
1924 // #111096#
1925 // Access to thext hidden flag
1926 sal_Bool SdrTextObj::GetTextHidden() const
1927 {
1928     return mbTextHidden;
1929 }
1930 
1931 void SdrTextObj::NbcSetTextHidden(sal_Bool bNew)
1932 {
1933     if(bNew != mbTextHidden)
1934     {
1935         mbTextHidden = bNew;
1936     }
1937 }
1938 
1939 // #111096#
1940 // Get necessary data for text scroll animation. ATM base it on a Text-Metafile and a
1941 // painting rectangle. Rotation is excluded from the returned values.
1942 GDIMetaFile* SdrTextObj::GetTextScrollMetaFileAndRectangle(
1943     Rectangle& rScrollRectangle, Rectangle& rPaintRectangle)
1944 {
1945     GDIMetaFile* pRetval = 0L;
1946     SdrOutliner& rOutliner = ImpGetDrawOutliner();
1947     Rectangle aTextRect;
1948     Rectangle aAnchorRect;
1949     Rectangle aPaintRect;
1950     Fraction aFitXKorreg(1,1);
1951     bool bContourFrame(IsContourTextFrame());
1952 
1953     // get outliner set up. To avoid getting a somehow rotated MetaFile,
1954     // temporarily disable object rotation.
1955     sal_Int32 nAngle(aGeo.nDrehWink);
1956     aGeo.nDrehWink = 0L;
1957     ImpSetupDrawOutlinerForPaint( bContourFrame, rOutliner, aTextRect, aAnchorRect, aPaintRect, aFitXKorreg );
1958     aGeo.nDrehWink = nAngle;
1959 
1960     Rectangle aScrollFrameRect(aPaintRect);
1961     const SfxItemSet& rSet = GetObjectItemSet();
1962     SdrTextAniDirection eDirection = ((SdrTextAniDirectionItem&)(rSet.Get(SDRATTR_TEXT_ANIDIRECTION))).GetValue();
1963 
1964     if(SDRTEXTANI_LEFT == eDirection || SDRTEXTANI_RIGHT == eDirection)
1965     {
1966         aScrollFrameRect.Left() = aAnchorRect.Left();
1967         aScrollFrameRect.Right() = aAnchorRect.Right();
1968     }
1969 
1970     if(SDRTEXTANI_UP == eDirection || SDRTEXTANI_DOWN == eDirection)
1971     {
1972         aScrollFrameRect.Top() = aAnchorRect.Top();
1973         aScrollFrameRect.Bottom() = aAnchorRect.Bottom();
1974     }
1975 
1976     // create the MetaFile
1977     pRetval = new GDIMetaFile;
1978     VirtualDevice aBlackHole;
1979     aBlackHole.EnableOutput(sal_False);
1980     pRetval->Record(&aBlackHole);
1981     Point aPaintPos = aPaintRect.TopLeft();
1982 
1983     rOutliner.Draw(&aBlackHole, aPaintPos);
1984 
1985     pRetval->Stop();
1986     pRetval->WindStart();
1987 
1988     // return PaintRectanglePixel and pRetval;
1989     rScrollRectangle = aScrollFrameRect;
1990     rPaintRectangle = aPaintRect;
1991 
1992     return pRetval;
1993 }
1994 
1995 // #111096#
1996 // Access to TextAnimationAllowed flag
1997 bool SdrTextObj::IsTextAnimationAllowed() const
1998 {
1999     return mbTextAnimationAllowed;
2000 }
2001 
2002 void SdrTextObj::SetTextAnimationAllowed(sal_Bool bNew)
2003 {
2004     if(mbTextAnimationAllowed != bNew)
2005     {
2006         mbTextAnimationAllowed = bNew;
2007         ActionChanged();
2008     }
2009 }
2010 
2011 /** called from the SdrObjEditView during text edit when the status of the edit outliner changes */
2012 void SdrTextObj::onEditOutlinerStatusEvent( EditStatus* pEditStatus )
2013 {
2014     const sal_uInt32 nStat = pEditStatus->GetStatusWord();
2015     const bool bGrowX=(nStat & EE_STAT_TEXTWIDTHCHANGED) !=0;
2016     const bool bGrowY=(nStat & EE_STAT_TEXTHEIGHTCHANGED) !=0;
2017     if(bTextFrame && (bGrowX || bGrowY))
2018     {
2019         const bool bAutoGrowHgt= bTextFrame && IsAutoGrowHeight();
2020         const bool bAutoGrowWdt= bTextFrame && IsAutoGrowWidth();
2021 
2022         if ((bGrowX && bAutoGrowWdt) || (bGrowY && bAutoGrowHgt))
2023         {
2024             AdjustTextFrameWidthAndHeight();
2025         }
2026     }
2027 }
2028 
2029 /** returns the currently active text. */
2030 SdrText* SdrTextObj::getActiveText() const
2031 {
2032     if( !mpText )
2033         return getText( 0 );
2034     else
2035         return mpText;
2036 }
2037 
2038 /** returns the nth available text. */
2039 SdrText* SdrTextObj::getText( sal_Int32 nIndex ) const
2040 {
2041     if( nIndex == 0 )
2042     {
2043         if( mpText == 0 )
2044             const_cast< SdrTextObj* >(this)->mpText = new SdrText( *(const_cast< SdrTextObj* >(this)) );
2045         return mpText;
2046     }
2047     else
2048     {
2049         return 0;
2050     }
2051 }
2052 
2053 /** returns the number of texts available for this object. */
2054 sal_Int32 SdrTextObj::getTextCount() const
2055 {
2056     return 1;
2057 }
2058 
2059 /** changes the current active text */
2060 void SdrTextObj::setActiveText( sal_Int32 /*nIndex*/ )
2061 {
2062 }
2063 
2064 /** returns the index of the text that contains the given point or -1 */
2065 sal_Int32 SdrTextObj::CheckTextHit(const Point& /*rPnt*/) const
2066 {
2067     return 0;
2068 }
2069 
2070 void SdrTextObj::SetObjectItemNoBroadcast(const SfxPoolItem& rItem)
2071 {
2072     static_cast< sdr::properties::TextProperties& >(GetProperties()).SetObjectItemNoBroadcast(rItem);
2073 }
2074 
2075 /////////////////////////////////////////////////////////////////////////////////////////////////
2076 //
2077 // Konzept des TextObjekts:
2078 // ~~~~~~~~~~~~~~~~~~~~~~~~
2079 // Attribute/Varianten:
2080 // - sal_Bool Textrahmen / beschriftetes Zeichenobjekt
2081 // - sal_Bool FontWork                 (wenn nicht Textrahmen und nicht ContourTextFrame)
2082 // - sal_Bool ContourTextFrame         (wenn nicht Textrahmen und nicht Fontwork)
2083 // - long Drehwinkel               (wenn nicht FontWork)
2084 // - long Textrahmenabstaende      (wenn nicht FontWork)
2085 // - sal_Bool FitToSize                (wenn nicht FontWork)
2086 // - sal_Bool AutoGrowingWidth/Height  (wenn nicht FitToSize und nicht FontWork)
2087 // - long Min/MaxFrameWidth/Height (wenn AutoGrowingWidth/Height)
2088 // - enum Horizontale Textverankerung Links,Mitte,Rechts,Block,Stretch(ni)
2089 // - enum Vertikale Textverankerung Oben,Mitte,Unten,Block,Stretch(ni)
2090 // - enum Laufschrift              (wenn nicht FontWork)
2091 //
2092 // Jedes abgeleitete Objekt ist entweder ein Textrahmen (bTextFrame=sal_True)
2093 // oder ein beschriftetes Zeichenobjekt (bTextFrame=sal_False).
2094 //
2095 // Defaultverankerung von Textrahmen:
2096 //   SDRTEXTHORZADJUST_BLOCK, SDRTEXTVERTADJUST_TOP
2097 //   = statische Pooldefaults
2098 // Defaultverankerung von beschrifteten Zeichenobjekten:
2099 //   SDRTEXTHORZADJUST_CENTER, SDRTEXTVERTADJUST_CENTER
2100 //   durch harte Attributierung von SdrAttrObj
2101 //
2102 // Jedes vom SdrTextObj abgeleitete Objekt muss ein "UnrotatedSnapRect"
2103 // (->TakeUnrotatedSnapRect()) liefern (Drehreferenz ist TopLeft dieses
2104 // Rechtecks (aGeo.nDrehWink)), welches die Grundlage der Textverankerung
2105 // bildet. Von diesem werden dann ringsum die Textrahmenabstaende abgezogen;
2106 // das Ergebnis ist der Ankerbereich (->TakeTextAnchorRect()). Innerhalb
2107 // dieses Bereichs wird dann in Abhaengigkeit von der horizontalen und
2108 // vertikalen Ausrichtung (SdrTextVertAdjust,SdrTextHorzAdjust) der Ankerpunkt
2109 // sowie der Ausgabebereich bestimmt. Bei beschrifteten Grafikobjekten kann
2110 // der Ausgabebereich durchaus groesser als der Ankerbereich werden, bei
2111 // Textrahmen ist er stets kleiner oder gleich (ausser bei negativen Textrahmen-
2112 // abstaenden).
2113 //
2114 // FitToSize hat Prioritaet vor Textverankerung und AutoGrowHeight/Width. Der
2115 // Ausgabebereich ist bei FitToSize immer genau der Ankerbereich. Weiterhin
2116 // gibt es bei FitToSize keinen automatischen Zeilenumbruch.
2117 //
2118 // ContourTextFrame:
2119 // - long Drehwinkel
2120 // - long Textrahmenabstaende         spaeter vielleicht
2121 // - sal_Bool FitToSize                   spaeter vielleicht
2122 // - sal_Bool AutoGrowingWidth/Height     viel spaeter vielleicht
2123 // - long Min/MaxFrameWidth/Height    viel spaeter vielleicht
2124 // - enum Horizontale Textverankerung spaeter vielleicht, erstmal Links, Absatz zentr.
2125 // - enum Vertikale Textverankerung   spaeter vielleicht, erstmal oben
2126 // - enum Laufschrift                 spaeter vielleicht (evtl. sogar mit korrektem Clipping)
2127 //
2128 // Bei Aenderungen zu beachten:
2129 // - Paint
2130 // - HitTest
2131 // - ConvertToPoly
2132 // - Edit
2133 // - Drucken,Speichern, Paint in Nachbarview waerend Edit
2134 // - ModelChanged (z.B. durch NachbarView oder Lineale) waerend Edit
2135 // - FillColorChanged waerend Edit
2136 // - uvm...
2137 //
2138 /////////////////////////////////////////////////////////////////////////////////////////////////
2139 
2140