LibreOffice Module svx (master)  1
svdotxdr.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/svdhdl.hxx>
23 #include <svx/svddrag.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/svdorect.hxx>
26 #include <svx/strings.hrc>
27 #include <svx/svdoashp.hxx>
28 #include <tools/bigint.hxx>
32 #include <vcl/canvastools.hxx>
33 #include <vcl/ptrstyle.hxx>
34 
35 
36 sal_uInt32 SdrTextObj::GetHdlCount() const
37 {
38  return 8L;
39 }
40 
41 void SdrTextObj::AddToHdlList(SdrHdlList& rHdlList) const
42 {
43  for(sal_uInt32 nHdlNum=0; nHdlNum<8; ++nHdlNum)
44  {
45  Point aPnt;
47  switch (nHdlNum) {
48  case 0: aPnt=maRect.TopLeft(); eKind=SdrHdlKind::UpperLeft; break;
49  case 1: aPnt=maRect.TopCenter(); eKind=SdrHdlKind::Upper; break;
50  case 2: aPnt=maRect.TopRight(); eKind=SdrHdlKind::UpperRight; break;
51  case 3: aPnt=maRect.LeftCenter(); eKind=SdrHdlKind::Left ; break;
52  case 4: aPnt=maRect.RightCenter(); eKind=SdrHdlKind::Right; break;
53  case 5: aPnt=maRect.BottomLeft(); eKind=SdrHdlKind::LowerLeft; break;
54  case 6: aPnt=maRect.BottomCenter(); eKind=SdrHdlKind::Lower; break;
55  case 7: aPnt=maRect.BottomRight(); eKind=SdrHdlKind::LowerRight; break;
56  }
59  std::unique_ptr<SdrHdl> pH(new SdrHdl(aPnt,eKind));
60  pH->SetObj(const_cast<SdrTextObj*>(this));
61  pH->SetRotationAngle(aGeo.nRotationAngle);
62  rHdlList.AddHdl(std::move(pH));
63  }
64 }
65 
66 
68 {
69  return true;
70 }
71 
73 {
74  tools::Rectangle aTmpRect(maRect);
75  const SdrHdl* pHdl=rDrag.GetHdl();
76  SdrHdlKind eHdl=pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind();
78  bool bOrtho=rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho();
79  bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho();
80  Point aPos(rDrag.GetNow());
81  // Unrotate:
82  if (aGeo.nRotationAngle!=0) RotatePoint(aPos,aTmpRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
83  // Unshear:
84  if (aGeo.nShearAngle!=0) ShearPoint(aPos,aTmpRect.TopLeft(),-aGeo.nTan);
85 
86  bool bLft=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft);
87  bool bRgt=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight);
88  bool bTop=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft);
89  bool bBtm=(eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft);
90  if (bLft) aTmpRect.SetLeft(aPos.X() );
91  if (bRgt) aTmpRect.SetRight(aPos.X() );
92  if (bTop) aTmpRect.SetTop(aPos.Y() );
93  if (bBtm) aTmpRect.SetBottom(aPos.Y() );
94  if (bOrtho) { // Ortho
95  long nWdt0=maRect.Right() -maRect.Left();
96  long nHgt0=maRect.Bottom()-maRect.Top();
97  long nXMul=aTmpRect.Right() -aTmpRect.Left();
98  long nYMul=aTmpRect.Bottom()-aTmpRect.Top();
99  long nXDiv=nWdt0;
100  long nYDiv=nHgt0;
101  bool bXNeg=(nXMul<0)!=(nXDiv<0);
102  bool bYNeg=(nYMul<0)!=(nYDiv<0);
103  nXMul=std::abs(nXMul);
104  nYMul=std::abs(nYMul);
105  nXDiv=std::abs(nXDiv);
106  nYDiv=std::abs(nYDiv);
107  Fraction aXFact(nXMul,nXDiv); // fractions for canceling
108  Fraction aYFact(nYMul,nYDiv); // and for comparing
109  nXMul=aXFact.GetNumerator();
110  nYMul=aYFact.GetNumerator();
111  nXDiv=aXFact.GetDenominator();
112  nYDiv=aYFact.GetDenominator();
113  if (bEcke) { // corner point handles
114  bool bUseX=(aXFact<aYFact) != bBigOrtho;
115  if (bUseX) {
116  long nNeed=long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv));
117  if (bYNeg) nNeed=-nNeed;
118  if (bTop) aTmpRect.SetTop(aTmpRect.Bottom()-nNeed );
119  if (bBtm) aTmpRect.SetBottom(aTmpRect.Top()+nNeed );
120  } else {
121  long nNeed=long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv));
122  if (bXNeg) nNeed=-nNeed;
123  if (bLft) aTmpRect.SetLeft(aTmpRect.Right()-nNeed );
124  if (bRgt) aTmpRect.SetRight(aTmpRect.Left()+nNeed );
125  }
126  } else { // apex handles
127  if ((bLft || bRgt) && nXDiv!=0) {
128  long nHgt0b=maRect.Bottom()-maRect.Top();
129  long nNeed=long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv));
130  aTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) );
131  aTmpRect.SetBottom(aTmpRect.Top()+nNeed );
132  }
133  if ((bTop || bBtm) && nYDiv!=0) {
134  long nWdt0b=maRect.Right()-maRect.Left();
135  long nNeed=long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv));
136  aTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) );
137  aTmpRect.SetRight(aTmpRect.Left()+nNeed );
138  }
139  }
140  }
141  if (dynamic_cast<const SdrObjCustomShape*>(this) == nullptr) // not justifying when in CustomShapes, to be able to detect if a shape has to be mirrored
142  ImpJustifyRect(aTmpRect);
143  return aTmpRect;
144 }
145 
146 
147 // drag
148 
150 {
151  tools::Rectangle aNewRect(ImpDragCalcRect(rDrag));
152 
153  if(aNewRect.TopLeft() != maRect.TopLeft() && (aGeo.nRotationAngle || aGeo.nShearAngle))
154  {
155  Point aNewPos(aNewRect.TopLeft());
156 
157  if(aGeo.nShearAngle)
158  ShearPoint(aNewPos,maRect.TopLeft(),aGeo.nTan);
159 
160  if(aGeo.nRotationAngle)
162 
163  aNewRect.SetPos(aNewPos);
164  }
165 
166  if (aNewRect != maRect)
167  {
168  NbcSetLogicRect(aNewRect);
169  }
170 
171  return true;
172 }
173 
174 OUString SdrTextObj::getSpecialDragComment(const SdrDragStat& /*rDrag*/) const
175 {
176  return ImpGetDescriptionStr(STR_DragRectResize);
177 }
178 
179 
180 // Create
181 
183 {
184  rStat.SetOrtho4Possible();
185  tools::Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
186  aRect1.Justify();
187  rStat.SetActionRect(aRect1);
188  maRect = aRect1;
189  return true;
190 }
191 
193 {
194  tools::Rectangle aRect1;
195  rStat.TakeCreateRect(aRect1);
196  ImpJustifyRect(aRect1);
197  rStat.SetActionRect(aRect1);
198  maRect = aRect1; // for ObjName
200  bSnapRectDirty=true;
201  if (dynamic_cast<const SdrRectObj *>(this) != nullptr) {
202  static_cast<SdrRectObj*>(this)->SetXPolyDirty();
203  }
204  return true;
205 }
206 
208 {
209  rStat.TakeCreateRect(maRect);
211 
213 
214  SetRectsDirty();
215  if (dynamic_cast<const SdrRectObj *>(this) != nullptr) {
216  static_cast<SdrRectObj*>(this)->SetXPolyDirty();
217  }
218  return (eCmd==SdrCreateCmd::ForceEnd || rStat.GetPointCount()>=2);
219 }
220 
222 {
223 }
224 
226 {
227  return true;
228 }
229 
231 {
232  tools::Rectangle aRect1;
233  rDrag.TakeCreateRect(aRect1);
234  aRect1.Justify();
235 
236  basegfx::B2DPolyPolygon aRetval;
239  return aRetval;
240 }
241 
243 {
244  if (IsTextFrame()) return PointerStyle::DrawText;
245  return PointerStyle::Cross;
246 }
247 
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
void SetPos(const Point &rPoint)
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:122
double nSin
Definition: svdtrans.hxx:219
const Point & GetStart() const
Definition: svddrag.hxx:92
Point BottomLeft() const
GeoStat aGeo
Definition: svdotext.hxx:185
SdrHdlKind
Definition: svdhdl.hxx:52
long AdjustLeft(long nHorzMoveDelta)
bool IsTextFrame() const
Definition: svdotext.hxx:343
long nRotationAngle
Definition: svdtrans.hxx:216
virtual sal_uInt32 GetHdlCount() const override
Via GetHdlCount the number of Handles can be retrieved.
Definition: svdotxdr.cxx:36
virtual void SetBoundRectDirty()
Definition: svdobj.cxx:336
virtual bool hasSpecialDrag() const override
The standard transformations (Move,Resize,Rotate,Mirror,Shear) are taken over by the View (TakeXorPol...
Definition: svdotxdr.cxx:67
virtual bool BegCreate(SdrDragStat &rStat) override
Every object must be able to create itself interactively.
Definition: svdotxdr.cxx:182
bool bSnapRectDirty
Definition: svdobj.hxx:928
Point RightCenter() const
Rectangle objects (rectangle, circle, ...)
Definition: svdorect.hxx:39
const SdrHdl * GetHdl() const
Definition: svddrag.hxx:101
long Right() const
bool IsOrtho() const
Definition: svdsnpv.hxx:246
virtual bool BckCreate(SdrDragStat &rStat) override
Definition: svdotxdr.cxx:225
Point BottomCenter() const
tools::Rectangle maRect
Definition: svdotext.hxx:182
void SetOrtho4Possible(bool bOn=true)
Definition: svddrag.hxx:126
void TakeCreateRect(tools::Rectangle &rRect) const
Definition: svddrag.cxx:115
long Top() const
Point LeftCenter() const
tools::Rectangle ImpDragCalcRect(const SdrDragStat &rDrag) const
Definition: svdotxdr.cxx:72
Point BottomRight() const
virtual bool applySpecialDrag(SdrDragStat &rDrag) override
Definition: svdotxdr.cxx:149
virtual OUString getSpecialDragComment(const SdrDragStat &rDrag) const override
Definition: svdotxdr.cxx:174
double nCos
Definition: svdtrans.hxx:220
void SetTop(long v)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
virtual void BrkCreate(SdrDragStat &rStat) override
Definition: svdotxdr.cxx:221
sal_Int32 GetPointCount() const
Definition: svddrag.hxx:91
void SetRight(long v)
double nTan
Definition: svdtrans.hxx:218
SdrView * GetView() const
Definition: svddrag.hxx:86
long Bottom() const
virtual void AdaptTextMinSize()
Definition: svdotext.cxx:486
long nShearAngle
Definition: svdtrans.hxx:217
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat &rDrag) const override
Polygon dragged by the user when creating the object.
Definition: svdotxdr.cxx:230
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:114
void SetActionRect(const tools::Rectangle &rR)
Definition: svddrag.hxx:157
sal_Int32 GetDenominator() const
OUString ImpGetDescriptionStr(const char *pStrCacheID) const
Definition: svdobj.cxx:1065
void SetBottom(long v)
long AdjustTop(long nVertMoveDelta)
sal_Int32 GetNumerator() const
const Point & GetNow() const
Definition: svddrag.hxx:95
long Left() const
PointerStyle
virtual void SetRectsDirty(bool bNotMyself=false, bool bRecursive=true)
Definition: svdobj.cxx:462
virtual bool EndCreate(SdrDragStat &rStat, SdrCreateCmd eCmd) override
Definition: svdotxdr.cxx:207
void SetLeft(long v)
virtual void NbcSetLogicRect(const tools::Rectangle &rRect) override
Definition: svdotxtr.cxx:78
SdrCreateCmd
Definition: svdtypes.hxx:27
bool IsBigOrtho() const
Definition: svdsnpv.hxx:258
virtual bool MovCreate(SdrDragStat &rStat) override
Definition: svdotxdr.cxx:192
static void ImpJustifyRect(tools::Rectangle &rRect)
Definition: svdotext.cxx:391
Point TopRight() const
virtual void AddToHdlList(SdrHdlList &rHdlList) const override
Definition: svdotxdr.cxx:41
void AddHdl(std::unique_ptr< SdrHdl > pHdl)
Definition: svdhdl.cxx:2299
Point TopCenter() const
SdrHdlKind GetKind() const
Definition: svdhdl.hxx:194
virtual PointerStyle GetCreatePointer() const override
get the cursor/pointer that signals creating this object
Definition: svdotxdr.cxx:242