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
9 // Copyright: (c) William Osborne
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_DRAGIMAG_H_
14 #define _WX_DRAGIMAG_H_
16 #include "wx/bitmap.h"
18 #include "wx/cursor.h"
19 #include "wx/treectrl.h"
20 #include "wx/listctrl.h"
22 // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
23 #define wxUSE_SIMPLER_DRAGIMAGE 0
26 To use this class, create a wxDragImage when you start dragging, for example:
28 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
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);
39 In your OnMouseMove function, hide the image, do any display updating required,
40 then move and show the image again:
42 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
44 if (m_dragMode == MY_TREE_DRAG_NONE)
50 // Prevent screen corruption by hiding the image
52 m_dragImage->Hide(this);
54 // Do some updating of the window, such as highlighting the drop target
57 // Move and show the image again
58 m_dragImage->Move(event.GetPosition(), this);
59 m_dragImage->Show(this);
62 Eventually we end the drag and delete the drag image.
64 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
68 // End the drag and delete the drag image
71 m_dragImage->EndDrag(this);
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
91 class WXDLLIMPEXP_CORE wxDragImage
: public wxObject
96 ////////////////////////////////////////////////////////////////////////////
99 wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
)
103 Create(image
, cursor
);
106 // Deprecated form of the above
107 wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
)
111 Create(image
, cursor
, cursorHotspot
);
114 wxDragImage(const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
)
118 Create(image
, cursor
);
121 // Deprecated form of the above
122 wxDragImage(const wxIcon
& image
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
)
126 Create(image
, cursor
, cursorHotspot
);
129 wxDragImage(const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
)
136 // Deprecated form of the above
137 wxDragImage(const wxString
& str
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
)
141 Create(str
, cursor
, cursorHotspot
);
145 wxDragImage(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
)
149 Create(treeCtrl
, id
);
154 wxDragImage(const wxListCtrl
& listCtrl
, long id
)
158 Create(listCtrl
, id
);
162 virtual ~wxDragImage();
165 ////////////////////////////////////////////////////////////////////////////
168 ////////////////////////////////////////////////////////////////////////////
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
))
174 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
175 return Create(image
, cursor
);
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
))
182 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
183 return Create(image
, cursor
);
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
))
190 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
191 return Create(str
, cursor
);
195 // Create a drag image for the given tree control item
196 bool Create(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
);
200 // Create a drag image for the given list control item
201 bool Create(const wxListCtrl
& listCtrl
, long id
);
204 // Begin drag. hotspot is the location of the drag position relative to the upper-left
205 // corner of the image.
206 bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
, bool fullScreen
= false, wxRect
* rect
= NULL
);
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
);
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
);
227 ////////////////////////////////////////////////////////////////////////////
229 // Initialize variables
232 // Returns the native image list handle
233 WXHIMAGELIST
GetHIMAGELIST() const { return m_hImageList
; }
235 #if !wxUSE_SIMPLER_DRAGIMAGE
236 // Returns the native image list handle for the cursor
237 WXHIMAGELIST
GetCursorHIMAGELIST() const { return m_hCursorImageList
; }
241 WXHIMAGELIST m_hImageList
;
243 #if wxUSE_SIMPLER_DRAGIMAGE
244 wxCursor m_oldCursor
;
246 WXHIMAGELIST m_hCursorImageList
;
250 // wxPoint m_cursorHotspot; // Obsolete
253 wxRect m_boundingRect
;
257 DECLARE_DYNAMIC_CLASS(wxDragImage
)
258 DECLARE_NO_COPY_CLASS(wxDragImage
)