xref: /aoo42x/main/svx/source/svdraw/svddrag.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <svx/svdview.hxx>
31 #include <svx/svddrag.hxx>
32 
33 void SdrDragStat::Clear(FASTBOOL bLeaveOne)
34 {
35 	void* pP=aPnts.First();
36 	while (pP!=NULL) {
37 		delete (Point*)pP;
38 		pP=aPnts.Next();
39 	}
40 	if (pUser!=NULL) delete pUser;
41 	pUser=NULL;
42 	aPnts.Clear();
43 	if (bLeaveOne) {
44 		aPnts.Insert(new Point,CONTAINER_APPEND);
45 	}
46 }
47 
48 void SdrDragStat::Reset()
49 {
50 	pView=NULL;
51 	pPageView=NULL;
52 	bShown=sal_False;
53 	nMinMov=1;
54 	bMinMoved=sal_False;
55 	bHorFixed=sal_False;
56 	bVerFixed=sal_False;
57 	bWantNoSnap=sal_False;
58 	pHdl=NULL;
59 	bOrtho4=sal_False;
60 	bOrtho8=sal_False;
61 	pDragMethod=NULL;
62 	bEndDragChangesAttributes=sal_False;
63 	bEndDragChangesGeoAndAttributes=sal_False;
64 	bMouseIsUp=sal_False;
65 	Clear(sal_True);
66 	aActionRect=Rectangle();
67 }
68 
69 void SdrDragStat::Reset(const Point& rPnt)
70 {
71 	Reset();
72 	Start()=rPnt;
73 	aPos0=rPnt;
74 	aRealPos0=rPnt;
75 	RealNow()=rPnt;
76 }
77 
78 void SdrDragStat::NextMove(const Point& rPnt)
79 {
80 	aRealPos0=GetRealNow();
81 	aPos0=GetNow();
82 	RealNow()=rPnt;
83 	Point aBla=KorregPos(GetRealNow(),GetPrev());
84 	Now()=aBla;
85 }
86 
87 void SdrDragStat::NextPoint(FASTBOOL bSaveReal)
88 {
89 	Point aPnt(GetNow());
90 	if (bSaveReal) aPnt=aRealNow;
91 	aPnts.Insert(new Point(KorregPos(GetRealNow(),aPnt)),CONTAINER_APPEND);
92 	Prev()=aPnt;
93 }
94 
95 void SdrDragStat::PrevPoint()
96 {
97 	if (aPnts.Count()>=2) { // einer muss immer da bleiben
98 		Point* pPnt=(Point*)(aPnts.GetObject(aPnts.Count()-2));
99 		aPnts.Remove(aPnts.Count()-2);
100 		delete pPnt;
101 		Now()=KorregPos(GetRealNow(),GetPrev());
102 	}
103 }
104 
105 Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
106 {
107 	Point aRet(rNow);
108 	return aRet;
109 }
110 
111 FASTBOOL SdrDragStat::CheckMinMoved(const Point& rPnt)
112 {
113 	if (!bMinMoved) {
114 		long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
115 		long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
116 		if (dx>=long(nMinMov) || dy>=long(nMinMov))
117 			bMinMoved=sal_True;
118 	}
119 	return bMinMoved;
120 }
121 
122 Fraction SdrDragStat::GetXFact() const
123 {
124 	long nMul=GetNow().X()-aRef1.X();
125 	long nDiv=GetPrev().X()-aRef1.X();
126 	if (nDiv==0) nDiv=1;
127 	if (bHorFixed) { nMul=1; nDiv=1; }
128 	return Fraction(nMul,nDiv);
129 }
130 
131 Fraction SdrDragStat::GetYFact() const
132 {
133 	long nMul=GetNow().Y()-aRef1.Y();
134 	long nDiv=GetPrev().Y()-aRef1.Y();
135 	if (nDiv==0) nDiv=1;
136 	if (bVerFixed) { nMul=1; nDiv=1; }
137 	return Fraction(nMul,nDiv);
138 }
139 
140 void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
141 {
142 	rRect=Rectangle(GetStart(),GetNow());
143 	if (GetPointAnz()>=2) {
144 		Point aBtmRgt(GetPoint(1));
145 		rRect.Right()=aBtmRgt.X();
146 		rRect.Bottom()=aBtmRgt.Y();
147 	}
148 	if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
149 		rRect.Top()+=rRect.Top()-rRect.Bottom();
150 		rRect.Left()+=rRect.Left()-rRect.Right();
151 	}
152 }
153 
154