Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <svx/svdotext.hxx>
22 : #include <svx/svdmodel.hxx>
23 : #include <svx/svdoutl.hxx>
24 : #include <editeng/editdata.hxx>
25 : #include <editeng/outliner.hxx>
26 : #include <editeng/editstat.hxx>
27 : #include <svl/itemset.hxx>
28 : #include <editeng/eeitem.hxx>
29 : #include <svx/sdtfchim.hxx>
30 :
31 :
32 0 : bool SdrTextObj::HasTextEdit() const
33 : {
34 : // linked text objects may be changed (no automatic reload)
35 0 : return true;
36 : }
37 :
38 0 : bool SdrTextObj::BegTextEdit(SdrOutliner& rOutl)
39 : {
40 0 : if (pEdtOutl!=NULL) return false; // Textedit might already run in another View!
41 0 : pEdtOutl=&rOutl;
42 :
43 0 : mbInEditMode = true;
44 :
45 0 : sal_uInt16 nOutlinerMode = OUTLINERMODE_OUTLINEOBJECT;
46 0 : if ( !IsOutlText() )
47 0 : nOutlinerMode = OUTLINERMODE_TEXTOBJECT;
48 0 : rOutl.Init( nOutlinerMode );
49 0 : rOutl.SetRefDevice( pModel->GetRefDevice() );
50 :
51 0 : bool bFitToSize(IsFitToSize());
52 0 : bool bContourFrame=IsContourTextFrame();
53 0 : ImpSetTextEditParams();
54 :
55 0 : if (!bContourFrame) {
56 0 : sal_uIntPtr nStat=rOutl.GetControlWord();
57 0 : nStat|=EE_CNTRL_AUTOPAGESIZE;
58 0 : if (bFitToSize || IsAutoFit())
59 0 : nStat|=EE_CNTRL_STRETCHING;
60 : else
61 0 : nStat&=~EE_CNTRL_STRETCHING;
62 0 : rOutl.SetControlWord(nStat);
63 : }
64 :
65 0 : OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
66 0 : if(pOutlinerParaObject!=NULL)
67 : {
68 0 : rOutl.SetText(*GetOutlinerParaObject());
69 0 : rOutl.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
70 : }
71 :
72 : // if necessary, set frame attributes for the first (new) paragraph of the
73 : // outliner
74 0 : if( !HasTextImpl( &rOutl ) )
75 : {
76 : // Outliner has no text so we must set some
77 : // empty text so the outliner initialise itself
78 0 : rOutl.SetText( "", rOutl.GetParagraph( 0 ) );
79 :
80 0 : if(GetStyleSheet())
81 0 : rOutl.SetStyleSheet( 0, GetStyleSheet());
82 :
83 : // When setting the "hard" attributes for first paragraph, the Parent
84 : // pOutlAttr (i. e. the template) has to be removed temporarily. Else,
85 : // at SetParaAttribs(), all attributes contained in the parent become
86 : // attributed hard to the paragraph.
87 0 : const SfxItemSet& rSet = GetObjectItemSet();
88 0 : SfxItemSet aFilteredSet(*rSet.GetPool(), EE_ITEMS_START, EE_ITEMS_END);
89 0 : aFilteredSet.Put(rSet);
90 0 : rOutl.SetParaAttribs(0, aFilteredSet);
91 : }
92 0 : if (bFitToSize)
93 : {
94 0 : Rectangle aAnchorRect;
95 0 : Rectangle aTextRect;
96 : TakeTextRect(rOutl, aTextRect, false,
97 0 : &aAnchorRect);
98 0 : Fraction aFitXKorreg(1,1);
99 0 : ImpSetCharStretching(rOutl,aTextRect.GetSize(),aAnchorRect.GetSize(),aFitXKorreg);
100 : }
101 0 : else if (IsAutoFit())
102 : {
103 0 : ImpAutoFitText(rOutl);
104 : }
105 :
106 0 : if(pOutlinerParaObject)
107 : {
108 0 : if(aGeo.nDrehWink || IsFontwork())
109 : {
110 : // only repaint here, no real objectchange
111 0 : BroadcastObjectChange();
112 : }
113 : }
114 :
115 0 : rOutl.UpdateFields();
116 0 : rOutl.ClearModifyFlag();
117 :
118 0 : return true;
119 : }
120 :
121 0 : void SdrTextObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const
122 : {
123 0 : bool bFitToSize(IsFitToSize());
124 0 : Size aPaperMin,aPaperMax;
125 0 : Rectangle aViewInit;
126 0 : TakeTextAnchorRect(aViewInit);
127 0 : if (aGeo.nDrehWink!=0) {
128 0 : Point aCenter(aViewInit.Center());
129 0 : aCenter-=aViewInit.TopLeft();
130 0 : Point aCenter0(aCenter);
131 0 : RotatePoint(aCenter,Point(),aGeo.nSin,aGeo.nCos);
132 0 : aCenter-=aCenter0;
133 0 : aViewInit.Move(aCenter.X(),aCenter.Y());
134 : }
135 0 : Size aAnkSiz(aViewInit.GetSize());
136 0 : aAnkSiz.Width()--; aAnkSiz.Height()--; // because GetSize() adds 1
137 0 : Size aMaxSiz(1000000,1000000);
138 0 : if (pModel!=NULL) {
139 0 : Size aTmpSiz(pModel->GetMaxObjSize());
140 0 : if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
141 0 : if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
142 : }
143 :
144 : // Done earlier since used in else tree below
145 0 : SdrTextHorzAdjust eHAdj(GetTextHorizontalAdjust());
146 0 : SdrTextVertAdjust eVAdj(GetTextVerticalAdjust());
147 :
148 0 : if(IsTextFrame())
149 : {
150 0 : long nMinWdt=GetMinTextFrameWidth();
151 0 : long nMinHgt=GetMinTextFrameHeight();
152 0 : long nMaxWdt=GetMaxTextFrameWidth();
153 0 : long nMaxHgt=GetMaxTextFrameHeight();
154 0 : if (nMinWdt<1) nMinWdt=1;
155 0 : if (nMinHgt<1) nMinHgt=1;
156 0 : if (!bFitToSize) {
157 0 : if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
158 0 : if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
159 :
160 0 : if (!IsAutoGrowWidth() )
161 : {
162 0 : nMinWdt = aAnkSiz.Width();
163 0 : nMaxWdt = nMinWdt;
164 : }
165 :
166 0 : if (!IsAutoGrowHeight())
167 : {
168 0 : nMinHgt = aAnkSiz.Height();
169 0 : nMaxHgt = nMinHgt;
170 : }
171 :
172 0 : SdrTextAniKind eAniKind=GetTextAniKind();
173 0 : SdrTextAniDirection eAniDirection=GetTextAniDirection();
174 :
175 0 : sal_Bool bInEditMode = IsInEditMode();
176 :
177 0 : if (!bInEditMode && (eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE))
178 : {
179 : // ticker text uses an unlimited paper size
180 0 : if (eAniDirection==SDRTEXTANI_LEFT || eAniDirection==SDRTEXTANI_RIGHT) nMaxWdt=1000000;
181 0 : if (eAniDirection==SDRTEXTANI_UP || eAniDirection==SDRTEXTANI_DOWN) nMaxHgt=1000000;
182 : }
183 :
184 : // #i119885# Do not limit/force height to geometrical frame (vice versa for vertical writing)
185 0 : if(IsVerticalWriting())
186 : {
187 0 : nMaxWdt = 1000000;
188 : }
189 : else
190 : {
191 0 : nMaxHgt = 1000000;
192 : }
193 :
194 0 : aPaperMax.Width()=nMaxWdt;
195 0 : aPaperMax.Height()=nMaxHgt;
196 : }
197 : else
198 : {
199 0 : aPaperMax=aMaxSiz;
200 : }
201 0 : aPaperMin.Width()=nMinWdt;
202 0 : aPaperMin.Height()=nMinHgt;
203 : }
204 : else
205 : {
206 : // aPaperMin needs to be set to object's size if full width is activated
207 : // for hor or ver writing respectively
208 0 : if((SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
209 0 : || (SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting()))
210 : {
211 0 : aPaperMin = aAnkSiz;
212 : }
213 :
214 0 : aPaperMax=aMaxSiz;
215 : }
216 :
217 0 : if (pViewMin!=NULL) {
218 0 : *pViewMin=aViewInit;
219 :
220 0 : long nXFree=aAnkSiz.Width()-aPaperMin.Width();
221 0 : if (eHAdj==SDRTEXTHORZADJUST_LEFT) pViewMin->Right()-=nXFree;
222 0 : else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) pViewMin->Left()+=nXFree;
223 0 : else { pViewMin->Left()+=nXFree/2; pViewMin->Right()=pViewMin->Left()+aPaperMin.Width(); }
224 :
225 0 : long nYFree=aAnkSiz.Height()-aPaperMin.Height();
226 0 : if (eVAdj==SDRTEXTVERTADJUST_TOP) pViewMin->Bottom()-=nYFree;
227 0 : else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) pViewMin->Top()+=nYFree;
228 0 : else { pViewMin->Top()+=nYFree/2; pViewMin->Bottom()=pViewMin->Top()+aPaperMin.Height(); }
229 : }
230 :
231 : // PaperSize should grow automatically in most cases
232 0 : if(IsVerticalWriting())
233 0 : aPaperMin.Width() = 0;
234 : else
235 0 : aPaperMin.Height() = 0;
236 :
237 0 : if(eHAdj!=SDRTEXTHORZADJUST_BLOCK || bFitToSize) {
238 0 : aPaperMin.Width()=0;
239 : }
240 :
241 : // For complete vertical adjustment support, set paper min height to 0, here.
242 0 : if(SDRTEXTVERTADJUST_BLOCK != eVAdj || bFitToSize)
243 : {
244 0 : aPaperMin.Height() = 0;
245 : }
246 :
247 0 : if (pPaperMin!=NULL) *pPaperMin=aPaperMin;
248 0 : if (pPaperMax!=NULL) *pPaperMax=aPaperMax;
249 0 : if (pViewInit!=NULL) *pViewInit=aViewInit;
250 0 : }
251 :
252 0 : void SdrTextObj::EndTextEdit(SdrOutliner& rOutl)
253 : {
254 0 : if(rOutl.IsModified())
255 : {
256 0 : OutlinerParaObject* pNewText = NULL;
257 :
258 : // to make the gray field background vanish again
259 0 : rOutl.UpdateFields();
260 :
261 0 : sal_Int32 nParaAnz = rOutl.GetParagraphCount();
262 0 : pNewText = rOutl.CreateParaObject( 0, nParaAnz );
263 :
264 : // need to end edit mode early since SetOutlinerParaObject already
265 : // uses GetCurrentBoundRect() which needs to take the text into account
266 : // to work correct
267 0 : mbInEditMode = false;
268 0 : SetOutlinerParaObject(pNewText);
269 : }
270 :
271 0 : pEdtOutl = NULL;
272 0 : rOutl.Clear();
273 0 : sal_uInt32 nStat = rOutl.GetControlWord();
274 0 : nStat &= ~EE_CNTRL_AUTOPAGESIZE;
275 0 : rOutl.SetControlWord(nStat);
276 :
277 0 : mbInEditMode = false;
278 0 : }
279 :
280 0 : sal_uInt16 SdrTextObj::GetOutlinerViewAnchorMode() const
281 : {
282 0 : SdrTextHorzAdjust eH=GetTextHorizontalAdjust();
283 0 : SdrTextVertAdjust eV=GetTextVerticalAdjust();
284 0 : EVAnchorMode eRet=ANCHOR_TOP_LEFT;
285 0 : if (IsContourTextFrame()) return (sal_uInt16)eRet;
286 0 : if (eH==SDRTEXTHORZADJUST_LEFT) {
287 0 : if (eV==SDRTEXTVERTADJUST_TOP) {
288 0 : eRet=ANCHOR_TOP_LEFT;
289 0 : } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
290 0 : eRet=ANCHOR_BOTTOM_LEFT;
291 : } else {
292 0 : eRet=ANCHOR_VCENTER_LEFT;
293 : }
294 0 : } else if (eH==SDRTEXTHORZADJUST_RIGHT) {
295 0 : if (eV==SDRTEXTVERTADJUST_TOP) {
296 0 : eRet=ANCHOR_TOP_RIGHT;
297 0 : } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
298 0 : eRet=ANCHOR_BOTTOM_RIGHT;
299 : } else {
300 0 : eRet=ANCHOR_VCENTER_RIGHT;
301 : }
302 : } else {
303 0 : if (eV==SDRTEXTVERTADJUST_TOP) {
304 0 : eRet=ANCHOR_TOP_HCENTER;
305 0 : } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
306 0 : eRet=ANCHOR_BOTTOM_HCENTER;
307 : } else {
308 0 : eRet=ANCHOR_VCENTER_HCENTER;
309 : }
310 : }
311 0 : return (sal_uInt16)eRet;
312 : }
313 :
314 0 : void SdrTextObj::ImpSetTextEditParams() const
315 : {
316 0 : if (pEdtOutl!=NULL) {
317 0 : bool bUpdMerk=pEdtOutl->GetUpdateMode();
318 0 : if (bUpdMerk) pEdtOutl->SetUpdateMode(false);
319 0 : Size aPaperMin;
320 0 : Size aPaperMax;
321 0 : Rectangle aEditArea;
322 0 : TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,NULL);
323 0 : bool bContourFrame=IsContourTextFrame();
324 0 : pEdtOutl->SetMinAutoPaperSize(aPaperMin);
325 0 : pEdtOutl->SetMaxAutoPaperSize(aPaperMax);
326 0 : pEdtOutl->SetPaperSize(Size());
327 0 : if (bContourFrame) {
328 0 : Rectangle aAnchorRect;
329 0 : TakeTextAnchorRect(aAnchorRect);
330 0 : ImpSetContourPolygon(*pEdtOutl,aAnchorRect, true);
331 : }
332 0 : if (bUpdMerk) pEdtOutl->SetUpdateMode(true);
333 : }
334 0 : }
335 :
336 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|