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_SVDHDL_HXX
21 #define INCLUDED_SVX_SVDHDL_HXX
23 #include <tools/gen.hxx>
24 #include <vcl/graph.hxx>
26 #include <svx/svdoedge.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <svx/sdr/overlay/overlayobjectlist.hxx>
29 #include <svx/svxdllapi.h>
40 namespace sdr::contact
{
44 // Every object must be able to create its handles. They will be fetched on
45 // selection, registered at the View and made visible.
46 // When a handle is touched by the mouse (IsHit()), from the view the matching mouse pointer
47 // is picked up from the handle and passed to the app (on demand) to be switched on
48 // Handles like e.g. rotation center or the mirror axis are generated by
49 // the view if the correct transformation mode was selected by the controller.
50 // SdrHdlKind::Move...SdrHdlKind::LowerRight should always be consecutive in the enum!
54 Move
, // Handle to move the object
55 UpperLeft
, // Upper left
57 UpperRight
, // Upper right
60 LowerLeft
, // Bottom left
62 LowerRight
, // Bottom right
63 Poly
, // Select point in polygon or beziercurve
64 BezierWeight
, // Weight of a beziercurve
65 Circle
, // Angle to circle segment, corner radius to rectangle
66 Ref1
, // Reference point 1, e.g. rotation center
67 Ref2
, // Reference point 2, e.g. endpoint of mirror axis
68 MirrorAxis
, // Mirror axis
70 Anchor
, // Anchor symbol (SD, SW)
71 Transparence
, // Interactive transparence
72 Gradient
, // Interactive gradient
73 Color
, // Interactive color
75 Anchor_TR
, // #101688# Anchor handle with (0,0) at top right for SW
77 // for SJ and the CustomShapeHandles:
84 enum class BitmapColorIndex
95 enum class BitmapMarkerKind
116 // #98388# add AnchorPressed to be able to animate anchor control, too.
119 // #101688# AnchorTR for SW
123 // for SJ and the CustomShapeHandles:
130 class SVXCORE_DLLPUBLIC SdrHdl
132 friend class SdrMarkView
; // for the access to nObjHdlNum
133 friend class SdrHdlList
;
136 SdrObject
* m_pObj
; // does handle belong to an object?
137 SdrPageView
* m_pPV
; // does handle belong to an object in certain pageview?
138 SdrHdlList
* m_pHdlList
; // to store the handlesize
140 sdr::overlay::OverlayObjectList maOverlayGroup
;
146 Degree100 m_nRotationAngle
; // turn handle or mousepointer
147 sal_uInt32 m_nObjHdlNum
; // required by MarkView
148 sal_uInt32 m_nPolyNum
; // Polygonpoint
149 sal_uInt32 m_nPPntNum
; // Point number of the polygon
150 sal_uInt32 m_nSourceHdlNum
; // still to implement
152 bool m_bSelect
: 1; // is a polygon point selected?
153 bool m_b1PixMore
: 1; // True=handle is shown 1 pixel larger
154 bool m_bPlusHdl
: 1; // for Hld-Paint optimisation at MarkPoint/UnmarkPoint, and other ...
156 bool mbMoveOutside
; // forces this handle to be moved outside of the selection rectangle
158 // create marker for this kind
159 virtual void CreateB2dIAObject();
161 // cleanup marker if one exists
162 void GetRidOfIAObject();
165 bool mbMouseOver
; // is true if the mouse is over this handle
168 SAL_DLLPRIVATE
std::unique_ptr
<sdr::overlay::OverlayObject
> CreateOverlayObject(
169 const basegfx::B2DPoint
& rPos
,
170 BitmapColorIndex eColIndex
, BitmapMarkerKind eKindOfMarker
,
171 Point aMoveOutsideOffset
= Point());
172 SAL_DLLPRIVATE
static BitmapMarkerKind
GetNextBigger(BitmapMarkerKind eKnd
);
174 // Helper to support inserting a new OverlayObject. It will do all
175 // necessary stuff involved with that:
176 // - add GridOffset for non-linear ViewToDevice transformation (calc)
177 // - add to OverlayManager
178 // - add to local OverlayObjectList - ownership change (!)
179 // It is centralized here (and protected) to avoid that new usages/
180 // implementations forget one of these needed steps.
181 void insertNewlyCreatedOverlayObjectForSdrHdl(
182 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject
,
183 const sdr::contact::ObjectContact
& rObjectContact
,
184 sdr::overlay::OverlayManager
& rOverlayManager
);
187 SAL_DLLPRIVATE
SdrHdl();
188 explicit SdrHdl(const Point
& rPnt
, SdrHdlKind eNewKind
);
191 const sdr::overlay::OverlayObjectList
& getOverlayObjectList() const { return maOverlayGroup
; }
193 SAL_DLLPRIVATE
void SetHdlList(SdrHdlList
* pList
);
194 SdrHdlKind
GetKind() const { return m_eKind
; }
197 const Point
& GetPos() const { return m_aPos
; }
198 void SetPos(const Point
& rPnt
);
200 SdrPageView
* GetPageView() const { return m_pPV
; }
201 void SetPageView(SdrPageView
* pNewPV
) { m_pPV
=pNewPV
; }
203 SdrObject
* GetObj() const { return m_pObj
; }
204 void SetObj(SdrObject
* pNewObj
);
206 bool IsSelected() const { return m_bSelect
; }
207 void SetSelected(bool bJa
=true);
209 SAL_DLLPRIVATE
void Set1PixMore(bool bJa
=true);
210 SAL_DLLPRIVATE
void SetRotationAngle(Degree100 n
);
212 bool IsCornerHdl() const { return m_eKind
==SdrHdlKind::UpperLeft
|| m_eKind
==SdrHdlKind::UpperRight
|| m_eKind
==SdrHdlKind::LowerLeft
|| m_eKind
==SdrHdlKind::LowerRight
; }
213 bool IsVertexHdl() const { return m_eKind
==SdrHdlKind::Upper
|| m_eKind
==SdrHdlKind::Lower
|| m_eKind
==SdrHdlKind::Left
|| m_eKind
==SdrHdlKind::Right
; }
215 void SetObjHdlNum(sal_uInt32 nNum
) { m_nObjHdlNum
=nNum
; }
216 sal_uInt32
GetObjHdlNum() const { return m_nObjHdlNum
; }
218 void SetPolyNum(sal_uInt32 nNum
) { m_nPolyNum
=nNum
; }
219 sal_uInt32
GetPolyNum() const { return m_nPolyNum
; }
221 void SetPointNum(sal_uInt32 nNum
) { m_nPPntNum
=nNum
; }
222 sal_uInt32
GetPointNum() const { return m_nPPntNum
; }
224 void SetPlusHdl(bool bOn
) { m_bPlusHdl
=bOn
; }
225 bool IsPlusHdl() const { return m_bPlusHdl
; }
227 void SetSourceHdlNum(sal_uInt32 nNum
) { m_nSourceHdlNum
=nNum
; }
228 sal_uInt32
GetSourceHdlNum() const { return m_nSourceHdlNum
; }
230 virtual PointerStyle
GetPointer() const;
231 SAL_DLLPRIVATE
bool IsHdlHit(const Point
& rPnt
) const;
233 virtual bool IsFocusHdl() const;
235 SAL_DLLPRIVATE
void SetMoveOutside( bool bMoveOutside
);
237 /** is called when the mouse enters the area of this handle. If the handle changes his
238 visualisation during mouse over it must override this method and call Touch(). */
239 virtual void onMouseEnter(const MouseEvent
& rMEvt
);
241 /** is called when help is requested for the area of this handle */
242 virtual void onHelpRequest();
244 /** is called when the mouse leaves the area of this handle. If the handle changes his
245 visualisation during mouse over it must override this method and call Touch(). */
246 virtual void onMouseLeave();
248 SAL_DLLPRIVATE
static BitmapEx
createGluePointBitmap();
252 #define SDR_HANDLE_COLOR_SIZE_NORMAL Size(13, 13)
253 #define SDR_HANDLE_COLOR_SIZE_SELECTED Size(17, 17)
255 class SVXCORE_DLLPUBLIC SdrHdlColor final
: public SdrHdl
257 // size of colr markers
261 Color m_aMarkerColor
;
263 // callback link when value changed
264 Link
<SdrHdlColor
*,void> m_aColorChangeHdl
;
266 // use luminance values only
267 bool m_bUseLuminance
: 1;
269 // create marker for this kind
270 SVX_DLLPRIVATE
virtual void CreateB2dIAObject() override
;
273 SVX_DLLPRIVATE BitmapEx
CreateColorDropper(Color aCol
);
274 SVX_DLLPRIVATE
static Color
GetLuminance(const Color
& rCol
);
277 SAL_DLLPRIVATE
explicit SdrHdlColor(const Point
& rRef
, Color aCol
, const Size
& rSize
, bool bLuminance
);
278 SAL_DLLPRIVATE
virtual ~SdrHdlColor() override
;
280 bool IsUseLuminance() const { return m_bUseLuminance
; }
282 const Color
& GetColor() const { return m_aMarkerColor
; }
283 void SetColor(Color aNew
, bool bCallLink
= false);
285 void SetSize(const Size
& rNew
);
287 void SetColorChangeHdl(const Link
<SdrHdlColor
*,void>& rLink
) { m_aColorChangeHdl
= rLink
; }
291 class SdrHdlGradient final
: public SdrHdl
294 // pointer to used color handles
295 SdrHdlColor
* m_pColHdl1
;
296 SdrHdlColor
* m_pColHdl2
;
301 // is this a gradient or a transparence
302 bool m_bGradient
: 1;
304 // select which handle to move
305 bool m_bMoveSingleHandle
: 1;
306 bool m_bMoveFirstHandle
: 1;
308 // create marker for this kind
309 virtual void CreateB2dIAObject() override
;
312 SdrHdlGradient(const Point
& rRef1
, const Point
& rRef2
, bool bGrad
);
313 virtual ~SdrHdlGradient() override
;
315 bool IsGradient() const { return m_bGradient
; }
317 // set the associated color handles
318 void SetColorHandles(SdrHdlColor
* pL1
, SdrHdlColor
* pL2
) { m_pColHdl1
= pL1
; m_pColHdl2
= pL2
; }
319 SdrHdlColor
* GetColorHdl1() const { return m_pColHdl1
; }
320 SdrHdlColor
* GetColorHdl2() const { return m_pColHdl2
; }
322 const Point
& Get2ndPos() const { return m_a2ndPos
; }
323 void Set2ndPos(const Point
& rPnt
);
325 // the link called by the color handles
326 DECL_LINK(ColorChangeHdl
, SdrHdlColor
*, void);
328 // transformation call, create gradient from this handle
329 void FromIAOToItem(SdrObject
* pObj
, bool bSetItemOnObject
, bool bUndo
);
331 // selection flags for interaction
332 bool IsMoveSingleHandle() const { return m_bMoveSingleHandle
; }
333 void SetMoveSingleHandle(bool bNew
) { m_bMoveSingleHandle
= bNew
; }
334 bool IsMoveFirstHandle() const { return m_bMoveFirstHandle
; }
335 void SetMoveFirstHandle(bool bNew
) { m_bMoveFirstHandle
= bNew
; }
340 class SdrHdlLine final
: public SdrHdl
342 // create marker for this kind
343 virtual void CreateB2dIAObject() override
;
349 SdrHdlLine(SdrHdl
& rHdl1
, SdrHdl
& rHdl2
, SdrHdlKind eNewKind
) { m_eKind
=eNewKind
; m_pHdl1
=&rHdl1
; m_pHdl2
=&rHdl2
; }
350 virtual ~SdrHdlLine() override
;
352 virtual PointerStyle
GetPointer() const override
;
355 // a SdrHdlBezWgt knows about its "base handle". Its draw method
356 // draws additionally a line from its position to the position
357 // of the base handle
358 class SdrHdlBezWgt final
: public SdrHdl
361 // this is not a Copy-Ctor!!!
362 SdrHdlBezWgt(const SdrHdl
* pRefHdl1
, SdrHdlKind eNewKind
=SdrHdlKind::BezierWeight
) { m_eKind
=eNewKind
; m_pHdl1
=pRefHdl1
; }
363 virtual ~SdrHdlBezWgt() override
;
366 // create marker for this kind
367 virtual void CreateB2dIAObject() override
;
369 const SdrHdl
* m_pHdl1
;
373 class E3dVolumeMarker final
: public SdrHdl
375 basegfx::B2DPolyPolygon m_aWireframePoly
;
377 // create marker for this kind
378 virtual void CreateB2dIAObject() override
;
381 explicit E3dVolumeMarker(const basegfx::B2DPolyPolygon
& rWireframePoly
);
385 class ImpEdgeHdl final
: public SdrHdl
387 SdrEdgeLineCode m_eLineCode
;
389 // create marker for this kind
390 virtual void CreateB2dIAObject() override
;
393 ImpEdgeHdl(const Point
& rPnt
, SdrHdlKind eNewKind
): SdrHdl(rPnt
,eNewKind
),m_eLineCode(SdrEdgeLineCode::MiddleLine
) {}
394 virtual ~ImpEdgeHdl() override
;
396 void SetLineCode(SdrEdgeLineCode eCode
);
397 SdrEdgeLineCode
GetLineCode() const { return m_eLineCode
; }
398 bool IsHorzDrag() const;
399 virtual PointerStyle
GetPointer() const override
;
403 class ImpMeasureHdl final
: public SdrHdl
405 // create marker for this kind
406 virtual void CreateB2dIAObject() override
;
409 ImpMeasureHdl(const Point
& rPnt
, SdrHdlKind eNewKind
): SdrHdl(rPnt
,eNewKind
) {}
410 virtual ~ImpMeasureHdl() override
;
412 virtual PointerStyle
GetPointer() const override
;
416 class ImpTextframeHdl final
: public SdrHdl
418 const tools::Rectangle maRect
;
420 // create marker for this kind
421 virtual void CreateB2dIAObject() override
;
424 explicit ImpTextframeHdl(const tools::Rectangle
& rRect
);
428 class SVXCORE_DLLPUBLIC SdrHdlList
431 SdrMarkView
* m_pView
;
432 std::deque
<std::unique_ptr
<SdrHdl
>> maList
;
433 sal_uInt16 m_nHdlSize
;
435 bool m_bRotateShear
: 1;
436 bool m_bDistortShear
: 1;
437 bool m_bMoveOutside
: 1; // move handles outwards (for TextEdit)
439 SVX_DLLPRIVATE
SdrHdlList(const SdrHdlList
&) = delete;
440 SVX_DLLPRIVATE
void operator=(const SdrHdlList
&) = delete;
443 explicit SdrHdlList(SdrMarkView
* pV
);
447 void TravelFocusHdl(bool bForward
);
448 SdrHdl
* GetFocusHdl() const;
449 void SetFocusHdl(SdrHdl
* pNew
);
450 void ResetFocusHdl();
453 SdrMarkView
* GetView() const { return m_pView
;}
455 // Sorting: 1.Level first reference point handle, then normal handles, next Glue, then User then Plushandles
456 // 2.Level PageView (Pointer)
457 // 3.Level Position (x+y)
458 SAL_DLLPRIVATE
void Sort();
459 size_t GetHdlCount() const { return maList
.size(); }
460 SdrHdl
* GetHdl(size_t nNum
) const { return nNum
< maList
.size() ? maList
[nNum
].get() : nullptr; }
461 size_t GetHdlNum(const SdrHdl
* pHdl
) const;
462 SAL_DLLPRIVATE
void SetHdlSize(sal_uInt16 nSiz
);
463 sal_uInt16
GetHdlSize() const { return m_nHdlSize
; }
464 SAL_DLLPRIVATE
void SetMoveOutside(bool bOn
);
465 bool IsMoveOutside() const { return m_bMoveOutside
; }
466 SAL_DLLPRIVATE
void SetRotateShear(bool bOn
);
467 bool IsRotateShear() const { return m_bRotateShear
; }
468 SAL_DLLPRIVATE
void SetDistortShear(bool bOn
);
469 bool IsDistortShear() const { return m_bDistortShear
; }
471 // AddHdl takes ownership of the handle. It should be on the Heap
472 // as Clear() deletes it.
473 void AddHdl(std::unique_ptr
<SdrHdl
> pHdl
);
474 SAL_DLLPRIVATE
std::unique_ptr
<SdrHdl
> RemoveHdl(size_t nNum
);
475 void RemoveAllByKind(SdrHdlKind eKind
);
477 // move the ownership of all the SdrHdl to rOther
478 void MoveTo(SdrHdlList
& rOther
);
480 // Last inserted handles are likely hit (if the handles are above each other)
481 SAL_DLLPRIVATE SdrHdl
* IsHdlListHit(const Point
& rPnt
) const;
482 SdrHdl
* GetHdl(SdrHdlKind eKind1
) const;
486 class SVXCORE_DLLPUBLIC SdrCropHdl final
: public SdrHdl
496 // create marker for this kind
497 virtual void CreateB2dIAObject() override
;
499 BitmapEx
GetBitmapForHandle( const BitmapEx
& rBitmap
, int nSize
);
501 // evtl. shear and rotation, equal to the object's one to allow adaptation of
502 // the visualization handles
508 class SdrCropViewHdl final
: public SdrHdl
511 basegfx::B2DHomMatrix maObjectTransform
;
520 basegfx::B2DHomMatrix aObjectTransform
,
528 // create marker for this kind
529 virtual void CreateB2dIAObject() override
;
533 #endif // INCLUDED_SVX_SVDHDL_HXX
535 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */