LibreOffice Module svx (master)  1
svdotxed.cxx
Go to the documentation of this file.
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/outlobj.hxx>
28 #include <editeng/editstat.hxx>
29 #include <svl/itemset.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <svx/sdtfchim.hxx>
32 #include <svx/textchain.hxx>
33 
34 
36 {
37  // linked text objects may be changed (no automatic reload)
38  return true;
39 }
40 
42 {
43  if (pEdtOutl!=nullptr) return false; // Textedit might already run in another View!
44  pEdtOutl=&rOutl;
45 
46  mbInEditMode = true;
47 
48  OutlinerMode nOutlinerMode = OutlinerMode::OutlineObject;
49  if ( !IsOutlText() )
50  nOutlinerMode = OutlinerMode::TextObject;
51  rOutl.Init( nOutlinerMode );
52  rOutl.SetRefDevice(getSdrModelFromSdrObject().GetRefDevice());
53 
54  bool bFitToSize(IsFitToSize());
55  bool bContourFrame=IsContourTextFrame();
57 
58  if (!bContourFrame) {
59  EEControlBits nStat=rOutl.GetControlWord();
60  nStat|=EEControlBits::AUTOPAGESIZE;
61  if (bFitToSize || IsAutoFit())
62  nStat|=EEControlBits::STRETCHING;
63  else
64  nStat&=~EEControlBits::STRETCHING;
65  rOutl.SetControlWord(nStat);
66  }
67 
68  // disable AUTOPAGESIZE if IsChainable (might be required for overflow check)
69  if ( IsChainable() ) {
70  EEControlBits nStat1=rOutl.GetControlWord();
71  nStat1 &=~EEControlBits::AUTOPAGESIZE;
72  rOutl.SetControlWord(nStat1);
73  }
74 
75 
76  OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
77  if(pOutlinerParaObject!=nullptr)
78  {
81  }
82 
83  // if necessary, set frame attributes for the first (new) paragraph of the
84  // outliner
85  if( !HasTextImpl( &rOutl ) )
86  {
87  // Outliner has no text so we must set some
88  // empty text so the outliner initialise itself
89  rOutl.SetText( "", rOutl.GetParagraph( 0 ) );
90 
91  if(GetStyleSheet())
92  rOutl.SetStyleSheet( 0, GetStyleSheet());
93 
94  // When setting the "hard" attributes for first paragraph, the Parent
95  // pOutlAttr (i. e. the template) has to be removed temporarily. Else,
96  // at SetParaAttribs(), all attributes contained in the parent become
97  // attributed hard to the paragraph.
98  const SfxItemSet& rSet = GetObjectItemSet();
100  aFilteredSet.Put(rSet);
101  rOutl.SetParaAttribs(0, aFilteredSet);
102  }
103  if (bFitToSize)
104  {
105  tools::Rectangle aAnchorRect;
106  tools::Rectangle aTextRect;
107  TakeTextRect(rOutl, aTextRect, false,
108  &aAnchorRect);
109  Fraction aFitXCorrection(1,1);
110  ImpSetCharStretching(rOutl,aTextRect.GetSize(),aAnchorRect.GetSize(),aFitXCorrection);
111  }
112  else if (IsAutoFit())
113  {
114  ImpAutoFitText(rOutl);
115  }
116 
117  if(pOutlinerParaObject)
118  {
120  {
121  // only repaint here, no real objectchange
123  }
124  }
125 
126  rOutl.UpdateFields();
127  rOutl.ClearModifyFlag();
128 
129  return true;
130 }
131 
132 void SdrTextObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, tools::Rectangle* pViewInit, tools::Rectangle* pViewMin) const
133 {
134  bool bFitToSize(IsFitToSize());
135  Size aPaperMin,aPaperMax;
136  tools::Rectangle aViewInit;
137  TakeTextAnchorRect(aViewInit);
138  if (aGeo.nRotationAngle!=0) {
139  Point aCenter(aViewInit.Center());
140  aCenter-=aViewInit.TopLeft();
141  Point aCenter0(aCenter);
142  RotatePoint(aCenter,Point(),aGeo.nSin,aGeo.nCos);
143  aCenter-=aCenter0;
144  aViewInit.Move(aCenter.X(),aCenter.Y());
145  }
146  Size aAnkSiz(aViewInit.GetSize());
147  aAnkSiz.AdjustWidth( -1 ); aAnkSiz.AdjustHeight( -1 ); // because GetSize() adds 1
148  Size aMaxSiz(1000000,1000000);
149  Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize());
150  if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() );
151  if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() );
152 
153  // Done earlier since used in else tree below
156 
157  if(IsTextFrame())
158  {
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 
169  if (!IsAutoGrowWidth() )
170  {
171  nMinWdt = aAnkSiz.Width();
172  nMaxWdt = nMinWdt;
173  }
174 
175  if (!IsAutoGrowHeight())
176  {
177  nMinHgt = aAnkSiz.Height();
178  nMaxHgt = nMinHgt;
179  }
180 
181  SdrTextAniKind eAniKind=GetTextAniKind();
183 
184  bool bInEditMode = IsInEditMode();
185 
186  if (!bInEditMode && (eAniKind==SdrTextAniKind::Scroll || eAniKind==SdrTextAniKind::Alternate || eAniKind==SdrTextAniKind::Slide))
187  {
188  // ticker text uses an unlimited paper size
189  if (eAniDirection==SdrTextAniDirection::Left || eAniDirection==SdrTextAniDirection::Right) nMaxWdt=1000000;
190  if (eAniDirection==SdrTextAniDirection::Up || eAniDirection==SdrTextAniDirection::Down) nMaxHgt=1000000;
191  }
192 
193  bool bChainedFrame = IsChainable();
194  // Might be required for overflow check working: do limit height to frame if box is chainable.
195  if (!bChainedFrame) {
196  // #i119885# Do not limit/force height to geometrical frame (vice versa for vertical writing)
197  if(IsVerticalWriting())
198  {
199  nMaxWdt = 1000000;
200  }
201  else
202  {
203  nMaxHgt = 1000000;
204  }
205  }
206 
207  aPaperMax.setWidth(nMaxWdt );
208  aPaperMax.setHeight(nMaxHgt );
209  }
210  else
211  {
212  aPaperMax=aMaxSiz;
213  }
214  aPaperMin.setWidth(nMinWdt );
215  aPaperMin.setHeight(nMinHgt );
216  }
217  else
218  {
219  // aPaperMin needs to be set to object's size if full width is activated
220  // for hor or ver writing respectively
221  if((SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
222  || (SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting()))
223  {
224  aPaperMin = aAnkSiz;
225  }
226 
227  aPaperMax=aMaxSiz;
228  }
229 
230  if (pViewMin!=nullptr) {
231  *pViewMin=aViewInit;
232 
233  long nXFree=aAnkSiz.Width()-aPaperMin.Width();
234  if (eHAdj==SDRTEXTHORZADJUST_LEFT) pViewMin->AdjustRight( -nXFree );
235  else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) pViewMin->AdjustLeft(nXFree );
236  else { pViewMin->AdjustLeft(nXFree/2 ); pViewMin->SetRight(pViewMin->Left()+aPaperMin.Width() ); }
237 
238  long nYFree=aAnkSiz.Height()-aPaperMin.Height();
239  if (eVAdj==SDRTEXTVERTADJUST_TOP) pViewMin->AdjustBottom( -nYFree );
240  else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) pViewMin->AdjustTop(nYFree );
241  else { pViewMin->AdjustTop(nYFree/2 ); pViewMin->SetBottom(pViewMin->Top()+aPaperMin.Height() ); }
242  }
243 
244  // PaperSize should grow automatically in most cases
245  if(IsVerticalWriting())
246  aPaperMin.setWidth( 0 );
247  else
248  aPaperMin.setHeight( 0 );
249 
250  if(eHAdj!=SDRTEXTHORZADJUST_BLOCK || bFitToSize) {
251  aPaperMin.setWidth(0 );
252  }
253 
254  // For complete vertical adjustment support, set paper min height to 0, here.
255  if(SDRTEXTVERTADJUST_BLOCK != eVAdj || bFitToSize)
256  {
257  aPaperMin.setHeight( 0 );
258  }
259 
260  if (pPaperMin!=nullptr) *pPaperMin=aPaperMin;
261  if (pPaperMax!=nullptr) *pPaperMax=aPaperMax;
262  if (pViewInit!=nullptr) *pViewInit=aViewInit;
263 }
264 
266 {
267  if(rOutl.IsModified())
268  {
269 
270  // to make the gray field background vanish again
271  rOutl.UpdateFields();
272 
273  std::unique_ptr<OutlinerParaObject> pNewText = rOutl.CreateParaObject( 0, rOutl.GetParagraphCount() );
274 
275  // need to end edit mode early since SetOutlinerParaObject already
276  // uses GetCurrentBoundRect() which needs to take the text into account
277  // to work correct
278  mbInEditMode = false;
279 
280  // We don't want broadcasting if we are merely trying to move to next box (this prevents infinite loops)
281  if (IsChainable() && GetTextChain()->GetSwitchingToNextBox(this)) {
282  GetTextChain()->SetSwitchingToNextBox(this, false);
283  if( getActiveText() )
284  {
285  getActiveText()->SetOutlinerParaObject( std::move(pNewText) );
286  }
287  } else { // If we are not doing in-chaining switching just set the ParaObject
288  SetOutlinerParaObject(std::move(pNewText));
289  }
290  }
291 
292  /* Chaining-related code */
293  rOutl.ClearOverflowingParaNum();
294 
295  pEdtOutl = nullptr;
296  rOutl.Clear();
297  EEControlBits nStat = rOutl.GetControlWord();
298  nStat &= ~EEControlBits::AUTOPAGESIZE;
299  rOutl.SetControlWord(nStat);
300 
301  mbInEditMode = false;
302 }
303 
305 {
308  EEAnchorMode eRet=EEAnchorMode::TopLeft;
309  if (IsContourTextFrame()) return eRet;
310  if (eH==SDRTEXTHORZADJUST_LEFT) {
311  if (eV==SDRTEXTVERTADJUST_TOP) {
312  eRet=EEAnchorMode::TopLeft;
313  } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
314  eRet=EEAnchorMode::BottomLeft;
315  } else {
316  eRet=EEAnchorMode::VCenterLeft;
317  }
318  } else if (eH==SDRTEXTHORZADJUST_RIGHT) {
319  if (eV==SDRTEXTVERTADJUST_TOP) {
320  eRet=EEAnchorMode::TopRight;
321  } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
322  eRet=EEAnchorMode::BottomRight;
323  } else {
324  eRet=EEAnchorMode::VCenterRight;
325  }
326  } else {
327  if (eV==SDRTEXTVERTADJUST_TOP) {
328  eRet=EEAnchorMode::TopHCenter;
329  } else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
330  eRet=EEAnchorMode::BottomHCenter;
331  } else {
332  eRet=EEAnchorMode::VCenterHCenter;
333  }
334  }
335  return eRet;
336 }
337 
339 {
340  if (pEdtOutl==nullptr)
341  return;
342 
343  bool bUpdBuf=pEdtOutl->GetUpdateMode();
344  if (bUpdBuf) pEdtOutl->SetUpdateMode(false);
345  Size aPaperMin;
346  Size aPaperMax;
347  tools::Rectangle aEditArea;
348  TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,nullptr);
349  bool bContourFrame=IsContourTextFrame();
350  pEdtOutl->SetMinAutoPaperSize(aPaperMin);
351  pEdtOutl->SetMaxAutoPaperSize(aPaperMax);
353  if (bContourFrame) {
354  tools::Rectangle aAnchorRect;
355  TakeTextAnchorRect(aAnchorRect);
356  ImpSetContourPolygon(*pEdtOutl,aAnchorRect, true);
357  }
358  if (bUpdBuf) pEdtOutl->SetUpdateMode(true);
359 }
360 
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
long Width() const
long GetMinTextFrameHeight() const
Definition: svdotext.cxx:1712
virtual bool IsAutoGrowHeight() const
Definition: svdotext.cxx:274
OutlinerMode
bool IsChainable() const
Definition: svdotext.cxx:1924
long AdjustWidth(long n)
std::string GetValue
long Height() const
double nSin
Definition: svdtrans.hxx:219
virtual void TakeTextEditArea(Size *pPaperMin, Size *pPaperMax, tools::Rectangle *pViewInit, tools::Rectangle *pViewMin) const
Definition: svdotxed.cxx:132
GeoStat aGeo
Definition: svdotext.hxx:185
void SetPaperSize(const Size &rSize)
SdrTextHorzAdjust
Definition: sdtaitm.hxx:53
long AdjustLeft(long nHorzMoveDelta)
long GetMinTextFrameWidth() const
Definition: svdotext.cxx:1722
SdrOutliner * pEdtOutl
Definition: svdotext.hxx:196
bool IsTextFrame() const
Definition: svdotext.hxx:343
long nRotationAngle
Definition: svdtrans.hxx:216
bool IsInEditMode() const
Definition: svdotext.hxx:323
SdrTextAniKind GetTextAniKind() const
Definition: svdotext.cxx:1770
void ImpSetContourPolygon(SdrOutliner &rOutliner, tools::Rectangle const &rAnchorRect, bool bLineWidth) const
Definition: svdotext.cxx:541
sal_Int32 GetParagraphCount() const
EEControlBits
virtual void EndTextEdit(SdrOutliner &rOutl)
Definition: svdotxed.cxx:265
SdrTextAniKind
Animation type for text frame.
Definition: sdtakitm.hxx:29
long AdjustBottom(long nVertMoveDelta)
bool mbInEditMode
Definition: svdotext.hxx:235
void Move(long nHorzMoveDelta, long nVertMoveDelta)
TextChain * GetTextChain() const
Definition: svdotext.cxx:1485
void SetControlWord(EEControlBits nWord)
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1906
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2162
void SetFixedCellHeight(bool bUseFixedCellHeight)
virtual bool HasTextEdit() const override
Definition: svdotxed.cxx:35
long Top() const
EEControlBits GetControlWord() const
virtual bool IsAutoGrowWidth() const
Definition: svdotext.cxx:299
void SetParaAttribs(sal_Int32 nPara, const SfxItemSet &)
bool GetSwitchingToNextBox(const SdrTextObj *)
Definition: textchain.cxx:83
SdrTextHorzAdjust GetTextHorizontalAdjust() const
Definition: svdotext.cxx:326
SdrTextVertAdjust GetTextVerticalAdjust() const
Definition: svdotext.cxx:358
double nCos
Definition: svdtrans.hxx:220
void SetText(const OutlinerParaObject &)
void SetSwitchingToNextBox(const SdrTextObj *, bool)
Definition: textchain.cxx:88
bool IsFitToSize() const
returns true if the old feature for fitting shape content should into shape is enabled. implies IsAutoFit()==false!
Definition: svdotext.cxx:1841
virtual bool BegTextEdit(SdrOutliner &rOutl)
Definition: svdotxed.cxx:41
void BroadcastObjectChange() const
Definition: svdobj.cxx:932
void SetRight(long v)
long GetMaxTextFrameHeight() const
Definition: svdotext.cxx:1717
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:299
bool IsModified() const
virtual void TakeTextAnchorRect(::tools::Rectangle &rAnchorRect) const
Definition: svdotext.cxx:603
virtual SdrText * getActiveText() const
returns the currently active text.
Definition: svdotext.cxx:2048
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
Definition: svdobj.cxx:1946
bool IsContourTextFrame() const
Definition: svdotext.cxx:1744
void ClearModifyFlag()
SfxItemPool * GetPool() const
void ClearOverflowingParaNum()
Size GetSize() const
Paragraph * GetParagraph(sal_Int32 nAbsPos) const
long GetMaxTextFrameWidth() const
Definition: svdotext.cxx:1727
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:114
std::unique_ptr< OutlinerParaObject > CreateParaObject(sal_Int32 nStartPara=0, sal_Int32 nParaCount=EE_PARA_ALL) const
virtual bool IsVerticalWriting() const
Definition: svdotext.cxx:1493
void SetMaxAutoPaperSize(const Size &rSz)
virtual void TakeTextRect(SdrOutliner &rOutliner, tools::Rectangle &rTextRect, bool bNoEditText, tools::Rectangle *pAnchorRect, bool bLineWidth=true) const
Definition: svdotext.cxx:638
long AdjustRight(long nHorzMoveDelta)
virtual OutlinerParaObject * GetOutlinerParaObject() const override
Definition: svdotext.cxx:1362
void SetMinAutoPaperSize(const Size &rSz)
virtual void SetOutlinerParaObject(std::unique_ptr< OutlinerParaObject > pTextObject)
Definition: svdtext.cxx:74
void SetBottom(long v)
void Init(OutlinerMode nOutlinerMode)
void SetOutlinerParaObject(std::unique_ptr< OutlinerParaObject > pTextObject)
Definition: svdobj.cxx:1755
void SetRefDevice(OutputDevice *pRefDev)
long AdjustTop(long nVertMoveDelta)
SdrTextAniDirection GetTextAniDirection() const
Definition: svdotext.cxx:1775
void SetUpdateMode(bool bUpdate)
long Left() const
SdrTextAniDirection
Definition: sdtaditm.hxx:29
void SetStyleSheet(sal_Int32 nPara, SfxStyleSheet *pStyle)
bool IsOutlText() const
Definition: svdotext.hxx:344
EEAnchorMode
bool IsAutoFit() const
returns true if the PPT autofit of text into shape bounds is enabled. implies IsFitToSize()==false! ...
Definition: svdotext.cxx:1836
#define SDRATTR_TEXT_USEFIXEDCELLHEIGHT
Definition: svddef.hxx:217
bool UpdateFields()
void Clear()
void ImpSetTextEditParams() const
Definition: svdotxed.cxx:338
void setWidth(long nWidth)
static bool HasTextImpl(SdrOutliner const *pOutliner)
returns false if the given pointer is NULL or if the given SdrOutliner contains no text...
Definition: svdotext.cxx:437
SdrTextVertAdjust
Definition: sdtaitm.hxx:29
virtual EEAnchorMode GetOutlinerViewAnchorMode() const
Definition: svdotxed.cxx:304
bool GetUpdateMode() const
Point Center() const
virtual bool IsFontwork() const
Definition: svdotext.cxx:1732
scroll back and forth
static void ImpSetCharStretching(SdrOutliner &rOutliner, const Size &rTextSize, const Size &rShapeSize, Fraction &rFitXCorrection)
Definition: svdotext.cxx:819
void ImpAutoFitText(SdrOutliner &rOutliner) const
Definition: svdotext.cxx:1262
void setHeight(long nHeight)