]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dragimag.h
Further performance optimizations
[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
65571936 10// Licence: wxWindows licence
7cf83330
JS
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_DRAGIMAG_H_
14#define _WX_DRAGIMAG_H_
15
93344f25
PC
16#if wxUSE_DRAGIMAGE
17
7cf83330
JS
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
aa2d25a5
JS
24// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
25#define wxUSE_SIMPLER_DRAGIMAGE 0
6ea5c52d 26
7cf83330
JS
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__
77ffb593 33 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWidgets
7cf83330
JS
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
53a2db12 102class WXDLLIMPEXP_CORE wxDragImage: public wxObject
7cf83330 103{
7cf83330 104public:
23f681ec 105
7cf83330
JS
106 // Ctors & dtor
107 ////////////////////////////////////////////////////////////////////////////
108
109 wxDragImage();
aa2d25a5
JS
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)
7cf83330 119 {
68be9f09
JS
120 Init();
121
6ea5c52d 122 Create(image, cursor, cursorHotspot);
7cf83330 123 }
aa2d25a5
JS
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)
7cf83330 134 {
68be9f09
JS
135 Init();
136
6ea5c52d 137 Create(image, cursor, cursorHotspot);
7cf83330 138 }
aa2d25a5
JS
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)
7cf83330 149 {
68be9f09
JS
150 Init();
151
6ea5c52d 152 Create(str, cursor, cursorHotspot);
7cf83330 153 }
aa2d25a5 154
3080bf59 155#if wxUSE_TREECTRL
7cf83330
JS
156 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
157 {
68be9f09
JS
158 Init();
159
7cf83330
JS
160 Create(treeCtrl, id);
161 }
3080bf59 162#endif
aa2d25a5 163
3080bf59 164#if wxUSE_LISTCTRL
7cf83330
JS
165 wxDragImage(const wxListCtrl& listCtrl, long id)
166 {
68be9f09
JS
167 Init();
168
7cf83330
JS
169 Create(listCtrl, id);
170 }
3080bf59 171#endif
aa2d25a5 172
d3c7fc99 173 virtual ~wxDragImage();
23f681ec 174
7cf83330
JS
175 // Attributes
176 ////////////////////////////////////////////////////////////////////////////
23f681ec 177
7cf83330
JS
178 // Operations
179 ////////////////////////////////////////////////////////////////////////////
23f681ec 180
7cf83330 181 // Create a drag image from a bitmap and optional cursor
aa2d25a5
JS
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 }
23f681ec 188
7cf83330 189 // Create a drag image from an icon and optional cursor
aa2d25a5
JS
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 }
23f681ec 196
7cf83330 197 // Create a drag image from a string and optional cursor
aa2d25a5
JS
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 }
7cf83330 204
3080bf59 205#if wxUSE_TREECTRL
7cf83330
JS
206 // Create a drag image for the given tree control item
207 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
3080bf59 208#endif
7cf83330 209
3080bf59 210#if wxUSE_LISTCTRL
7cf83330
JS
211 // Create a drag image for the given list control item
212 bool Create(const wxListCtrl& listCtrl, long id);
3080bf59 213#endif
7cf83330
JS
214
215 // Begin drag. hotspot is the location of the drag position relative to the upper-left
216 // corner of the image.
d71cc120 217 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = (wxRect*) NULL);
68be9f09
JS
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);
23f681ec 223
7cf83330 224 // End drag
68be9f09 225 bool EndDrag();
23f681ec 226
7cf83330
JS
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.
68be9f09 229 bool Move(const wxPoint& pt);
7cf83330
JS
230
231 // Show the image
68be9f09 232 bool Show();
7cf83330
JS
233
234 // Hide the image
68be9f09 235 bool Hide();
23f681ec 236
7cf83330
JS
237 // Implementation
238 ////////////////////////////////////////////////////////////////////////////
23f681ec 239
68be9f09
JS
240 // Initialize variables
241 void Init();
242
7cf83330 243 // Returns the native image list handle
23f681ec
VZ
244 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
245
6ea5c52d 246#if !wxUSE_SIMPLER_DRAGIMAGE
68be9f09
JS
247 // Returns the native image list handle for the cursor
248 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
6ea5c52d 249#endif
68be9f09 250
7cf83330
JS
251protected:
252 WXHIMAGELIST m_hImageList;
6ea5c52d
JS
253
254#if wxUSE_SIMPLER_DRAGIMAGE
255 wxCursor m_oldCursor;
256#else
68be9f09 257 WXHIMAGELIST m_hCursorImageList;
6ea5c52d
JS
258#endif
259
7cf83330 260 wxCursor m_cursor;
aa2d25a5 261// wxPoint m_cursorHotspot; // Obsolete
7cf83330 262 wxPoint m_position;
68be9f09
JS
263 wxWindow* m_window;
264 wxRect m_boundingRect;
265 bool m_fullScreen;
23f681ec
VZ
266
267private:
268 DECLARE_DYNAMIC_CLASS(wxDragImage)
22f3361e 269 DECLARE_NO_COPY_CLASS(wxDragImage)
7cf83330
JS
270};
271
93344f25 272#endif // wxUSE_DRAGIMAGE
7cf83330
JS
273#endif
274 // _WX_DRAGIMAG_H_