LibreOffice Module svx (master)  1
svddrag.hxx
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 #ifndef INCLUDED_SVX_SVDDRAG_HXX
21 #define INCLUDED_SVX_SVDDRAG_HXX
22 
23 
24 #include <tools/gen.hxx>
25 #include <tools/fract.hxx>
26 #include <svx/svxdllapi.h>
27 
28 #include <memory>
29 #include <vector>
30 
31 // Status information for specialized object dragging. In order for the model
32 // to stay status free, the status data is kept on the View
33 // and handed over to the object at the appropriate time as a parameter.
34 // This also includes the status of the operation and Interactive
35 // Object creation. In this case, pHdl is null.
36 class SdrHdl;
37 class SdrView;
38 class SdrPageView;
39 class SdrDragMethod;
40 
42 {
43  virtual ~SdrDragStatUserData() = 0;
44 };
45 
47 {
48  SdrHdl* pHdl; // The Handle for the User
51  std::vector<Point> mvPnts; // All previous Points: [0]=Start, [Count()-2]=Prev
52  Point aRef1; // Referencepoint: Resize fixed point, (axis of rotation,
53  Point aRef2; // axis of reflection, ...)
54  Point aPos0; // Position at the last Event
55  Point aRealNow; // Current dragging position without Snap, Ortho and Limit
57 
62  bool bMouseIsUp;
63 
64  bool bShown; // Xor visible?
65  sal_uInt16 nMinMov; // So much has to be minimally moved first
66  bool bMinMoved; // MinMove surpassed?
67 
68  bool bHorFixed; // Dragging only vertical
69  bool bVerFixed; // Dragging only horizontal
70  bool bWantNoSnap; // To decide if pObj-> MovCreate () should use NoSnapPos or not.
71  // Therefore, NoSnapPos is written into the buffer.
72  bool bOrtho4;
73  bool bOrtho8;
74 
76  std::unique_ptr<SdrDragStatUserData> mpUserData; // Userdata
77 
78  void Clear();
79 
80  sal_Int32 GetPrevPos() const { return mvPnts.size()-(mvPnts.size()>1 ? 2 : 1); }
81 
82 public:
83  SdrDragStat() { Reset(); }
84  ~SdrDragStat();
85  void Reset();
86  SdrView* GetView() const { return pView; }
87  void SetView(SdrView* pV) { pView=pV; }
88  SdrPageView* GetPageView() const { return pPageView; }
89  void SetPageView(SdrPageView* pPV) { pPageView=pPV; }
90  const Point& GetPoint(sal_Int32 nNum) const { return mvPnts[nNum]; }
91  sal_Int32 GetPointCount() const { return mvPnts.size(); }
92  const Point& GetStart() const { return mvPnts[0]; }
93  const Point& GetPrev() const { return mvPnts[GetPrevPos()]; }
94  const Point& GetPos0() const { return aPos0; }
95  const Point& GetNow() const { return mvPnts.back(); }
96  void SetNow(Point const &pt) { mvPnts.back() = pt; }
97  const Point& GetRef1() const { return aRef1; }
98  void SetRef1(const Point &pt) { aRef1 = pt; }
99  const Point& GetRef2() const { return aRef2; }
100  void SetRef2(const Point &pt) { aRef2 = pt; }
101  const SdrHdl* GetHdl() const { return pHdl; }
102  void SetHdl(SdrHdl* pH) { pHdl=pH; }
103  SdrDragStatUserData* GetUser() const { return mpUserData.get(); }
104  void SetUser(std::unique_ptr<SdrDragStatUserData> pU) { mpUserData = std::move(pU); }
105  bool IsShown() const { return bShown; }
106  void SetShown(bool bOn) { bShown=bOn; }
107 
108  bool IsMinMoved() const { return bMinMoved; }
109  void SetMinMoved() { bMinMoved=true; }
110  void ResetMinMoved() { bMinMoved=false; }
111  void SetMinMove(sal_uInt16 nDist) { nMinMov=nDist; if (nMinMov<1) nMinMov=1; }
112 
113  bool IsHorFixed() const { return bHorFixed; }
114  void SetHorFixed(bool bOn) { bHorFixed=bOn; }
115  bool IsVerFixed() const { return bVerFixed; }
116  void SetVerFixed(bool bOn) { bVerFixed=bOn; }
117 
118  // Here, the object can say: "I do not want to snap to coordinates!"
119  // for example, the angle of the arc ...
120  bool IsNoSnap() const { return bWantNoSnap; }
121  void SetNoSnap(bool bOn = true) { bWantNoSnap=bOn; }
122 
123  // And here the Obj say which Ortho (if there is one) can be usefully applied to him.
124  // Ortho4 means Ortho in four directions (for Rect and CIRT)
125  bool IsOrtho4Possible() const { return bOrtho4; }
126  void SetOrtho4Possible(bool bOn = true) { bOrtho4=bOn; }
127  // Ortho8 means Ortho in 8 directions (for lines)
128  bool IsOrtho8Possible() const { return bOrtho8; }
129  void SetOrtho8Possible(bool bOn = true) { bOrtho8=bOn; }
130 
131  // Is set by an object that was dragged.
132  bool IsEndDragChangesAttributes() const { return bEndDragChangesAttributes; }
133  void SetEndDragChangesAttributes(bool bOn) { bEndDragChangesAttributes=bOn; }
134  bool IsEndDragChangesGeoAndAttributes() const { return bEndDragChangesGeoAndAttributes; }
135  void SetEndDragChangesGeoAndAttributes(bool bOn) { bEndDragChangesGeoAndAttributes=bOn; }
136  bool IsEndDragChangesLayout() const { return mbEndDragChangesLayout; }
137  void SetEndDragChangesLayout(bool bOn) { mbEndDragChangesLayout=bOn; }
138 
139  // Is set by the view and can be evaluated by Obj
140  bool IsMouseDown() const { return !bMouseIsUp; }
141  void SetMouseDown(bool bDown) { bMouseIsUp=!bDown; }
142 
143  void Reset(const Point& rPnt);
144  void NextMove(const Point& rPnt);
145  void NextPoint();
146  void PrevPoint();
147  bool CheckMinMoved(const Point& rPnt);
148  long GetDX() const { return GetNow().X()-GetPrev().X(); }
149  long GetDY() const { return GetNow().Y()-GetPrev().Y(); }
150  Fraction GetXFact() const;
151  Fraction GetYFact() const;
152 
153  SdrDragMethod* GetDragMethod() const { return pDragMethod; }
154  void SetDragMethod(SdrDragMethod* pMth) { pDragMethod=pMth; }
155 
156  const tools::Rectangle& GetActionRect() const { return aActionRect; }
157  void SetActionRect(const tools::Rectangle& rR) { aActionRect=rR; }
158 
159  // Also considering 1stPointAsCenter
160  void TakeCreateRect(tools::Rectangle& rRect) const;
161 };
162 
163 #endif // INCLUDED_SVX_SVDDRAG_HXX
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMinMove(sal_uInt16 nDist)
Definition: svddrag.hxx:111
tools::Rectangle aActionRect
Definition: svddrag.hxx:56
bool IsHorFixed() const
Definition: svddrag.hxx:113
SdrPageView * GetPageView() const
Definition: svddrag.hxx:88
bool IsShown() const
Definition: svddrag.hxx:105
void SetVerFixed(bool bOn)
Definition: svddrag.hxx:116
sal_Int32 GetPrevPos() const
Definition: svddrag.hxx:80
const Point & GetStart() const
Definition: svddrag.hxx:92
void SetDragMethod(SdrDragMethod *pMth)
Definition: svddrag.hxx:154
Point aRealNow
Definition: svddrag.hxx:55
bool IsEndDragChangesGeoAndAttributes() const
Definition: svddrag.hxx:134
const Point & GetPoint(sal_Int32 nNum) const
Definition: svddrag.hxx:90
bool bEndDragChangesGeoAndAttributes
Definition: svddrag.hxx:59
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
void SetMouseDown(bool bDown)
Definition: svddrag.hxx:141
SdrView * pView
Definition: svddrag.hxx:49
bool IsOrtho8Possible() const
Definition: svddrag.hxx:128
void SetOrtho8Possible(bool bOn=true)
Definition: svddrag.hxx:129
void ResetMinMoved()
Definition: svddrag.hxx:110
const SdrHdl * GetHdl() const
Definition: svddrag.hxx:101
long GetDX() const
Definition: svddrag.hxx:148
void SetHorFixed(bool bOn)
Definition: svddrag.hxx:114
bool bMinMoved
Definition: svddrag.hxx:66
SdrHdl * pHdl
Definition: svddrag.hxx:48
void SetOrtho4Possible(bool bOn=true)
Definition: svddrag.hxx:126
const Point & GetPos0() const
Definition: svddrag.hxx:94
bool bEndDragChangesAttributes
Definition: svddrag.hxx:58
bool bShown
Definition: svddrag.hxx:64
bool IsMinMoved() const
Definition: svddrag.hxx:108
Point aPos0
Definition: svddrag.hxx:54
void SetEndDragChangesLayout(bool bOn)
Definition: svddrag.hxx:137
std::vector< Point > mvPnts
Definition: svddrag.hxx:51
void SetRef2(const Point &pt)
Definition: svddrag.hxx:100
Point aRef2
Definition: svddrag.hxx:53
void SetNoSnap(bool bOn=true)
Definition: svddrag.hxx:121
void SetEndDragChangesGeoAndAttributes(bool bOn)
Definition: svddrag.hxx:135
bool bMouseIsUp
Definition: svddrag.hxx:62
void SetRef1(const Point &pt)
Definition: svddrag.hxx:98
const tools::Rectangle & GetActionRect() const
Definition: svddrag.hxx:156
std::unique_ptr< SdrDragStatUserData > mpUserData
Definition: svddrag.hxx:76
sal_Int32 GetPointCount() const
Definition: svddrag.hxx:91
bool mbEndDragChangesLayout
Table row drag: table will re-layout itself later.
Definition: svddrag.hxx:61
SdrView * GetView() const
Definition: svddrag.hxx:86
SdrDragMethod * pDragMethod
Definition: svddrag.hxx:75
bool IsEndDragChangesLayout() const
Definition: svddrag.hxx:136
void SetEndDragChangesAttributes(bool bOn)
Definition: svddrag.hxx:133
void SetHdl(SdrHdl *pH)
Definition: svddrag.hxx:102
sal_uInt16 nMinMov
Definition: svddrag.hxx:65
virtual ~SdrDragStatUserData()=0
const Point & GetRef1() const
Definition: svddrag.hxx:97
SdrDragMethod * GetDragMethod() const
Definition: svddrag.hxx:153
const Point & GetPrev() const
Definition: svddrag.hxx:93
long GetDY() const
Definition: svddrag.hxx:149
void SetActionRect(const tools::Rectangle &rR)
Definition: svddrag.hxx:157
bool bHorFixed
Definition: svddrag.hxx:68
bool bWantNoSnap
Definition: svddrag.hxx:70
Point aRef1
Definition: svddrag.hxx:52
void SetUser(std::unique_ptr< SdrDragStatUserData > pU)
Definition: svddrag.hxx:104
bool IsOrtho4Possible() const
Definition: svddrag.hxx:125
void SetNow(Point const &pt)
Definition: svddrag.hxx:96
bool IsMouseDown() const
Definition: svddrag.hxx:140
const Point & GetNow() const
Definition: svddrag.hxx:95
void SetView(SdrView *pV)
Definition: svddrag.hxx:87
void SetMinMoved()
Definition: svddrag.hxx:109
void SetShown(bool bOn)
Definition: svddrag.hxx:106
void SetPageView(SdrPageView *pPV)
Definition: svddrag.hxx:89
SdrDragStatUserData * GetUser() const
Definition: svddrag.hxx:103
SdrPageView * pPageView
Definition: svddrag.hxx:50
bool IsVerFixed() const
Definition: svddrag.hxx:115
bool bOrtho8
Definition: svddrag.hxx:73
bool bOrtho4
Definition: svddrag.hxx:72
const Point & GetRef2() const
Definition: svddrag.hxx:99
bool bVerFixed
Definition: svddrag.hxx:69
bool IsNoSnap() const
Definition: svddrag.hxx:120
bool IsEndDragChangesAttributes() const
Definition: svddrag.hxx:132