Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / svdraw / svddrag.cxx
blob478e8c39acaf65eb2efda3f54848924652345401
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <svx/svdview.hxx>
30 #include <svx/svddrag.hxx>
32 void SdrDragStat::Clear(bool bLeaveOne)
34 void* pP=aPnts.First();
35 while (pP!=NULL) {
36 delete (Point*)pP;
37 pP=aPnts.Next();
39 if (pUser!=NULL) delete pUser;
40 pUser=NULL;
41 aPnts.Clear();
42 if (bLeaveOne) {
43 aPnts.Insert(new Point,CONTAINER_APPEND);
47 void SdrDragStat::Reset()
49 pView=NULL;
50 pPageView=NULL;
51 bShown=sal_False;
52 nMinMov=1;
53 bMinMoved=sal_False;
54 bHorFixed=sal_False;
55 bVerFixed=sal_False;
56 bWantNoSnap=sal_False;
57 pHdl=NULL;
58 bOrtho4=sal_False;
59 bOrtho8=sal_False;
60 pDragMethod=NULL;
61 bEndDragChangesAttributes=sal_False;
62 bEndDragChangesGeoAndAttributes=sal_False;
63 bMouseIsUp=sal_False;
64 Clear(sal_True);
65 aActionRect=Rectangle();
68 void SdrDragStat::Reset(const Point& rPnt)
70 Reset();
71 Start()=rPnt;
72 aPos0=rPnt;
73 aRealPos0=rPnt;
74 RealNow()=rPnt;
77 void SdrDragStat::NextMove(const Point& rPnt)
79 aRealPos0=GetRealNow();
80 aPos0=GetNow();
81 RealNow()=rPnt;
82 Point aBla=KorregPos(GetRealNow(),GetPrev());
83 Now()=aBla;
86 void SdrDragStat::NextPoint(bool bSaveReal)
88 Point aPnt(GetNow());
89 if (bSaveReal) aPnt=aRealNow;
90 aPnts.Insert(new Point(KorregPos(GetRealNow(),aPnt)),CONTAINER_APPEND);
91 Prev()=aPnt;
94 void SdrDragStat::PrevPoint()
96 if (aPnts.Count()>=2) { // one has to remain at all times
97 Point* pPnt=(Point*)(aPnts.GetObject(aPnts.Count()-2));
98 aPnts.Remove(aPnts.Count()-2);
99 delete pPnt;
100 Now()=KorregPos(GetRealNow(),GetPrev());
104 Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
106 Point aRet(rNow);
107 return aRet;
110 bool SdrDragStat::CheckMinMoved(const Point& rPnt)
112 if (!bMinMoved) {
113 long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
114 long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
115 if (dx>=long(nMinMov) || dy>=long(nMinMov))
116 bMinMoved=sal_True;
118 return bMinMoved;
121 Fraction SdrDragStat::GetXFact() const
123 long nMul=GetNow().X()-aRef1.X();
124 long nDiv=GetPrev().X()-aRef1.X();
125 if (nDiv==0) nDiv=1;
126 if (bHorFixed) { nMul=1; nDiv=1; }
127 return Fraction(nMul,nDiv);
130 Fraction SdrDragStat::GetYFact() const
132 long nMul=GetNow().Y()-aRef1.Y();
133 long nDiv=GetPrev().Y()-aRef1.Y();
134 if (nDiv==0) nDiv=1;
135 if (bVerFixed) { nMul=1; nDiv=1; }
136 return Fraction(nMul,nDiv);
139 void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
141 rRect=Rectangle(GetStart(),GetNow());
142 if (GetPointAnz()>=2) {
143 Point aBtmRgt(GetPoint(1));
144 rRect.Right()=aBtmRgt.X();
145 rRect.Bottom()=aBtmRgt.Y();
147 if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
148 rRect.Top()+=rRect.Top()-rRect.Bottom();
149 rRect.Left()+=rRect.Left()-rRect.Right();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */