bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svx / svdhdl.hxx
bloba8e77e4ed285545fe0019f325c3e73cf3c56a42e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
34 #include <deque>
36 class OutputDevice;
37 class SdrHdlList;
38 class SdrMarkView;
39 class SdrObject;
40 class SdrPageView;
41 class MouseEvent;
43 namespace sdr { namespace contact {
44 class ObjectContact;
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!
55 enum class SdrHdlKind
57 Move, // Handle to move the object
58 UpperLeft, // Upper left
59 Upper, // Upper
60 UpperRight, // Upper right
61 Left, // Left
62 Right, // Right
63 LowerLeft, // Bottom left
64 Lower, // Bottom
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
72 Glue, // GluePoint
73 Anchor, // Anchor symbol (SD, SW)
74 Transparence, // Interactive transparence
75 Gradient, // Interactive gradient
76 Color, // Interactive color
77 User,
78 Anchor_TR, // #101688# Anchor handle with (0,0) at top right for SW
80 // for SJ and the CustomShapeHandles:
81 CustomShape1,
83 SmartTag
87 enum class BitmapColorIndex
89 LightGreen = 0,
90 Cyan = 1,
91 LightCyan = 2,
92 Red = 3,
93 LightRed = 4,
94 Yellow = 5,
98 enum class BitmapMarkerKind
100 Rect_7x7,
101 Rect_9x9,
102 Rect_11x11,
103 Rect_13x13,
104 Circ_7x7,
105 Circ_9x9,
106 Circ_11x11,
107 Elli_7x9,
108 Elli_9x11,
109 Elli_9x7,
110 Elli_11x9,
111 RectPlus_7x7,
112 RectPlus_9x9,
113 RectPlus_11x11,
114 Crosshair,
115 Glue,
116 Glue_Deselected,
117 Anchor,
119 // #98388# add AnchorPressed to be able to animate anchor control, too.
120 AnchorPressed,
122 // #101688# AnchorTR for SW
123 AnchorTR,
124 AnchorPressedTR,
126 // for SJ and the CustomShapeHandles:
127 Customshape_7x7,
128 Customshape_9x9,
129 Customshape_11x11
133 class SVX_DLLPUBLIC SdrHdl
135 friend class SdrMarkView; // for the access to nObjHdlNum
136 friend class SdrHdlList;
138 protected:
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
142 // OVERLAYMANAGER
143 sdr::overlay::OverlayObjectList maOverlayGroup;
145 Point aPos;
147 SdrHdlKind eKind;
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();
167 private:
168 bool mbMouseOver; // is true if the mouse is over this handle
170 protected:
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);
189 public:
190 SdrHdl();
191 explicit SdrHdl(const Point& rPnt, SdrHdlKind eNewKind);
192 virtual ~SdrHdl();
194 const sdr::overlay::OverlayObjectList& getOverlayObjectList() const { return maOverlayGroup; }
196 void SetHdlList(SdrHdlList* pList);
197 SdrHdlKind GetKind() const { return eKind; }
198 void Touch();
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
261 Size aMarkerSize;
263 // color
264 Color aMarkerColor;
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;
275 // help functions
276 SVX_DLLPRIVATE BitmapEx CreateColorDropper(Color aCol);
277 SVX_DLLPRIVATE static Color GetLuminance(const Color& rCol);
279 public:
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
296 private:
297 // pointer to used color handles
298 SdrHdlColor* pColHdl1;
299 SdrHdlColor* pColHdl2;
301 // 2nd position
302 Point a2ndPos;
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;
314 public:
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; }
342 // Spiegelachse
343 class SdrHdlLine final : public SdrHdl
345 // create marker for this kind
346 virtual void CreateB2dIAObject() override;
348 SdrHdl* pHdl1;
349 SdrHdl* pHdl2;
351 public:
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
363 public:
364 // this is not a Copy-Ctor!!!
365 SdrHdlBezWgt(const SdrHdl* pRefHdl1, SdrHdlKind eNewKind=SdrHdlKind::BezierWeight) { eKind=eNewKind; pHdl1=pRefHdl1; }
366 virtual ~SdrHdlBezWgt() override;
368 private:
369 // create marker for this kind
370 virtual void CreateB2dIAObject() override;
372 const SdrHdl* pHdl1;
376 class E3dVolumeMarker : public SdrHdl
378 basegfx::B2DPolyPolygon aWireframePoly;
380 // create marker for this kind
381 virtual void CreateB2dIAObject() override;
383 public:
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;
395 public:
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;
411 public:
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;
426 public:
427 explicit ImpTextframeHdl(const tools::Rectangle& rRect);
431 class SVX_DLLPUBLIC SdrHdlList
433 protected:
434 size_t mnFocusIndex;
435 SdrMarkView* const pView;
436 std::deque<std::unique_ptr<SdrHdl>> maList;
437 sal_uInt16 nHdlSize;
439 bool bRotateShear : 1;
440 bool bDistortShear : 1;
441 bool bMoveOutside : 1; // move handles outwards (for TextEdit)
443 private:
444 SVX_DLLPRIVATE SdrHdlList(const SdrHdlList&) = delete;
445 SVX_DLLPRIVATE void operator=(const SdrHdlList&) = delete;
447 public:
448 explicit SdrHdlList(SdrMarkView* pV);
449 ~SdrHdlList();
450 void Clear();
452 void TravelFocusHdl(bool bForward);
453 SdrHdl* GetFocusHdl() const;
454 void SetFocusHdl(SdrHdl* pNew);
455 void ResetFocusHdl();
457 // Access to View
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)
463 void Sort();
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
493 public:
494 SdrCropHdl(
495 const Point& rPnt,
496 SdrHdlKind eNewKind,
497 double fShearX,
498 double fRotation);
500 private:
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
515 private:
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;
523 public:
524 SdrCropViewHdl(
525 const basegfx::B2DHomMatrix& rObjectTransform,
526 const Graphic& rGraphic,
527 double fCropLeft,
528 double fCropTop,
529 double fCropRight,
530 double fCropBottom);
532 protected:
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: */