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 <svl/solar.hrc>
28 #include <svx/xpoly.hxx>
29 #include <svx/svdoedge.hxx>
30 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <svx/sdgcpitm.hxx>
32 #include <svx/sdr/overlay/overlayobjectlist.hxx>
33 #include <svx/svxdllapi.h>
43 namespace sdr
{ namespace contact
{
47 // Every object must be able to create its handles. They will be fetched on
48 // selection, registered at the View and made visible.
49 // When a handle is touched by the mouse (IsHit()), from the view the matching mouse pointer
50 // is picked up from the handle and passed to the app (on demand) to be switched on
51 // Handles like e.g. rotation center or the mirror axis are generated by
52 // the view if the correct transformation mode was selected by the controller.
53 // SdrHdlKind::Move...SdrHdlKind::LowerRight should always be consecutive in the enum!
57 Move
, // Handle to move the object
58 UpperLeft
, // Upper left
60 UpperRight
, // Upper right
63 LowerLeft
, // Bottom left
65 LowerRight
, // Bottom right
66 Poly
, // Select point in polygon or beziercurve
67 BezierWeight
, // Weight of a beziercurve
68 Circle
, // Angle to circle segment, corner radius to rectangle
69 Ref1
, // Reference point 1, e.g. rotation center
70 Ref2
, // Reference point 2, e.g. endpoint of mirror axis
71 MirrorAxis
, // Mirror axis
73 Anchor
, // Anchor symbol (SD, SW)
74 Transparence
, // Interactive transparence
75 Gradient
, // Interactive gradient
76 Color
, // Interactive color
78 Anchor_TR
, // #101688# Anchor handle with (0,0) at top right for SW
80 // for SJ and the CustomShapeHandles:
87 enum class BitmapColorIndex
98 enum class BitmapMarkerKind
119 // #98388# add AnchorPressed to be able to animate anchor control, too.
122 // #101688# AnchorTR for SW
126 // for SJ and the CustomShapeHandles:
133 class SVX_DLLPUBLIC SdrHdl
135 friend class SdrMarkView
; // for the access to nObjHdlNum
136 friend class SdrHdlList
;
139 SdrObject
* pObj
; // does handle belong to an object?
140 SdrPageView
* pPV
; // does handle belong to an object in certain pageview?
141 SdrHdlList
* pHdlList
; // to store the handlesize
143 sdr::overlay::OverlayObjectList maOverlayGroup
;
149 long nRotationAngle
; // turn handle or mousepointer
150 sal_uInt32 nObjHdlNum
; // required by MarkView
151 sal_uInt32 nPolyNum
; // Polygonpoint
152 sal_uInt32 nPPntNum
; // Point number of the polygon
153 sal_uInt32 nSourceHdlNum
; // still to implement
155 bool bSelect
: 1; // is a polygon point selected?
156 bool b1PixMore
: 1; // True=handle is shown 1 pixel larger
157 bool bPlusHdl
: 1; // for Hld-Paint optimisation at MarkPoint/UnmarkPoint, and other ...
159 bool mbMoveOutside
; // forces this handle to be moved outside of the selection rectangle
161 // create marker for this kind
162 virtual void CreateB2dIAObject();
164 // cleanup marker if one exists
165 void GetRidOfIAObject();
168 bool mbMouseOver
; // is true if the mouse is over this handle
171 std::unique_ptr
<sdr::overlay::OverlayObject
> CreateOverlayObject(
172 const basegfx::B2DPoint
& rPos
,
173 BitmapColorIndex eColIndex
, BitmapMarkerKind eKindOfMarker
,
174 Point aMoveOutsideOffset
= Point());
175 static BitmapMarkerKind
GetNextBigger(BitmapMarkerKind eKnd
);
177 // Helper to support inserting a new OverlayObject. It will do all
178 // necessary stuff involved with that:
179 // - add GridOffset for non-linear ViewToDevice transformation (calc)
180 // - add to OverlayManager
181 // - add to local OverlayObjectList - ownership change (!)
182 // It is centralized here (and protected) to avoid that new usages/
183 // implementations forget one of these needed steps.
184 void insertNewlyCreatedOverlayObjectForSdrHdl(
185 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject
,
186 const sdr::contact::ObjectContact
& rObjectContact
,
187 sdr::overlay::OverlayManager
& rOverlayManager
);
191 explicit SdrHdl(const Point
& rPnt
, SdrHdlKind eNewKind
);
194 const sdr::overlay::OverlayObjectList
& getOverlayObjectList() const { return maOverlayGroup
; }
196 void SetHdlList(SdrHdlList
* pList
);
197 SdrHdlKind
GetKind() const { return eKind
; }
200 const Point
& GetPos() const { return aPos
; }
201 void SetPos(const Point
& rPnt
);
203 SdrPageView
* GetPageView() const { return pPV
; }
204 void SetPageView(SdrPageView
* pNewPV
) { pPV
=pNewPV
; }
206 SdrObject
* GetObj() const { return pObj
; }
207 void SetObj(SdrObject
* pNewObj
);
209 bool IsSelected() const { return bSelect
; }
210 void SetSelected(bool bJa
=true);
212 void Set1PixMore(bool bJa
=true);
213 void SetRotationAngle(long n
);
215 bool IsCornerHdl() const { return eKind
==SdrHdlKind::UpperLeft
|| eKind
==SdrHdlKind::UpperRight
|| eKind
==SdrHdlKind::LowerLeft
|| eKind
==SdrHdlKind::LowerRight
; }
216 bool IsVertexHdl() const { return eKind
==SdrHdlKind::Upper
|| eKind
==SdrHdlKind::Lower
|| eKind
==SdrHdlKind::Left
|| eKind
==SdrHdlKind::Right
; }
218 void SetObjHdlNum(sal_uInt32 nNum
) { nObjHdlNum
=nNum
; }
219 sal_uInt32
GetObjHdlNum() const { return nObjHdlNum
; }
221 void SetPolyNum(sal_uInt32 nNum
) { nPolyNum
=nNum
; }
222 sal_uInt32
GetPolyNum() const { return nPolyNum
; }
224 void SetPointNum(sal_uInt32 nNum
) { nPPntNum
=nNum
; }
225 sal_uInt32
GetPointNum() const { return nPPntNum
; }
227 void SetPlusHdl(bool bOn
) { bPlusHdl
=bOn
; }
228 bool IsPlusHdl() const { return bPlusHdl
; }
230 void SetSourceHdlNum(sal_uInt32 nNum
) { nSourceHdlNum
=nNum
; }
231 sal_uInt32
GetSourceHdlNum() const { return nSourceHdlNum
; }
233 virtual PointerStyle
GetPointer() const;
234 bool IsHdlHit(const Point
& rPnt
) const;
236 virtual bool IsFocusHdl() const;
238 void SetMoveOutside( bool bMoveOutside
);
240 /** is called when the mouse enters the area of this handle. If the handle changes his
241 visualisation during mouse over it must override this method and call Touch(). */
242 virtual void onMouseEnter(const MouseEvent
& rMEvt
);
244 /** is called when help is requested for the area of this handle */
245 virtual void onHelpRequest(const HelpEvent
& rHEvt
);
247 /** is called when the mouse leaves the area of this handle. If the handle changes his
248 visualisation during mouse over it must override this method and call Touch(). */
249 virtual void onMouseLeave();
251 static BitmapEx
createGluePointBitmap();
255 #define SDR_HANDLE_COLOR_SIZE_NORMAL Size(13, 13)
256 #define SDR_HANDLE_COLOR_SIZE_SELECTED Size(17, 17)
258 class SVX_DLLPUBLIC SdrHdlColor
: public SdrHdl
260 // size of colr markers
266 // callback link when value changed
267 Link
<SdrHdlColor
*,void> aColorChangeHdl
;
269 // use luminance values only
270 bool const bUseLuminance
: 1;
272 // create marker for this kind
273 SVX_DLLPRIVATE
virtual void CreateB2dIAObject() override
;
276 SVX_DLLPRIVATE BitmapEx
CreateColorDropper(Color aCol
);
277 SVX_DLLPRIVATE
static Color
GetLuminance(const Color
& rCol
);
280 explicit SdrHdlColor(const Point
& rRef
, Color aCol
, const Size
& rSize
, bool bLuminance
);
281 virtual ~SdrHdlColor() override
;
283 bool IsUseLuminance() const { return bUseLuminance
; }
285 const Color
& GetColor() const { return aMarkerColor
; }
286 void SetColor(Color aNew
, bool bCallLink
= false);
288 void SetSize(const Size
& rNew
);
290 void SetColorChangeHdl(const Link
<SdrHdlColor
*,void>& rLink
) { aColorChangeHdl
= rLink
; }
294 class SdrHdlGradient
: public SdrHdl
297 // pointer to used color handles
298 SdrHdlColor
* pColHdl1
;
299 SdrHdlColor
* pColHdl2
;
304 // is this a gradient or a transparence
305 bool const bGradient
: 1;
307 // select which handle to move
308 bool bMoveSingleHandle
: 1;
309 bool bMoveFirstHandle
: 1;
311 // create marker for this kind
312 virtual void CreateB2dIAObject() override
;
315 SdrHdlGradient(const Point
& rRef1
, const Point
& rRef2
, bool bGrad
);
316 virtual ~SdrHdlGradient() override
;
318 bool IsGradient() const { return bGradient
; }
320 // set the associated color handles
321 void SetColorHandles(SdrHdlColor
* pL1
, SdrHdlColor
* pL2
) { pColHdl1
= pL1
; pColHdl2
= pL2
; }
322 SdrHdlColor
* GetColorHdl1() const { return pColHdl1
; }
323 SdrHdlColor
* GetColorHdl2() const { return pColHdl2
; }
325 const Point
& Get2ndPos() const { return a2ndPos
; }
326 void Set2ndPos(const Point
& rPnt
);
328 // the link called by the color handles
329 DECL_LINK(ColorChangeHdl
, SdrHdlColor
*, void);
331 // transformation call, create gradient from this handle
332 void FromIAOToItem(SdrObject
* pObj
, bool bSetItemOnObject
, bool bUndo
);
334 // selection flags for interaction
335 bool IsMoveSingleHandle() const { return bMoveSingleHandle
; }
336 void SetMoveSingleHandle(bool bNew
) { bMoveSingleHandle
= bNew
; }
337 bool IsMoveFirstHandle() const { return bMoveFirstHandle
; }
338 void SetMoveFirstHandle(bool bNew
) { bMoveFirstHandle
= bNew
; }
343 class SdrHdlLine final
: public SdrHdl
345 // create marker for this kind
346 virtual void CreateB2dIAObject() override
;
352 SdrHdlLine(SdrHdl
& rHdl1
, SdrHdl
& rHdl2
, SdrHdlKind eNewKind
) { eKind
=eNewKind
; pHdl1
=&rHdl1
; pHdl2
=&rHdl2
; }
353 virtual ~SdrHdlLine() override
;
355 virtual PointerStyle
GetPointer() const override
;
358 // a SdrHdlBezWgt knows about its "base handle". Its draw method
359 // draws additionally a line from its position to the position
360 // of the base handle
361 class SdrHdlBezWgt final
: public SdrHdl
364 // this is not a Copy-Ctor!!!
365 SdrHdlBezWgt(const SdrHdl
* pRefHdl1
, SdrHdlKind eNewKind
=SdrHdlKind::BezierWeight
) { eKind
=eNewKind
; pHdl1
=pRefHdl1
; }
366 virtual ~SdrHdlBezWgt() override
;
369 // create marker for this kind
370 virtual void CreateB2dIAObject() override
;
376 class E3dVolumeMarker
: public SdrHdl
378 basegfx::B2DPolyPolygon aWireframePoly
;
380 // create marker for this kind
381 virtual void CreateB2dIAObject() override
;
384 explicit E3dVolumeMarker(const basegfx::B2DPolyPolygon
& rWireframePoly
);
388 class ImpEdgeHdl
: public SdrHdl
390 SdrEdgeLineCode eLineCode
;
392 // create marker for this kind
393 virtual void CreateB2dIAObject() override
;
396 ImpEdgeHdl(const Point
& rPnt
, SdrHdlKind eNewKind
): SdrHdl(rPnt
,eNewKind
),eLineCode(SdrEdgeLineCode::MiddleLine
) {}
397 virtual ~ImpEdgeHdl() override
;
399 void SetLineCode(SdrEdgeLineCode eCode
);
400 SdrEdgeLineCode
GetLineCode() const { return eLineCode
; }
401 bool IsHorzDrag() const;
402 virtual PointerStyle
GetPointer() const override
;
406 class ImpMeasureHdl
: public SdrHdl
408 // create marker for this kind
409 virtual void CreateB2dIAObject() override
;
412 ImpMeasureHdl(const Point
& rPnt
, SdrHdlKind eNewKind
): SdrHdl(rPnt
,eNewKind
) {}
413 virtual ~ImpMeasureHdl() override
;
415 virtual PointerStyle
GetPointer() const override
;
419 class ImpTextframeHdl
: public SdrHdl
421 const tools::Rectangle maRect
;
423 // create marker for this kind
424 virtual void CreateB2dIAObject() override
;
427 explicit ImpTextframeHdl(const tools::Rectangle
& rRect
);
431 class SVX_DLLPUBLIC SdrHdlList
435 SdrMarkView
* const pView
;
436 std::deque
<std::unique_ptr
<SdrHdl
>> maList
;
439 bool bRotateShear
: 1;
440 bool bDistortShear
: 1;
441 bool bMoveOutside
: 1; // move handles outwards (for TextEdit)
444 SVX_DLLPRIVATE
SdrHdlList(const SdrHdlList
&) = delete;
445 SVX_DLLPRIVATE
void operator=(const SdrHdlList
&) = delete;
448 explicit SdrHdlList(SdrMarkView
* pV
);
452 void TravelFocusHdl(bool bForward
);
453 SdrHdl
* GetFocusHdl() const;
454 void SetFocusHdl(SdrHdl
* pNew
);
455 void ResetFocusHdl();
458 SdrMarkView
* GetView() const { return pView
;}
460 // Sorting: 1.Level first reference point handle, then normal handles, next Glue, then User then Plushandles
461 // 2.Level PageView (Pointer)
462 // 3.Level Position (x+y)
464 size_t GetHdlCount() const { return maList
.size(); }
465 SdrHdl
* GetHdl(size_t nNum
) const { return maList
[nNum
].get(); }
466 size_t GetHdlNum(const SdrHdl
* pHdl
) const;
467 void SetHdlSize(sal_uInt16 nSiz
);
468 sal_uInt16
GetHdlSize() const { return nHdlSize
; }
469 void SetMoveOutside(bool bOn
);
470 bool IsMoveOutside() const { return bMoveOutside
; }
471 void SetRotateShear(bool bOn
);
472 bool IsRotateShear() const { return bRotateShear
; }
473 void SetDistortShear(bool bOn
);
474 bool IsDistortShear() const { return bDistortShear
; }
476 // AddHdl takes ownership of the handle. It should be on the Heap
477 // as Clear() deletes it.
478 void AddHdl(std::unique_ptr
<SdrHdl
> pHdl
);
479 std::unique_ptr
<SdrHdl
> RemoveHdl(size_t nNum
);
480 void RemoveAllByKind(SdrHdlKind eKind
);
482 // move the ownership of all the SdrHdl to rOther
483 void MoveTo(SdrHdlList
& rOther
);
485 // Last inserted handles are likely hit (if the handles are above each other)
486 SdrHdl
* IsHdlListHit(const Point
& rPnt
) const;
487 SdrHdl
* GetHdl(SdrHdlKind eKind1
) const;
491 class SVX_DLLPUBLIC SdrCropHdl final
: public SdrHdl
501 // create marker for this kind
502 virtual void CreateB2dIAObject() override
;
504 BitmapEx
GetBitmapForHandle( const BitmapEx
& rBitmap
, int nSize
);
506 // evtl. shear and rotation, equal to the object's one to allow adaption of
507 // the visualization handles
508 double const mfShearX
;
509 double const mfRotation
;
513 class SVX_DLLPUBLIC SdrCropViewHdl
: public SdrHdl
516 basegfx::B2DHomMatrix
const maObjectTransform
;
517 Graphic
const maGraphic
;
518 double const mfCropLeft
;
519 double const mfCropTop
;
520 double const mfCropRight
;
521 double const mfCropBottom
;
525 const basegfx::B2DHomMatrix
& rObjectTransform
,
526 const Graphic
& rGraphic
,
533 // create marker for this kind
534 virtual void CreateB2dIAObject() override
;
538 #endif // INCLUDED_SVX_SVDHDL_HXX
540 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */