Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / svdraw / svddrag.cxx
blob3c0f109954b00b61d856cbbef39f4866628a36fd
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=false;
42 nMinMov=1;
43 bMinMoved=false;
44 bHorFixed=false;
45 bVerFixed=false;
46 bWantNoSnap=false;
47 pHdl=NULL;
48 bOrtho4=false;
49 bOrtho8=false;
50 pDragMethod=NULL;
51 bEndDragChangesAttributes=false;
52 bEndDragChangesGeoAndAttributes=false;
53 bMouseIsUp=false;
54 Clear(true);
55 aActionRect=Rectangle();
58 void SdrDragStat::Reset(const Point& rPnt)
60 Reset();
61 Start()=rPnt;
62 aPos0=rPnt;
63 RealNow()=rPnt;
66 void SdrDragStat::NextMove(const Point& rPnt)
68 aPos0=GetNow();
69 RealNow()=rPnt;
70 Point aBla=KorregPos(GetRealNow(),GetPrev());
71 Now()=aBla;
74 void SdrDragStat::NextPoint(bool bSaveReal)
76 Point aPnt(GetNow());
77 if (bSaveReal) aPnt=aRealNow;
78 aPnts.push_back(new Point(KorregPos(GetRealNow(),aPnt)));
79 Prev()=aPnt;
82 void SdrDragStat::PrevPoint()
84 if (aPnts.size()>=2) { // one has to remain at all times
85 Point* pPnt=aPnts[aPnts.size()-2];
86 aPnts.erase(aPnts.begin()+aPnts.size()-2);
87 delete pPnt;
88 Now()=KorregPos(GetRealNow(),GetPrev());
92 Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
94 Point aRet(rNow);
95 return aRet;
98 bool SdrDragStat::CheckMinMoved(const Point& rPnt)
100 if (!bMinMoved) {
101 long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
102 long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
103 if (dx>=long(nMinMov) || dy>=long(nMinMov))
104 bMinMoved=true;
106 return bMinMoved;
109 Fraction SdrDragStat::GetXFact() const
111 long nMul=GetNow().X()-aRef1.X();
112 long nDiv=GetPrev().X()-aRef1.X();
113 if (nDiv==0) nDiv=1;
114 if (bHorFixed) { nMul=1; nDiv=1; }
115 return Fraction(nMul,nDiv);
118 Fraction SdrDragStat::GetYFact() const
120 long nMul=GetNow().Y()-aRef1.Y();
121 long nDiv=GetPrev().Y()-aRef1.Y();
122 if (nDiv==0) nDiv=1;
123 if (bVerFixed) { nMul=1; nDiv=1; }
124 return Fraction(nMul,nDiv);
127 void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
129 rRect=Rectangle(GetStart(),GetNow());
130 if (GetPointAnz()>=2) {
131 Point aBtmRgt(GetPoint(1));
132 rRect.Right()=aBtmRgt.X();
133 rRect.Bottom()=aBtmRgt.Y();
135 if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
136 rRect.Top()+=rRect.Top()-rRect.Bottom();
137 rRect.Left()+=rRect.Left()-rRect.Right();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */