Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / svx / source / svdraw / svdotxed.cxx
blob3d3acc3860372d47caab16f782cf0ce3c2d4a4ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svx/svdotext.hxx>
31 #include "svx/svditext.hxx"
32 #include <svx/svdmodel.hxx> // for GetMaxObjSize
33 #include <svx/svdoutl.hxx>
34 #include <editeng/outliner.hxx>
35 #include <editeng/editstat.hxx>
36 #include <svl/itemset.hxx>
37 #include <editeng/eeitem.hxx>
38 #include <svx/sdtfchim.hxx>
41 bool SdrTextObj::HasTextEdit() const
43 // linked text objects may be changed (no automatic reload)
44 return true;
47 sal_Bool SdrTextObj::BegTextEdit(SdrOutliner& rOutl)
49 if (pEdtOutl!=NULL) return sal_False; // Textedit might already run in another View!
50 pEdtOutl=&rOutl;
52 mbInEditMode = sal_True;
54 sal_uInt16 nOutlinerMode = OUTLINERMODE_OUTLINEOBJECT;
55 if ( !IsOutlText() )
56 nOutlinerMode = OUTLINERMODE_TEXTOBJECT;
57 rOutl.Init( nOutlinerMode );
58 rOutl.SetRefDevice( pModel->GetRefDevice() );
60 bool bFitToSize(IsFitToSize());
61 bool bContourFrame=IsContourTextFrame();
62 ImpSetTextEditParams();
64 if (!bContourFrame) {
65 sal_uIntPtr nStat=rOutl.GetControlWord();
66 nStat|=EE_CNTRL_AUTOPAGESIZE;
67 if (bFitToSize || IsAutoFit())
68 nStat|=EE_CNTRL_STRETCHING;
69 else
70 nStat&=~EE_CNTRL_STRETCHING;
71 rOutl.SetControlWord(nStat);
74 OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
75 if(pOutlinerParaObject!=NULL)
77 rOutl.SetText(*GetOutlinerParaObject());
78 rOutl.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
81 // if necessary, set frame attributes for the first (new) paragraph of the
82 // outliner
83 if( !HasTextImpl( &rOutl ) )
85 // Outliner has no text so we must set some
86 // empty text so the outliner initialise itself
87 rOutl.SetText( String(), rOutl.GetParagraph( 0 ) );
89 if(GetStyleSheet())
90 rOutl.SetStyleSheet( 0, GetStyleSheet());
92 // When setting the "hard" attributes for first paragraph, the Parent
93 // pOutlAttr (i. e. the template) has to be removed temporarily. Else,
94 // at SetParaAttribs(), all attributes contained in the parent become
95 // attributed hard to the paragraph.
96 const SfxItemSet& rSet = GetObjectItemSet();
97 SfxItemSet aFilteredSet(*rSet.GetPool(), EE_ITEMS_START, EE_ITEMS_END);
98 aFilteredSet.Put(rSet);
99 rOutl.SetParaAttribs(0, aFilteredSet);
101 if (bFitToSize)
103 Rectangle aAnchorRect;
104 Rectangle aTextRect;
105 TakeTextRect(rOutl, aTextRect, sal_False,
106 &aAnchorRect);
107 Fraction aFitXKorreg(1,1);
108 ImpSetCharStretching(rOutl,aTextRect.GetSize(),aAnchorRect.GetSize(),aFitXKorreg);
110 else if (IsAutoFit())
112 ImpAutoFitText(rOutl);
115 if(pOutlinerParaObject)
117 if(aGeo.nDrehWink || IsFontwork())
119 // only repaint here, no real objectchange
120 BroadcastObjectChange();
124 rOutl.UpdateFields();
125 rOutl.ClearModifyFlag();
127 return sal_True;
130 void SdrTextObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const
132 bool bFitToSize(IsFitToSize());
133 Size aPaperMin,aPaperMax;
134 Rectangle aViewInit;
135 TakeTextAnchorRect(aViewInit);
136 if (aGeo.nDrehWink!=0) {
137 Point aCenter(aViewInit.Center());
138 aCenter-=aViewInit.TopLeft();
139 Point aCenter0(aCenter);
140 RotatePoint(aCenter,Point(),aGeo.nSin,aGeo.nCos);
141 aCenter-=aCenter0;
142 aViewInit.Move(aCenter.X(),aCenter.Y());
144 Size aAnkSiz(aViewInit.GetSize());
145 aAnkSiz.Width()--; aAnkSiz.Height()--; // because GetSize() adds 1
146 Size aMaxSiz(1000000,1000000);
147 if (pModel!=NULL) {
148 Size aTmpSiz(pModel->GetMaxObjSize());
149 if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
150 if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
153 // Done earlier since used in else tree below
154 SdrTextHorzAdjust eHAdj(GetTextHorizontalAdjust());
155 SdrTextVertAdjust eVAdj(GetTextVerticalAdjust());
157 if(IsTextFrame())
159 long nMinWdt=GetMinTextFrameWidth();
160 long nMinHgt=GetMinTextFrameHeight();
161 long nMaxWdt=GetMaxTextFrameWidth();
162 long nMaxHgt=GetMaxTextFrameHeight();
163 if (nMinWdt<1) nMinWdt=1;
164 if (nMinHgt<1) nMinHgt=1;
165 if (!bFitToSize) {
166 if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
167 if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
168 if (!IsAutoGrowWidth() ) { nMaxWdt=aAnkSiz.Width(); nMinWdt=nMaxWdt; }
169 if (!IsAutoGrowHeight()) { nMaxHgt=aAnkSiz.Height(); nMinHgt=nMaxHgt; }
170 SdrTextAniKind eAniKind=GetTextAniKind();
171 SdrTextAniDirection eAniDirection=GetTextAniDirection();
173 sal_Bool bInEditMode = IsInEditMode();
175 if (!bInEditMode && (eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE))
177 // ticker text uses an unlimited paper size
178 if (eAniDirection==SDRTEXTANI_LEFT || eAniDirection==SDRTEXTANI_RIGHT) nMaxWdt=1000000;
179 if (eAniDirection==SDRTEXTANI_UP || eAniDirection==SDRTEXTANI_DOWN) nMaxHgt=1000000;
181 aPaperMax.Width()=nMaxWdt;
182 aPaperMax.Height()=nMaxHgt;
183 } else {
184 aPaperMax=aMaxSiz;
186 aPaperMin.Width()=nMinWdt;
187 aPaperMin.Height()=nMinHgt;
189 else
191 // aPaperMin needs to be set to object's size if full width is activated
192 // for hor or ver writing respectively
193 if((SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
194 || (SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting()))
196 aPaperMin = aAnkSiz;
199 aPaperMax=aMaxSiz;
202 if (pViewMin!=NULL) {
203 *pViewMin=aViewInit;
205 long nXFree=aAnkSiz.Width()-aPaperMin.Width();
206 if (eHAdj==SDRTEXTHORZADJUST_LEFT) pViewMin->Right()-=nXFree;
207 else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) pViewMin->Left()+=nXFree;
208 else { pViewMin->Left()+=nXFree/2; pViewMin->Right()=pViewMin->Left()+aPaperMin.Width(); }
210 long nYFree=aAnkSiz.Height()-aPaperMin.Height();
211 if (eVAdj==SDRTEXTVERTADJUST_TOP) pViewMin->Bottom()-=nYFree;
212 else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) pViewMin->Top()+=nYFree;
213 else { pViewMin->Top()+=nYFree/2; pViewMin->Bottom()=pViewMin->Top()+aPaperMin.Height(); }
216 // PaperSize should grow automatically in most cases
217 if(IsVerticalWriting())
218 aPaperMin.Width() = 0;
219 else
220 aPaperMin.Height() = 0;
222 if(eHAdj!=SDRTEXTHORZADJUST_BLOCK || bFitToSize) {
223 aPaperMin.Width()=0;
226 // For complete vertical adjustment support, set paper min height to 0, here.
227 if(SDRTEXTVERTADJUST_BLOCK != eVAdj || bFitToSize)
229 aPaperMin.Height() = 0;
232 if (pPaperMin!=NULL) *pPaperMin=aPaperMin;
233 if (pPaperMax!=NULL) *pPaperMax=aPaperMax;
234 if (pViewInit!=NULL) *pViewInit=aViewInit;
237 void SdrTextObj::EndTextEdit(SdrOutliner& rOutl)
239 if(rOutl.IsModified())
241 OutlinerParaObject* pNewText = NULL;
243 if(HasTextImpl( &rOutl ) )
245 // to make the gray field background vanish again
246 rOutl.UpdateFields();
248 sal_uInt16 nParaAnz = static_cast< sal_uInt16 >( rOutl.GetParagraphCount() );
249 pNewText = rOutl.CreateParaObject( 0, nParaAnz );
252 // need to end edit mode early since SetOutlinerParaObject already
253 // uses GetCurrentBoundRect() which needs to take the text into account
254 // to work correct
255 mbInEditMode = sal_False;
256 SetOutlinerParaObject(pNewText);
259 pEdtOutl = NULL;
260 rOutl.Clear();
261 sal_uInt32 nStat = rOutl.GetControlWord();
262 nStat &= ~EE_CNTRL_AUTOPAGESIZE;
263 rOutl.SetControlWord(nStat);
265 mbInEditMode = sal_False;
268 sal_uInt16 SdrTextObj::GetOutlinerViewAnchorMode() const
270 SdrTextHorzAdjust eH=GetTextHorizontalAdjust();
271 SdrTextVertAdjust eV=GetTextVerticalAdjust();
272 EVAnchorMode eRet=ANCHOR_TOP_LEFT;
273 if (IsContourTextFrame()) return (sal_uInt16)eRet;
274 if (eH==SDRTEXTHORZADJUST_LEFT) {
275 if (eV==SDRTEXTVERTADJUST_TOP) {
276 eRet=ANCHOR_TOP_LEFT;
277 } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
278 eRet=ANCHOR_BOTTOM_LEFT;
279 } else {
280 eRet=ANCHOR_VCENTER_LEFT;
282 } else if (eH==SDRTEXTHORZADJUST_RIGHT) {
283 if (eV==SDRTEXTVERTADJUST_TOP) {
284 eRet=ANCHOR_TOP_RIGHT;
285 } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
286 eRet=ANCHOR_BOTTOM_RIGHT;
287 } else {
288 eRet=ANCHOR_VCENTER_RIGHT;
290 } else {
291 if (eV==SDRTEXTVERTADJUST_TOP) {
292 eRet=ANCHOR_TOP_HCENTER;
293 } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
294 eRet=ANCHOR_BOTTOM_HCENTER;
295 } else {
296 eRet=ANCHOR_VCENTER_HCENTER;
299 return (sal_uInt16)eRet;
302 void SdrTextObj::ImpSetTextEditParams() const
304 if (pEdtOutl!=NULL) {
305 bool bUpdMerk=pEdtOutl->GetUpdateMode();
306 if (bUpdMerk) pEdtOutl->SetUpdateMode(sal_False);
307 Size aPaperMin;
308 Size aPaperMax;
309 Rectangle aEditArea;
310 TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,NULL);
311 bool bContourFrame=IsContourTextFrame();
312 pEdtOutl->SetMinAutoPaperSize(aPaperMin);
313 pEdtOutl->SetMaxAutoPaperSize(aPaperMax);
314 pEdtOutl->SetPaperSize(Size());
315 if (bContourFrame) {
316 Rectangle aAnchorRect;
317 TakeTextAnchorRect(aAnchorRect);
318 ImpSetContourPolygon(*pEdtOutl,aAnchorRect, sal_True);
320 if (bUpdMerk) pEdtOutl->SetUpdateMode(sal_True);
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */