Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svx/svdotext.hxx>
31 : : #include <svx/svdhdl.hxx>
32 : : #include <svx/svddrag.hxx>
33 : : #include <svx/svdview.hxx>
34 : : #include <svx/svdorect.hxx> // for SetXPolyDirty in MovCreate at SolidDragging
35 : : #include "svx/svdglob.hxx" // Stringcache
36 : : #include "svx/svdstr.hrc" // the object's name
37 : : #include <svx/svdoashp.hxx>
38 : : #include <tools/bigint.hxx>
39 : : #include <basegfx/polygon/b2dpolygon.hxx>
40 : : #include <basegfx/range/b2drange.hxx>
41 : : #include <basegfx/polygon/b2dpolygontools.hxx>
42 : :
43 : :
44 : 0 : sal_uInt32 SdrTextObj::GetHdlCount() const
45 : : {
46 : 0 : return 8L;
47 : : }
48 : :
49 : 0 : SdrHdl* SdrTextObj::GetHdl(sal_uInt32 nHdlNum) const
50 : : {
51 : 0 : SdrHdl* pH=NULL;
52 : 0 : Point aPnt;
53 : 0 : SdrHdlKind eKind=HDL_MOVE;
54 [ # # # # : 0 : switch (nHdlNum) {
# # # #
# ]
55 : 0 : case 0: aPnt=aRect.TopLeft(); eKind=HDL_UPLFT; break;
56 [ # # ]: 0 : case 1: aPnt=aRect.TopCenter(); eKind=HDL_UPPER; break;
57 [ # # ]: 0 : case 2: aPnt=aRect.TopRight(); eKind=HDL_UPRGT; break;
58 [ # # ]: 0 : case 3: aPnt=aRect.LeftCenter(); eKind=HDL_LEFT ; break;
59 [ # # ]: 0 : case 4: aPnt=aRect.RightCenter(); eKind=HDL_RIGHT; break;
60 [ # # ]: 0 : case 5: aPnt=aRect.BottomLeft(); eKind=HDL_LWLFT; break;
61 [ # # ]: 0 : case 6: aPnt=aRect.BottomCenter(); eKind=HDL_LOWER; break;
62 [ # # ]: 0 : case 7: aPnt=aRect.BottomRight(); eKind=HDL_LWRGT; break;
63 : : }
64 [ # # ]: 0 : if (aGeo.nShearWink!=0) ShearPoint(aPnt,aRect.TopLeft(),aGeo.nTan);
65 [ # # ]: 0 : if (aGeo.nDrehWink!=0) RotatePoint(aPnt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
66 [ # # ]: 0 : if (eKind!=HDL_MOVE) {
67 [ # # ][ # # ]: 0 : pH=new SdrHdl(aPnt,eKind);
68 [ # # ]: 0 : pH->SetObj((SdrObject*)this);
69 [ # # ]: 0 : pH->SetDrehWink(aGeo.nDrehWink);
70 : : }
71 : 0 : return pH;
72 : : }
73 : :
74 : : ////////////////////////////////////////////////////////////////////////////////////////////////////
75 : :
76 : 0 : bool SdrTextObj::hasSpecialDrag() const
77 : : {
78 : 0 : return true;
79 : : }
80 : :
81 : 0 : Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const
82 : : {
83 : 0 : Rectangle aTmpRect(aRect);
84 : 0 : const SdrHdl* pHdl=rDrag.GetHdl();
85 [ # # ]: 0 : SdrHdlKind eHdl=pHdl==NULL ? HDL_MOVE : pHdl->GetKind();
86 [ # # ][ # # ]: 0 : bool bEcke=(eHdl==HDL_UPLFT || eHdl==HDL_UPRGT || eHdl==HDL_LWLFT || eHdl==HDL_LWRGT);
[ # # ][ # # ]
87 [ # # ][ # # ]: 0 : bool bOrtho=rDrag.GetView()!=NULL && rDrag.GetView()->IsOrtho();
88 [ # # ][ # # ]: 0 : bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho();
[ # # ]
89 [ # # ]: 0 : Point aPos(rDrag.GetNow());
90 : : // Unrotate:
91 [ # # ]: 0 : if (aGeo.nDrehWink!=0) RotatePoint(aPos,aTmpRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
92 : : // Unshear:
93 [ # # ]: 0 : if (aGeo.nShearWink!=0) ShearPoint(aPos,aTmpRect.TopLeft(),-aGeo.nTan);
94 : : //
95 [ # # ][ # # ]: 0 : bool bLft=(eHdl==HDL_UPLFT || eHdl==HDL_LEFT || eHdl==HDL_LWLFT);
[ # # ]
96 [ # # ][ # # ]: 0 : bool bRgt=(eHdl==HDL_UPRGT || eHdl==HDL_RIGHT || eHdl==HDL_LWRGT);
[ # # ]
97 [ # # ][ # # ]: 0 : bool bTop=(eHdl==HDL_UPRGT || eHdl==HDL_UPPER || eHdl==HDL_UPLFT);
[ # # ]
98 [ # # ][ # # ]: 0 : bool bBtm=(eHdl==HDL_LWRGT || eHdl==HDL_LOWER || eHdl==HDL_LWLFT);
[ # # ]
99 [ # # ]: 0 : if (bLft) aTmpRect.Left() =aPos.X();
100 [ # # ]: 0 : if (bRgt) aTmpRect.Right() =aPos.X();
101 [ # # ]: 0 : if (bTop) aTmpRect.Top() =aPos.Y();
102 [ # # ]: 0 : if (bBtm) aTmpRect.Bottom()=aPos.Y();
103 [ # # ]: 0 : if (bOrtho) { // Ortho
104 : 0 : long nWdt0=aRect.Right() -aRect.Left();
105 : 0 : long nHgt0=aRect.Bottom()-aRect.Top();
106 : 0 : long nXMul=aTmpRect.Right() -aTmpRect.Left();
107 : 0 : long nYMul=aTmpRect.Bottom()-aTmpRect.Top();
108 : 0 : long nXDiv=nWdt0;
109 : 0 : long nYDiv=nHgt0;
110 : 0 : bool bXNeg=(nXMul<0)!=(nXDiv<0);
111 : 0 : bool bYNeg=(nYMul<0)!=(nYDiv<0);
112 : 0 : nXMul=Abs(nXMul);
113 : 0 : nYMul=Abs(nYMul);
114 : 0 : nXDiv=Abs(nXDiv);
115 : 0 : nYDiv=Abs(nYDiv);
116 [ # # ]: 0 : Fraction aXFact(nXMul,nXDiv); // fractions for canceling
117 [ # # ]: 0 : Fraction aYFact(nYMul,nYDiv); // and for comparing
118 : 0 : nXMul=aXFact.GetNumerator();
119 : 0 : nYMul=aYFact.GetNumerator();
120 : 0 : nXDiv=aXFact.GetDenominator();
121 : 0 : nYDiv=aYFact.GetDenominator();
122 [ # # ]: 0 : if (bEcke) { // corner point handles
123 [ # # ]: 0 : bool bUseX=(aXFact<aYFact) != bBigOrtho;
124 [ # # ]: 0 : if (bUseX) {
125 [ # # ][ # # ]: 0 : long nNeed=long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv));
[ # # ][ # # ]
[ # # ][ # # ]
126 [ # # ]: 0 : if (bYNeg) nNeed=-nNeed;
127 [ # # ]: 0 : if (bTop) aTmpRect.Top()=aTmpRect.Bottom()-nNeed;
128 [ # # ]: 0 : if (bBtm) aTmpRect.Bottom()=aTmpRect.Top()+nNeed;
129 : : } else {
130 [ # # ][ # # ]: 0 : long nNeed=long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv));
[ # # ][ # # ]
[ # # ][ # # ]
131 [ # # ]: 0 : if (bXNeg) nNeed=-nNeed;
132 [ # # ]: 0 : if (bLft) aTmpRect.Left()=aTmpRect.Right()-nNeed;
133 [ # # ]: 0 : if (bRgt) aTmpRect.Right()=aTmpRect.Left()+nNeed;
134 : : }
135 : : } else { // apex handles
136 [ # # ][ # # ]: 0 : if ((bLft || bRgt) && nXDiv!=0) {
[ # # ]
137 : 0 : long nHgt0b=aRect.Bottom()-aRect.Top();
138 [ # # ][ # # ]: 0 : long nNeed=long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv));
[ # # ][ # # ]
[ # # ][ # # ]
139 : 0 : aTmpRect.Top()-=(nNeed-nHgt0b)/2;
140 : 0 : aTmpRect.Bottom()=aTmpRect.Top()+nNeed;
141 : : }
142 [ # # ][ # # ]: 0 : if ((bTop || bBtm) && nYDiv!=0) {
[ # # ]
143 : 0 : long nWdt0b=aRect.Right()-aRect.Left();
144 [ # # ][ # # ]: 0 : long nNeed=long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv));
[ # # ][ # # ]
[ # # ][ # # ]
145 : 0 : aTmpRect.Left()-=(nNeed-nWdt0b)/2;
146 : 0 : aTmpRect.Right()=aTmpRect.Left()+nNeed;
147 : : }
148 : : }
149 : : }
150 [ # # ][ # # ]: 0 : if (!ISA(SdrObjCustomShape)) // not justifying when in CustomShapes, to be able to detect if a shape has to be mirrored
[ # # ]
151 [ # # ]: 0 : ImpJustifyRect(aTmpRect);
152 : 0 : return aTmpRect;
153 : : }
154 : :
155 : : ////////////////////////////////////////////////////////////////////////////////////////////////////
156 : : // drag
157 : :
158 : 0 : bool SdrTextObj::applySpecialDrag(SdrDragStat& rDrag)
159 : : {
160 [ # # ]: 0 : Rectangle aNewRect(ImpDragCalcRect(rDrag));
161 : :
162 [ # # ][ # # ]: 0 : if(aNewRect.TopLeft() != aRect.TopLeft() && (aGeo.nDrehWink || aGeo.nShearWink))
[ # # ][ # # ]
[ # # ][ # # ]
163 : : {
164 : 0 : Point aNewPos(aNewRect.TopLeft());
165 : :
166 [ # # ]: 0 : if(aGeo.nShearWink)
167 : 0 : ShearPoint(aNewPos,aRect.TopLeft(),aGeo.nTan);
168 : :
169 [ # # ]: 0 : if(aGeo.nDrehWink)
170 : 0 : RotatePoint(aNewPos,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
171 : :
172 : 0 : aNewRect.SetPos(aNewPos);
173 : : }
174 : :
175 [ # # ][ # # ]: 0 : if(aNewRect != aRect)
176 : : {
177 [ # # ]: 0 : NbcSetLogicRect(aNewRect);
178 : : }
179 : :
180 : 0 : return true;
181 : : }
182 : :
183 : 0 : String SdrTextObj::getSpecialDragComment(const SdrDragStat& /*rDrag*/) const
184 : : {
185 : 0 : rtl::OUString aStr;
186 [ # # ]: 0 : ImpTakeDescriptionStr(STR_DragRectResize,aStr);
187 [ # # ]: 0 : return aStr;
188 : : }
189 : :
190 : : ////////////////////////////////////////////////////////////////////////////////////////////////////
191 : : // Create
192 : :
193 : 0 : bool SdrTextObj::BegCreate(SdrDragStat& rStat)
194 : : {
195 : 0 : rStat.SetOrtho4Possible();
196 [ # # ][ # # ]: 0 : Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
[ # # ]
197 [ # # ]: 0 : aRect1.Justify();
198 : 0 : rStat.SetActionRect(aRect1);
199 : 0 : aRect = aRect1;
200 : 0 : return true;
201 : : }
202 : :
203 : 0 : bool SdrTextObj::MovCreate(SdrDragStat& rStat)
204 : : {
205 [ # # ]: 0 : Rectangle aRect1;
206 [ # # ]: 0 : rStat.TakeCreateRect(aRect1);
207 [ # # ]: 0 : ImpJustifyRect(aRect1);
208 : 0 : rStat.SetActionRect(aRect1);
209 : 0 : aRect=aRect1; // for ObjName
210 [ # # ]: 0 : SetBoundRectDirty();
211 : 0 : bSnapRectDirty=sal_True;
212 [ # # ][ # # ]: 0 : if (HAS_BASE(SdrRectObj,this)) {
[ # # ][ # # ]
[ # # ]
213 [ # # ]: 0 : ((SdrRectObj*)this)->SetXPolyDirty();
214 : : }
215 : 0 : return true;
216 : : }
217 : :
218 : 0 : bool SdrTextObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
219 : : {
220 : 0 : rStat.TakeCreateRect(aRect);
221 : 0 : ImpJustifyRect(aRect);
222 [ # # ]: 0 : if (bTextFrame) {
223 [ # # ]: 0 : if (IsAutoGrowHeight()) {
224 : : // MinTextHeight
225 : 0 : long nHgt=aRect.GetHeight()-1;
226 [ # # ]: 0 : if (nHgt==1) nHgt=0;
227 : 0 : NbcSetMinTextFrameHeight(nHgt);
228 : : }
229 [ # # ]: 0 : if (IsAutoGrowWidth()) {
230 : : // MinTextWidth
231 : 0 : long nWdt=aRect.GetWidth()-1;
232 [ # # ]: 0 : if (nWdt==1) nWdt=0;
233 : 0 : NbcSetMinTextFrameWidth(nWdt);
234 : : }
235 : : // re-calculate text frame
236 : 0 : NbcAdjustTextFrameWidthAndHeight();
237 : : }
238 : 0 : SetRectsDirty();
239 [ # # ][ # # ]: 0 : if (HAS_BASE(SdrRectObj,this)) {
[ # # ]
240 : 0 : ((SdrRectObj*)this)->SetXPolyDirty();
241 : : }
242 [ # # ][ # # ]: 0 : return (eCmd==SDRCREATE_FORCEEND || rStat.GetPointAnz()>=2);
243 : : }
244 : :
245 : 0 : void SdrTextObj::BrkCreate(SdrDragStat& /*rStat*/)
246 : : {
247 : 0 : }
248 : :
249 : 0 : bool SdrTextObj::BckCreate(SdrDragStat& /*rStat*/)
250 : : {
251 : 0 : return true;
252 : : }
253 : :
254 : 0 : basegfx::B2DPolyPolygon SdrTextObj::TakeCreatePoly(const SdrDragStat& rDrag) const
255 : : {
256 [ # # ]: 0 : Rectangle aRect1;
257 [ # # ]: 0 : rDrag.TakeCreateRect(aRect1);
258 [ # # ]: 0 : aRect1.Justify();
259 : :
260 [ # # ]: 0 : basegfx::B2DPolyPolygon aRetval;
261 [ # # ]: 0 : const basegfx::B2DRange aRange(aRect1.Left(), aRect1.Top(), aRect1.Right(), aRect1.Bottom());
262 [ # # ][ # # ]: 0 : aRetval.append(basegfx::tools::createPolygonFromRect(aRange));
[ # # ]
263 : 0 : return aRetval;
264 : : }
265 : :
266 : 0 : Pointer SdrTextObj::GetCreatePointer() const
267 : : {
268 [ # # ]: 0 : if (IsTextFrame()) return Pointer(POINTER_DRAW_TEXT);
269 : 0 : return Pointer(POINTER_CROSS);
270 : : }
271 : :
272 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|