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