Line data Source code
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 "svdglob.hxx"
27 : #include "svx/svdstr.hrc"
28 : #include <svx/svdoashp.hxx>
29 : #include <tools/bigint.hxx>
30 : #include <basegfx/polygon/b2dpolygon.hxx>
31 : #include <basegfx/range/b2drange.hxx>
32 : #include <basegfx/polygon/b2dpolygontools.hxx>
33 :
34 :
35 89 : sal_uInt32 SdrTextObj::GetHdlCount() const
36 : {
37 89 : return 8L;
38 : }
39 :
40 74 : SdrHdl* SdrTextObj::GetHdl(sal_uInt32 nHdlNum) const
41 : {
42 74 : SdrHdl* pH=NULL;
43 74 : Point aPnt;
44 74 : SdrHdlKind eKind=HDL_MOVE;
45 74 : switch (nHdlNum) {
46 9 : case 0: aPnt=maRect.TopLeft(); eKind=HDL_UPLFT; break;
47 9 : case 1: aPnt=maRect.TopCenter(); eKind=HDL_UPPER; break;
48 9 : case 2: aPnt=maRect.TopRight(); eKind=HDL_UPRGT; break;
49 9 : case 3: aPnt=maRect.LeftCenter(); eKind=HDL_LEFT ; break;
50 9 : case 4: aPnt=maRect.RightCenter(); eKind=HDL_RIGHT; break;
51 9 : case 5: aPnt=maRect.BottomLeft(); eKind=HDL_LWLFT; break;
52 11 : case 6: aPnt=maRect.BottomCenter(); eKind=HDL_LOWER; break;
53 9 : case 7: aPnt=maRect.BottomRight(); eKind=HDL_LWRGT; break;
54 : }
55 74 : if (aGeo.nShearAngle!=0) ShearPoint(aPnt,maRect.TopLeft(),aGeo.nTan);
56 74 : if (aGeo.nRotationAngle!=0) RotatePoint(aPnt,maRect.TopLeft(),aGeo.nSin,aGeo.nCos);
57 74 : if (eKind!=HDL_MOVE) {
58 74 : pH=new SdrHdl(aPnt,eKind);
59 74 : pH->SetObj(const_cast<SdrTextObj*>(this));
60 74 : pH->SetRotationAngle(aGeo.nRotationAngle);
61 : }
62 74 : return pH;
63 : }
64 :
65 :
66 :
67 0 : bool SdrTextObj::hasSpecialDrag() const
68 : {
69 0 : return true;
70 : }
71 :
72 6 : Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const
73 : {
74 6 : Rectangle aTmpRect(maRect);
75 6 : const SdrHdl* pHdl=rDrag.GetHdl();
76 6 : SdrHdlKind eHdl=pHdl==NULL ? HDL_MOVE : pHdl->GetKind();
77 6 : bool bEcke=(eHdl==HDL_UPLFT || eHdl==HDL_UPRGT || eHdl==HDL_LWLFT || eHdl==HDL_LWRGT);
78 6 : bool bOrtho=rDrag.GetView()!=NULL && rDrag.GetView()->IsOrtho();
79 6 : bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho();
80 6 : Point aPos(rDrag.GetNow());
81 : // Unrotate:
82 6 : if (aGeo.nRotationAngle!=0) RotatePoint(aPos,aTmpRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
83 : // Unshear:
84 6 : if (aGeo.nShearAngle!=0) ShearPoint(aPos,aTmpRect.TopLeft(),-aGeo.nTan);
85 :
86 6 : bool bLft=(eHdl==HDL_UPLFT || eHdl==HDL_LEFT || eHdl==HDL_LWLFT);
87 6 : bool bRgt=(eHdl==HDL_UPRGT || eHdl==HDL_RIGHT || eHdl==HDL_LWRGT);
88 6 : bool bTop=(eHdl==HDL_UPRGT || eHdl==HDL_UPPER || eHdl==HDL_UPLFT);
89 6 : bool bBtm=(eHdl==HDL_LWRGT || eHdl==HDL_LOWER || eHdl==HDL_LWLFT);
90 6 : if (bLft) aTmpRect.Left() =aPos.X();
91 6 : if (bRgt) aTmpRect.Right() =aPos.X();
92 6 : if (bTop) aTmpRect.Top() =aPos.Y();
93 6 : if (bBtm) aTmpRect.Bottom()=aPos.Y();
94 6 : if (bOrtho) { // Ortho
95 0 : long nWdt0=maRect.Right() -maRect.Left();
96 0 : long nHgt0=maRect.Bottom()-maRect.Top();
97 0 : long nXMul=aTmpRect.Right() -aTmpRect.Left();
98 0 : long nYMul=aTmpRect.Bottom()-aTmpRect.Top();
99 0 : long nXDiv=nWdt0;
100 0 : long nYDiv=nHgt0;
101 0 : bool bXNeg=(nXMul<0)!=(nXDiv<0);
102 0 : bool bYNeg=(nYMul<0)!=(nYDiv<0);
103 0 : nXMul=std::abs(nXMul);
104 0 : nYMul=std::abs(nYMul);
105 0 : nXDiv=std::abs(nXDiv);
106 0 : nYDiv=std::abs(nYDiv);
107 0 : Fraction aXFact(nXMul,nXDiv); // fractions for canceling
108 0 : Fraction aYFact(nYMul,nYDiv); // and for comparing
109 0 : nXMul=aXFact.GetNumerator();
110 0 : nYMul=aYFact.GetNumerator();
111 0 : nXDiv=aXFact.GetDenominator();
112 0 : nYDiv=aYFact.GetDenominator();
113 0 : if (bEcke) { // corner point handles
114 0 : bool bUseX=(aXFact<aYFact) != bBigOrtho;
115 0 : if (bUseX) {
116 0 : long nNeed=long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv));
117 0 : if (bYNeg) nNeed=-nNeed;
118 0 : if (bTop) aTmpRect.Top()=aTmpRect.Bottom()-nNeed;
119 0 : if (bBtm) aTmpRect.Bottom()=aTmpRect.Top()+nNeed;
120 : } else {
121 0 : long nNeed=long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv));
122 0 : if (bXNeg) nNeed=-nNeed;
123 0 : if (bLft) aTmpRect.Left()=aTmpRect.Right()-nNeed;
124 0 : if (bRgt) aTmpRect.Right()=aTmpRect.Left()+nNeed;
125 : }
126 : } else { // apex handles
127 0 : if ((bLft || bRgt) && nXDiv!=0) {
128 0 : long nHgt0b=maRect.Bottom()-maRect.Top();
129 0 : long nNeed=long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv));
130 0 : aTmpRect.Top()-=(nNeed-nHgt0b)/2;
131 0 : aTmpRect.Bottom()=aTmpRect.Top()+nNeed;
132 : }
133 0 : if ((bTop || bBtm) && nYDiv!=0) {
134 0 : long nWdt0b=maRect.Right()-maRect.Left();
135 0 : long nNeed=long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv));
136 0 : aTmpRect.Left()-=(nNeed-nWdt0b)/2;
137 0 : aTmpRect.Right()=aTmpRect.Left()+nNeed;
138 : }
139 0 : }
140 : }
141 6 : if (!ISA(SdrObjCustomShape)) // not justifying when in CustomShapes, to be able to detect if a shape has to be mirrored
142 0 : ImpJustifyRect(aTmpRect);
143 6 : return aTmpRect;
144 : }
145 :
146 :
147 : // drag
148 :
149 0 : bool SdrTextObj::applySpecialDrag(SdrDragStat& rDrag)
150 : {
151 0 : Rectangle aNewRect(ImpDragCalcRect(rDrag));
152 :
153 0 : if(aNewRect.TopLeft() != maRect.TopLeft() && (aGeo.nRotationAngle || aGeo.nShearAngle))
154 : {
155 0 : Point aNewPos(aNewRect.TopLeft());
156 :
157 0 : if(aGeo.nShearAngle)
158 0 : ShearPoint(aNewPos,maRect.TopLeft(),aGeo.nTan);
159 :
160 0 : if(aGeo.nRotationAngle)
161 0 : RotatePoint(aNewPos,maRect.TopLeft(),aGeo.nSin,aGeo.nCos);
162 :
163 0 : aNewRect.SetPos(aNewPos);
164 : }
165 :
166 0 : if (aNewRect != maRect)
167 : {
168 0 : NbcSetLogicRect(aNewRect);
169 : }
170 :
171 0 : return true;
172 : }
173 :
174 1 : OUString SdrTextObj::getSpecialDragComment(const SdrDragStat& /*rDrag*/) const
175 : {
176 1 : OUString aStr;
177 1 : ImpTakeDescriptionStr(STR_DragRectResize,aStr);
178 1 : return aStr;
179 : }
180 :
181 :
182 : // Create
183 :
184 0 : bool SdrTextObj::BegCreate(SdrDragStat& rStat)
185 : {
186 0 : rStat.SetOrtho4Possible();
187 0 : Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
188 0 : aRect1.Justify();
189 0 : rStat.SetActionRect(aRect1);
190 0 : maRect = aRect1;
191 0 : return true;
192 : }
193 :
194 0 : bool SdrTextObj::MovCreate(SdrDragStat& rStat)
195 : {
196 0 : Rectangle aRect1;
197 0 : rStat.TakeCreateRect(aRect1);
198 0 : ImpJustifyRect(aRect1);
199 0 : rStat.SetActionRect(aRect1);
200 0 : maRect = aRect1; // for ObjName
201 0 : SetBoundRectDirty();
202 0 : bSnapRectDirty=true;
203 0 : if (HAS_BASE(SdrRectObj,this)) {
204 0 : static_cast<SdrRectObj*>(this)->SetXPolyDirty();
205 : }
206 0 : return true;
207 : }
208 :
209 0 : bool SdrTextObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
210 : {
211 0 : rStat.TakeCreateRect(maRect);
212 0 : ImpJustifyRect(maRect);
213 :
214 : // #115391#
215 0 : AdaptTextMinSize();
216 :
217 0 : SetRectsDirty();
218 0 : if (HAS_BASE(SdrRectObj,this)) {
219 0 : static_cast<SdrRectObj*>(this)->SetXPolyDirty();
220 : }
221 0 : return (eCmd==SDRCREATE_FORCEEND || rStat.GetPointAnz()>=2);
222 : }
223 :
224 0 : void SdrTextObj::BrkCreate(SdrDragStat& /*rStat*/)
225 : {
226 0 : }
227 :
228 0 : bool SdrTextObj::BckCreate(SdrDragStat& /*rStat*/)
229 : {
230 0 : return true;
231 : }
232 :
233 0 : basegfx::B2DPolyPolygon SdrTextObj::TakeCreatePoly(const SdrDragStat& rDrag) const
234 : {
235 0 : Rectangle aRect1;
236 0 : rDrag.TakeCreateRect(aRect1);
237 0 : aRect1.Justify();
238 :
239 0 : basegfx::B2DPolyPolygon aRetval;
240 0 : const basegfx::B2DRange aRange(aRect1.Left(), aRect1.Top(), aRect1.Right(), aRect1.Bottom());
241 0 : aRetval.append(basegfx::tools::createPolygonFromRect(aRange));
242 0 : return aRetval;
243 : }
244 :
245 0 : Pointer SdrTextObj::GetCreatePointer() const
246 : {
247 0 : if (IsTextFrame()) return Pointer(PointerStyle::DrawText);
248 0 : return Pointer(PointerStyle::Cross);
249 435 : }
250 :
251 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|