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