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