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