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