xref: /AOO41X/main/svx/source/svdraw/svddrag.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 #include <svx/svdview.hxx>
31*cdf0e10cSrcweir #include <svx/svddrag.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir void SdrDragStat::Clear(FASTBOOL bLeaveOne)
34*cdf0e10cSrcweir {
35*cdf0e10cSrcweir 	void* pP=aPnts.First();
36*cdf0e10cSrcweir 	while (pP!=NULL) {
37*cdf0e10cSrcweir 		delete (Point*)pP;
38*cdf0e10cSrcweir 		pP=aPnts.Next();
39*cdf0e10cSrcweir 	}
40*cdf0e10cSrcweir 	if (pUser!=NULL) delete pUser;
41*cdf0e10cSrcweir 	pUser=NULL;
42*cdf0e10cSrcweir 	aPnts.Clear();
43*cdf0e10cSrcweir 	if (bLeaveOne) {
44*cdf0e10cSrcweir 		aPnts.Insert(new Point,CONTAINER_APPEND);
45*cdf0e10cSrcweir 	}
46*cdf0e10cSrcweir }
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir void SdrDragStat::Reset()
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 	pView=NULL;
51*cdf0e10cSrcweir 	pPageView=NULL;
52*cdf0e10cSrcweir 	bShown=sal_False;
53*cdf0e10cSrcweir 	nMinMov=1;
54*cdf0e10cSrcweir 	bMinMoved=sal_False;
55*cdf0e10cSrcweir 	bHorFixed=sal_False;
56*cdf0e10cSrcweir 	bVerFixed=sal_False;
57*cdf0e10cSrcweir 	bWantNoSnap=sal_False;
58*cdf0e10cSrcweir 	pHdl=NULL;
59*cdf0e10cSrcweir 	bOrtho4=sal_False;
60*cdf0e10cSrcweir 	bOrtho8=sal_False;
61*cdf0e10cSrcweir 	pDragMethod=NULL;
62*cdf0e10cSrcweir 	bEndDragChangesAttributes=sal_False;
63*cdf0e10cSrcweir 	bEndDragChangesGeoAndAttributes=sal_False;
64*cdf0e10cSrcweir 	bMouseIsUp=sal_False;
65*cdf0e10cSrcweir 	Clear(sal_True);
66*cdf0e10cSrcweir 	aActionRect=Rectangle();
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir void SdrDragStat::Reset(const Point& rPnt)
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	Reset();
72*cdf0e10cSrcweir 	Start()=rPnt;
73*cdf0e10cSrcweir 	aPos0=rPnt;
74*cdf0e10cSrcweir 	aRealPos0=rPnt;
75*cdf0e10cSrcweir 	RealNow()=rPnt;
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir void SdrDragStat::NextMove(const Point& rPnt)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	aRealPos0=GetRealNow();
81*cdf0e10cSrcweir 	aPos0=GetNow();
82*cdf0e10cSrcweir 	RealNow()=rPnt;
83*cdf0e10cSrcweir 	Point aBla=KorregPos(GetRealNow(),GetPrev());
84*cdf0e10cSrcweir 	Now()=aBla;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir void SdrDragStat::NextPoint(FASTBOOL bSaveReal)
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	Point aPnt(GetNow());
90*cdf0e10cSrcweir 	if (bSaveReal) aPnt=aRealNow;
91*cdf0e10cSrcweir 	aPnts.Insert(new Point(KorregPos(GetRealNow(),aPnt)),CONTAINER_APPEND);
92*cdf0e10cSrcweir 	Prev()=aPnt;
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void SdrDragStat::PrevPoint()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir 	if (aPnts.Count()>=2) { // einer muss immer da bleiben
98*cdf0e10cSrcweir 		Point* pPnt=(Point*)(aPnts.GetObject(aPnts.Count()-2));
99*cdf0e10cSrcweir 		aPnts.Remove(aPnts.Count()-2);
100*cdf0e10cSrcweir 		delete pPnt;
101*cdf0e10cSrcweir 		Now()=KorregPos(GetRealNow(),GetPrev());
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir 	Point aRet(rNow);
108*cdf0e10cSrcweir 	return aRet;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir FASTBOOL SdrDragStat::CheckMinMoved(const Point& rPnt)
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	if (!bMinMoved) {
114*cdf0e10cSrcweir 		long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
115*cdf0e10cSrcweir 		long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
116*cdf0e10cSrcweir 		if (dx>=long(nMinMov) || dy>=long(nMinMov))
117*cdf0e10cSrcweir 			bMinMoved=sal_True;
118*cdf0e10cSrcweir 	}
119*cdf0e10cSrcweir 	return bMinMoved;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir Fraction SdrDragStat::GetXFact() const
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	long nMul=GetNow().X()-aRef1.X();
125*cdf0e10cSrcweir 	long nDiv=GetPrev().X()-aRef1.X();
126*cdf0e10cSrcweir 	if (nDiv==0) nDiv=1;
127*cdf0e10cSrcweir 	if (bHorFixed) { nMul=1; nDiv=1; }
128*cdf0e10cSrcweir 	return Fraction(nMul,nDiv);
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir Fraction SdrDragStat::GetYFact() const
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	long nMul=GetNow().Y()-aRef1.Y();
134*cdf0e10cSrcweir 	long nDiv=GetPrev().Y()-aRef1.Y();
135*cdf0e10cSrcweir 	if (nDiv==0) nDiv=1;
136*cdf0e10cSrcweir 	if (bVerFixed) { nMul=1; nDiv=1; }
137*cdf0e10cSrcweir 	return Fraction(nMul,nDiv);
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir 	rRect=Rectangle(GetStart(),GetNow());
143*cdf0e10cSrcweir 	if (GetPointAnz()>=2) {
144*cdf0e10cSrcweir 		Point aBtmRgt(GetPoint(1));
145*cdf0e10cSrcweir 		rRect.Right()=aBtmRgt.X();
146*cdf0e10cSrcweir 		rRect.Bottom()=aBtmRgt.Y();
147*cdf0e10cSrcweir 	}
148*cdf0e10cSrcweir 	if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
149*cdf0e10cSrcweir 		rRect.Top()+=rRect.Top()-rRect.Bottom();
150*cdf0e10cSrcweir 		rRect.Left()+=rRect.Left()-rRect.Right();
151*cdf0e10cSrcweir 	}
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154