xref: /aoo41x/main/svx/source/svdraw/svddrag.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/svdview.hxx>
27 #include <svx/svddrag.hxx>
28 
Clear(FASTBOOL bLeaveOne)29 void SdrDragStat::Clear(FASTBOOL bLeaveOne)
30 {
31 	void* pP=aPnts.First();
32 	while (pP!=NULL) {
33 		delete (Point*)pP;
34 		pP=aPnts.Next();
35 	}
36 	if (pUser!=NULL) delete pUser;
37 	pUser=NULL;
38 	aPnts.Clear();
39 	if (bLeaveOne) {
40 		aPnts.Insert(new Point,CONTAINER_APPEND);
41 	}
42 }
43 
Reset()44 void SdrDragStat::Reset()
45 {
46 	pView=NULL;
47 	pPageView=NULL;
48 	bShown=sal_False;
49 	nMinMov=1;
50 	bMinMoved=sal_False;
51 	bHorFixed=sal_False;
52 	bVerFixed=sal_False;
53 	bWantNoSnap=sal_False;
54 	pHdl=NULL;
55 	bOrtho4=sal_False;
56 	bOrtho8=sal_False;
57 	pDragMethod=NULL;
58 	bEndDragChangesAttributes=sal_False;
59 	bEndDragChangesGeoAndAttributes=sal_False;
60 	bMouseIsUp=sal_False;
61 	Clear(sal_True);
62 	aActionRect=Rectangle();
63 }
64 
Reset(const Point & rPnt)65 void SdrDragStat::Reset(const Point& rPnt)
66 {
67 	Reset();
68 	Start()=rPnt;
69 	aPos0=rPnt;
70 	aRealPos0=rPnt;
71 	RealNow()=rPnt;
72 }
73 
NextMove(const Point & rPnt)74 void SdrDragStat::NextMove(const Point& rPnt)
75 {
76 	aRealPos0=GetRealNow();
77 	aPos0=GetNow();
78 	RealNow()=rPnt;
79 	Point aBla=KorregPos(GetRealNow(),GetPrev());
80 	Now()=aBla;
81 }
82 
NextPoint(FASTBOOL bSaveReal)83 void SdrDragStat::NextPoint(FASTBOOL bSaveReal)
84 {
85 	Point aPnt(GetNow());
86 	if (bSaveReal) aPnt=aRealNow;
87 	aPnts.Insert(new Point(KorregPos(GetRealNow(),aPnt)),CONTAINER_APPEND);
88 	Prev()=aPnt;
89 }
90 
PrevPoint()91 void SdrDragStat::PrevPoint()
92 {
93 	if (aPnts.Count()>=2) { // einer muss immer da bleiben
94 		Point* pPnt=(Point*)(aPnts.GetObject(aPnts.Count()-2));
95 		aPnts.Remove(aPnts.Count()-2);
96 		delete pPnt;
97 		Now()=KorregPos(GetRealNow(),GetPrev());
98 	}
99 }
100 
KorregPos(const Point & rNow,const Point &) const101 Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
102 {
103 	Point aRet(rNow);
104 	return aRet;
105 }
106 
CheckMinMoved(const Point & rPnt)107 FASTBOOL SdrDragStat::CheckMinMoved(const Point& rPnt)
108 {
109 	if (!bMinMoved) {
110 		long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
111 		long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
112 		if (dx>=long(nMinMov) || dy>=long(nMinMov))
113 			bMinMoved=sal_True;
114 	}
115 	return bMinMoved;
116 }
117 
GetXFact() const118 Fraction SdrDragStat::GetXFact() const
119 {
120 	long nMul=GetNow().X()-aRef1.X();
121 	long nDiv=GetPrev().X()-aRef1.X();
122 	if (nDiv==0) nDiv=1;
123 	if (bHorFixed) { nMul=1; nDiv=1; }
124 	return Fraction(nMul,nDiv);
125 }
126 
GetYFact() const127 Fraction SdrDragStat::GetYFact() const
128 {
129 	long nMul=GetNow().Y()-aRef1.Y();
130 	long nDiv=GetPrev().Y()-aRef1.Y();
131 	if (nDiv==0) nDiv=1;
132 	if (bVerFixed) { nMul=1; nDiv=1; }
133 	return Fraction(nMul,nDiv);
134 }
135 
TakeCreateRect(Rectangle & rRect) const136 void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
137 {
138 	rRect=Rectangle(GetStart(),GetNow());
139 	if (GetPointAnz()>=2) {
140 		Point aBtmRgt(GetPoint(1));
141 		rRect.Right()=aBtmRgt.X();
142 		rRect.Bottom()=aBtmRgt.Y();
143 	}
144 	if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
145 		rRect.Top()+=rRect.Top()-rRect.Bottom();
146 		rRect.Left()+=rRect.Left()-rRect.Right();
147 	}
148 }
149 
150