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 .
23 #include <tools/gen.hxx>
25 #include <vcl/pointr.hxx>
27 #include <svl/solar.hrc>
29 #include <svx/xpoly.hxx>
30 #include <svx/svdoedge.hxx>
31 #include <svx/sdr/overlay/overlayobjectlist.hxx>
32 #include "svx/svxdllapi.h"
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 // Jedes Objekt muss in der Lage seine Handles zu erzeugen. Diese werden dann
47 // bei einer Selektion abgeholt, bei der View angemeldet und sichtbar gemacht.
48 // Wird ein Handle von der Maus beruehrt (IsHit()), so wird von der View der
49 // entsprechende Mauszeiger vom Handle abgeholt und der App auf Anfrage zum
50 // reinschalten uebergeben.
51 // Handles wie z.B. der Rotationsmittelpunkt oder die Spiegelachse werden von
52 // der View generiert, wenn vom Controller der entsprechende Transformations-
53 // Modus selektiert wird.
54 // HDL_MOVE...HDL_LWRGT muessen im enum immer zusammen stehen bleiben!
58 HDL_MOVE
, // Handle zum Verschieben des Objekts
59 HDL_UPLFT
, // Oben links
61 HDL_UPRGT
, // Oben rechts
64 HDL_LWLFT
, // Unten links
66 HDL_LWRGT
, // Unten rechts
67 HDL_POLY
, // Punktselektion an Polygon oder Bezierkurve
68 HDL_BWGT
, // Gewicht an einer Bezierkurve
69 HDL_CIRC
, // Winkel an Kreissegmenten, Eckenradius am Rect
70 HDL_REF1
, // Referenzpunkt 1, z.B. Rotationsmitte
71 HDL_REF2
, // Referenzpunkt 2, z.B. Endpunkt der Spiegelachse
72 HDL_MIRX
, // Die Spiegelachse selbst
73 HDL_GLUE
, // GluePoint
74 HDL_GLUE_DESELECTED
, // GluePoint
75 HDL_ANCHOR
, // anchor symbol (SD, SW)
76 HDL_TRNS
, // interactive transparence
77 HDL_GRAD
, // interactive gradient
78 HDL_COLR
, // interactive color
80 HDL_ANCHOR_TR
, // #101688# Anchor handle with (0,0) at top right for SW
82 // for SJ and the CustomShapeHandles:
88 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 ////////////////////////////////////////////////////////////////////////////////////////////////////
102 enum BitmapMarkerKind
123 // #98388# add AnchorPressed to be able to aninate anchor control, too.
126 // #101688# AnchorTR for SW
130 // for SJ and the CustomShapeHandles:
134 ////////////////////////////////////////////////////////////////////////////////////////////////////
136 class SVX_DLLPUBLIC SdrHdl
138 friend class SdrMarkView
; // fuer den Zugriff auf nObjHdlNum
139 friend class SdrHdlList
;
141 static BitmapEx
ImpGetBitmapEx(BitmapMarkerKind eKindOfMarker
, sal_uInt16 nInd
);
144 SdrObject
* pObj
; // Gehoert das Handle zu einem Objekt?
145 SdrPageView
* pPV
; // Gehoert das Handle zu einem Objekt in einer bestimmten PageView?
146 SdrHdlList
* pHdlList
; // Zum Feststelen der Handlegroesse
149 ::sdr::overlay::OverlayObjectList maOverlayGroup
;
155 long nDrehWink
; // Handles bzw. Mauszeiger drehen
156 sal_uInt32 nObjHdlNum
; // wird von der MarkView benoetigt
157 sal_uInt32 nPolyNum
; // Polygonpunktes
158 sal_uInt32 nPPntNum
; // Punktnummer des Polygons
159 sal_uInt32 nSourceHdlNum
; // ist noch vollstaendig zu implementieren
161 unsigned bSelect
: 1; // Ein selektierter Polygonpunkt?
162 unsigned b1PixMore
: 1; // True=Handle wird 1 Pixel groesser dargestellt
163 unsigned bPlusHdl
: 1; // u.a. fuer Hld-Paint Optimierung bei MarkPoint/UnmarkPoint, ...
165 bool mbMoveOutside
; // forces this handle to be moved outside of the selection rectangle
167 // create marker for this kind
168 virtual void CreateB2dIAObject();
170 // cleanup marker if one exists
171 void GetRidOfIAObject();
174 bool mbMouseOver
; // is true if the mouse is over this handle
177 ::sdr::overlay::OverlayObject
* CreateOverlayObject(
178 const basegfx::B2DPoint
& rPos
,
179 BitmapColorIndex eColIndex
, BitmapMarkerKind eKindOfMarker
, Point aMoveOutsideOffset
= Point());
180 BitmapMarkerKind
GetNextBigger(BitmapMarkerKind eKnd
) const;
184 explicit SdrHdl(const Point
& rPnt
, SdrHdlKind eNewKind
=HDL_MOVE
);
187 const ::sdr::overlay::OverlayObjectList
& getOverlayObjectList() const { return maOverlayGroup
; }
189 void SetHdlList(SdrHdlList
* pList
);
190 SdrHdlKind
GetKind() const { return eKind
; }
193 const Point
& GetPos() const { return aPos
; }
194 void SetPos(const Point
& rPnt
);
196 SdrPageView
* GetPageView() const { return pPV
; }
197 void SetPageView(SdrPageView
* pNewPV
) { pPV
=pNewPV
; }
199 SdrObject
* GetObj() const { return pObj
; }
200 void SetObj(SdrObject
* pNewObj
);
202 sal_Bool
IsSelected() const { return bSelect
; }
203 void SetSelected(sal_Bool bJa
=sal_True
);
205 void Set1PixMore(sal_Bool bJa
=sal_True
);
206 void SetDrehWink(long n
);
208 sal_Bool
IsCornerHdl() const { return eKind
==HDL_UPLFT
|| eKind
==HDL_UPRGT
|| eKind
==HDL_LWLFT
|| eKind
==HDL_LWRGT
; }
209 sal_Bool
IsVertexHdl() const { return eKind
==HDL_UPPER
|| eKind
==HDL_LOWER
|| eKind
==HDL_LEFT
|| eKind
==HDL_RIGHT
; }
211 void SetObjHdlNum(sal_uInt32 nNum
) { nObjHdlNum
=nNum
; }
212 sal_uInt32
GetObjHdlNum() const { return nObjHdlNum
; }
214 void SetPolyNum(sal_uInt32 nNum
) { nPolyNum
=nNum
; }
215 sal_uInt32
GetPolyNum() const { return nPolyNum
; }
217 void SetPointNum(sal_uInt32 nNum
) { nPPntNum
=nNum
; }
218 sal_uInt32
GetPointNum() const { return nPPntNum
; }
220 void SetPlusHdl(sal_Bool bOn
) { bPlusHdl
=bOn
; }
221 sal_Bool
IsPlusHdl() const { return bPlusHdl
; }
223 void SetSourceHdlNum(sal_uInt32 nNum
) { nSourceHdlNum
=nNum
; }
224 sal_uInt32
GetSourceHdlNum() const { return nSourceHdlNum
; }
226 virtual Pointer
GetPointer() const;
227 bool IsHdlHit(const Point
& rPnt
) const;
230 virtual sal_Bool
IsFocusHdl() const;
232 void SetMoveOutside( bool bMoveOutside
);
234 /** is called when the mouse enters the area of this handle. If the handle changes his
235 visualisation during mouse over it must override this method and call Touch(). */
236 virtual void onMouseEnter(const MouseEvent
& rMEvt
);
238 /** is called when the mouse leaves the area of this handle. If the handle changes his
239 visualisation during mouse over it must override this method and call Touch(). */
240 virtual void onMouseLeave();
242 static BitmapEx
createGluePointBitmap() { return ImpGetBitmapEx(Glue_Deselected
, 0); }
245 ////////////////////////////////////////////////////////////////////////////////////////////////////
247 #define SDR_HANDLE_COLOR_SIZE_NORMAL Size(13, 13)
248 #define SDR_HANDLE_COLOR_SIZE_SELECTED Size(17, 17)
250 class SVX_DLLPUBLIC SdrHdlColor
: public SdrHdl
253 // size of colr markers
259 // callback link when value changed
260 Link aColorChangeHdl
;
262 // use luminance values only
263 unsigned bUseLuminance
: 1;
265 // create marker for this kind
266 SVX_DLLPRIVATE
virtual void CreateB2dIAObject();
269 SVX_DLLPRIVATE Bitmap
CreateColorDropper(Color aCol
);
270 SVX_DLLPRIVATE Color
GetLuminance(const Color
& rCol
);
271 SVX_DLLPRIVATE
void CallColorChangeLink();
274 explicit SdrHdlColor(const Point
& rRef
, Color aCol
= Color(COL_BLACK
), const Size
& rSize
= Size(11, 11), sal_Bool bLum
= sal_False
);
275 virtual ~SdrHdlColor();
277 sal_Bool
IsUseLuminance() const { return bUseLuminance
; }
279 Color
GetColor() const { return aMarkerColor
; }
280 void SetColor(Color aNew
, sal_Bool bCallLink
= sal_False
);
282 const Size
& GetSize() const { return aMarkerSize
; }
283 void SetSize(const Size
& rNew
);
285 void SetColorChangeHdl(const Link
& rLink
) { aColorChangeHdl
= rLink
; }
286 const Link
& GetColorChangeHdl() const { return aColorChangeHdl
; }
289 ////////////////////////////////////////////////////////////////////////////////////////////////////
291 class SdrHdlGradient
: public SdrHdl
294 // pointer to used color handles
295 SdrHdlColor
* pColHdl1
;
296 SdrHdlColor
* pColHdl2
;
301 // is this a gradient or a transparence
302 unsigned bGradient
: 1;
304 // select which handle to move
305 bool bMoveSingleHandle
: 1;
306 bool bMoveFirstHandle
: 1;
308 // create marker for this kind
309 virtual void CreateB2dIAObject();
312 SdrHdlGradient(const Point
& rRef1
, const Point
& rRef2
, sal_Bool bGrad
= sal_True
);
313 virtual ~SdrHdlGradient();
315 sal_Bool
IsGradient() const { return bGradient
; }
317 // set the associated color handles
318 void SetColorHandles(SdrHdlColor
* pL1
, SdrHdlColor
* pL2
) { pColHdl1
= pL1
; pColHdl2
= pL2
; }
319 SdrHdlColor
* GetColorHdl1() const { return pColHdl1
; }
320 SdrHdlColor
* GetColorHdl2() const { return pColHdl2
; }
322 const Point
& Get2ndPos() const { return a2ndPos
; }
323 void Set2ndPos(const Point
& rPnt
);
325 // the link called by the color handles
326 DECL_LINK(ColorChangeHdl
, SdrHdl
*);
328 // transformation call, create gradient from this handle
329 void FromIAOToItem(SdrObject
* pObj
, sal_Bool bSetItemOnObject
, sal_Bool bUndo
);
331 // selection flags for interaction
332 bool IsMoveSingleHandle() const { return bMoveSingleHandle
; }
333 void SetMoveSingleHandle(bool bNew
) { bMoveSingleHandle
= bNew
; }
334 bool IsMoveFirstHandle() const { return bMoveFirstHandle
; }
335 void SetMoveFirstHandle(bool bNew
) { bMoveFirstHandle
= bNew
; }
338 ////////////////////////////////////////////////////////////////////////////////////////////////////
341 class SdrHdlLine
: public SdrHdl
343 // create marker for this kind
344 virtual void CreateB2dIAObject();
351 SdrHdlLine(SdrHdl
& rHdl1
, SdrHdl
& rHdl2
, SdrHdlKind eNewKind
=HDL_MIRX
) { eKind
=eNewKind
; pHdl1
=&rHdl1
; pHdl2
=&rHdl2
; }
352 virtual ~SdrHdlLine();
354 virtual Pointer
GetPointer() const;
357 // Ein SdrHdlBezWgt hat Kenntnis von seinem "BasisHandle". Seine Draw-Methode
358 // zeichnet zusaetzlich eine Linie von seiner Position zur Position dieses
360 class SdrHdlBezWgt
: public SdrHdl
362 // create marker for this kind
363 virtual void CreateB2dIAObject();
369 // das ist kein Copy-Ctor!!!
370 SdrHdlBezWgt(const SdrHdl
* pRefHdl1
, SdrHdlKind eNewKind
=HDL_BWGT
) { eKind
=eNewKind
; pHdl1
=pRefHdl1
; }
371 virtual ~SdrHdlBezWgt();
374 ////////////////////////////////////////////////////////////////////////////////////////////////////
376 class E3dVolumeMarker
: public SdrHdl
378 basegfx::B2DPolyPolygon aWireframePoly
;
380 // create marker for this kind
381 virtual void CreateB2dIAObject();
384 explicit E3dVolumeMarker(const basegfx::B2DPolyPolygon
& rWireframePoly
);
387 ////////////////////////////////////////////////////////////////////////////////////////////////////
389 class ImpEdgeHdl
: public SdrHdl
391 SdrEdgeLineCode eLineCode
;
393 // create marker for this kind
394 virtual void CreateB2dIAObject();
397 ImpEdgeHdl(const Point
& rPnt
, SdrHdlKind eNewKind
): SdrHdl(rPnt
,eNewKind
),eLineCode(MIDDLELINE
) {}
398 virtual ~ImpEdgeHdl();
400 void SetLineCode(SdrEdgeLineCode eCode
);
401 SdrEdgeLineCode
GetLineCode() const { return eLineCode
; }
402 sal_Bool
IsHorzDrag() const;
403 virtual Pointer
GetPointer() const;
406 ////////////////////////////////////////////////////////////////////////////////////////////////////
408 class ImpMeasureHdl
: public SdrHdl
410 // create marker for this kind
411 virtual void CreateB2dIAObject();
414 ImpMeasureHdl(const Point
& rPnt
, SdrHdlKind eNewKind
): SdrHdl(rPnt
,eNewKind
) {}
415 virtual ~ImpMeasureHdl();
417 virtual Pointer
GetPointer() const;
420 ////////////////////////////////////////////////////////////////////////////////////////////////////
422 class ImpTextframeHdl
: public SdrHdl
424 const Rectangle maRect
;
426 // create marker for this kind
427 virtual void CreateB2dIAObject();
430 explicit ImpTextframeHdl(const Rectangle
& rRect
);
433 ////////////////////////////////////////////////////////////////////////////////////////////////////
434 ////////////////////////////////////////////////////////////////////////////////////////////////////
435 ////////////////////////////////////////////////////////////////////////////////////////////////////
437 class SVX_DLLPUBLIC SdrHdlList
440 sal_uIntPtr mnFocusIndex
;
442 std::deque
<SdrHdl
*> aList
;
445 unsigned bRotateShear
: 1;
446 unsigned bDistortShear
: 1;
447 unsigned bMoveOutside
: 1; // Handles nach aussen ruecken (fuer TextEdit)
450 SVX_DLLPRIVATE
SdrHdlList(const SdrHdlList
&): aList() {}
451 SVX_DLLPRIVATE
void operator=(const SdrHdlList
&) {}
452 SVX_DLLPRIVATE sal_Bool
operator==(const SdrHdlList
&) const { return sal_False
; }
453 SVX_DLLPRIVATE sal_Bool
operator!=(const SdrHdlList
&) const { return sal_False
; }
456 explicit SdrHdlList(SdrMarkView
* pV
);
461 void TravelFocusHdl(sal_Bool bForward
);
462 SdrHdl
* GetFocusHdl() const;
463 void SetFocusHdl(SdrHdl
* pNew
);
464 void ResetFocusHdl();
467 SdrMarkView
* GetView() const;
469 // Sortierung: 1.Level Erst Refpunkt-Handles, dann normale Handles, dann Glue, dann User, dann Plushandles
470 // 2.Level PageView (Pointer)
471 // 3.Level Position (x+y)
473 sal_uIntPtr
GetHdlCount() const { return aList
.size(); }
474 SdrHdl
* GetHdl(sal_uIntPtr nNum
) const { return nNum
!= CONTAINER_ENTRY_NOTFOUND
? aList
[nNum
] : NULL
; }
475 sal_uIntPtr
GetHdlNum(const SdrHdl
* pHdl
) const;
476 void SetHdlSize(sal_uInt16 nSiz
);
477 sal_uInt16
GetHdlSize() const { return nHdlSize
; }
478 void SetMoveOutside(sal_Bool bOn
);
479 sal_Bool
IsMoveOutside() const { return bMoveOutside
; }
480 void SetRotateShear(sal_Bool bOn
);
481 sal_Bool
IsRotateShear() const { return bRotateShear
; }
482 void SetDistortShear(sal_Bool bOn
);
483 sal_Bool
IsDistortShear() const { return bDistortShear
; }
485 // AddHdl uebernimmt das Handle in sein Eigentum. Es muss
486 // also auf dem Heap stehen, da Clear() ein delete macht.
487 void AddHdl(SdrHdl
* pHdl
, sal_Bool bAtBegin
=sal_False
);
488 SdrHdl
* RemoveHdl(sal_uIntPtr nNum
);
489 void RemoveAllByKind(SdrHdlKind eKind
);
491 // Zuletzt eingefuegte Handles werden am ehesten getroffen
492 // (wenn Handles uebereinander liegen).
493 SdrHdl
* IsHdlListHit(const Point
& rPnt
, sal_Bool bBack
=sal_False
, sal_Bool bNext
=sal_False
, SdrHdl
* pHdl0
=NULL
) const;
494 SdrHdl
* GetHdl(SdrHdlKind eKind1
) const;
497 ////////////////////////////////////////////////////////////////////////////////////////////////////
499 class SVX_DLLPUBLIC SdrCropHdl
: public SdrHdl
502 SdrCropHdl(const Point
& rPnt
, SdrHdlKind eNewKind
);
505 // create marker for this kind
506 virtual void CreateB2dIAObject();
508 BitmapEx
GetBitmapForHandle( const BitmapEx
& rBitmap
, int nSize
);
510 static BitmapEx
GetHandlesBitmap();
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */