xref: /AOO41X/main/svx/inc/svx/svdhdl.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SVDHDL_HXX
29 #define _SVDHDL_HXX
30 
31 #include <tools/gen.hxx>
32 
33 #ifndef _POINTR_HXX //autogen
34 #include <vcl/pointr.hxx>
35 #endif
36 #include <tools/contnr.hxx>
37 
38 #ifndef _SOLAR_HRC
39 #include <svl/solar.hrc>
40 #endif
41 
42 #include <svx/xpoly.hxx>
43 #include <svx/svdoedge.hxx>
44 #include <svx/sdr/overlay/overlayobjectlist.hxx>
45 #include "svx/svxdllapi.h"
46 
47 #include <svx/xpoly.hxx>
48 #include <svx/svdoedge.hxx>
49 
50 class VirtualDevice;
51 class OutputDevice;
52 class Region;
53 class Window;
54 class SdrHdlList;
55 class SdrMarkView;
56 class SdrObject;
57 class SdrPageView;
58 class MouseEvent;
59 
60 ////////////////////////////////////////////////////////////////////////////////////////////////////
61 
62 // Jedes Objekt muss in der Lage seine Handles zu erzeugen. Diese werden dann
63 // bei einer Selektion abgeholt, bei der View angemeldet und sichtbar gemacht.
64 // Wird ein Handle von der Maus beruehrt (IsHit()), so wird von der View der
65 // entsprechende Mauszeiger vom Handle abgeholt und der App auf Anfrage zum
66 // reinschalten uebergeben.
67 // Handles wie z.B. der Rotationsmittelpunkt oder die Spiegelachse werden von
68 // der View generiert, wenn vom Controller der entsprechende Transformations-
69 // Modus selektiert wird.
70 // HDL_MOVE...HDL_LWRGT muessen im enum immer zusammen stehen bleiben!
71 
72 enum SdrHdlKind
73 {
74 	HDL_MOVE,		// Handle zum Verschieben des Objekts
75 	HDL_UPLFT,		// Oben links
76 	HDL_UPPER,		// Oben
77 	HDL_UPRGT,		// Oben rechts
78 	HDL_LEFT,		// Links
79 	HDL_RIGHT,		// Rechts
80 	HDL_LWLFT,		// Unten links
81 	HDL_LOWER,		// Unten
82 	HDL_LWRGT,		// Unten rechts
83 	HDL_POLY,		// Punktselektion an Polygon oder Bezierkurve
84 	HDL_BWGT,		// Gewicht an einer Bezierkurve
85 	HDL_CIRC,		// Winkel an Kreissegmenten, Eckenradius am Rect
86 	HDL_REF1,		// Referenzpunkt 1, z.B. Rotationsmitte
87 	HDL_REF2,		// Referenzpunkt 2, z.B. Endpunkt der Spiegelachse
88 	HDL_MIRX,		// Die Spiegelachse selbst
89 	HDL_GLUE,		// GluePoint
90 	HDL_ANCHOR,		// anchor symbol (SD, SW)
91 	HDL_TRNS,		// interactive transparence
92 	HDL_GRAD,		// interactive gradient
93 	HDL_COLR,		// interactive color
94 	HDL_USER,
95 	HDL_ANCHOR_TR,	// #101688# Anchor handle with (0,0) at top right for SW
96 
97 	// for SJ and the CustomShapeHandles:
98 	HDL_CUSTOMSHAPE1,
99 
100 	HDL_SMARTTAG
101 };
102 
103 ////////////////////////////////////////////////////////////////////////////////////////////////////
104 
105 enum BitmapColorIndex
106 {
107 	LightGreen,
108 	Cyan,
109 	LightCyan,
110 	Red,
111 	LightRed,
112 	Yellow
113 };
114 
115 ////////////////////////////////////////////////////////////////////////////////////////////////////
116 
117 enum BitmapMarkerKind
118 {
119 	Rect_7x7,
120 	Rect_9x9,
121 	Rect_11x11,
122 	Rect_13x13,
123 	Circ_7x7,
124 	Circ_9x9,
125 	Circ_11x11,
126 	Elli_7x9,
127 	Elli_9x11,
128 	Elli_9x7,
129 	Elli_11x9,
130 	RectPlus_7x7,
131 	RectPlus_9x9,
132 	RectPlus_11x11,
133 	Crosshair,
134 	Glue,
135 	Anchor,
136 
137 	// #98388# add AnchorPressed to be able to aninate anchor control, too.
138 	AnchorPressed,
139 
140 	// #101688# AnchorTR for SW
141 	AnchorTR,
142 	AnchorPressedTR,
143 
144 	// for SJ and the CustomShapeHandles:
145 	Customshape1
146 };
147 
148 ////////////////////////////////////////////////////////////////////////////////////////////////////
149 
150 class SVX_DLLPUBLIC SdrHdl
151 {
152 	friend class				SdrMarkView; // fuer den Zugriff auf nObjHdlNum
153 	friend class				SdrHdlList;
154 
155 	// #101928#
156 	BitmapEx ImpGetBitmapEx(BitmapMarkerKind eKindOfMarker, sal_uInt16 nInd, sal_Bool bFine, sal_Bool bIsHighContrast);
157 
158 protected:
159 	SdrObject*					pObj;      // Gehoert das Handle zu einem Objekt?
160 	SdrPageView*				pPV;       // Gehoert das Handle zu einem Objekt in einer bestimmten PageView?
161 	SdrHdlList*					pHdlList;  // Zum Feststelen der Handlegroesse
162 
163 	// OVERLAYMANAGER
164 	::sdr::overlay::OverlayObjectList			maOverlayGroup;
165 
166 	Point						aPos;
167 
168 	SdrHdlKind					eKind;
169 
170 	long						nDrehWink; // Handles bzw. Mauszeiger drehen
171 	sal_uInt32					nObjHdlNum; // wird von der MarkView benoetigt
172 	sal_uInt32					nPolyNum;  // Polygonpunktes
173 	sal_uInt32					nPPntNum;  // Punktnummer des Polygons
174 	sal_uInt32					nSourceHdlNum; // ist noch vollstaendig zu implementieren
175 
176 	unsigned					bSelect : 1;   // Ein selektierter Polygonpunkt?
177 	unsigned					b1PixMore : 1; // True=Handle wird 1 Pixel groesser dargestellt
178 	unsigned					bPlusHdl : 1;  // u.a. fuer Hld-Paint Optimierung bei MarkPoint/UnmarkPoint, ...
179 
180 	bool						mbMoveOutside; // forces this handle to be moved outside of the selection rectangle
181 
182 	// create marker for this kind
183 	virtual void CreateB2dIAObject();
184 
185 	// cleanup marker if one exists
186 	void GetRidOfIAObject();
187 
188 private:
189 	bool						mbMouseOver;	// is true if the mouse is over this handle
190 
191 protected:
192 	::sdr::overlay::OverlayObject* CreateOverlayObject(
193 		const basegfx::B2DPoint& rPos,
194 		BitmapColorIndex eColIndex, BitmapMarkerKind eKindOfMarker, Point aMoveOutsideOffset = Point());
195 	BitmapMarkerKind GetNextBigger(BitmapMarkerKind eKnd) const;
196 
197 public:
198 	SdrHdl();
199 	SdrHdl(const Point& rPnt, SdrHdlKind eNewKind=HDL_MOVE);
200 	virtual ~SdrHdl();
201 
202 	const ::sdr::overlay::OverlayObjectList& getOverlayObjectList() const { return maOverlayGroup; }
203 
204 	void SetHdlList(SdrHdlList* pList);
205 	SdrHdlKind GetKind() const { return eKind; }
206 	void Touch();
207 
208 	const Point& GetPos() const { return aPos; }
209 	void SetPos(const Point& rPnt);
210 
211 	SdrPageView* GetPageView() const { return pPV; }
212 	void SetPageView(SdrPageView* pNewPV) { pPV=pNewPV; }
213 
214 	SdrObject* GetObj() const { return pObj;  }
215 	void SetObj(SdrObject* pNewObj);
216 
217 	sal_Bool IsSelected() const { return bSelect; }
218 	void SetSelected(sal_Bool bJa=sal_True);
219 
220 	void Set1PixMore(sal_Bool bJa=sal_True);
221 	void SetDrehWink(long n);
222 
223 	sal_Bool IsCornerHdl() const { return eKind==HDL_UPLFT || eKind==HDL_UPRGT || eKind==HDL_LWLFT || eKind==HDL_LWRGT; }
224 	sal_Bool IsVertexHdl() const { return eKind==HDL_UPPER || eKind==HDL_LOWER || eKind==HDL_LEFT  || eKind==HDL_RIGHT; }
225 
226 	void SetObjHdlNum(sal_uInt32 nNum) { nObjHdlNum=nNum; }
227 	sal_uInt32 GetObjHdlNum() const { return nObjHdlNum; }
228 
229 	void SetPolyNum(sal_uInt32 nNum) { nPolyNum=nNum; }
230 	sal_uInt32 GetPolyNum() const { return nPolyNum; }
231 
232 	void SetPointNum(sal_uInt32 nNum) { nPPntNum=nNum; }
233 	sal_uInt32 GetPointNum() const { return nPPntNum; }
234 
235 	void SetPlusHdl(sal_Bool bOn) { bPlusHdl=bOn; }
236 	sal_Bool IsPlusHdl() const { return bPlusHdl; }
237 
238 	void SetSourceHdlNum(sal_uInt32 nNum) { nSourceHdlNum=nNum; }
239 	sal_uInt32 GetSourceHdlNum() const { return nSourceHdlNum; }
240 
241 	virtual Pointer GetPointer() const;
242 	bool IsHdlHit(const Point& rPnt) const;
243 
244 	// #97016# II
245 	virtual sal_Bool IsFocusHdl() const;
246 
247 	void SetMoveOutside( bool bMoveOutside );
248 
249 	/** is called when the mouse enters the area of this handle. If the handle changes his
250 		visualisation during mouse over it must override this method and call Touch(). */
251 	virtual void onMouseEnter(const MouseEvent& rMEvt);
252 
253 	/** is called when the mouse leaves the area of this handle. If the handle changes his
254 		visualisation during mouse over it must override this method and call Touch(). */
255 	virtual void onMouseLeave();
256 
257 	bool isMouseOver() const;
258 };
259 
260 ////////////////////////////////////////////////////////////////////////////////////////////////////
261 
262 #define	SDR_HANDLE_COLOR_SIZE_NORMAL			Size(13, 13)
263 #define	SDR_HANDLE_COLOR_SIZE_SELECTED			Size(17, 17)
264 
265 class SVX_DLLPUBLIC SdrHdlColor : public SdrHdl
266 {
267 private:
268 	// size of colr markers
269 	Size						aMarkerSize;
270 
271 	// color
272 	Color						aMarkerColor;
273 
274 	// callback link when value changed
275     Link						aColorChangeHdl;
276 
277 	// use luminance values only
278 	unsigned					bUseLuminance : 1;
279 
280 	// create marker for this kind
281 	SVX_DLLPRIVATE virtual void CreateB2dIAObject();
282 
283 	// help functions
284 	SVX_DLLPRIVATE Bitmap CreateColorDropper(Color aCol);
285 	SVX_DLLPRIVATE Color GetLuminance(const Color& rCol);
286 	SVX_DLLPRIVATE void CallColorChangeLink();
287 
288 public:
289 	SdrHdlColor(const Point& rRef, Color aCol = Color(COL_BLACK), const Size& rSize = Size(11, 11), sal_Bool bLum = sal_False);
290 	virtual ~SdrHdlColor();
291 
292 	sal_Bool IsUseLuminance() const { return bUseLuminance; }
293 
294 	Color GetColor() const { return aMarkerColor; }
295 	void SetColor(Color aNew, sal_Bool bCallLink = sal_False);
296 
297 	const Size& GetSize() const { return aMarkerSize; }
298 	void SetSize(const Size& rNew);
299 
300     void SetColorChangeHdl(const Link& rLink) { aColorChangeHdl = rLink; }
301     const Link& GetColorChangeHdl() const { return aColorChangeHdl; }
302 };
303 
304 ////////////////////////////////////////////////////////////////////////////////////////////////////
305 
306 class SdrHdlGradient : public SdrHdl
307 {
308 private:
309 	// pointer to used color handles
310 	SdrHdlColor*				pColHdl1;
311 	SdrHdlColor*				pColHdl2;
312 
313 	// 2nd position
314 	Point						a2ndPos;
315 
316 	// is this a gradient or a transparence
317 	unsigned					bGradient : 1;
318 
319 	// select which handle to move
320 	unsigned					bMoveSingleHandle : 1;
321 	unsigned					bMoveFirstHandle : 1;
322 
323 	// create marker for this kind
324 	virtual void CreateB2dIAObject();
325 
326 public:
327 	SdrHdlGradient(const Point& rRef1, const Point& rRef2, sal_Bool bGrad = sal_True);
328 	virtual ~SdrHdlGradient();
329 
330 	sal_Bool IsGradient() const { return bGradient; }
331 
332 	// set the associated color handles
333 	void SetColorHandles(SdrHdlColor* pL1, SdrHdlColor* pL2) { pColHdl1 = pL1; pColHdl2 = pL2; }
334 	SdrHdlColor* GetColorHdl1() const { return pColHdl1; }
335 	SdrHdlColor* GetColorHdl2() const { return pColHdl2; }
336 
337 	const Point& Get2ndPos() const { return a2ndPos; }
338 	void Set2ndPos(const Point& rPnt);
339 
340 	// the link called by the color handles
341 	DECL_LINK(ColorChangeHdl, SdrHdl*);
342 
343 	// transformation call, create gradient from this handle
344 	void FromIAOToItem(SdrObject* pObj, sal_Bool bSetItemOnObject, sal_Bool bUndo);
345 
346 	// selection flags for interaction
347 	sal_Bool IsMoveSingleHandle() const { return bMoveSingleHandle; }
348 	void SetMoveSingleHandle(sal_Bool bNew) { bMoveSingleHandle = bNew; }
349 	sal_Bool IsMoveFirstHandle() const { return bMoveFirstHandle; }
350 	void SetMoveFirstHandle(sal_Bool bNew) { bMoveFirstHandle = bNew; }
351 };
352 
353 ////////////////////////////////////////////////////////////////////////////////////////////////////
354 
355 // Spiegelachse
356 class SdrHdlLine: public SdrHdl
357 {
358 	// create marker for this kind
359 	virtual void CreateB2dIAObject();
360 
361 protected:
362 	SdrHdl*						pHdl1;
363 	SdrHdl*						pHdl2;
364 
365 public:
366 	SdrHdlLine(SdrHdl& rHdl1, SdrHdl& rHdl2, SdrHdlKind eNewKind=HDL_MIRX) { eKind=eNewKind; pHdl1=&rHdl1; pHdl2=&rHdl2; }
367 	virtual ~SdrHdlLine();
368 
369 	virtual Pointer GetPointer() const;
370 };
371 
372 // Ein SdrHdlBezWgt hat Kenntnis von seinem "BasisHandle". Seine Draw-Methode
373 // zeichnet zusaetzlich eine Linie von seiner Position zur Position dieses
374 // BasisHandles.
375 class SdrHdlBezWgt: public SdrHdl
376 {
377 	// create marker for this kind
378 	virtual void CreateB2dIAObject();
379 
380 protected:
381 	const SdrHdl* pHdl1;
382 
383 public:
384 	// das ist kein Copy-Ctor!!!
385 	SdrHdlBezWgt(const SdrHdl* pRefHdl1, SdrHdlKind eNewKind=HDL_BWGT) { eKind=eNewKind; pHdl1=pRefHdl1; }
386 	virtual ~SdrHdlBezWgt();
387 };
388 
389 ////////////////////////////////////////////////////////////////////////////////////////////////////
390 
391 class E3dVolumeMarker : public SdrHdl
392 {
393 	basegfx::B2DPolyPolygon				aWireframePoly;
394 
395 	// create marker for this kind
396 	virtual void CreateB2dIAObject();
397 
398 public:
399 	E3dVolumeMarker(const basegfx::B2DPolyPolygon& rWireframePoly);
400 };
401 
402 ////////////////////////////////////////////////////////////////////////////////////////////////////
403 
404 class ImpEdgeHdl: public SdrHdl
405 {
406 	SdrEdgeLineCode eLineCode;
407 
408 	// create marker for this kind
409 	virtual void CreateB2dIAObject();
410 
411 public:
412 	ImpEdgeHdl(const Point& rPnt, SdrHdlKind eNewKind): SdrHdl(rPnt,eNewKind),eLineCode(MIDDLELINE) {}
413 	virtual ~ImpEdgeHdl();
414 
415 	void SetLineCode(SdrEdgeLineCode eCode);
416 	SdrEdgeLineCode GetLineCode() const     { return eLineCode; }
417 	sal_Bool IsHorzDrag() const;
418 	virtual Pointer GetPointer() const;
419 };
420 
421 ////////////////////////////////////////////////////////////////////////////////////////////////////
422 
423 class ImpMeasureHdl: public SdrHdl
424 {
425 	// create marker for this kind
426 	virtual void CreateB2dIAObject();
427 
428 public:
429 	ImpMeasureHdl(const Point& rPnt, SdrHdlKind eNewKind): SdrHdl(rPnt,eNewKind) {}
430 	virtual ~ImpMeasureHdl();
431 
432 	virtual Pointer GetPointer() const;
433 };
434 
435 ////////////////////////////////////////////////////////////////////////////////////////////////////
436 
437 class ImpTextframeHdl: public SdrHdl
438 {
439     const Rectangle maRect;
440 
441 	// create marker for this kind
442 	virtual void CreateB2dIAObject();
443 
444 public:
445 	explicit ImpTextframeHdl(const Rectangle& rRect);
446 };
447 
448 ////////////////////////////////////////////////////////////////////////////////////////////////////
449 ////////////////////////////////////////////////////////////////////////////////////////////////////
450 ////////////////////////////////////////////////////////////////////////////////////////////////////
451 
452 // #97016# II
453 class ImplHdlListData;
454 
455 class SVX_DLLPUBLIC SdrHdlList
456 {
457 protected:
458 	sal_uIntPtr					mnFocusIndex;
459 	SdrMarkView*				pView;
460 	Container					aList;
461 	sal_uInt16						nHdlSize;
462 
463 	unsigned					bRotateShear : 1;
464 	unsigned					bDistortShear : 1;
465 	unsigned					bMoveOutside : 1;      // Handles nach aussen ruecken (fuer TextEdit)
466 	unsigned					bFineHandles : 1;
467 
468 private:
469 	SVX_DLLPRIVATE SdrHdlList(const SdrHdlList&): aList(1024,64,64)  {}
470 	SVX_DLLPRIVATE void operator=(const SdrHdlList&)                 {}
471 	SVX_DLLPRIVATE sal_Bool operator==(const SdrHdlList&) const      { return sal_False; }
472 	SVX_DLLPRIVATE sal_Bool operator!=(const SdrHdlList&) const      { return sal_False; }
473 
474 public:
475 	SdrHdlList(SdrMarkView* pV);
476 	~SdrHdlList();
477 	void Clear();
478 
479 	// #97016# II
480 	void TravelFocusHdl(sal_Bool bForward);
481 	SdrHdl* GetFocusHdl() const;
482 	void SetFocusHdl(SdrHdl* pNew);
483 	void ResetFocusHdl();
484 
485 	// Access to View
486 	SdrMarkView* GetView() const;
487 
488 	// Sortierung: 1.Level Erst Refpunkt-Handles, dann normale Handles, dann Glue, dann User, dann Plushandles
489 	//             2.Level PageView (Pointer)
490 	//             3.Level Position (x+y)
491 	void     Sort();
492 	sal_uIntPtr    GetHdlCount() const                       { return aList.Count(); }
493 	SdrHdl*  GetHdl(sal_uIntPtr nNum) const                  { return (SdrHdl*)(aList.GetObject(nNum)); }
494 	sal_uIntPtr    GetHdlNum(const SdrHdl* pHdl) const;
495 	void     SetHdlSize(sal_uInt16 nSiz);
496 	sal_uInt16   GetHdlSize() const                        { return nHdlSize; }
497 	void     SetMoveOutside(sal_Bool bOn);
498 	sal_Bool IsMoveOutside() const                     { return bMoveOutside; }
499 	void     SetRotateShear(sal_Bool bOn);
500 	sal_Bool IsRotateShear() const                     { return bRotateShear; }
501 	void     SetDistortShear(sal_Bool bOn);
502 	sal_Bool IsDistortShear() const                    { return bDistortShear; }
503 	void     SetFineHdl(sal_Bool bOn);
504 	sal_Bool IsFineHdl() const                        { return bFineHandles; }
505 
506 	// AddHdl uebernimmt das Handle in sein Eigentum. Es muss
507 	// also auf dem Heap stehen, da Clear() ein delete macht.
508 	void    AddHdl(SdrHdl* pHdl, sal_Bool bAtBegin=sal_False);
509 	SdrHdl* RemoveHdl(sal_uIntPtr nNum);
510 
511 	// Zuletzt eingefuegte Handles werden am ehesten getroffen
512 	// (wenn Handles uebereinander liegen).
513 	SdrHdl* IsHdlListHit(const Point& rPnt, sal_Bool bBack=sal_False, sal_Bool bNext=sal_False, SdrHdl* pHdl0=NULL) const;
514 	SdrHdl* GetHdl(SdrHdlKind eKind1) const;
515 };
516 
517 ////////////////////////////////////////////////////////////////////////////////////////////////////
518 
519 class SVX_DLLPUBLIC SdrCropHdl : public SdrHdl
520 {
521 public:
522 	SdrCropHdl(const Point& rPnt, SdrHdlKind eNewKind);
523 
524 protected:
525 	// create marker for this kind
526 	virtual void CreateB2dIAObject();
527 
528 	BitmapEx GetBitmapForHandle( const BitmapEx& rBitmap, int nSize );
529 
530 	static BitmapEx GetHandlesBitmap( bool bIsFineHdl, bool bIsHighContrast );
531 };
532 
533 #endif //_SVDHDL_HXX
534 
535