]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dragimgg.h
declare the wx2os2PenStyle helper in the header.
[wxWidgets.git] / include / wx / generic / dragimgg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dragimgg.h
3 // Purpose: wxDragImage class: a kind of a cursor, that can cope
4 // with more sophisticated images
5 // Author: Julian Smart
6 // Modified by:
7 // Created: 29/2/2000
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_DRAGIMGG_H_
14 #define _WX_DRAGIMGG_H_
15
16 #ifdef __GNUG__
17 #pragma interface "dragimgg.h"
18 #endif
19
20 #include "wx/bitmap.h"
21 #include "wx/icon.h"
22 #include "wx/cursor.h"
23 #include "wx/treectrl.h"
24 #include "wx/listctrl.h"
25
26 /*
27 To use this class, create a wxDragImage when you start dragging, for example:
28
29 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
30 {
31 #ifdef __WXMSW__
32 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWindows
33 #endif
34
35 CaptureMouse();
36
37 m_dragImage = new wxDragImage(* this, itemId);
38 m_dragImage->BeginDrag(wxPoint(0, 0), this);
39 m_dragImage->Move(pt, this);
40 m_dragImage->Show(this);
41 ...
42 }
43
44 In your OnMouseMove function, hide the image, do any display updating required,
45 then move and show the image again:
46
47 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
48 {
49 if (m_dragMode == MY_TREE_DRAG_NONE)
50 {
51 event.Skip();
52 return;
53 }
54
55 // Prevent screen corruption by hiding the image
56 if (m_dragImage)
57 m_dragImage->Hide(this);
58
59 // Do some updating of the window, such as highlighting the drop target
60 ...
61
62 #ifdef __WXMSW__
63 if (updateWindow)
64 ::UpdateWindow((HWND) GetHWND());
65 #endif
66
67 // Move and show the image again
68 m_dragImage->Move(event.GetPosition(), this);
69 m_dragImage->Show(this);
70 }
71
72 Eventually we end the drag and delete the drag image.
73
74 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
75 {
76 ...
77
78 // End the drag and delete the drag image
79 if (m_dragImage)
80 {
81 m_dragImage->EndDrag(this);
82 delete m_dragImage;
83 m_dragImage = NULL;
84 }
85 ReleaseMouse();
86 }
87 */
88
89 /*
90 * wxGenericDragImage
91 */
92
93 class WXDLLEXPORT wxGenericDragImage: public wxObject
94 {
95 public:
96
97 // Ctors & dtor
98 ////////////////////////////////////////////////////////////////////////////
99
100 wxGenericDragImage(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
101 {
102 Init();
103 Create(cursor, hotspot);
104 }
105 wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
106 {
107 Init();
108
109 Create(image, cursor, hotspot);
110 }
111 wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
112 {
113 Init();
114
115 Create(image, cursor, hotspot);
116 }
117 wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
118 {
119 Init();
120
121 Create(str, cursor, hotspot);
122 }
123 wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
124 {
125 Init();
126
127 Create(treeCtrl, id);
128 }
129 wxGenericDragImage(const wxListCtrl& listCtrl, long id)
130 {
131 Init();
132
133 Create(listCtrl, id);
134 }
135 ~wxGenericDragImage();
136
137 // Attributes
138 ////////////////////////////////////////////////////////////////////////////
139
140 // For efficiency, tell wxGenericDragImage to use a bitmap that's already
141 // created (e.g. from last drag)
142 void SetBackingBitmap(wxBitmap* bitmap) { m_pBackingBitmap = bitmap; }
143
144 // Operations
145 ////////////////////////////////////////////////////////////////////////////
146
147 // Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
148 bool Create(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
149
150 // Create a drag image from a bitmap and optional cursor
151 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
152
153 // Create a drag image from an icon and optional cursor
154 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
155
156 // Create a drag image from a string and optional cursor
157 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
158
159 // Create a drag image for the given tree control item
160 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
161
162 // Create a drag image for the given list control item
163 bool Create(const wxListCtrl& listCtrl, long id);
164
165 // Begin drag. hotspot is the location of the drag position relative to the upper-left
166 // corner of the image.
167 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = FALSE, wxRect* rect = (wxRect*) NULL);
168
169 // Begin drag. hotspot is the location of the drag position relative to the upper-left
170 // corner of the image. This is full screen only. fullScreenRect gives the
171 // position of the window on the screen, to restrict the drag to.
172 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
173
174 // End drag
175 bool EndDrag();
176
177 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
178 // is non-NULL, or in screen coordinates if NULL.
179 bool Move(const wxPoint& pt);
180
181 // Show the image
182 bool Show();
183
184 // Hide the image
185 bool Hide();
186
187 // Implementation
188 ////////////////////////////////////////////////////////////////////////////
189
190 void Init();
191
192 // Override this if you are using a virtual image (drawing your own image)
193 virtual wxRect GetImageRect(const wxPoint& pos) const;
194
195 // Override this if you are using a virtual image (drawing your own image)
196 virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
197
198 // Override this if you wish to draw the window contents to the backing bitmap
199 // yourself. This can be desirable if you wish to avoid flicker by not having to
200 // redraw the window itself before dragging in order to be graphic-minus-dragged-objects.
201 // Instead, paint the drag image's backing bitmap to be correct, and leave the window
202 // to be updated only when dragging the objects away (thus giving a smoother appearance).
203 virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
204 const wxRect& sourceRect, const wxRect& destRect) const;
205
206 // Erase and redraw simultaneously if possible
207 virtual bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew);
208
209 protected:
210 wxBitmap m_bitmap;
211 wxIcon m_icon;
212 wxCursor m_cursor;
213 wxCursor m_oldCursor;
214 wxPoint m_hotspot;
215 wxPoint m_offset; // The hostpot value passed to BeginDrag
216 wxPoint m_position;
217 bool m_isDirty;
218 bool m_isShown;
219 wxWindow* m_window;
220 wxDC* m_windowDC;
221
222 // Stores the window contents while we're dragging the image around
223 wxBitmap m_backingBitmap;
224 wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap
225 // (pass to wxGenericDragImage as an efficiency measure)
226 // A temporary bitmap for repairing/redrawing
227 wxBitmap m_repairBitmap;
228
229 wxRect m_boundingRect;
230 bool m_fullScreen;
231
232 private:
233 DECLARE_DYNAMIC_CLASS(wxGenericDragImage)
234 };
235
236 #endif
237 // _WX_DRAGIMGG_H_