1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdotxed.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svdotext.hxx>
35 #include "svditext.hxx"
36 #include <svx/svdmodel.hxx> // fuer GetMaxObjSize
37 #include <svx/svdoutl.hxx>
38 #include <svx/outliner.hxx>
39 #include <editstat.hxx>
40 #include <svtools/itemset.hxx>
41 #include <svx/eeitem.hxx>
42 #include <svx/sdtfchim.hxx>
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 // @@@@@@ @@@@@ @@ @@ @@@@@@ @@@@ @@@@@ @@@@@@
47 // @@ @@ @@@ @@@ @@ @@ @@ @@ @@ @@
48 // @@ @@ @@@@@ @@ @@ @@ @@ @@ @@
49 // @@ @@@@ @@@ @@ @@ @@ @@@@@ @@
50 // @@ @@ @@@@@ @@ @@ @@ @@ @@ @@
51 // @@ @@ @@@ @@@ @@ @@ @@ @@ @@ @@ @@
52 // @@ @@@@@ @@ @@ @@ @@@@ @@@@@ @@@@
56 ////////////////////////////////////////////////////////////////////////////////////////////////////
58 FASTBOOL
SdrTextObj::HasTextEdit() const
60 // lt. Anweisung von MB duerfen gelinkte Textobjekte nun doch
61 // geaendert werden (kein automatisches Reload)
65 sal_Bool
SdrTextObj::BegTextEdit(SdrOutliner
& rOutl
)
67 if (pEdtOutl
!=NULL
) return sal_False
; // Textedit laeuft evtl. schon an einer anderen View!
73 USHORT nOutlinerMode
= OUTLINERMODE_OUTLINEOBJECT
;
75 nOutlinerMode
= OUTLINERMODE_TEXTOBJECT
;
76 rOutl
.Init( nOutlinerMode
);
77 rOutl
.SetRefDevice( pModel
->GetRefDevice() );
79 FASTBOOL
bFitToSize(IsFitToSize());
80 FASTBOOL bContourFrame
=IsContourTextFrame();
81 ImpSetTextEditParams();
84 ULONG nStat
=rOutl
.GetControlWord();
85 nStat
|=EE_CNTRL_AUTOPAGESIZE
;
86 if (bFitToSize
|| IsAutoFit())
87 nStat
|=EE_CNTRL_STRETCHING
;
89 nStat
&=~EE_CNTRL_STRETCHING
;
90 rOutl
.SetControlWord(nStat
);
93 OutlinerParaObject
* pOutlinerParaObject
= GetOutlinerParaObject();
94 if(pOutlinerParaObject
!=NULL
)
96 rOutl
.SetText(*GetOutlinerParaObject());
97 rOutl
.SetFixedCellHeight(((const SdrTextFixedCellHeightItem
&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT
)).GetValue());
100 // ggf. Rahmenattribute am 1. (neuen) Absatz des Outliners setzen
101 if( !HasTextImpl( &rOutl
) )
103 // Outliner has no text so we must set some
104 // empty text so the outliner initialise itself
105 rOutl
.SetText( String(), rOutl
.GetParagraph( 0 ) );
108 rOutl
.SetStyleSheet( 0, GetStyleSheet());
110 // Beim setzen der harten Attribute an den ersten Absatz muss
111 // der Parent pOutlAttr (=die Vorlage) temporaer entfernt
112 // werden, da sonst bei SetParaAttribs() auch alle in diesem
113 // Parent enthaltenen Items hart am Absatz attributiert werden.
115 const SfxItemSet
& rSet
= GetObjectItemSet();
116 SfxItemSet
aFilteredSet(*rSet
.GetPool(), EE_ITEMS_START
, EE_ITEMS_END
);
117 aFilteredSet
.Put(rSet
);
118 rOutl
.SetParaAttribs(0, aFilteredSet
);
122 Rectangle aAnchorRect
;
124 TakeTextRect(rOutl
, aTextRect
, FALSE
,
125 &aAnchorRect
/* #97097# give TRUE here, not FALSE */);
126 Fraction
aFitXKorreg(1,1);
127 ImpSetCharStretching(rOutl
,aTextRect
.GetSize(),aAnchorRect
.GetSize(),aFitXKorreg
);
129 else if (IsAutoFit())
131 ImpAutoFitText(rOutl
);
134 if(pOutlinerParaObject
)
136 // #78476# also repaint when animated text is put to edit mode
137 // to not make appear the text double
138 // #111096# should now repaint automatically.
139 // BOOL bIsAnimated(pPlusData && pPlusData->pAnimator);
141 if(aGeo
.nDrehWink
|| IsFontwork() /*|| bIsAnimated*/)
143 // only repaint here, no real objectchange
146 BroadcastObjectChange();
150 rOutl
.UpdateFields();
151 rOutl
.ClearModifyFlag();
156 void SdrTextObj::TakeTextEditArea(Size
* pPaperMin
, Size
* pPaperMax
, Rectangle
* pViewInit
, Rectangle
* pViewMin
) const
158 FASTBOOL
bFitToSize(IsFitToSize());
159 Size aPaperMin
,aPaperMax
;
161 TakeTextAnchorRect(aViewInit
);
162 if (aGeo
.nDrehWink
!=0) {
163 Point
aCenter(aViewInit
.Center());
164 aCenter
-=aViewInit
.TopLeft();
165 Point
aCenter0(aCenter
);
166 RotatePoint(aCenter
,Point(),aGeo
.nSin
,aGeo
.nCos
);
168 aViewInit
.Move(aCenter
.X(),aCenter
.Y());
170 Size
aAnkSiz(aViewInit
.GetSize());
171 aAnkSiz
.Width()--; aAnkSiz
.Height()--; // weil GetSize() ein draufaddiert
172 Size
aMaxSiz(1000000,1000000);
174 Size
aTmpSiz(pModel
->GetMaxObjSize());
175 if (aTmpSiz
.Width()!=0) aMaxSiz
.Width()=aTmpSiz
.Width();
176 if (aTmpSiz
.Height()!=0) aMaxSiz
.Height()=aTmpSiz
.Height();
180 // Done earlier since used in else tree below
181 SdrTextHorzAdjust
eHAdj(GetTextHorizontalAdjust());
182 SdrTextVertAdjust
eVAdj(GetTextVerticalAdjust());
186 long nMinWdt
=GetMinTextFrameWidth();
187 long nMinHgt
=GetMinTextFrameHeight();
188 long nMaxWdt
=GetMaxTextFrameWidth();
189 long nMaxHgt
=GetMaxTextFrameHeight();
190 if (nMinWdt
<1) nMinWdt
=1;
191 if (nMinHgt
<1) nMinHgt
=1;
193 if (nMaxWdt
==0 || nMaxWdt
>aMaxSiz
.Width()) nMaxWdt
=aMaxSiz
.Width();
194 if (nMaxHgt
==0 || nMaxHgt
>aMaxSiz
.Height()) nMaxHgt
=aMaxSiz
.Height();
195 if (!IsAutoGrowWidth() ) { nMaxWdt
=aAnkSiz
.Width(); nMinWdt
=nMaxWdt
; }
196 if (!IsAutoGrowHeight()) { nMaxHgt
=aAnkSiz
.Height(); nMinHgt
=nMaxHgt
; }
197 SdrTextAniKind eAniKind
=GetTextAniKind();
198 SdrTextAniDirection eAniDirection
=GetTextAniDirection();
201 BOOL bInEditMode
= IsInEditMode();
203 if (!bInEditMode
&& (eAniKind
==SDRTEXTANI_SCROLL
|| eAniKind
==SDRTEXTANI_ALTERNATE
|| eAniKind
==SDRTEXTANI_SLIDE
))
205 // Grenzenlose Papiergroesse fuer Laufschrift
206 if (eAniDirection
==SDRTEXTANI_LEFT
|| eAniDirection
==SDRTEXTANI_RIGHT
) nMaxWdt
=1000000;
207 if (eAniDirection
==SDRTEXTANI_UP
|| eAniDirection
==SDRTEXTANI_DOWN
) nMaxHgt
=1000000;
209 aPaperMax
.Width()=nMaxWdt
;
210 aPaperMax
.Height()=nMaxHgt
;
214 aPaperMin
.Width()=nMinWdt
;
215 aPaperMin
.Height()=nMinHgt
;
220 // aPaperMin needs to be set to object's size if full width is activated
221 // for hor or ver writing respectively
222 if((SDRTEXTHORZADJUST_BLOCK
== eHAdj
&& !IsVerticalWriting())
223 || (SDRTEXTVERTADJUST_BLOCK
== eVAdj
&& IsVerticalWriting()))
231 if (pViewMin
!=NULL
) {
234 long nXFree
=aAnkSiz
.Width()-aPaperMin
.Width();
235 if (eHAdj
==SDRTEXTHORZADJUST_LEFT
) pViewMin
->Right()-=nXFree
;
236 else if (eHAdj
==SDRTEXTHORZADJUST_RIGHT
) pViewMin
->Left()+=nXFree
;
237 else { pViewMin
->Left()+=nXFree
/2; pViewMin
->Right()=pViewMin
->Left()+aPaperMin
.Width(); }
239 long nYFree
=aAnkSiz
.Height()-aPaperMin
.Height();
240 if (eVAdj
==SDRTEXTVERTADJUST_TOP
) pViewMin
->Bottom()-=nYFree
;
241 else if (eVAdj
==SDRTEXTVERTADJUST_BOTTOM
) pViewMin
->Top()+=nYFree
;
242 else { pViewMin
->Top()+=nYFree
/2; pViewMin
->Bottom()=pViewMin
->Top()+aPaperMin
.Height(); }
245 // Die PaperSize soll in den meisten Faellen von selbst wachsen
247 if(IsVerticalWriting())
248 aPaperMin
.Width() = 0;
250 aPaperMin
.Height() = 0; // #33102#
252 if(eHAdj
!=SDRTEXTHORZADJUST_BLOCK
|| bFitToSize
) {
256 // #103516# For complete ver adjust support, set paper min height to 0, here.
257 if(SDRTEXTVERTADJUST_BLOCK
!= eVAdj
|| bFitToSize
)
259 aPaperMin
.Height() = 0;
262 if (pPaperMin
!=NULL
) *pPaperMin
=aPaperMin
;
263 if (pPaperMax
!=NULL
) *pPaperMax
=aPaperMax
;
264 if (pViewInit
!=NULL
) *pViewInit
=aViewInit
;
267 void SdrTextObj::EndTextEdit(SdrOutliner
& rOutl
)
269 if(rOutl
.IsModified())
271 OutlinerParaObject
* pNewText
= NULL
;
273 if(HasTextImpl( &rOutl
) )
275 // Damit der grauen Feldhintergrund wieder verschwindet
276 rOutl
.UpdateFields();
278 sal_uInt16 nParaAnz
= static_cast< sal_uInt16
>( rOutl
.GetParagraphCount() );
279 pNewText
= rOutl
.CreateParaObject( 0, nParaAnz
);
282 // need to end edit mode early since SetOutlinerParaObject already
283 // uses GetCurrentBoundRect() which needs to take the text into account
285 mbInEditMode
= FALSE
;
286 SetOutlinerParaObject(pNewText
);
291 UINT32 nStat
= rOutl
.GetControlWord();
292 nStat
&= ~EE_CNTRL_AUTOPAGESIZE
;
293 rOutl
.SetControlWord(nStat
);
296 mbInEditMode
= FALSE
;
299 USHORT
SdrTextObj::GetOutlinerViewAnchorMode() const
301 SdrTextHorzAdjust eH
=GetTextHorizontalAdjust();
302 SdrTextVertAdjust eV
=GetTextVerticalAdjust();
303 EVAnchorMode eRet
=ANCHOR_TOP_LEFT
;
304 if (IsContourTextFrame()) return (USHORT
)eRet
;
305 if (eH
==SDRTEXTHORZADJUST_LEFT
) {
306 if (eV
==SDRTEXTVERTADJUST_TOP
) {
307 eRet
=ANCHOR_TOP_LEFT
;
308 } else if (eV
==SDRTEXTVERTADJUST_BOTTOM
) {
309 eRet
=ANCHOR_BOTTOM_LEFT
;
311 eRet
=ANCHOR_VCENTER_LEFT
;
313 } else if (eH
==SDRTEXTHORZADJUST_RIGHT
) {
314 if (eV
==SDRTEXTVERTADJUST_TOP
) {
315 eRet
=ANCHOR_TOP_RIGHT
;
316 } else if (eV
==SDRTEXTVERTADJUST_BOTTOM
) {
317 eRet
=ANCHOR_BOTTOM_RIGHT
;
319 eRet
=ANCHOR_VCENTER_RIGHT
;
322 if (eV
==SDRTEXTVERTADJUST_TOP
) {
323 eRet
=ANCHOR_TOP_HCENTER
;
324 } else if (eV
==SDRTEXTVERTADJUST_BOTTOM
) {
325 eRet
=ANCHOR_BOTTOM_HCENTER
;
327 eRet
=ANCHOR_VCENTER_HCENTER
;
333 void SdrTextObj::ImpSetTextEditParams() const
335 if (pEdtOutl
!=NULL
) {
336 FASTBOOL bUpdMerk
=pEdtOutl
->GetUpdateMode();
337 if (bUpdMerk
) pEdtOutl
->SetUpdateMode(FALSE
);
341 TakeTextEditArea(&aPaperMin
,&aPaperMax
,&aEditArea
,NULL
);
342 //SdrFitToSizeType eFit=GetFitToSize();
343 //FASTBOOL bFitToSize=(eFit==SDRTEXTFIT_PROPORTIONAL || eFit==SDRTEXTFIT_ALLLINES);
344 FASTBOOL bContourFrame
=IsContourTextFrame();
345 //EVAnchorMode eAM=(EVAnchorMode)GetOutlinerViewAnchorMode();
346 //ULONG nViewAnz=pEdtOutl->GetViewCount();
347 pEdtOutl
->SetMinAutoPaperSize(aPaperMin
);
348 pEdtOutl
->SetMaxAutoPaperSize(aPaperMax
);
349 pEdtOutl
->SetPaperSize(Size());
351 Rectangle aAnchorRect
;
352 TakeTextAnchorRect(aAnchorRect
);
353 ImpSetContourPolygon(*pEdtOutl
,aAnchorRect
, TRUE
);
355 if (bUpdMerk
) pEdtOutl
->SetUpdateMode(TRUE
);