1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5f6e50924SAndrew Rist * distributed with this work for additional information
6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist * software distributed under the License is distributed on an
15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17f6e50924SAndrew Rist * specific language governing permissions and limitations
18f6e50924SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20f6e50924SAndrew Rist *************************************************************/
21f6e50924SAndrew Rist
22f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <svx/svdotext.hxx>
28cdf0e10cSrcweir #include <svx/svdhdl.hxx>
29cdf0e10cSrcweir #include <svx/svddrag.hxx>
30cdf0e10cSrcweir #include <svx/svdview.hxx>
31cdf0e10cSrcweir #include <svx/svdorect.hxx> // fuer SetXPolyDirty in MovCreate bei SolidDragging
32cdf0e10cSrcweir #include "svx/svdglob.hxx" // Stringcache
33cdf0e10cSrcweir #include "svx/svdstr.hrc" // Objektname
34cdf0e10cSrcweir #include <svx/svdoashp.hxx>
35cdf0e10cSrcweir #include <tools/bigint.hxx>
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
37cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
38cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
41cdf0e10cSrcweir //
42cdf0e10cSrcweir // @@@@@@ @@@@@ @@ @@ @@@@@@ @@@@ @@@@@ @@@@@@
43cdf0e10cSrcweir // @@ @@ @@@ @@@ @@ @@ @@ @@ @@ @@
44cdf0e10cSrcweir // @@ @@ @@@@@ @@ @@ @@ @@ @@ @@
45cdf0e10cSrcweir // @@ @@@@ @@@ @@ @@ @@ @@@@@ @@
46cdf0e10cSrcweir // @@ @@ @@@@@ @@ @@ @@ @@ @@ @@
47cdf0e10cSrcweir // @@ @@ @@@ @@@ @@ @@ @@ @@ @@ @@ @@
48cdf0e10cSrcweir // @@ @@@@@ @@ @@ @@ @@@@ @@@@@ @@@@
49cdf0e10cSrcweir //
50cdf0e10cSrcweir // Dragging, Handles, Create
51cdf0e10cSrcweir //
52cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
53cdf0e10cSrcweir
GetHdlCount() const54cdf0e10cSrcweir sal_uInt32 SdrTextObj::GetHdlCount() const
55cdf0e10cSrcweir {
56cdf0e10cSrcweir return 8L;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
GetHdl(sal_uInt32 nHdlNum) const59cdf0e10cSrcweir SdrHdl* SdrTextObj::GetHdl(sal_uInt32 nHdlNum) const
60cdf0e10cSrcweir {
61cdf0e10cSrcweir SdrHdl* pH=NULL;
62cdf0e10cSrcweir Point aPnt;
63cdf0e10cSrcweir SdrHdlKind eKind=HDL_MOVE;
64cdf0e10cSrcweir switch (nHdlNum) {
65cdf0e10cSrcweir case 0: aPnt=aRect.TopLeft(); eKind=HDL_UPLFT; break; // Oben links
66cdf0e10cSrcweir case 1: aPnt=aRect.TopCenter(); eKind=HDL_UPPER; break; // Oben
67cdf0e10cSrcweir case 2: aPnt=aRect.TopRight(); eKind=HDL_UPRGT; break; // Oben rechts
68cdf0e10cSrcweir case 3: aPnt=aRect.LeftCenter(); eKind=HDL_LEFT ; break; // Links
69cdf0e10cSrcweir case 4: aPnt=aRect.RightCenter(); eKind=HDL_RIGHT; break; // Rechts
70cdf0e10cSrcweir case 5: aPnt=aRect.BottomLeft(); eKind=HDL_LWLFT; break; // Unten links
71cdf0e10cSrcweir case 6: aPnt=aRect.BottomCenter(); eKind=HDL_LOWER; break; // Unten
72cdf0e10cSrcweir case 7: aPnt=aRect.BottomRight(); eKind=HDL_LWRGT; break; // Unten rechts
73cdf0e10cSrcweir }
74cdf0e10cSrcweir if (aGeo.nShearWink!=0) ShearPoint(aPnt,aRect.TopLeft(),aGeo.nTan);
75cdf0e10cSrcweir if (aGeo.nDrehWink!=0) RotatePoint(aPnt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
76cdf0e10cSrcweir if (eKind!=HDL_MOVE) {
77cdf0e10cSrcweir pH=new SdrHdl(aPnt,eKind);
78cdf0e10cSrcweir pH->SetObj((SdrObject*)this);
79cdf0e10cSrcweir pH->SetDrehWink(aGeo.nDrehWink);
80cdf0e10cSrcweir }
81cdf0e10cSrcweir return pH;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
85cdf0e10cSrcweir
hasSpecialDrag() const86cdf0e10cSrcweir bool SdrTextObj::hasSpecialDrag() const
87cdf0e10cSrcweir {
88cdf0e10cSrcweir return true;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
ImpDragCalcRect(const SdrDragStat & rDrag) const91cdf0e10cSrcweir Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const
92cdf0e10cSrcweir {
93cdf0e10cSrcweir Rectangle aTmpRect(aRect);
94cdf0e10cSrcweir const SdrHdl* pHdl=rDrag.GetHdl();
95cdf0e10cSrcweir SdrHdlKind eHdl=pHdl==NULL ? HDL_MOVE : pHdl->GetKind();
96cdf0e10cSrcweir FASTBOOL bEcke=(eHdl==HDL_UPLFT || eHdl==HDL_UPRGT || eHdl==HDL_LWLFT || eHdl==HDL_LWRGT);
97cdf0e10cSrcweir FASTBOOL bOrtho=rDrag.GetView()!=NULL && rDrag.GetView()->IsOrtho();
98cdf0e10cSrcweir FASTBOOL bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho();
99cdf0e10cSrcweir Point aPos(rDrag.GetNow());
100cdf0e10cSrcweir // Unrotate:
101cdf0e10cSrcweir if (aGeo.nDrehWink!=0) RotatePoint(aPos,aTmpRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
102cdf0e10cSrcweir // Unshear:
103cdf0e10cSrcweir if (aGeo.nShearWink!=0) ShearPoint(aPos,aTmpRect.TopLeft(),-aGeo.nTan);
104cdf0e10cSrcweir //
105cdf0e10cSrcweir FASTBOOL bLft=(eHdl==HDL_UPLFT || eHdl==HDL_LEFT || eHdl==HDL_LWLFT);
106cdf0e10cSrcweir FASTBOOL bRgt=(eHdl==HDL_UPRGT || eHdl==HDL_RIGHT || eHdl==HDL_LWRGT);
107cdf0e10cSrcweir FASTBOOL bTop=(eHdl==HDL_UPRGT || eHdl==HDL_UPPER || eHdl==HDL_UPLFT);
108cdf0e10cSrcweir FASTBOOL bBtm=(eHdl==HDL_LWRGT || eHdl==HDL_LOWER || eHdl==HDL_LWLFT);
109cdf0e10cSrcweir if (bLft) aTmpRect.Left() =aPos.X();
110cdf0e10cSrcweir if (bRgt) aTmpRect.Right() =aPos.X();
111cdf0e10cSrcweir if (bTop) aTmpRect.Top() =aPos.Y();
112cdf0e10cSrcweir if (bBtm) aTmpRect.Bottom()=aPos.Y();
113cdf0e10cSrcweir if (bOrtho) { // Ortho
114cdf0e10cSrcweir long nWdt0=aRect.Right() -aRect.Left();
115cdf0e10cSrcweir long nHgt0=aRect.Bottom()-aRect.Top();
116cdf0e10cSrcweir long nXMul=aTmpRect.Right() -aTmpRect.Left();
117cdf0e10cSrcweir long nYMul=aTmpRect.Bottom()-aTmpRect.Top();
118cdf0e10cSrcweir long nXDiv=nWdt0;
119cdf0e10cSrcweir long nYDiv=nHgt0;
120cdf0e10cSrcweir FASTBOOL bXNeg=(nXMul<0)!=(nXDiv<0);
121cdf0e10cSrcweir FASTBOOL bYNeg=(nYMul<0)!=(nYDiv<0);
122cdf0e10cSrcweir nXMul=Abs(nXMul);
123cdf0e10cSrcweir nYMul=Abs(nYMul);
124cdf0e10cSrcweir nXDiv=Abs(nXDiv);
125cdf0e10cSrcweir nYDiv=Abs(nYDiv);
126cdf0e10cSrcweir Fraction aXFact(nXMul,nXDiv); // Fractions zum kuerzen
127cdf0e10cSrcweir Fraction aYFact(nYMul,nYDiv); // und zum vergleichen
128cdf0e10cSrcweir nXMul=aXFact.GetNumerator();
129cdf0e10cSrcweir nYMul=aYFact.GetNumerator();
130cdf0e10cSrcweir nXDiv=aXFact.GetDenominator();
131cdf0e10cSrcweir nYDiv=aYFact.GetDenominator();
132cdf0e10cSrcweir if (bEcke) { // Eckpunkthandles
133cdf0e10cSrcweir FASTBOOL bUseX=(aXFact<aYFact) != bBigOrtho;
134cdf0e10cSrcweir if (bUseX) {
135cdf0e10cSrcweir long nNeed=long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv));
136cdf0e10cSrcweir if (bYNeg) nNeed=-nNeed;
137cdf0e10cSrcweir if (bTop) aTmpRect.Top()=aTmpRect.Bottom()-nNeed;
138cdf0e10cSrcweir if (bBtm) aTmpRect.Bottom()=aTmpRect.Top()+nNeed;
139cdf0e10cSrcweir } else {
140cdf0e10cSrcweir long nNeed=long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv));
141cdf0e10cSrcweir if (bXNeg) nNeed=-nNeed;
142cdf0e10cSrcweir if (bLft) aTmpRect.Left()=aTmpRect.Right()-nNeed;
143cdf0e10cSrcweir if (bRgt) aTmpRect.Right()=aTmpRect.Left()+nNeed;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir } else { // Scheitelpunkthandles
146cdf0e10cSrcweir if ((bLft || bRgt) && nXDiv!=0) {
147cdf0e10cSrcweir long nHgt0b=aRect.Bottom()-aRect.Top();
148cdf0e10cSrcweir long nNeed=long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv));
149cdf0e10cSrcweir aTmpRect.Top()-=(nNeed-nHgt0b)/2;
150cdf0e10cSrcweir aTmpRect.Bottom()=aTmpRect.Top()+nNeed;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir if ((bTop || bBtm) && nYDiv!=0) {
153cdf0e10cSrcweir long nWdt0b=aRect.Right()-aRect.Left();
154cdf0e10cSrcweir long nNeed=long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv));
155cdf0e10cSrcweir aTmpRect.Left()-=(nNeed-nWdt0b)/2;
156cdf0e10cSrcweir aTmpRect.Right()=aTmpRect.Left()+nNeed;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir if (!ISA(SdrObjCustomShape)) // not justifying for CustomShapes to be able to detect if a shape has to be mirrored
161cdf0e10cSrcweir ImpJustifyRect(aTmpRect);
162cdf0e10cSrcweir return aTmpRect;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
165cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
166cdf0e10cSrcweir // drag
167cdf0e10cSrcweir
applySpecialDrag(SdrDragStat & rDrag)168cdf0e10cSrcweir bool SdrTextObj::applySpecialDrag(SdrDragStat& rDrag)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir Rectangle aNewRect(ImpDragCalcRect(rDrag));
171cdf0e10cSrcweir
172cdf0e10cSrcweir if(aNewRect.TopLeft() != aRect.TopLeft() && (aGeo.nDrehWink || aGeo.nShearWink))
173cdf0e10cSrcweir {
174cdf0e10cSrcweir Point aNewPos(aNewRect.TopLeft());
175cdf0e10cSrcweir
176cdf0e10cSrcweir if(aGeo.nShearWink)
177cdf0e10cSrcweir ShearPoint(aNewPos,aRect.TopLeft(),aGeo.nTan);
178cdf0e10cSrcweir
179cdf0e10cSrcweir if(aGeo.nDrehWink)
180cdf0e10cSrcweir RotatePoint(aNewPos,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
181cdf0e10cSrcweir
182cdf0e10cSrcweir aNewRect.SetPos(aNewPos);
183cdf0e10cSrcweir }
184cdf0e10cSrcweir
185cdf0e10cSrcweir if(aNewRect != aRect)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir NbcSetLogicRect(aNewRect);
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190cdf0e10cSrcweir return true;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
getSpecialDragComment(const SdrDragStat &) const193cdf0e10cSrcweir String SdrTextObj::getSpecialDragComment(const SdrDragStat& /*rDrag*/) const
194cdf0e10cSrcweir {
195cdf0e10cSrcweir XubString aStr;
196cdf0e10cSrcweir ImpTakeDescriptionStr(STR_DragRectResize,aStr);
197cdf0e10cSrcweir return aStr;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
201cdf0e10cSrcweir // Create
202cdf0e10cSrcweir
BegCreate(SdrDragStat & rStat)203cdf0e10cSrcweir FASTBOOL SdrTextObj::BegCreate(SdrDragStat& rStat)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir rStat.SetOrtho4Possible();
206cdf0e10cSrcweir Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
207cdf0e10cSrcweir aRect1.Justify();
208cdf0e10cSrcweir rStat.SetActionRect(aRect1);
209cdf0e10cSrcweir aRect = aRect1;
210cdf0e10cSrcweir return sal_True;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
MovCreate(SdrDragStat & rStat)213cdf0e10cSrcweir FASTBOOL SdrTextObj::MovCreate(SdrDragStat& rStat)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir Rectangle aRect1;
216cdf0e10cSrcweir rStat.TakeCreateRect(aRect1);
217cdf0e10cSrcweir ImpJustifyRect(aRect1);
218cdf0e10cSrcweir rStat.SetActionRect(aRect1);
219cdf0e10cSrcweir aRect=aRect1; // fuer ObjName
220cdf0e10cSrcweir SetBoundRectDirty();
221cdf0e10cSrcweir bSnapRectDirty=sal_True;
222cdf0e10cSrcweir if (HAS_BASE(SdrRectObj,this)) {
223cdf0e10cSrcweir ((SdrRectObj*)this)->SetXPolyDirty();
224cdf0e10cSrcweir }
225cdf0e10cSrcweir return sal_True;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
EndCreate(SdrDragStat & rStat,SdrCreateCmd eCmd)228cdf0e10cSrcweir FASTBOOL SdrTextObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir rStat.TakeCreateRect(aRect);
231cdf0e10cSrcweir ImpJustifyRect(aRect);
232*215d8f42SArmin Le Grand
233*215d8f42SArmin Le Grand // #115391#
234*215d8f42SArmin Le Grand AdaptTextMinSize();
235*215d8f42SArmin Le Grand
236cdf0e10cSrcweir SetRectsDirty();
237cdf0e10cSrcweir if (HAS_BASE(SdrRectObj,this)) {
238cdf0e10cSrcweir ((SdrRectObj*)this)->SetXPolyDirty();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir return (eCmd==SDRCREATE_FORCEEND || rStat.GetPointAnz()>=2);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
BrkCreate(SdrDragStat &)243cdf0e10cSrcweir void SdrTextObj::BrkCreate(SdrDragStat& /*rStat*/)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
BckCreate(SdrDragStat &)247cdf0e10cSrcweir FASTBOOL SdrTextObj::BckCreate(SdrDragStat& /*rStat*/)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir return sal_True;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
TakeCreatePoly(const SdrDragStat & rDrag) const252cdf0e10cSrcweir basegfx::B2DPolyPolygon SdrTextObj::TakeCreatePoly(const SdrDragStat& rDrag) const
253cdf0e10cSrcweir {
254cdf0e10cSrcweir Rectangle aRect1;
255cdf0e10cSrcweir rDrag.TakeCreateRect(aRect1);
256cdf0e10cSrcweir aRect1.Justify();
257cdf0e10cSrcweir
258cdf0e10cSrcweir basegfx::B2DPolyPolygon aRetval;
259cdf0e10cSrcweir const basegfx::B2DRange aRange(aRect1.Left(), aRect1.Top(), aRect1.Right(), aRect1.Bottom());
260cdf0e10cSrcweir aRetval.append(basegfx::tools::createPolygonFromRect(aRange));
261cdf0e10cSrcweir return aRetval;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
GetCreatePointer() const264cdf0e10cSrcweir Pointer SdrTextObj::GetCreatePointer() const
265cdf0e10cSrcweir {
266cdf0e10cSrcweir if (IsTextFrame()) return Pointer(POINTER_DRAW_TEXT);
267cdf0e10cSrcweir return Pointer(POINTER_CROSS);
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270