LibreOffice Module svx (master)  1
svddrag.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <svx/svdview.hxx>
21 #include <svx/svddrag.hxx>
22 
24 
26 {
27 }
28 
30 {
31  mpUserData.reset();
32  mvPnts.clear();
33  mvPnts.emplace_back();
34 }
35 
37 {
38  pView=nullptr;
39  pPageView=nullptr;
40  bShown=false;
41  nMinMov=1;
42  bMinMoved=false;
43  bHorFixed=false;
44  bVerFixed=false;
45  bWantNoSnap=false;
46  pHdl=nullptr;
47  bOrtho4=false;
48  bOrtho8=false;
49  pDragMethod=nullptr;
53  bMouseIsUp=false;
54  Clear();
56 }
57 
58 void SdrDragStat::Reset(const Point& rPnt)
59 {
60  Reset();
61  mvPnts[0]=rPnt;
62  aPos0=rPnt;
63  aRealNow=rPnt;
64 }
65 
66 void SdrDragStat::NextMove(const Point& rPnt)
67 {
68  aPos0=mvPnts.back();
69  aRealNow=rPnt;
70  mvPnts.back()=rPnt;
71 }
72 
74 {
75  mvPnts.emplace_back(aRealNow);
76 }
77 
79 {
80  if (mvPnts.size()>1) { // one has to remain at all times
81  mvPnts.erase(mvPnts.begin()+mvPnts.size()-2);
82  mvPnts.back() = aRealNow;
83  }
84 }
85 
87 {
88  if (!bMinMoved) {
89  long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
90  long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
91  if (dx>=long(nMinMov) || dy>=long(nMinMov))
92  bMinMoved=true;
93  }
94  return bMinMoved;
95 }
96 
98 {
99  long nMul=mvPnts.back().X()-aRef1.X();
100  long nDiv=GetPrev().X()-aRef1.X();
101  if (nDiv==0) nDiv=1;
102  if (bHorFixed) { nMul=1; nDiv=1; }
103  return Fraction(nMul,nDiv);
104 }
105 
107 {
108  long nMul=mvPnts.back().Y()-aRef1.Y();
109  long nDiv=GetPrev().Y()-aRef1.Y();
110  if (nDiv==0) nDiv=1;
111  if (bVerFixed) { nMul=1; nDiv=1; }
112  return Fraction(nMul,nDiv);
113 }
114 
116 {
117  rRect=tools::Rectangle(mvPnts[0], mvPnts.back());
118  if (mvPnts.size()>1) {
119  Point aBtmRgt(mvPnts[1]);
120  rRect.SetRight(aBtmRgt.X() );
121  rRect.SetBottom(aBtmRgt.Y() );
122  }
123  if (pView!=nullptr && pView->IsCreate1stPointAsCenter()) {
124  rRect.AdjustTop(rRect.Top()-rRect.Bottom() );
125  rRect.AdjustLeft(rRect.Left()-rRect.Right() );
126  }
127 }
128 
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Rectangle aActionRect
Definition: svddrag.hxx:56
void Reset()
Definition: svddrag.cxx:36
~SdrDragStat()
Definition: svddrag.cxx:25
long AdjustLeft(long nHorzMoveDelta)
bool CheckMinMoved(const Point &rPnt)
Definition: svddrag.cxx:86
Point aRealNow
Definition: svddrag.hxx:55
bool bEndDragChangesGeoAndAttributes
Definition: svddrag.hxx:59
SdrView * pView
Definition: svddrag.hxx:49
long Right() const
bool bMinMoved
Definition: svddrag.hxx:66
SdrHdl * pHdl
Definition: svddrag.hxx:48
void TakeCreateRect(tools::Rectangle &rRect) const
Definition: svddrag.cxx:115
bool bEndDragChangesAttributes
Definition: svddrag.hxx:58
long Top() const
bool bShown
Definition: svddrag.hxx:64
Point aPos0
Definition: svddrag.hxx:54
std::vector< Point > mvPnts
Definition: svddrag.hxx:51
bool bMouseIsUp
Definition: svddrag.hxx:62
std::unique_ptr< SdrDragStatUserData > mpUserData
Definition: svddrag.hxx:76
void SetRight(long v)
bool mbEndDragChangesLayout
Table row drag: table will re-layout itself later.
Definition: svddrag.hxx:61
SdrDragMethod * pDragMethod
Definition: svddrag.hxx:75
long Bottom() const
void NextMove(const Point &rPnt)
Definition: svddrag.cxx:66
void NextPoint()
Definition: svddrag.cxx:73
void Clear()
Definition: svddrag.cxx:29
bool IsCreate1stPointAsCenter() const
Definition: svdcrtv.hxx:132
sal_uInt16 nMinMov
Definition: svddrag.hxx:65
virtual ~SdrDragStatUserData()=0
long X() const
const Point & GetPrev() const
Definition: svddrag.hxx:93
Fraction GetXFact() const
Definition: svddrag.cxx:97
bool bHorFixed
Definition: svddrag.hxx:68
bool bWantNoSnap
Definition: svddrag.hxx:70
Point aRef1
Definition: svddrag.hxx:52
Fraction GetYFact() const
Definition: svddrag.cxx:106
void SetBottom(long v)
long AdjustTop(long nVertMoveDelta)
long Left() const
void PrevPoint()
Definition: svddrag.cxx:78
SdrPageView * pPageView
Definition: svddrag.hxx:50
bool bOrtho8
Definition: svddrag.hxx:73
bool bOrtho4
Definition: svddrag.hxx:72
bool bVerFixed
Definition: svddrag.hxx:69
long Y() const