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 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(maGeo.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:
83 // Unshear:
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
97 tools::Long nXMul=aTmpRect.Right() -aTmpRect.Left();
98 tools::Long nYMul=aTmpRect.Bottom()-aTmpRect.Top();
99 tools::Long nXDiv=nWdt0;
100 tools::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 tools::Long nNeed=tools::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 tools::Long nNeed=tools::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) {
129 tools::Long nNeed=tools::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) {
135 tools::Long nNeed=tools::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() && (maGeo.nRotationAngle || maGeo.nShearAngle))
154 {
155 Point aNewPos(aNewRect.TopLeft());
156
157 if (maGeo.nShearAngle)
159
162
163 aNewRect.SetPos(aNewPos);
164 }
165
166 if (aNewRect != maRect)
167 {
168 NbcSetLogicRect(aNewRect);
169 }
170
171 return true;
172}
173
174OUString 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.Normalize();
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 m_bSnapRectDirty=true;
201 if (auto pRectObj = dynamic_cast<SdrRectObj *>(this)) {
202 pRectObj->SetXPolyDirty();
203 }
204 return true;
205}
206
208{
209 rStat.TakeCreateRect(maRect);
211
213
215 if (auto pRectObj = dynamic_cast<SdrRectObj *>(this)) {
216 pRectObj->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.Normalize();
235
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: */
sal_Int32 GetNumerator() const
sal_Int32 GetDenominator() const
double mfTanShearAngle
Definition: svdtrans.hxx:205
double mfCosRotationAngle
Definition: svdtrans.hxx:207
Degree100 nShearAngle
Definition: svdtrans.hxx:204
double mfSinRotationAngle
Definition: svdtrans.hxx:206
Degree100 nRotationAngle
Definition: svdtrans.hxx:203
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:908
OUString ImpGetDescriptionStr(TranslateId pStrCacheID) const
Definition: svdobj.cxx:1067
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:171
virtual void AdaptTextMinSize()
Definition: svdotext.cxx:501
virtual OUString getSpecialDragComment(const SdrDragStat &rDrag) const override
Definition: svdotxdr.cxx:174
virtual bool applySpecialDrag(SdrDragStat &rDrag) override
Definition: svdotxdr.cxx:149
virtual bool MovCreate(SdrDragStat &rStat) override
Definition: svdotxdr.cxx:192
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:182
tools::Rectangle maRect
Definition: svdotext.hxx:168
virtual PointerStyle GetCreatePointer() const override
get the cursor/pointer that signals creating this object
Definition: svdotxdr.cxx:242
static void ImpJustifyRect(tools::Rectangle &rRect)
Definition: svdotext.cxx:405
virtual void BrkCreate(SdrDragStat &rStat) override
Definition: svdotxdr.cxx:221
virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat &rDrag) const override
Polygon dragged by the user when creating the object.
Definition: svdotxdr.cxx:230
tools::Rectangle ImpDragCalcRect(const SdrDragStat &rDrag) const
Definition: svdotxdr.cxx:72
virtual bool BckCreate(SdrDragStat &rStat) override
Definition: svdotxdr.cxx:225
virtual void AddToHdlList(SdrHdlList &rHdlList) const override
Definition: svdotxdr.cxx:41
bool IsTextFrame() const
Definition: svdotext.hxx:332
virtual bool EndCreate(SdrDragStat &rStat, SdrCreateCmd eCmd) override
Definition: svdotxdr.cxx:207
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 void NbcSetLogicRect(const tools::Rectangle &rRect) override
Definition: svdotxtr.cxx:74
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 Point RightCenter() const
constexpr Point BottomCenter() const
constexpr void SetBottom(tools::Long v)
constexpr Point BottomRight() const
constexpr Point TopRight() const
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr Point LeftCenter() const
constexpr Point TopCenter() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
constexpr Point BottomLeft() 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