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