1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SVX_SVDDRAG_HXX
21 #define INCLUDED_SVX_SVDDRAG_HXX
24 #include <tools/gen.hxx>
25 #include <tools/fract.hxx>
26 #include <svx/svxdllapi.h>
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.
41 struct SdrDragStatUserData
43 virtual ~SdrDragStatUserData() = 0;
46 class SVX_DLLPUBLIC SdrDragStat final
48 SdrHdl
* pHdl
; // The Handle for the User
50 SdrPageView
* pPageView
;
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
56 tools::Rectangle aActionRect
;
58 bool bEndDragChangesAttributes
;
59 bool bEndDragChangesGeoAndAttributes
;
60 /// Table row drag: table will re-layout itself later.
61 bool mbEndDragChangesLayout
;
64 bool bShown
; // Xor visible?
65 sal_uInt16 nMinMov
; // So much has to be minimally moved first
66 bool bMinMoved
; // MinMove surpassed?
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.
75 SdrDragMethod
* pDragMethod
;
76 std::unique_ptr
<SdrDragStatUserData
> mpUserData
; // Userdata
80 sal_Int32
GetPrevPos() const { return mvPnts
.size()-(mvPnts
.size()>1 ? 2 : 1); }
83 SdrDragStat() { 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
; }
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; }
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
; }
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
; }
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
; }
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
; }
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
; }
143 void Reset(const Point
& rPnt
);
144 void NextMove(const Point
& rPnt
);
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;
153 SdrDragMethod
* GetDragMethod() const { return pDragMethod
; }
154 void SetDragMethod(SdrDragMethod
* pMth
) { pDragMethod
=pMth
; }
156 const tools::Rectangle
& GetActionRect() const { return aActionRect
; }
157 void SetActionRect(const tools::Rectangle
& rR
) { aActionRect
=rR
; }
159 // Also considering 1stPointAsCenter
160 void TakeCreateRect(tools::Rectangle
& rRect
) const;
163 #endif // INCLUDED_SVX_SVDDRAG_HXX
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */