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