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