Implemented Chuck Messenger's naming and simplification improvements,
[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 #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
26 // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage,
27 // and some other simplifications
28 #define wxUSE_SIMPLER_DRAGIMAGE 1
29
30 /*
31 To use this class, create a wxDragImage when you start dragging, for example:
32
33 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
34 {
35 #ifdef __WXMSW__
36 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWindows
37 #endif
38
39 CaptureMouse();
40
41 m_dragImage = new wxDragImage(* this, itemId);
42 m_dragImage->BeginDrag(wxPoint(0, 0), this);
43 m_dragImage->Move(pt, this);
44 m_dragImage->Show(this);
45 ...
46 }
47
48 In your OnMouseMove function, hide the image, do any display updating required,
49 then move and show the image again:
50
51 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
52 {
53 if (m_dragMode == MY_TREE_DRAG_NONE)
54 {
55 event.Skip();
56 return;
57 }
58
59 // Prevent screen corruption by hiding the image
60 if (m_dragImage)
61 m_dragImage->Hide(this);
62
63 // Do some updating of the window, such as highlighting the drop target
64 ...
65
66 #ifdef __WXMSW__
67 if (updateWindow)
68 ::UpdateWindow((HWND) GetHWND());
69 #endif
70
71 // Move and show the image again
72 m_dragImage->Move(event.GetPosition(), this);
73 m_dragImage->Show(this);
74 }
75
76 Eventually we end the drag and delete the drag image.
77
78 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
79 {
80 ...
81
82 // End the drag and delete the drag image
83 if (m_dragImage)
84 {
85 m_dragImage->EndDrag(this);
86 delete m_dragImage;
87 m_dragImage = NULL;
88 }
89 ReleaseMouse();
90 }
91 */
92
93 /*
94 Notes for Unix version:
95 Can we simply use cursors instead, creating a cursor dynamically, setting it into the window
96 in BeginDrag, and restoring the old cursor in EndDrag?
97 For a really bog-standard implementation, we could simply use a normal dragging cursor
98 and ignore the image.
99 */
100
101 /*
102 * wxDragImage
103 */
104
105 class WXDLLEXPORT wxDragImage: public wxObject
106 {
107 public:
108
109 // Ctors & dtor
110 ////////////////////////////////////////////////////////////////////////////
111
112 wxDragImage();
113 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
114 {
115 Init();
116
117 Create(image, cursor, cursorHotspot);
118 }
119 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
120 {
121 Init();
122
123 Create(image, cursor, cursorHotspot);
124 }
125 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
126 {
127 Init();
128
129 Create(str, cursor, cursorHotspot);
130 }
131 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
132 {
133 Init();
134
135 Create(treeCtrl, id);
136 }
137 wxDragImage(const wxListCtrl& listCtrl, long id)
138 {
139 Init();
140
141 Create(listCtrl, id);
142 }
143 ~wxDragImage();
144
145 // Attributes
146 ////////////////////////////////////////////////////////////////////////////
147
148 // Operations
149 ////////////////////////////////////////////////////////////////////////////
150
151 // Create a drag image from a bitmap and optional cursor
152 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
153
154 // Create a drag image from an icon and optional cursor
155 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
156
157 // Create a drag image from a string and optional cursor
158 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
159
160 // Create a drag image for the given tree control item
161 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
162
163 // Create a drag image for the given list control item
164 bool Create(const wxListCtrl& listCtrl, long id);
165
166 // Begin drag. hotspot is the location of the drag position relative to the upper-left
167 // corner of the image.
168 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = FALSE, wxRect* rect = (wxRect*) NULL);
169
170 // Begin drag. hotspot is the location of the drag position relative to the upper-left
171 // corner of the image. This is full screen only. fullScreenRect gives the
172 // position of the window on the screen, to restrict the drag to.
173 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
174
175 // End drag
176 bool EndDrag();
177
178 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
179 // is non-NULL, or in screen coordinates if NULL.
180 bool Move(const wxPoint& pt);
181
182 // Show the image
183 bool Show();
184
185 // Hide the image
186 bool Hide();
187
188 // Implementation
189 ////////////////////////////////////////////////////////////////////////////
190
191 // Initialize variables
192 void Init();
193
194 // Returns the native image list handle
195 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
196
197 #if !wxUSE_SIMPLER_DRAGIMAGE
198 // Returns the native image list handle for the cursor
199 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
200 #endif
201
202 protected:
203 WXHIMAGELIST m_hImageList;
204
205 #if wxUSE_SIMPLER_DRAGIMAGE
206 wxCursor m_oldCursor;
207 #else
208 WXHIMAGELIST m_hCursorImageList;
209 #endif
210
211 wxCursor m_cursor;
212 wxPoint m_cursorHotspot;
213 wxPoint m_position;
214 wxWindow* m_window;
215 wxRect m_boundingRect;
216 bool m_fullScreen;
217
218 private:
219 DECLARE_DYNAMIC_CLASS(wxDragImage)
220 };
221
222 #endif
223 // _WX_DRAGIMAG_H_