bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svddrag.cxx
blob0a982d2a40cfbe3ad7a686ab5f508d732dd2e142
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdview.hxx>
21 #include <svx/svddrag.hxx>
23 void SdrDragStat::Clear(bool bLeaveOne)
25 while (!aPnts.empty()) {
26 delete aPnts.back();
27 aPnts.pop_back();
29 delete pUser;
30 pUser=NULL;
31 aPnts.clear();
32 if (bLeaveOne) {
33 aPnts.push_back(new Point);
37 void SdrDragStat::Reset()
39 pView=NULL;
40 pPageView=NULL;
41 bShown=sal_False;
42 nMinMov=1;
43 bMinMoved=sal_False;
44 bHorFixed=sal_False;
45 bVerFixed=sal_False;
46 bWantNoSnap=sal_False;
47 pHdl=NULL;
48 bOrtho4=sal_False;
49 bOrtho8=sal_False;
50 pDragMethod=NULL;
51 bEndDragChangesAttributes=sal_False;
52 bEndDragChangesGeoAndAttributes=sal_False;
53 bMouseIsUp=sal_False;
54 Clear(sal_True);
55 aActionRect=Rectangle();
58 void SdrDragStat::Reset(const Point& rPnt)
60 Reset();
61 Start()=rPnt;
62 aPos0=rPnt;
63 aRealPos0=rPnt;
64 RealNow()=rPnt;
67 void SdrDragStat::NextMove(const Point& rPnt)
69 aRealPos0=GetRealNow();
70 aPos0=GetNow();
71 RealNow()=rPnt;
72 Point aBla=KorregPos(GetRealNow(),GetPrev());
73 Now()=aBla;
76 void SdrDragStat::NextPoint(bool bSaveReal)
78 Point aPnt(GetNow());
79 if (bSaveReal) aPnt=aRealNow;
80 aPnts.push_back(new Point(KorregPos(GetRealNow(),aPnt)));
81 Prev()=aPnt;
84 void SdrDragStat::PrevPoint()
86 if (aPnts.size()>=2) { // one has to remain at all times
87 Point* pPnt=aPnts[aPnts.size()-2];
88 aPnts.erase(aPnts.begin()+aPnts.size()-2);
89 delete pPnt;
90 Now()=KorregPos(GetRealNow(),GetPrev());
94 Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
96 Point aRet(rNow);
97 return aRet;
100 bool SdrDragStat::CheckMinMoved(const Point& rPnt)
102 if (!bMinMoved) {
103 long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
104 long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
105 if (dx>=long(nMinMov) || dy>=long(nMinMov))
106 bMinMoved=sal_True;
108 return bMinMoved;
111 Fraction SdrDragStat::GetXFact() const
113 long nMul=GetNow().X()-aRef1.X();
114 long nDiv=GetPrev().X()-aRef1.X();
115 if (nDiv==0) nDiv=1;
116 if (bHorFixed) { nMul=1; nDiv=1; }
117 return Fraction(nMul,nDiv);
120 Fraction SdrDragStat::GetYFact() const
122 long nMul=GetNow().Y()-aRef1.Y();
123 long nDiv=GetPrev().Y()-aRef1.Y();
124 if (nDiv==0) nDiv=1;
125 if (bVerFixed) { nMul=1; nDiv=1; }
126 return Fraction(nMul,nDiv);
129 void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
131 rRect=Rectangle(GetStart(),GetNow());
132 if (GetPointAnz()>=2) {
133 Point aBtmRgt(GetPoint(1));
134 rRect.Right()=aBtmRgt.X();
135 rRect.Bottom()=aBtmRgt.Y();
137 if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
138 rRect.Top()+=rRect.Top()-rRect.Bottom();
139 rRect.Left()+=rRect.Left()-rRect.Right();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */