]> git.saurik.com Git - wxWidgets.git/blob - include/wx/palmos/dragimag.h
added wxDynamicLibrary::GetSymbolAorW()
[wxWidgets.git] / include / wx / palmos / dragimag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/dragimag.h
3 // Purpose: wxDragImage class: a kind of a cursor, that can cope
4 // with more sophisticated images
5 // Author: William Osborne - minimal working wxPalmOS port
6 // Modified by:
7 // Created: 10/13/04
8 // RCS-ID: $Id$
9 // Copyright: (c) William Osborne
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_DRAGIMAG_H_
14 #define _WX_DRAGIMAG_H_
15
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #define wxUSE_SIMPLER_DRAGIMAGE 0
28
29 /*
30 To use this class, create a wxDragImage when you start dragging, for example:
31
32 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
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 // Move and show the image again
62 m_dragImage->Move(event.GetPosition(), this);
63 m_dragImage->Show(this);
64 }
65
66 Eventually we end the drag and delete the drag image.
67
68 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
69 {
70 ...
71
72 // End the drag and delete the drag image
73 if (m_dragImage)
74 {
75 m_dragImage->EndDrag(this);
76 delete m_dragImage;
77 m_dragImage = NULL;
78 }
79 ReleaseMouse();
80 }
81 */
82
83 /*
84 Notes for Unix version:
85 Can we simply use cursors instead, creating a cursor dynamically, setting it into the window
86 in BeginDrag, and restoring the old cursor in EndDrag?
87 For a really bog-standard implementation, we could simply use a normal dragging cursor
88 and ignore the image.
89 */
90
91 /*
92 * wxDragImage
93 */
94
95 class WXDLLEXPORT wxDragImage: public wxObject
96 {
97 public:
98
99 // Ctors & dtor
100 ////////////////////////////////////////////////////////////////////////////
101
102 wxDragImage();
103 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
104 {
105 Init();
106
107 Create(image, cursor);
108 }
109
110 // Deprecated form of the above
111 wxDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
112 {
113 Init();
114
115 Create(image, cursor, cursorHotspot);
116 }
117
118 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
119 {
120 Init();
121
122 Create(image, cursor);
123 }
124
125 // Deprecated form of the above
126 wxDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
127 {
128 Init();
129
130 Create(image, cursor, cursorHotspot);
131 }
132
133 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
134 {
135 Init();
136
137 Create(str, cursor);
138 }
139
140 // Deprecated form of the above
141 wxDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
142 {
143 Init();
144
145 Create(str, cursor, cursorHotspot);
146 }
147
148 #if wxUSE_TREECTRL
149 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
150 {
151 Init();
152
153 Create(treeCtrl, id);
154 }
155 #endif
156
157 #if wxUSE_LISTCTRL
158 wxDragImage(const wxListCtrl& listCtrl, long id)
159 {
160 Init();
161
162 Create(listCtrl, id);
163 }
164 #endif
165
166 ~wxDragImage();
167
168 // Attributes
169 ////////////////////////////////////////////////////////////////////////////
170
171 // Operations
172 ////////////////////////////////////////////////////////////////////////////
173
174 // Create a drag image from a bitmap and optional cursor
175 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
176 bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
177 {
178 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
179 return Create(image, cursor);
180 }
181
182 // Create a drag image from an icon and optional cursor
183 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
184 bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
185 {
186 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
187 return Create(image, cursor);
188 }
189
190 // Create a drag image from a string and optional cursor
191 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
192 bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
193 {
194 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
195 return Create(str, cursor);
196 }
197
198 #if wxUSE_TREECTRL
199 // Create a drag image for the given tree control item
200 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
201 #endif
202
203 #if wxUSE_LISTCTRL
204 // Create a drag image for the given list control item
205 bool Create(const wxListCtrl& listCtrl, long id);
206 #endif
207
208 // Begin drag. hotspot is the location of the drag position relative to the upper-left
209 // corner of the image.
210 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = (wxRect*) NULL);
211
212 // Begin drag. hotspot is the location of the drag position relative to the upper-left
213 // corner of the image. This is full screen only. fullScreenRect gives the
214 // position of the window on the screen, to restrict the drag to.
215 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
216
217 // End drag
218 bool EndDrag();
219
220 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
221 // is non-NULL, or in screen coordinates if NULL.
222 bool Move(const wxPoint& pt);
223
224 // Show the image
225 bool Show();
226
227 // Hide the image
228 bool Hide();
229
230 // Implementation
231 ////////////////////////////////////////////////////////////////////////////
232
233 // Initialize variables
234 void Init();
235
236 // Returns the native image list handle
237 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
238
239 #if !wxUSE_SIMPLER_DRAGIMAGE
240 // Returns the native image list handle for the cursor
241 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
242 #endif
243
244 protected:
245 WXHIMAGELIST m_hImageList;
246
247 #if wxUSE_SIMPLER_DRAGIMAGE
248 wxCursor m_oldCursor;
249 #else
250 WXHIMAGELIST m_hCursorImageList;
251 #endif
252
253 wxCursor m_cursor;
254 // wxPoint m_cursorHotspot; // Obsolete
255 wxPoint m_position;
256 wxWindow* m_window;
257 wxRect m_boundingRect;
258 bool m_fullScreen;
259
260 private:
261 DECLARE_DYNAMIC_CLASS(wxDragImage)
262 DECLARE_NO_COPY_CLASS(wxDragImage)
263 };
264
265 #endif
266 // _WX_DRAGIMAG_H_