]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dragimag.h
moved wxUSE_MS_HTML_HELP to MSW-specific setup.h, it's not used on other platforms
[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
7cf83330
JS
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
aa2d25a5
JS
22// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
23#define wxUSE_SIMPLER_DRAGIMAGE 0
6ea5c52d 24
7cf83330
JS
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__
77ffb593 31 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWidgets
7cf83330
JS
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
100class WXDLLEXPORT wxDragImage: public wxObject
101{
7cf83330 102public:
23f681ec 103
7cf83330
JS
104 // Ctors & dtor
105 ////////////////////////////////////////////////////////////////////////////
106
107 wxDragImage();
aa2d25a5
JS
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)
7cf83330 117 {
68be9f09
JS
118 Init();
119
6ea5c52d 120 Create(image, cursor, cursorHotspot);
7cf83330 121 }
aa2d25a5
JS
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)
7cf83330 132 {
68be9f09
JS
133 Init();
134
6ea5c52d 135 Create(image, cursor, cursorHotspot);
7cf83330 136 }
aa2d25a5
JS
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)
7cf83330 147 {
68be9f09
JS
148 Init();
149
6ea5c52d 150 Create(str, cursor, cursorHotspot);
7cf83330 151 }
aa2d25a5 152
3080bf59 153#if wxUSE_TREECTRL
7cf83330
JS
154 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
155 {
68be9f09
JS
156 Init();
157
7cf83330
JS
158 Create(treeCtrl, id);
159 }
3080bf59 160#endif
aa2d25a5 161
3080bf59 162#if wxUSE_LISTCTRL
7cf83330
JS
163 wxDragImage(const wxListCtrl& listCtrl, long id)
164 {
68be9f09
JS
165 Init();
166
7cf83330
JS
167 Create(listCtrl, id);
168 }
3080bf59 169#endif
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 202
3080bf59 203#if wxUSE_TREECTRL
7cf83330
JS
204 // Create a drag image for the given tree control item
205 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
3080bf59 206#endif
7cf83330 207
3080bf59 208#if wxUSE_LISTCTRL
7cf83330
JS
209 // Create a drag image for the given list control item
210 bool Create(const wxListCtrl& listCtrl, long id);
3080bf59 211#endif
7cf83330
JS
212
213 // Begin drag. hotspot is the location of the drag position relative to the upper-left
214 // corner of the image.
d71cc120 215 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = (wxRect*) NULL);
68be9f09
JS
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);
23f681ec 221
7cf83330 222 // End drag
68be9f09 223 bool EndDrag();
23f681ec 224
7cf83330
JS
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.
68be9f09 227 bool Move(const wxPoint& pt);
7cf83330
JS
228
229 // Show the image
68be9f09 230 bool Show();
7cf83330
JS
231
232 // Hide the image
68be9f09 233 bool Hide();
23f681ec 234
7cf83330
JS
235 // Implementation
236 ////////////////////////////////////////////////////////////////////////////
23f681ec 237
68be9f09
JS
238 // Initialize variables
239 void Init();
240
7cf83330 241 // Returns the native image list handle
23f681ec
VZ
242 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
243
6ea5c52d 244#if !wxUSE_SIMPLER_DRAGIMAGE
68be9f09
JS
245 // Returns the native image list handle for the cursor
246 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
6ea5c52d 247#endif
68be9f09 248
7cf83330
JS
249protected:
250 WXHIMAGELIST m_hImageList;
6ea5c52d
JS
251
252#if wxUSE_SIMPLER_DRAGIMAGE
253 wxCursor m_oldCursor;
254#else
68be9f09 255 WXHIMAGELIST m_hCursorImageList;
6ea5c52d
JS
256#endif
257
7cf83330 258 wxCursor m_cursor;
aa2d25a5 259// wxPoint m_cursorHotspot; // Obsolete
7cf83330 260 wxPoint m_position;
68be9f09
JS
261 wxWindow* m_window;
262 wxRect m_boundingRect;
263 bool m_fullScreen;
23f681ec
VZ
264
265private:
266 DECLARE_DYNAMIC_CLASS(wxDragImage)
22f3361e 267 DECLARE_NO_COPY_CLASS(wxDragImage)
7cf83330
JS
268};
269
270#endif
271 // _WX_DRAGIMAG_H_