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