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