]>
Commit | Line | Data |
---|---|---|
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 | |
7cf83330 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
7cf83330 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_DRAGIMAG_H_ | |
13 | #define _WX_DRAGIMAG_H_ | |
14 | ||
93344f25 PC |
15 | #if wxUSE_DRAGIMAGE |
16 | ||
7cf83330 JS |
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 | ||
aa2d25a5 JS |
23 | // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage |
24 | #define wxUSE_SIMPLER_DRAGIMAGE 0 | |
6ea5c52d | 25 | |
7cf83330 JS |
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__ | |
77ffb593 | 32 | ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWidgets |
7cf83330 JS |
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 | ||
53a2db12 | 101 | class WXDLLIMPEXP_CORE wxDragImage: public wxObject |
7cf83330 | 102 | { |
7cf83330 | 103 | public: |
23f681ec | 104 | |
7cf83330 JS |
105 | // Ctors & dtor |
106 | //////////////////////////////////////////////////////////////////////////// | |
107 | ||
108 | wxDragImage(); | |
aa2d25a5 JS |
109 | wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor) |
110 | { | |
111 | Init(); | |
112 | ||
113 | Create(image, cursor); | |
114 | } | |
115 | ||
aa2d25a5 JS |
116 | wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor) |
117 | { | |
118 | Init(); | |
119 | ||
120 | Create(image, cursor); | |
121 | } | |
122 | ||
aa2d25a5 JS |
123 | wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor) |
124 | { | |
125 | Init(); | |
126 | ||
127 | Create(str, cursor); | |
128 | } | |
129 | ||
3080bf59 | 130 | #if wxUSE_TREECTRL |
7cf83330 JS |
131 | wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) |
132 | { | |
68be9f09 JS |
133 | Init(); |
134 | ||
7cf83330 JS |
135 | Create(treeCtrl, id); |
136 | } | |
3080bf59 | 137 | #endif |
aa2d25a5 | 138 | |
3080bf59 | 139 | #if wxUSE_LISTCTRL |
7cf83330 JS |
140 | wxDragImage(const wxListCtrl& listCtrl, long id) |
141 | { | |
68be9f09 JS |
142 | Init(); |
143 | ||
7cf83330 JS |
144 | Create(listCtrl, id); |
145 | } | |
3080bf59 | 146 | #endif |
aa2d25a5 | 147 | |
d3c7fc99 | 148 | virtual ~wxDragImage(); |
23f681ec | 149 | |
7cf83330 JS |
150 | // Attributes |
151 | //////////////////////////////////////////////////////////////////////////// | |
23f681ec | 152 | |
7cf83330 JS |
153 | // Operations |
154 | //////////////////////////////////////////////////////////////////////////// | |
23f681ec | 155 | |
7cf83330 | 156 | // Create a drag image from a bitmap and optional cursor |
aa2d25a5 | 157 | bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor); |
23f681ec | 158 | |
7cf83330 | 159 | // Create a drag image from an icon and optional cursor |
aa2d25a5 | 160 | bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor); |
23f681ec | 161 | |
7cf83330 | 162 | // Create a drag image from a string and optional cursor |
aa2d25a5 | 163 | bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor); |
7cf83330 | 164 | |
3080bf59 | 165 | #if wxUSE_TREECTRL |
7cf83330 JS |
166 | // Create a drag image for the given tree control item |
167 | bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id); | |
3080bf59 | 168 | #endif |
7cf83330 | 169 | |
3080bf59 | 170 | #if wxUSE_LISTCTRL |
7cf83330 JS |
171 | // Create a drag image for the given list control item |
172 | bool Create(const wxListCtrl& listCtrl, long id); | |
3080bf59 | 173 | #endif |
7cf83330 JS |
174 | |
175 | // Begin drag. hotspot is the location of the drag position relative to the upper-left | |
176 | // corner of the image. | |
d3b9f782 | 177 | bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = NULL); |
68be9f09 JS |
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); | |
23f681ec | 183 | |
7cf83330 | 184 | // End drag |
68be9f09 | 185 | bool EndDrag(); |
23f681ec | 186 | |
7cf83330 JS |
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. | |
68be9f09 | 189 | bool Move(const wxPoint& pt); |
7cf83330 JS |
190 | |
191 | // Show the image | |
68be9f09 | 192 | bool Show(); |
7cf83330 JS |
193 | |
194 | // Hide the image | |
68be9f09 | 195 | bool Hide(); |
23f681ec | 196 | |
7cf83330 JS |
197 | // Implementation |
198 | //////////////////////////////////////////////////////////////////////////// | |
23f681ec | 199 | |
68be9f09 JS |
200 | // Initialize variables |
201 | void Init(); | |
202 | ||
7cf83330 | 203 | // Returns the native image list handle |
23f681ec VZ |
204 | WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; } |
205 | ||
6ea5c52d | 206 | #if !wxUSE_SIMPLER_DRAGIMAGE |
68be9f09 JS |
207 | // Returns the native image list handle for the cursor |
208 | WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; } | |
6ea5c52d | 209 | #endif |
68be9f09 | 210 | |
82b30473 VZ |
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 | ||
7cf83330 JS |
221 | protected: |
222 | WXHIMAGELIST m_hImageList; | |
6ea5c52d JS |
223 | |
224 | #if wxUSE_SIMPLER_DRAGIMAGE | |
225 | wxCursor m_oldCursor; | |
226 | #else | |
68be9f09 | 227 | WXHIMAGELIST m_hCursorImageList; |
6ea5c52d JS |
228 | #endif |
229 | ||
7cf83330 | 230 | wxCursor m_cursor; |
aa2d25a5 | 231 | // wxPoint m_cursorHotspot; // Obsolete |
7cf83330 | 232 | wxPoint m_position; |
68be9f09 JS |
233 | wxWindow* m_window; |
234 | wxRect m_boundingRect; | |
235 | bool m_fullScreen; | |
23f681ec VZ |
236 | |
237 | private: | |
238 | DECLARE_DYNAMIC_CLASS(wxDragImage) | |
c0c133e1 | 239 | wxDECLARE_NO_COPY_CLASS(wxDragImage); |
7cf83330 JS |
240 | }; |
241 | ||
93344f25 | 242 | #endif // wxUSE_DRAGIMAGE |
7cf83330 JS |
243 | #endif |
244 | // _WX_DRAGIMAG_H_ |