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_SVDDRGMT_HXX
21 #define INCLUDED_SVX_SVDDRGMT_HXX
22 
23 #include <svx/svddrgv.hxx>
24 #include <svx/svxdllapi.h>
25 #include <svx/sdr/contact/objectcontact.hxx>
26 #include <memory>
27 
28 class SdrDragView;
29 class SdrDragStat;
30 
31 class SAL_DLLPUBLIC_RTTI SdrDragEntry
32 {
33 private:
34     bool                        mbAddToTransparent : 1;
35 
36 protected:
37     // access for derived classes
setAddToTransparent(bool bNew)38     void setAddToTransparent(bool bNew) { mbAddToTransparent = bNew; }
39 
40 public:
41     SdrDragEntry();
42     virtual ~SdrDragEntry();
43 
44     virtual drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod) = 0;
45 
46     // data read access
getAddToTransparent() const47     bool getAddToTransparent() const { return mbAddToTransparent; }
48 };
49 
50 
51 class SVXCORE_DLLPUBLIC SdrDragEntryPolyPolygon final : public SdrDragEntry
52 {
53 private:
54     basegfx::B2DPolyPolygon             maOriginalPolyPolygon;
55 
56 public:
57     SdrDragEntryPolyPolygon(const basegfx::B2DPolyPolygon& rOriginalPolyPolygon);
58     virtual ~SdrDragEntryPolyPolygon() override;
59 
60     virtual drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod) override;
61 };
62 
63 
64 class SdrDragEntrySdrObject final : public SdrDragEntry
65 {
66 private:
67     const SdrObject&                                maOriginal;
68     SdrObjectUniquePtr                              mxClone;
69     bool                                            mbModify;
70 
71 public:
72     SdrDragEntrySdrObject(
73         const SdrObject& rOriginal,
74         bool bModify);
75     virtual ~SdrDragEntrySdrObject() override;
76 
77     // #i54102# Split createPrimitive2DSequenceInCurrentState in prepareCurrentState and processing,
78     // added accessors to original and clone
79     void prepareCurrentState(SdrDragMethod& rDragMethod);
getOriginal() const80     const SdrObject& getOriginal() const { return maOriginal; }
getClone()81     SdrObject* getClone() { return mxClone.get(); }
82 
83     virtual drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod) override;
84 };
85 
86 
87 class SdrDragEntryPrimitive2DSequence final : public SdrDragEntry
88 {
89 private:
90     drawinglayer::primitive2d::Primitive2DContainer  maPrimitive2DSequence;
91 
92 public:
93     SdrDragEntryPrimitive2DSequence(
94         const drawinglayer::primitive2d::Primitive2DContainer& rSequence);
95     virtual ~SdrDragEntryPrimitive2DSequence() override;
96 
97     virtual drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod) override;
98 };
99 
100 
101 class SdrDragEntryPointGlueDrag final : public SdrDragEntry
102 {
103 private:
104     std::vector< basegfx::B2DPoint >                maPositions;
105     bool                                            mbIsPointDrag;
106 
107 public:
108     SdrDragEntryPointGlueDrag(const std::vector< basegfx::B2DPoint >& rPositions, bool bIsPointDrag);
109     virtual ~SdrDragEntryPointGlueDrag() override;
110 
111     virtual drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod) override;
112 };
113 
114 
115 class SVXCORE_DLLPUBLIC SdrDragMethod
116 {
117 private:
118     std::vector< std::unique_ptr<SdrDragEntry> > maSdrDragEntries;
119     sdr::overlay::OverlayObjectList         maOverlayObjectList;
120     SdrDragView&                            mrSdrDragView;
121 
122     bool                                    mbMoveOnly : 1;
123     bool                                    mbSolidDraggingActive : 1;
124     bool                                    mbShiftPressed : 1;
125 
126 protected:
127     // access for derivated classes to maSdrDragEntries
128     void clearSdrDragEntries();
129     void addSdrDragEntry(std::unique_ptr<SdrDragEntry> pNew);
130     virtual void createSdrDragEntries();
131     virtual void createSdrDragEntryForSdrObject(const SdrObject& rOriginal);
132 
133     // Helper to support inserting a new OverlayObject. It will do all
134     // necessary stuff involved with that:
135     // - add GridOffset for non-linear ViewToDevice transformation (calc)
136     // - add to OverlayManager
137     // - add to local OverlayObjectList - ownership change (!)
138     // It is centralized here (and protected) to avoid that new usages/
139     // implementations forget one of these needed steps.
140     void insertNewlyCreatedOverlayObjectForSdrDragMethod(
141         std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject,
142         const sdr::contact::ObjectContact& rObjectContact,
143         sdr::overlay::OverlayManager& rOverlayManager);
144 
145     // access for derivated classes to mrSdrDragView
getSdrDragView()146     SdrDragView& getSdrDragView() { return mrSdrDragView; }
getSdrDragView() const147     const SdrDragView& getSdrDragView() const { return mrSdrDragView; }
148 
149     // access for derivated classes for bools
setMoveOnly(bool bNew)150     void setMoveOnly(bool bNew) { mbMoveOnly = bNew; }
setSolidDraggingActive(bool bNew)151     void setSolidDraggingActive(bool bNew) { mbSolidDraggingActive = bNew; }
152 
153     // internal helpers for creation of standard drag entries
154     void createSdrDragEntries_SolidDrag();
155     void createSdrDragEntries_PolygonDrag();
156     void createSdrDragEntries_PointDrag();
157     void createSdrDragEntries_GlueDrag();
158 
159     // old call forwarders to the SdrDragView
160     OUString           ImpGetDescriptionStr(const char* pStrCacheID) const;
GetDragHdl() const161     SdrHdl*            GetDragHdl() const              { return getSdrDragView().mpDragHdl; }
GetDragHdlKind() const162     SdrHdlKind         GetDragHdlKind() const          { return getSdrDragView().meDragHdl; }
DragStat()163     SdrDragStat&       DragStat()                      { return getSdrDragView().maDragStat; }
DragStat() const164     const SdrDragStat& DragStat() const                { return getSdrDragView().maDragStat; }
Ref1() const165     Point&             Ref1() const                    { return mrSdrDragView.maRef1; }
Ref2() const166     Point&             Ref2() const                    { return mrSdrDragView.maRef2; }
GetHdlList() const167     const SdrHdlList&  GetHdlList() const              { return getSdrDragView().GetHdlList(); }
AddUndo(std::unique_ptr<SdrUndoAction> pUndo)168     void               AddUndo(std::unique_ptr<SdrUndoAction> pUndo) { getSdrDragView().AddUndo(std::move(pUndo)); }
IsDragLimit()169     bool               IsDragLimit()                   { return getSdrDragView().mbDragLimit; }
GetDragLimitRect()170     const tools::Rectangle&   GetDragLimitRect()              { return getSdrDragView().maDragLimit; }
GetMarkedObjectList()171     const SdrMarkList& GetMarkedObjectList()                   { return getSdrDragView().GetMarkedObjectList(); }
GetSnapPos(const Point & rPt) const172     Point              GetSnapPos(const Point& rPt) const { return getSdrDragView().GetSnapPos(rPt,getSdrDragView().mpMarkedPV); }
SnapPos(Point & rPt) const173     SdrSnap            SnapPos(Point& rPt) const       { return getSdrDragView().SnapPos(rPt,getSdrDragView().mpMarkedPV); }
174     inline const tools::Rectangle& GetMarkedRect() const;
175     SdrPageView*       GetDragPV() const;
176     SdrObject*         GetDragObj() const;
IsDraggingPoints() const177     bool               IsDraggingPoints() const        { return getSdrDragView().IsDraggingPoints(); }
IsDraggingGluePoints() const178     bool               IsDraggingGluePoints() const    { return getSdrDragView().IsDraggingGluePoints(); }
179 
180     bool DoAddConnectorOverlays();
181     drawinglayer::primitive2d::Primitive2DContainer AddConnectorOverlays();
182 
183 public:
184 
185     void resetSdrDragEntries();
186     basegfx::B2DRange getCurrentRange() const;
187 
188     // #i58950# also moved constructor implementation to cxx
189     SdrDragMethod(SdrDragView& rNewView);
190 
191     // #i58950# virtual destructor was missing
192     virtual ~SdrDragMethod();
193 
194     void Show();
195     void Hide();
IsShiftPressed() const196     bool IsShiftPressed() const { return mbShiftPressed; }
SetShiftPressed(bool bShiftPressed)197     void SetShiftPressed(bool bShiftPressed) { mbShiftPressed = bShiftPressed; }
198     virtual OUString GetSdrDragComment() const=0;
199     virtual bool BeginSdrDrag()=0;
200     virtual void MoveSdrDrag(const Point& rPnt)=0;
201     virtual bool EndSdrDrag(bool bCopy)=0;
202     virtual void CancelSdrDrag();
203     virtual PointerStyle GetSdrDragPointer() const=0;
204 
205     virtual void CreateOverlayGeometry(
206         sdr::overlay::OverlayManager& rOverlayManager,
207         const sdr::contact::ObjectContact& rObjectContact);
208     void destroyOverlayGeometry();
209 
210     virtual basegfx::B2DHomMatrix getCurrentTransformation();
211     virtual void applyCurrentTransformationToSdrObject(SdrObject& rTarget);
212     virtual void applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget);
213 
214     // data read access
getMoveOnly() const215     bool getMoveOnly() const { return mbMoveOnly; }
getSolidDraggingActive() const216     bool getSolidDraggingActive() const { return mbSolidDraggingActive; }
217 };
218 
GetMarkedRect() const219 inline const tools::Rectangle& SdrDragMethod::GetMarkedRect() const
220 {
221     return getSdrDragView().meDragHdl==SdrHdlKind::Poly ? getSdrDragView().GetMarkedPointsRect() :
222            getSdrDragView().meDragHdl==SdrHdlKind::Glue ? getSdrDragView().GetMarkedGluePointsRect() :
223            getSdrDragView().GetMarkedObjRect();
224 }
225 
226 
227 //   SdrDragMove
228 
229 class SVXCORE_DLLPUBLIC SdrDragMove : public SdrDragMethod
230 {
231 private:
232     tools::Long                        nBestXSnap;
233     tools::Long                        nBestYSnap;
234     bool                        bXSnapped;
235     bool                        bYSnapped;
236 
237     void ImpCheckSnap(const Point& rPt);
238 
239 protected:
240     virtual void createSdrDragEntryForSdrObject(const SdrObject& rOriginal) override;
241 
242 public:
243     SdrDragMove(SdrDragView& rNewView);
244 
245     virtual OUString GetSdrDragComment() const override;
246     virtual bool BeginSdrDrag() override;
247     virtual void MoveSdrDrag(const Point& rPnt) override;
248     virtual bool EndSdrDrag(bool bCopy) override;
249     virtual PointerStyle GetSdrDragPointer() const override;
250 
251     virtual basegfx::B2DHomMatrix getCurrentTransformation() override;
252     virtual void applyCurrentTransformationToSdrObject(SdrObject& rTarget) override;
253 };
254 
255 
256 //   SdrDragResize
257 
258 class SVXCORE_DLLPUBLIC SdrDragResize : public SdrDragMethod
259 {
260 protected:
261     Fraction                    aXFact;
262     Fraction                    aYFact;
263 
264 public:
265     SdrDragResize(SdrDragView& rNewView);
266 
267     virtual OUString GetSdrDragComment() const override;
268     virtual bool BeginSdrDrag() override;
269     virtual void MoveSdrDrag(const Point& rPnt) override;
270     virtual bool EndSdrDrag(bool bCopy) override;
271     virtual PointerStyle GetSdrDragPointer() const override;
272 
273     virtual basegfx::B2DHomMatrix getCurrentTransformation() override;
274     virtual void applyCurrentTransformationToSdrObject(SdrObject& rTarget) override;
275 };
276 
277 
278 //   SdrDragObjOwn
279 
280 class SVXCORE_DLLPUBLIC SdrDragObjOwn : public SdrDragMethod
281 {
282 private:
283     // SdrDragObjOwn always works on a clone since it has no transformation
284     // mechanism to modify wireframe visualisations, but uses the
285     // SdrObject::applySpecialDrag() method to change a clone of the
286     // SdrObject
287     SdrObjectUniquePtr               mxClone;
288 
289 protected:
290     virtual void createSdrDragEntries() override;
291 
292 public:
293     SdrDragObjOwn(SdrDragView& rNewView);
294     virtual ~SdrDragObjOwn() override;
295 
296     virtual OUString GetSdrDragComment() const override;
297     virtual bool BeginSdrDrag() override;
298     virtual void MoveSdrDrag(const Point& rPnt) override;
299     virtual bool EndSdrDrag(bool bCopy) override;
300     virtual PointerStyle GetSdrDragPointer() const override;
301 };
302 
303 #endif // INCLUDED_SVX_SVDDRGMT_HXX
304 
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
306