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>
29 /** return value for SnapPos() method */
35 XYSNAPPED
= XSNAPPED
| YSNAPPED
,
39 template<> struct typed_flags
<SdrSnap
> : is_typed_flags
<SdrSnap
, 3> {};
42 // SDRCROOK_STRETCH is not implemented yet!
50 // #114409#-1 Migrate PageOrigin
51 class ImplPageOriginOverlay
;
53 class SVX_DLLPUBLIC SdrSnapView
: public SdrPaintView
56 // #114409#-1 Migrate PageOrigin
57 class ImplPageOriginOverlay
* mpPageOriginOverlay
;
59 // #114409#-2 Migrate HelpLine
60 class ImplHelpLineOverlay
* mpHelpLineOverlay
;
66 sal_uInt16 nMagnSizPix
;
68 long nEliminatePolyPointLimitAngle
;
70 SdrCrookMode eCrookMode
;
74 bool bSnapTo1Pix
: 1; // If GridSnap off, snap to one Pixel to avoid values like 10.01
80 bool bMoveMFrmSnap
: 1;
81 bool bMoveOFrmSnap
: 1;
82 bool bMoveOPntSnap
: 1;
83 bool bMoveOConSnap
: 1;
84 bool bMoveSnapOnlyTopLeft
: 1; // Special for dialogeditor
87 bool bAngleSnapEnab
: 1;
88 bool bMoveOnlyDragging
: 1; // only move objects while Resize/Rotate/...
89 bool bSlantButShear
: 1; // use slant instead of shear
90 bool bCrookNoContortion
: 1; // no contorsion while Crook
91 bool bHlplFixed
: 1; // sal_True= fixed auxiliary lines, so it isn't movable
92 bool bEliminatePolyPoints
: 1;
95 SVX_DLLPRIVATE
void ClearVars();
98 // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
99 SdrSnapView(SdrModel
* pModel1
, OutputDevice
* pOut
= 0L);
100 virtual ~SdrSnapView();
103 virtual bool IsAction() const SAL_OVERRIDE
;
104 virtual void MovAction(const Point
& rPnt
) SAL_OVERRIDE
;
105 virtual void EndAction() SAL_OVERRIDE
;
106 virtual void BckAction() SAL_OVERRIDE
;
107 virtual void BrkAction() SAL_OVERRIDE
; // break actions for derived classes e.g. interrupt dragging.
108 virtual void TakeActionRect(Rectangle
& rRect
) const SAL_OVERRIDE
;
110 void SetSnapGridWidth(const Fraction
& rX
, const Fraction
& rY
) { aSnapWdtX
=rX
; aSnapWdtY
=rY
; }
111 const Fraction
& GetSnapGridWidthX() const { return aSnapWdtX
; }
112 const Fraction
& GetSnapGridWidthY() const { return aSnapWdtY
; }
114 void SetSnapMagnetic(const Size
& rSiz
) { if (rSiz
!=aMagnSiz
) { aMagnSiz
=rSiz
; } }
115 const Size
& GetSnapMagnetic() const { return aMagnSiz
; }
116 void SetSnapMagneticPixel(sal_uInt16 nPix
) { nMagnSizPix
=nPix
; }
117 sal_uInt16
GetSnapMagneticPixel() const { return nMagnSizPix
; }
119 // RecalcLogicSnapMagnetic has to be called for every change of OutputDevices and every change of the MapMode!
120 void RecalcLogicSnapMagnetic(const OutputDevice
& rOut
) { SetSnapMagnetic(rOut
.PixelToLogic(Size(nMagnSizPix
,nMagnSizPix
))); }
121 void SetActualWin(const OutputDevice
* pWin
) { SdrPaintView::SetActualWin(pWin
); if (pWin
!=NULL
) RecalcLogicSnapMagnetic(*pWin
); }
123 // Coordinates referred to the view!
124 // Returnvalues are SdrSnap::NOTSNAPPED,SdrSnap::XSNAPPED,
125 // SdrSnap::YSNAPPED or SdrSnap::XYSNAPPED
126 SdrSnap
SnapPos(Point
& rPnt
, const SdrPageView
* pPV
) const;
127 Point
GetSnapPos(const Point
& rPnt
, const SdrPageView
* pPV
) const;
128 void CheckSnap(const Point
& rPt
, const SdrPageView
* pPV
, long& nBestXSnap
, long& nBestYSnap
, bool& bXSnapped
, bool& bYSnapped
) const;
130 // All attitudes to snap are persistent.
131 bool IsSnapEnabled() const { return bSnapEnab
; }
132 bool IsGridSnap() const { return bGridSnap
; } // Snap to grid
133 bool IsBordSnap() const { return bBordSnap
; } // Snap to border
134 bool IsHlplSnap() const { return bHlplSnap
; } // Snap to auxiliary line
135 bool IsOFrmSnap() const { return bOFrmSnap
; } // Snap to LogFram from surrounding drawing objects
136 bool IsOPntSnap() const { return bOPntSnap
; } // Snap to distinct points from surrounding drawing objects
137 bool IsOConSnap() const { return bOConSnap
; } // Snap to connectors of the drawing objects
138 void SetSnapEnabled(bool bOn
) { bSnapEnab
=bOn
; }
139 void SetGridSnap(bool bOn
) { bGridSnap
=bOn
; }
140 void SetBordSnap(bool bOn
) { bBordSnap
=bOn
; }
141 void SetHlplSnap(bool bOn
) { bHlplSnap
=bOn
; }
142 void SetOFrmSnap(bool bOn
) { bOFrmSnap
=bOn
; }
143 void SetOPntSnap(bool bOn
) { bOPntSnap
=bOn
; }
144 void SetOConSnap(bool bOn
) { bOConSnap
=bOn
; }
146 // Usually every 4 corners of Object-SnapRects are snapped for Move-Dragging.
147 // The following attitudes e.g. if you only want to snap the left corner on the top (e.g. DialogEditor)
148 // persistent, Default=FALSE.
149 void SetMoveSnapOnlyTopLeft(bool bOn
) { bMoveSnapOnlyTopLeft
=bOn
; }
150 bool IsMoveSnapOnlyTopLeft() const { return bMoveSnapOnlyTopLeft
; }
152 // auxiliary lines fixed (not moveable)
153 // persistent, Default=FALSE.
154 bool IsHlplFixed() const { return bHlplFixed
; }
155 void SetHlplFixed(bool bOn
) { bHlplFixed
=bOn
; }
157 bool IsMoveMFrmSnap() const { return bMoveMFrmSnap
; } // Fang des LogFram aller markierten Objekte
158 bool IsMoveOFrmSnap() const { return bMoveOFrmSnap
; } // Fang aller LogFram der markierten Objekte
159 bool IsMoveOPntSnap() const { return bMoveOPntSnap
; } // Fang ausgepraegter Punkte der markierten Objekte
160 bool IsMoveOConSnap() const { return bMoveOConSnap
; } // Fang der Konnektoren der markierten Objekte
162 void SetMoveMFrmSnap(bool bOn
) { bMoveMFrmSnap
=bOn
; }
163 void SetMoveOFrmSnap(bool bOn
) { bMoveOFrmSnap
=bOn
; }
164 void SetMoveOPntSnap(bool bOn
) { bMoveOPntSnap
=bOn
; }
165 void SetMoveOConSnap(bool bOn
) { bMoveOConSnap
=bOn
; }
167 // #114409#-1 Migrate PageOrigin
168 bool BegSetPageOrg(const Point
& rPnt
);
169 void MovSetPageOrg(const Point
& rPnt
);
170 bool EndSetPageOrg();
171 void BrkSetPageOrg();
172 bool IsSetPageOrg() const { return (0L != mpPageOriginOverlay
); }
174 // HitTest. If sal_True, in rnHelpLineNum is the number of the auxiliary line and in rpPv
175 // the appendent PageView.
176 bool PickHelpLine(const Point
& rPnt
, short nTol
, const OutputDevice
& rOut
, sal_uInt16
& rnHelpLineNum
, SdrPageView
*& rpPV
) const;
178 // Move of an available auxiliary line. Use nHelpLineNum and pPV from PickHelpLine.
179 bool BegDragHelpLine(sal_uInt16 nHelpLineNum
, SdrPageView
* pPV
);
180 // interactive insertionof a new auxiliary line
181 bool BegDragHelpLine(const Point
& rPnt
, SdrHelpLineKind eNewKind
);
182 Pointer
GetDraggedHelpLinePointer() const;
184 // change the type of auxiliary line while dragging
185 // void SetDraggedHelpLineKind(SdrHelpLineKind eNewKind);
186 void MovDragHelpLine(const Point
& rPnt
);
187 bool EndDragHelpLine();
188 void BrkDragHelpLine();
189 bool IsDragHelpLine() const { return (0L != mpHelpLineOverlay
); }
191 // SnapAngle is for angles in circle, RotateDragging, ...
192 // The snapping of an angle is beared down, if it is swiched off
193 // with SetAngleSnapEnabled(sal_False)
194 // The snapping angles is independent of snapping coordinates
195 // and so independent of the attitude IsSnapEnabled()
196 // Only values should be specified for them is applied:
197 // 36000 modulu nAngle = 0
199 // - Rotate (Dragging)
200 // - Shear (Dragging)
201 // - circular arc/-sector/-section angle (Create and Dragging)
203 void SetAngleSnapEnabled(bool bOn
) { bAngleSnapEnab
=bOn
; }
204 bool IsAngleSnapEnabled() const { return bAngleSnapEnab
; }
205 void SetSnapAngle(long nAngle
) { nSnapAngle
=nAngle
; }
206 long GetSnapAngle() const { return nSnapAngle
; }
208 // different effects from Ortho (depending on the context):
210 // - only lines in 45deg grid
211 // - instead of rectangles squares are created
212 // - instead of ellipse circles are created
214 // - general Dragging
215 // - Move only horizontal, vertical or 45deg
216 // - Resize proportional
218 // - Shear without Resize
219 // - Crook without Resize
221 // - mirror axis only 45deg grid
222 // - object-specific Dragging
223 // - rectangle corner radius: nothing
224 // - circle object angle: nothing
225 // - line keeps while Dragging the angle and is only stretched/ contracted
226 // Default value for Ortho is off. persistent.
227 void SetOrtho(bool bOn
) { bOrtho
=bOn
; } // unvollstaendig
228 bool IsOrtho() const { return bOrtho
; }
230 // BigOrtho is only relevant if Ortho is switched on.
231 // Example: rectangle is created and ortho is switched on (--> square)
232 // and the Mouse was dragged from zero to the coordinates
233 // (80,30). Now there are 2 alternatives to determine the edge length
234 // of the square: 30 and 80.
235 // The standard Ortho-Function took 30 (every time the smaller length)
236 // If BigOrtho is switched on, you get a square with edge length of 80.
237 // The same also applies to Resize.
238 // Default value for BigOrtho is on. persistent.
239 void SetBigOrtho(bool bOn
) { bBigOrtho
=bOn
; }
240 bool IsBigOrtho() const { return bBigOrtho
; }
242 // If MoveOnlyDragging=sal_True only the center of the marked objects is
243 // transformed when Resize/Rotate/Shear/Mirror/Crook is executed.
244 // Size, form and rotation angle of the objects are conserved only their positions
245 // are changed. persistent. Default=FALSE. (ni)
246 void SetMoveOnlyDragging(bool bOn
) { bMoveOnlyDragging
=bOn
; }
247 bool IsMoveOnlyDragging() const { return bMoveOnlyDragging
; }
249 // Use Slant instead of Shear. persistent. Default=FALSE.
250 void SetSlantButShear(bool bOn
) { bSlantButShear
=bOn
; }
251 bool IsSlantButShear() const { return bSlantButShear
; }
253 // Don't contort objecte while Crook. persistent. Default=FALSE. (ni)
254 void SetCrookNoContortion(bool bOn
) { bCrookNoContortion
=bOn
; }
255 bool IsCrookNoContortion() const { return bCrookNoContortion
; }
257 // Crook-Mode. persistent. Default=SDRCROOK_ROTATE. (ni)
258 void SetCrookMode(SdrCrookMode eMode
) { eCrookMode
=eMode
; }
259 SdrCrookMode
GetCrookMode() const { return eCrookMode
; }
261 // Special for IBM: While Dragging of a traverse station, it is deleted
262 // if its adjacent lines are almost a solid line.
263 void SetEliminatePolyPoints(bool bOn
) { bEliminatePolyPoints
=bOn
; }
264 bool IsEliminatePolyPoints() const { return bEliminatePolyPoints
; }
265 void SetEliminatePolyPointLimitAngle(long nAngle
) { nEliminatePolyPointLimitAngle
=nAngle
; }
266 long GetEliminatePolyPointLimitAngle() const { return nEliminatePolyPointLimitAngle
; }
270 // - snap something= e.g. the mouse pointer or some marked objects in drag can be snapped
271 // - snap on sth.= you can e.g. snap on the grid or on auxiliary lines.
274 // Grundsaetzlich wird nur gefangen auf sichtbare Elemente (-> Border,
275 // Hilfslinien, Konnektoren; Ausnahme: Grid). Ebenso koennen nur sichtbare
276 // Elemente gefangen werden (->Konnektoren).
278 // Auf's Grid wird immer erst dann gefangen, wenn nix Anderes in der Naehe
281 // Der "Cursor" (also der Mauszeiger) beim Erzeugen von Objekten, beim Draggen
282 // von Polygonpunkten, ... wird immer auf allen eingeschalteten Fangalternativen
285 // Beim Verschieben markierter Objekte ist das etwas anders. Statt des einen
286 // Mauscursors gibt es hier 4 Alternativen an den markierten Objekten, die
287 // gefangen werden koennen:
288 // 1. die logisch-umschliessenden Rahmen der einzelnen Objekte
289 // 2. der logisch-umschliessende Rahmen aller markierten Objekte
290 // 3. ausgezeichnete Punkte der markierten Objekte (Polygonpunkte, ...)
291 // 4. die Konnektoren der markierten Objekte
292 // Da 1. und 2. einander ausschliessen (2. ist eine Verfeinerung von 1.)
293 // bleiben 3 voneinander unabhaengige Alternativen. Bei 6. Moeglichkeiten auf
294 // die gefangen werden kann kaeme man auf max. 18 Kombinationsmoeglichkeiten!
295 // Deshalb werden folgende Vereinfachungen festgelegt:
296 // 1. Konnektoren fangen sich nur auf Konnektoren.
297 // Verbleiben also nun noch max. 2x5+1=11 Fangkombinationen beim MoveDrag:
298 // 1-3. umschliessende(r) Rahmen auf Grid/Border/Hilfslinien
299 // 4. umschliessende(r) Rahmen auf ausgezeichnete Objektpunkte
300 // 5. umschliessende(r) Rahmen auf umschliessenden Rahmen
301 // 6-8. ausgezeichnete Punkte auf Grid/Border/Hilfslinien
302 // 7. ausgezeichnete Punkte auf ausgezeichnete Objektpunkte
303 // 8-10. ausgezeichnete Punkte auf umschliessenden Rahmen
304 // 11. Konnektoren auf Konnektoren
305 // Beim MouseMove-Event im DragMove werden also diese bis zu max. 11 moeglichen
306 // Alternativen durchgetestet und die mit dem gerigsten Korrekturaufwand
309 // Beim Resize, ... wird immer nur der logisch-umschliessende Rahmen der
310 // markierten Objekte gefangen.
312 #endif // INCLUDED_SVX_SVDSNPV_HXX
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */