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_SVDSNPV_HXX
21 #define INCLUDED_SVX_SVDSNPV_HXX
23 #include <svx/svdpntv.hxx>
24 #include <svx/svdhlpln.hxx>
25 #include <svx/svxdllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
30 * - snap something means e.g. the mouse pointer or some marked objects in drag can be snapped
31 * - snap on something means you can e.g. snap on the grid or on auxiliary lines
34 * Basically, we only catch visible elements (borders, helper lines, connectors),
35 * with the exception of the grid. Likewise, we can only catch visible elements (i.e. connectors).
36 * We only catch on the grid, if nothing else is close by (magnetic behaviour).
38 * The cursor which is used during creation of objects, while dragging polygon points
39 * etc. (i.e. the mouse cursor) is always caught on all enabled catch alternatives (max 6).
41 * This is different, when moving selected objects. Instead of one mouse cursor, there are
42 * four alternatives, which can be caught at the selected objects:
43 * 1. the logically enclosing frame of every single object
44 * 2. the logically enclosing frame of all selected objects
45 * 3. highlighted points of all selected objects (polygon points, ...)
46 * 4. the connectors of the selected objects
48 * As the first and second case exclude each other (the second is a refinement of the first one)
49 * three alternatives remain, which are independent from each other. For 6 possible values for the
50 * caught ones, we would end up with max. 18 different possible combinations!
52 * Therefore, we introduce the following simplifications:
53 * 1. Connectors only catch on connectors
55 * Only max. 2*5+1 = 11 combinations remain for MoveDrag:
56 * 1-3. enclosing frame on grid/border/helper lines
57 * 4. enclosing frame on highlighted object points
58 * 5. enclosing frame on enclosing frame
59 * 6-8. highlighted points on grid/border/helper lines
60 * 7. highlighted points on highlighted object points
61 * 8-10. highlighted points on enclosing frame
62 * 11. connectors on connectors
64 * We test for all of these possible 11 combinations in the MouseMove event in the DragMove
65 * and those with the least need of correction are carried out.
67 * In the Resize() etc. methods we only catch the logically enclosing frame of the highlighted objects.
70 /** Return value for SnapPos() method */
79 template<> struct typed_flags
<SdrSnap
> : is_typed_flags
<SdrSnap
, 3> {};
82 // SdrCrookMode::Stretch is not implemented yet!
83 enum class SdrCrookMode
{
90 // #114409#-1 Migrate PageOrigin
91 class ImplPageOriginOverlay
;
93 class SVX_DLLPUBLIC SdrSnapView
: public SdrPaintView
96 // #114409#-1 Migrate PageOrigin
97 class ImplPageOriginOverlay
* mpPageOriginOverlay
;
99 // #114409#-2 Migrate HelpLine
100 class ImplHelpLineOverlay
* mpHelpLineOverlay
;
106 sal_uInt16 nMagnSizPix
;
108 long nEliminatePolyPointLimitAngle
;
110 SdrCrookMode eCrookMode
;
119 bool bMoveSnapOnlyTopLeft
: 1; // Special for dialogeditor
122 bool bAngleSnapEnab
: 1;
123 bool bMoveOnlyDragging
: 1; // only move objects while Resize/Rotate/...
124 bool bSlantButShear
: 1; // use slant instead of shear
125 bool bCrookNoContortion
: 1; // no contorsion while Crook
126 bool bEliminatePolyPoints
: 1;
129 // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
130 SdrSnapView(SdrModel
* pModel1
, OutputDevice
* pOut
);
131 virtual ~SdrSnapView() override
;
134 virtual bool IsAction() const override
;
135 virtual void MovAction(const Point
& rPnt
) override
;
136 virtual void EndAction() override
;
137 virtual void BckAction() override
;
138 virtual void BrkAction() override
; // break actions for derived classes e.g. interrupt dragging.
139 virtual void TakeActionRect(tools::Rectangle
& rRect
) const override
;
141 void SetSnapGridWidth(const Fraction
& rX
, const Fraction
& rY
) { aSnapWdtX
=rX
; aSnapWdtY
=rY
; }
142 const Fraction
& GetSnapGridWidthX() const { return aSnapWdtX
; }
143 const Fraction
& GetSnapGridWidthY() const { return aSnapWdtY
; }
145 void SetSnapMagnetic(const Size
& rSiz
) { if (rSiz
!=aMagnSiz
) { aMagnSiz
=rSiz
; } }
146 void SetSnapMagneticPixel(sal_uInt16 nPix
) { nMagnSizPix
=nPix
; }
147 sal_uInt16
GetSnapMagneticPixel() const { return nMagnSizPix
; }
149 // RecalcLogicSnapMagnetic has to be called for every change of OutputDevices and every change of the MapMode!
150 void RecalcLogicSnapMagnetic(const OutputDevice
& rOut
) { SetSnapMagnetic(rOut
.PixelToLogic(Size(nMagnSizPix
,nMagnSizPix
))); }
151 void SetActualWin(const OutputDevice
* pWin
) { SdrPaintView::SetActualWin(pWin
); if (pWin
!=nullptr) RecalcLogicSnapMagnetic(*pWin
); }
153 // Coordinates referred to the view!
154 // Returnvalues are SdrSnap::NOTSNAPPED,SdrSnap::XSNAPPED,
155 // SdrSnap::YSNAPPED or SdrSnap::XYSNAPPED
156 SdrSnap
SnapPos(Point
& rPnt
, const SdrPageView
* pPV
) const;
157 Point
GetSnapPos(const Point
& rPnt
, const SdrPageView
* pPV
) const;
158 void CheckSnap(const Point
& rPt
, long& nBestXSnap
, long& nBestYSnap
, bool& bXSnapped
, bool& bYSnapped
) const;
160 // All attitudes to snap are persistent.
161 bool IsSnapEnabled() const { return bSnapEnab
; }
162 bool IsGridSnap() const { return bGridSnap
; } // Snap to grid
163 bool IsBordSnap() const { return bBordSnap
; } // Snap to border
164 bool IsHlplSnap() const { return bHlplSnap
; } // Snap to auxiliary line
165 bool IsOFrmSnap() const { return bOFrmSnap
; } // Snap to LogFram from surrounding drawing objects
166 bool IsOPntSnap() const { return bOPntSnap
; } // Snap to distinct points from surrounding drawing objects
167 bool IsOConSnap() const { return bOConSnap
; } // Snap to connectors of the drawing objects
168 void SetSnapEnabled(bool bOn
) { bSnapEnab
=bOn
; }
169 void SetGridSnap(bool bOn
) { bGridSnap
=bOn
; }
170 void SetBordSnap(bool bOn
) { bBordSnap
=bOn
; }
171 void SetHlplSnap(bool bOn
) { bHlplSnap
=bOn
; }
172 void SetOFrmSnap(bool bOn
) { bOFrmSnap
=bOn
; }
173 void SetOPntSnap(bool bOn
) { bOPntSnap
=bOn
; }
174 void SetOConSnap(bool bOn
) { bOConSnap
=bOn
; }
176 // Usually every 4 corners of Object-SnapRects are snapped for Move-Dragging.
177 // The following attitudes e.g. if you only want to snap the left corner on the top (e.g. DialogEditor)
178 // persistent, Default=FALSE.
179 void SetMoveSnapOnlyTopLeft(bool bOn
) { bMoveSnapOnlyTopLeft
=bOn
; }
180 bool IsMoveSnapOnlyTopLeft() const { return bMoveSnapOnlyTopLeft
; }
182 // #114409#-1 Migrate PageOrigin
183 void BegSetPageOrg(const Point
& rPnt
);
184 void MovSetPageOrg(const Point
& rPnt
);
185 void EndSetPageOrg();
186 void BrkSetPageOrg();
187 bool IsSetPageOrg() const { return (nullptr != mpPageOriginOverlay
); }
189 // HitTest. If sal_True, in rnHelpLineNum is the number of the auxiliary line and in rpPv
190 // the appended PageView.
191 bool PickHelpLine(const Point
& rPnt
, short nTol
, const OutputDevice
& rOut
, sal_uInt16
& rnHelpLineNum
, SdrPageView
*& rpPV
) const;
193 // Move of an available auxiliary line. Use nHelpLineNum and pPV from PickHelpLine.
194 bool BegDragHelpLine(sal_uInt16 nHelpLineNum
, SdrPageView
* pPV
);
195 // interactive insertion of a new auxiliary line
196 void BegDragHelpLine(const Point
& rPnt
, SdrHelpLineKind eNewKind
);
197 Pointer
GetDraggedHelpLinePointer() const;
199 // change the type of auxiliary line while dragging
200 // void SetDraggedHelpLineKind(SdrHelpLineKind eNewKind);
201 void MovDragHelpLine(const Point
& rPnt
);
202 bool EndDragHelpLine();
203 void BrkDragHelpLine();
204 bool IsDragHelpLine() const { return (nullptr != mpHelpLineOverlay
); }
206 // SnapAngle is for angles in circle, RotateDragging, ...
207 // The snapping of an angle is beared down, if it is switched off
208 // with SetAngleSnapEnabled(sal_False)
209 // The snapping angles is independent of snapping coordinates
210 // and so independent of the attitude IsSnapEnabled()
211 // Only values should be specified for them is applied:
212 // 36000 modulo nAngle = 0
214 // - Rotate (Dragging)
215 // - Shear (Dragging)
216 // - circular arc/-sector/-section angle (Create and Dragging)
218 void SetAngleSnapEnabled(bool bOn
) { bAngleSnapEnab
=bOn
; }
219 bool IsAngleSnapEnabled() const { return bAngleSnapEnab
; }
220 void SetSnapAngle(long nAngle
) { nSnapAngle
=nAngle
; }
221 long GetSnapAngle() const { return nSnapAngle
; }
223 // different effects from Ortho (depending on the context):
225 // - only lines in 45deg grid
226 // - instead of rectangles squares are created
227 // - instead of ellipse circles are created
229 // - general Dragging
230 // - Move only horizontal, vertical or 45deg
231 // - Resize proportional
233 // - Shear without Resize
234 // - Crook without Resize
236 // - mirror axis only 45deg grid
237 // - object-specific Dragging
238 // - rectangle corner radius: nothing
239 // - circle object angle: nothing
240 // - line keeps while Dragging the angle and is only stretched/ contracted
241 // Default value for Ortho is off. persistent.
242 void SetOrtho(bool bOn
) { bOrtho
=bOn
; } // unvollstaendig
243 bool IsOrtho() const { return bOrtho
; }
245 // BigOrtho is only relevant if Ortho is switched on.
246 // Example: rectangle is created and ortho is switched on (--> square)
247 // and the Mouse was dragged from zero to the coordinates
248 // (80,30). Now there are 2 alternatives to determine the edge length
249 // of the square: 30 and 80.
250 // The standard Ortho-Function took 30 (every time the smaller length)
251 // If BigOrtho is switched on, you get a square with edge length of 80.
252 // The same also applies to Resize.
253 // Default value for BigOrtho is on. persistent.
254 void SetBigOrtho(bool bOn
) { bBigOrtho
=bOn
; }
255 bool IsBigOrtho() const { return bBigOrtho
; }
257 // If MoveOnlyDragging=sal_True only the center of the marked objects is
258 // transformed when Resize/Rotate/Shear/Mirror/Crook is executed.
259 // Size, form and rotation angle of the objects are conserved only their positions
260 // are changed. persistent. Default=FALSE. (ni)
261 void SetMoveOnlyDragging(bool bOn
) { bMoveOnlyDragging
=bOn
; }
262 bool IsMoveOnlyDragging() const { return bMoveOnlyDragging
; }
264 // Use Slant instead of Shear. persistent. Default=FALSE.
265 void SetSlantButShear(bool bOn
) { bSlantButShear
=bOn
; }
266 bool IsSlantButShear() const { return bSlantButShear
; }
268 // Don't contort objecte while Crook. persistent. Default=FALSE. (ni)
269 void SetCrookNoContortion(bool bOn
) { bCrookNoContortion
=bOn
; }
270 bool IsCrookNoContortion() const { return bCrookNoContortion
; }
272 // Crook-Mode. persistent. Default=SdrCrookMode::Rotate. (ni)
273 void SetCrookMode(SdrCrookMode eMode
) { eCrookMode
=eMode
; }
274 SdrCrookMode
GetCrookMode() const { return eCrookMode
; }
276 // Special for IBM: While Dragging of a traverse station, it is deleted
277 // if its adjacent lines are almost a solid line.
278 void SetEliminatePolyPoints(bool bOn
) { bEliminatePolyPoints
=bOn
; }
279 bool IsEliminatePolyPoints() const { return bEliminatePolyPoints
; }
280 void SetEliminatePolyPointLimitAngle(long nAngle
) { nEliminatePolyPointLimitAngle
=nAngle
; }
281 long GetEliminatePolyPointLimitAngle() const { return nEliminatePolyPointLimitAngle
; }
284 #endif // INCLUDED_SVX_SVDSNPV_HXX
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */