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 (mpEditingOutliner!=nullptr) return false; // Textedit might already run in another View!
43 mpEditingOutliner=&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.
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
131void 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);
138 Point aCenter(aViewInit.Center());
139 aCenter-=aViewInit.TopLeft();
140 Point aCenter0(aCenter);
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 {
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
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)
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
222 {
223 aPaperMin = aAnkSiz;
224 }
225
226 aPaperMax=aMaxSiz;
227 }
228
229 if (pViewMin!=nullptr) {
230 *pViewMin=aViewInit;
231
232 tools::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 tools::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
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
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 */
293
294 mpEditingOutliner = 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 (mpEditingOutliner==nullptr)
340 return;
341
342 bool bUpdBuf=mpEditingOutliner->SetUpdateLayout(false);
343 Size aPaperMin;
344 Size aPaperMax;
345 tools::Rectangle aEditArea;
346 TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,nullptr);
347 bool bContourFrame=IsContourTextFrame();
352 if (bContourFrame) {
353 tools::Rectangle aAnchorRect;
354 TakeTextAnchorRect(aAnchorRect);
355 ImpSetContourPolygon(*mpEditingOutliner,aAnchorRect, true);
356 }
357 if (bUpdBuf) mpEditingOutliner->SetUpdateLayout(true);
358}
359
360/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double mfCosRotationAngle
Definition: svdtrans.hxx:207
double mfSinRotationAngle
Definition: svdtrans.hxx:206
Degree100 m_nRotationAngle
Definition: svdtrans.hxx:203
void SetMaxAutoPaperSize(const Size &rSz)
void SetText(const OutlinerParaObject &)
void ClearOverflowingParaNum()
void SetTextColumns(sal_Int16 nColumns, sal_Int32 nSpacing)
Paragraph * GetParagraph(sal_Int32 nAbsPos) const
void SetMinAutoPaperSize(const Size &rSz)
std::optional< OutlinerParaObject > CreateParaObject(sal_Int32 nStartPara=0, sal_Int32 nParaCount=EE_PARA_ALL) const
void SetPaperSize(const Size &rSize)
void Clear()
void SetStyleSheet(sal_Int32 nPara, SfxStyleSheet *pStyle)
bool SetUpdateLayout(bool bUpdate)
void SetParaAttribs(sal_Int32 nPara, const SfxItemSet &)
void SetFixedCellHeight(bool bUseFixedCellHeight)
EEControlBits GetControlWord() const
void SetControlWord(EEControlBits nWord)
bool UpdateFields()
void SetRefDevice(OutputDevice *pRefDev)
void ClearModifyFlag()
void Init(OutlinerMode nMode)
bool IsModified() const
sal_Int32 GetParagraphCount() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
Definition: svdobj.cxx:2009
void SetOutlinerParaObject(std::optional< OutlinerParaObject > pTextObject)
Definition: svdobj.cxx:1798
void BroadcastObjectChange() const
Definition: svdobj.cxx:1018
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:289
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2244
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1969
SdrTextHorzAdjust GetTextHorizontalAdjust() const
Definition: svdotext.cxx:346
GeoStat maGeo
Definition: svdotext.hxx:196
virtual bool IsAutoGrowWidth() const
Definition: svdotext.cxx:319
tools::Long GetMaxTextFrameHeight() const
Definition: svdotext.cxx:1786
virtual void TakeTextEditArea(Size *pPaperMin, Size *pPaperMax, tools::Rectangle *pViewInit, tools::Rectangle *pViewMin) const
Definition: svdotxed.cxx:131
bool IsChainable() const
Definition: svdotext.cxx:2023
sal_Int32 GetTextColumnsSpacing() const
Definition: svdotext.cxx:1869
tools::Long GetMinTextFrameHeight() const
Definition: svdotext.cxx:1781
bool IsAutoFit() const
returns true if the PPT autofit of text into shape bounds is enabled. implies IsFitToSize()==false!
Definition: svdotext.cxx:1935
bool mbInEditMode
Definition: svdotext.hxx:246
virtual bool BegTextEdit(SdrOutliner &rOutl)
Definition: svdotxed.cxx:40
bool IsFitToSize() const
returns true if the old feature for fitting shape content should into shape is enabled....
Definition: svdotext.cxx:1940
bool IsInEditMode() const
Definition: svdotext.hxx:339
static void ImpSetCharStretching(SdrOutliner &rOutliner, const Size &rTextSize, const Size &rShapeSize, Fraction &rFitXCorrection)
Definition: svdotext.cxx:873
virtual SdrText * getActiveText() const
returns the currently active text.
Definition: svdotext.cxx:2147
SdrOutliner * mpEditingOutliner
Definition: svdotext.hxx:207
tools::Long GetMaxTextFrameWidth() const
Definition: svdotext.cxx:1796
virtual void TakeTextAnchorRect(::tools::Rectangle &rAnchorRect) const
Definition: svdotext.cxx:656
void ImpSetContourPolygon(SdrOutliner &rOutliner, tools::Rectangle const &rAnchorRect, bool bLineWidth) const
Definition: svdotext.cxx:561
virtual OutlinerParaObject * GetOutlinerParaObject() const override
Definition: svdotext.cxx:1412
virtual bool HasTextEdit() const override
Definition: svdotxed.cxx:34
virtual bool IsAutoGrowHeight() const
Definition: svdotext.cxx:294
void ImpAutoFitText(SdrOutliner &rOutliner) const
Definition: svdotext.cxx:1263
virtual bool IsFontwork() const
Definition: svdotext.cxx:1801
SdrTextAniDirection GetTextAniDirection() const
Definition: svdotext.cxx:1844
void ImpSetTextEditParams() const
Definition: svdotxed.cxx:337
bool IsContourTextFrame() const
Definition: svdotext.cxx:1813
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:458
virtual void TakeTextRect(SdrOutliner &rOutliner, tools::Rectangle &rTextRect, bool bNoEditText, tools::Rectangle *pAnchorRect, bool bLineWidth=true) const
Definition: svdotext.cxx:680
bool IsOutlText() const
Definition: svdotext.hxx:360
tools::Long GetMinTextFrameWidth() const
Definition: svdotext.cxx:1791
bool IsTextFrame() const
Definition: svdotext.hxx:359
SdrTextVertAdjust GetTextVerticalAdjust() const
Definition: svdotext.cxx:378
TextChain * GetTextChain() const
Definition: svdotext.cxx:1544
SdrTextAniKind GetTextAniKind() const
Definition: svdotext.cxx:1839
virtual EEAnchorMode GetOutlinerViewAnchorMode() const
Definition: svdotxed.cxx:303
virtual void EndTextEdit(SdrOutliner &rOutl)
Definition: svdotxed.cxx:264
sal_Int16 GetTextColumnsNumber() const
Definition: svdotext.cxx:1854
virtual bool IsVerticalWriting() const
Definition: svdotext.cxx:1552
virtual void SetOutlinerParaObject(std::optional< OutlinerParaObject > pTextObject)
Definition: svdtext.cxx:72
SfxItemPool * GetPool() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
void SetSwitchingToNextBox(const SdrTextObj *, bool)
Definition: textchain.cxx:87
constexpr Point Center() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr void SetRight(tools::Long v)
constexpr Size GetSize() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
constexpr void SetBottom(tools::Long v)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr tools::Long Left() const
EEAnchorMode
EEControlBits
long Long
const char GetValue[]
OutlinerMode
SdrTextAniDirection
Definition: sdtaditm.hxx:30
SdrTextVertAdjust
Definition: sdtaitm.hxx:29
@ SDRTEXTVERTADJUST_BOTTOM
Definition: sdtaitm.hxx:31
@ SDRTEXTVERTADJUST_BLOCK
Definition: sdtaitm.hxx:32
@ SDRTEXTVERTADJUST_TOP
Definition: sdtaitm.hxx:29
SdrTextHorzAdjust
Definition: sdtaitm.hxx:53
@ SDRTEXTHORZADJUST_LEFT
Definition: sdtaitm.hxx:53
@ SDRTEXTHORZADJUST_BLOCK
Definition: sdtaitm.hxx:56
@ SDRTEXTHORZADJUST_RIGHT
Definition: sdtaitm.hxx:55
SdrTextAniKind
Animation type for text frame.
Definition: sdtakitm.hxx:29
@ Scroll
blinking
@ Slide
scroll back and forth
@ Alternate
scroll through
static SfxItemSet & rSet
constexpr TypedWhichId< SdrTextFixedCellHeightItem > SDRATTR_TEXT_USEFIXEDCELLHEIGHT(SDRATTR_MISC_FIRST+23)
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:101