]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dragimag.h
Allow to customize wxGrid column auto-sizing.
[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 #if wxUSE_DRAGIMAGE
17
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
24 // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
25 #define wxUSE_SIMPLER_DRAGIMAGE 0
26
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__
33 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWidgets
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
102 class WXDLLIMPEXP_CORE wxDragImage: public wxObject
103 {
104 public:
105
106 // Ctors & dtor
107 ////////////////////////////////////////////////////////////////////////////
108
109 wxDragImage();
110 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
111 {
112 Init();
113
114 Create(image, cursor);
115 }
116
117 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
118 {
119 Init();
120
121 Create(image, cursor);
122 }
123
124 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
125 {
126 Init();
127
128 Create(str, cursor);
129 }
130
131 #if wxUSE_TREECTRL
132 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
133 {
134 Init();
135
136 Create(treeCtrl, id);
137 }
138 #endif
139
140 #if wxUSE_LISTCTRL
141 wxDragImage(const wxListCtrl& listCtrl, long id)
142 {
143 Init();
144
145 Create(listCtrl, id);
146 }
147 #endif
148
149 virtual ~wxDragImage();
150
151 // Attributes
152 ////////////////////////////////////////////////////////////////////////////
153
154 // Operations
155 ////////////////////////////////////////////////////////////////////////////
156
157 // Create a drag image from a bitmap and optional cursor
158 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
159
160 // Create a drag image from an icon and optional cursor
161 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
162
163 // Create a drag image from a string and optional cursor
164 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
165
166 #if wxUSE_TREECTRL
167 // Create a drag image for the given tree control item
168 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
169 #endif
170
171 #if wxUSE_LISTCTRL
172 // Create a drag image for the given list control item
173 bool Create(const wxListCtrl& listCtrl, long id);
174 #endif
175
176 // Begin drag. hotspot is the location of the drag position relative to the upper-left
177 // corner of the image.
178 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = NULL);
179
180 // Begin drag. hotspot is the location of the drag position relative to the upper-left
181 // corner of the image. This is full screen only. fullScreenRect gives the
182 // position of the window on the screen, to restrict the drag to.
183 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
184
185 // End drag
186 bool EndDrag();
187
188 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
189 // is non-NULL, or in screen coordinates if NULL.
190 bool Move(const wxPoint& pt);
191
192 // Show the image
193 bool Show();
194
195 // Hide the image
196 bool Hide();
197
198 // Implementation
199 ////////////////////////////////////////////////////////////////////////////
200
201 // Initialize variables
202 void Init();
203
204 // Returns the native image list handle
205 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
206
207 #if !wxUSE_SIMPLER_DRAGIMAGE
208 // Returns the native image list handle for the cursor
209 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
210 #endif
211
212 // don't use in new code, use versions without hot spot parameter
213 #if WXWIN_COMPATIBILITY_2_8
214 wxDEPRECATED_CONSTRUCTOR( wxDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
215 wxDEPRECATED_CONSTRUCTOR( wxDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot) );
216 wxDEPRECATED_CONSTRUCTOR( wxDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
217 wxDEPRECATED( bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
218 wxDEPRECATED( bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
219 wxDEPRECATED( bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot) );
220 #endif // WXWIN_COMPATIBILITY_2_8
221
222 protected:
223 WXHIMAGELIST m_hImageList;
224
225 #if wxUSE_SIMPLER_DRAGIMAGE
226 wxCursor m_oldCursor;
227 #else
228 WXHIMAGELIST m_hCursorImageList;
229 #endif
230
231 wxCursor m_cursor;
232 // wxPoint m_cursorHotspot; // Obsolete
233 wxPoint m_position;
234 wxWindow* m_window;
235 wxRect m_boundingRect;
236 bool m_fullScreen;
237
238 private:
239 DECLARE_DYNAMIC_CLASS(wxDragImage)
240 wxDECLARE_NO_COPY_CLASS(wxDragImage);
241 };
242
243 #endif // wxUSE_DRAGIMAGE
244 #endif
245 // _WX_DRAGIMAG_H_