]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dragimag.h
Generate correct events for extended keys in wxMSW wxUIActionSimulator.
[wxWidgets.git] / include / wx / msw / dragimag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/dragimag.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: 08/04/99
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_DRAGIMAG_H_
14 #define _WX_DRAGIMAG_H_
15
16 #if wxUSE_DRAGIMAGE
17
18 #include "wx/bitmap.h"
19 #include "wx/icon.h"
20 #include "wx/cursor.h"
21 #include "wx/treectrl.h"
22 #include "wx/listctrl.h"
23
24 // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
25 #define wxUSE_SIMPLER_DRAGIMAGE 0
26
27 /*
28 To use this class, create a wxDragImage when you start dragging, for example:
29
30 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
31 {
32 #ifdef __WXMSW__
33 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWidgets
34 #endif
35
36 CaptureMouse();
37
38 m_dragImage = new wxDragImage(* this, itemId);
39 m_dragImage->BeginDrag(wxPoint(0, 0), this);
40 m_dragImage->Move(pt, this);
41 m_dragImage->Show(this);
42 ...
43 }
44
45 In your OnMouseMove function, hide the image, do any display updating required,
46 then move and show the image again:
47
48 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
49 {
50 if (m_dragMode == MY_TREE_DRAG_NONE)
51 {
52 event.Skip();
53 return;
54 }
55
56 // Prevent screen corruption by hiding the image
57 if (m_dragImage)
58 m_dragImage->Hide(this);
59
60 // Do some updating of the window, such as highlighting the drop target
61 ...
62
63 #ifdef __WXMSW__
64 if (updateWindow)
65 ::UpdateWindow((HWND) GetHWND());
66 #endif
67
68 // Move and show the image again
69 m_dragImage->Move(event.GetPosition(), this);
70 m_dragImage->Show(this);
71 }
72
73 Eventually we end the drag and delete the drag image.
74
75 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
76 {
77 ...
78
79 // End the drag and delete the drag image
80 if (m_dragImage)
81 {
82 m_dragImage->EndDrag(this);
83 delete m_dragImage;
84 m_dragImage = NULL;
85 }
86 ReleaseMouse();
87 }
88 */
89
90 /*
91 Notes for Unix version:
92 Can we simply use cursors instead, creating a cursor dynamically, setting it into the window
93 in BeginDrag, and restoring the old cursor in EndDrag?
94 For a really bog-standard implementation, we could simply use a normal dragging cursor
95 and ignore the image.
96 */
97
98 /*
99 * wxDragImage
100 */
101
102 class WXDLLIMPEXP_CORE wxDragImage: public wxObject
103 {
104 public:
105
106 // Ctors & dtor
107 ////////////////////////////////////////////////////////////////////////////
108
109 wxDragImage();
110 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
111 {
112 Init();
113
114 Create(image, cursor);
115 }
116
117 // Deprecated form of the above
118 wxDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
119 {
120 Init();
121
122 Create(image, cursor, cursorHotspot);
123 }
124
125 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
126 {
127 Init();
128
129 Create(image, cursor);
130 }
131
132 // Deprecated form of the above
133 wxDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
134 {
135 Init();
136
137 Create(image, cursor, cursorHotspot);
138 }
139
140 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
141 {
142 Init();
143
144 Create(str, cursor);
145 }
146
147 // Deprecated form of the above
148 wxDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
149 {
150 Init();
151
152 Create(str, cursor, cursorHotspot);
153 }
154
155 #if wxUSE_TREECTRL
156 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
157 {
158 Init();
159
160 Create(treeCtrl, id);
161 }
162 #endif
163
164 #if wxUSE_LISTCTRL
165 wxDragImage(const wxListCtrl& listCtrl, long id)
166 {
167 Init();
168
169 Create(listCtrl, id);
170 }
171 #endif
172
173 virtual ~wxDragImage();
174
175 // Attributes
176 ////////////////////////////////////////////////////////////////////////////
177
178 // Operations
179 ////////////////////////////////////////////////////////////////////////////
180
181 // Create a drag image from a bitmap and optional cursor
182 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
183 bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
184 {
185 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
186 return Create(image, cursor);
187 }
188
189 // Create a drag image from an icon and optional cursor
190 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
191 bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
192 {
193 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
194 return Create(image, cursor);
195 }
196
197 // Create a drag image from a string and optional cursor
198 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
199 bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
200 {
201 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
202 return Create(str, cursor);
203 }
204
205 #if wxUSE_TREECTRL
206 // Create a drag image for the given tree control item
207 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
208 #endif
209
210 #if wxUSE_LISTCTRL
211 // Create a drag image for the given list control item
212 bool Create(const wxListCtrl& listCtrl, long id);
213 #endif
214
215 // Begin drag. hotspot is the location of the drag position relative to the upper-left
216 // corner of the image.
217 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = NULL);
218
219 // Begin drag. hotspot is the location of the drag position relative to the upper-left
220 // corner of the image. This is full screen only. fullScreenRect gives the
221 // position of the window on the screen, to restrict the drag to.
222 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
223
224 // End drag
225 bool EndDrag();
226
227 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
228 // is non-NULL, or in screen coordinates if NULL.
229 bool Move(const wxPoint& pt);
230
231 // Show the image
232 bool Show();
233
234 // Hide the image
235 bool Hide();
236
237 // Implementation
238 ////////////////////////////////////////////////////////////////////////////
239
240 // Initialize variables
241 void Init();
242
243 // Returns the native image list handle
244 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
245
246 #if !wxUSE_SIMPLER_DRAGIMAGE
247 // Returns the native image list handle for the cursor
248 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
249 #endif
250
251 protected:
252 WXHIMAGELIST m_hImageList;
253
254 #if wxUSE_SIMPLER_DRAGIMAGE
255 wxCursor m_oldCursor;
256 #else
257 WXHIMAGELIST m_hCursorImageList;
258 #endif
259
260 wxCursor m_cursor;
261 // wxPoint m_cursorHotspot; // Obsolete
262 wxPoint m_position;
263 wxWindow* m_window;
264 wxRect m_boundingRect;
265 bool m_fullScreen;
266
267 private:
268 DECLARE_DYNAMIC_CLASS(wxDragImage)
269 wxDECLARE_NO_COPY_CLASS(wxDragImage);
270 };
271
272 #endif // wxUSE_DRAGIMAGE
273 #endif
274 // _WX_DRAGIMAG_H_