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 "svx/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 0 : sal_uInt32 SdrTextObj::GetHdlCount() const
36 : {
37 0 : return 8L;
38 : }
39 :
40 0 : SdrHdl* SdrTextObj::GetHdl(sal_uInt32 nHdlNum) const
41 : {
42 0 : SdrHdl* pH=NULL;
43 0 : Point aPnt;
44 0 : SdrHdlKind eKind=HDL_MOVE;
45 0 : switch (nHdlNum) {
46 0 : case 0: aPnt=aRect.TopLeft(); eKind=HDL_UPLFT; break;
47 0 : case 1: aPnt=aRect.TopCenter(); eKind=HDL_UPPER; break;
48 0 : case 2: aPnt=aRect.TopRight(); eKind=HDL_UPRGT; break;
49 0 : case 3: aPnt=aRect.LeftCenter(); eKind=HDL_LEFT ; break;
50 0 : case 4: aPnt=aRect.RightCenter(); eKind=HDL_RIGHT; break;
51 0 : case 5: aPnt=aRect.BottomLeft(); eKind=HDL_LWLFT; break;
52 0 : case 6: aPnt=aRect.BottomCenter(); eKind=HDL_LOWER; break;
53 0 : case 7: aPnt=aRect.BottomRight(); eKind=HDL_LWRGT; break;
54 : }
55 0 : if (aGeo.nShearWink!=0) ShearPoint(aPnt,aRect.TopLeft(),aGeo.nTan);
56 0 : if (aGeo.nDrehWink!=0) RotatePoint(aPnt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
57 0 : if (eKind!=HDL_MOVE) {
58 0 : pH=new SdrHdl(aPnt,eKind);
59 0 : pH->SetObj((SdrObject*)this);
60 0 : pH->SetDrehWink(aGeo.nDrehWink);
61 : }
62 0 : return pH;
63 : }
64 :
65 :
66 :
67 0 : bool SdrTextObj::hasSpecialDrag() const
68 : {
69 0 : return true;
70 : }
71 :
72 0 : Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const
73 : {
74 0 : Rectangle aTmpRect(aRect);
75 0 : const SdrHdl* pHdl=rDrag.GetHdl();
76 0 : SdrHdlKind eHdl=pHdl==NULL ? HDL_MOVE : pHdl->GetKind();
77 0 : bool bEcke=(eHdl==HDL_UPLFT || eHdl==HDL_UPRGT || eHdl==HDL_LWLFT || eHdl==HDL_LWRGT);
78 0 : bool bOrtho=rDrag.GetView()!=NULL && rDrag.GetView()->IsOrtho();
79 0 : bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho();
80 0 : Point aPos(rDrag.GetNow());
81 : // Unrotate:
82 0 : if (aGeo.nDrehWink!=0) RotatePoint(aPos,aTmpRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
83 : // Unshear:
84 0 : if (aGeo.nShearWink!=0) ShearPoint(aPos,aTmpRect.TopLeft(),-aGeo.nTan);
85 :
86 0 : bool bLft=(eHdl==HDL_UPLFT || eHdl==HDL_LEFT || eHdl==HDL_LWLFT);
87 0 : bool bRgt=(eHdl==HDL_UPRGT || eHdl==HDL_RIGHT || eHdl==HDL_LWRGT);
88 0 : bool bTop=(eHdl==HDL_UPRGT || eHdl==HDL_UPPER || eHdl==HDL_UPLFT);
89 0 : bool bBtm=(eHdl==HDL_LWRGT || eHdl==HDL_LOWER || eHdl==HDL_LWLFT);
90 0 : if (bLft) aTmpRect.Left() =aPos.X();
91 0 : if (bRgt) aTmpRect.Right() =aPos.X();
92 0 : if (bTop) aTmpRect.Top() =aPos.Y();
93 0 : if (bBtm) aTmpRect.Bottom()=aPos.Y();
94 0 : if (bOrtho) { // Ortho
95 0 : long nWdt0=aRect.Right() -aRect.Left();
96 0 : long nHgt0=aRect.Bottom()-aRect.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=aRect.Bottom()-aRect.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=aRect.Right()-aRect.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 : }
140 : }
141 0 : 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 0 : 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() != aRect.TopLeft() && (aGeo.nDrehWink || aGeo.nShearWink))
154 : {
155 0 : Point aNewPos(aNewRect.TopLeft());
156 :
157 0 : if(aGeo.nShearWink)
158 0 : ShearPoint(aNewPos,aRect.TopLeft(),aGeo.nTan);
159 :
160 0 : if(aGeo.nDrehWink)
161 0 : RotatePoint(aNewPos,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
162 :
163 0 : aNewRect.SetPos(aNewPos);
164 : }
165 :
166 0 : if(aNewRect != aRect)
167 : {
168 0 : NbcSetLogicRect(aNewRect);
169 : }
170 :
171 0 : return true;
172 : }
173 :
174 0 : OUString SdrTextObj::getSpecialDragComment(const SdrDragStat& /*rDrag*/) const
175 : {
176 0 : OUString aStr;
177 0 : ImpTakeDescriptionStr(STR_DragRectResize,aStr);
178 0 : 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 : aRect = 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 : aRect=aRect1; // for ObjName
201 0 : SetBoundRectDirty();
202 0 : bSnapRectDirty=true;
203 0 : if (HAS_BASE(SdrRectObj,this)) {
204 0 : ((SdrRectObj*)this)->SetXPolyDirty();
205 : }
206 0 : return true;
207 : }
208 :
209 0 : bool SdrTextObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
210 : {
211 0 : rStat.TakeCreateRect(aRect);
212 0 : ImpJustifyRect(aRect);
213 :
214 : // #115391#
215 0 : AdaptTextMinSize();
216 :
217 0 : SetRectsDirty();
218 0 : if (HAS_BASE(SdrRectObj,this)) {
219 0 : ((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(POINTER_DRAW_TEXT);
248 0 : return Pointer(POINTER_CROSS);
249 : }
250 :
251 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|