Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/svdview.hxx>
30 : : #include <svx/svddrag.hxx>
31 : :
32 : 9207 : void SdrDragStat::Clear(bool bLeaveOne)
33 : : {
34 [ + + ]: 13715 : while (!aPnts.empty()) {
35 : 4508 : delete aPnts.back();
36 : 4508 : aPnts.pop_back();
37 : : }
38 [ - + ]: 9207 : if (pUser!=NULL) delete pUser;
39 : 9207 : pUser=NULL;
40 : 9207 : aPnts.clear();
41 [ + + ]: 9207 : if (bLeaveOne) {
42 [ + - ]: 4699 : aPnts.push_back(new Point);
43 : : }
44 : 9207 : }
45 : :
46 : 4699 : void SdrDragStat::Reset()
47 : : {
48 : 4699 : pView=NULL;
49 : 4699 : pPageView=NULL;
50 : 4699 : bShown=sal_False;
51 : 4699 : nMinMov=1;
52 : 4699 : bMinMoved=sal_False;
53 : 4699 : bHorFixed=sal_False;
54 : 4699 : bVerFixed=sal_False;
55 : 4699 : bWantNoSnap=sal_False;
56 : 4699 : pHdl=NULL;
57 : 4699 : bOrtho4=sal_False;
58 : 4699 : bOrtho8=sal_False;
59 : 4699 : pDragMethod=NULL;
60 : 4699 : bEndDragChangesAttributes=sal_False;
61 : 4699 : bEndDragChangesGeoAndAttributes=sal_False;
62 : 4699 : bMouseIsUp=sal_False;
63 : 4699 : Clear(sal_True);
64 : 4699 : aActionRect=Rectangle();
65 : 4699 : }
66 : :
67 : 0 : void SdrDragStat::Reset(const Point& rPnt)
68 : : {
69 : 0 : Reset();
70 : 0 : Start()=rPnt;
71 : 0 : aPos0=rPnt;
72 : 0 : aRealPos0=rPnt;
73 : 0 : RealNow()=rPnt;
74 : 0 : }
75 : :
76 : 0 : void SdrDragStat::NextMove(const Point& rPnt)
77 : : {
78 : 0 : aRealPos0=GetRealNow();
79 [ # # ]: 0 : aPos0=GetNow();
80 : 0 : RealNow()=rPnt;
81 [ # # ][ # # ]: 0 : Point aBla=KorregPos(GetRealNow(),GetPrev());
82 [ # # ]: 0 : Now()=aBla;
83 : 0 : }
84 : :
85 : 0 : void SdrDragStat::NextPoint(bool bSaveReal)
86 : : {
87 [ # # ]: 0 : Point aPnt(GetNow());
88 [ # # ]: 0 : if (bSaveReal) aPnt=aRealNow;
89 [ # # ][ # # ]: 0 : aPnts.push_back(new Point(KorregPos(GetRealNow(),aPnt)));
[ # # ]
90 [ # # ]: 0 : Prev()=aPnt;
91 : 0 : }
92 : :
93 : 0 : void SdrDragStat::PrevPoint()
94 : : {
95 [ # # ]: 0 : if (aPnts.size()>=2) { // one has to remain at all times
96 : 0 : Point* pPnt=aPnts[aPnts.size()-2];
97 [ # # ][ # # ]: 0 : aPnts.erase(aPnts.begin()+aPnts.size()-2);
[ # # ]
98 : 0 : delete pPnt;
99 : 0 : Now()=KorregPos(GetRealNow(),GetPrev());
100 : : }
101 : 0 : }
102 : :
103 : 0 : Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/) const
104 : : {
105 : 0 : Point aRet(rNow);
106 : 0 : return aRet;
107 : : }
108 : :
109 : 0 : bool SdrDragStat::CheckMinMoved(const Point& rPnt)
110 : : {
111 [ # # ]: 0 : if (!bMinMoved) {
112 [ # # ]: 0 : long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
113 [ # # ]: 0 : long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
114 [ # # ][ # # ]: 0 : if (dx>=long(nMinMov) || dy>=long(nMinMov))
115 : 0 : bMinMoved=sal_True;
116 : : }
117 : 0 : return bMinMoved;
118 : : }
119 : :
120 : 0 : Fraction SdrDragStat::GetXFact() const
121 : : {
122 : 0 : long nMul=GetNow().X()-aRef1.X();
123 : 0 : long nDiv=GetPrev().X()-aRef1.X();
124 [ # # ]: 0 : if (nDiv==0) nDiv=1;
125 [ # # ]: 0 : if (bHorFixed) { nMul=1; nDiv=1; }
126 : 0 : return Fraction(nMul,nDiv);
127 : : }
128 : :
129 : 0 : Fraction SdrDragStat::GetYFact() const
130 : : {
131 : 0 : long nMul=GetNow().Y()-aRef1.Y();
132 : 0 : long nDiv=GetPrev().Y()-aRef1.Y();
133 [ # # ]: 0 : if (nDiv==0) nDiv=1;
134 [ # # ]: 0 : if (bVerFixed) { nMul=1; nDiv=1; }
135 : 0 : return Fraction(nMul,nDiv);
136 : : }
137 : :
138 : 0 : void SdrDragStat::TakeCreateRect(Rectangle& rRect) const
139 : : {
140 : 0 : rRect=Rectangle(GetStart(),GetNow());
141 [ # # ]: 0 : if (GetPointAnz()>=2) {
142 [ # # ]: 0 : Point aBtmRgt(GetPoint(1));
143 : 0 : rRect.Right()=aBtmRgt.X();
144 : 0 : rRect.Bottom()=aBtmRgt.Y();
145 : : }
146 [ # # ][ # # ]: 0 : if (pView!=NULL && pView->IsCreate1stPointAsCenter()) {
[ # # ]
147 : 0 : rRect.Top()+=rRect.Top()-rRect.Bottom();
148 : 0 : rRect.Left()+=rRect.Left()-rRect.Right();
149 : : }
150 : 0 : }
151 : :
152 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|