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
9 // Copyright: (c) William Osborne
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_DRAGIMAG_H_
14 #define _WX_DRAGIMAG_H_
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "dragimag.h"
20 #include "wx/bitmap.h"
22 #include "wx/cursor.h"
23 #include "wx/treectrl.h"
24 #include "wx/listctrl.h"
26 // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
27 #define wxUSE_SIMPLER_DRAGIMAGE 0
30 To use this class, create a wxDragImage when you start dragging, for example:
32 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
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);
43 In your OnMouseMove function, hide the image, do any display updating required,
44 then move and show the image again:
46 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
48 if (m_dragMode == MY_TREE_DRAG_NONE)
54 // Prevent screen corruption by hiding the image
56 m_dragImage->Hide(this);
58 // Do some updating of the window, such as highlighting the drop target
61 // Move and show the image again
62 m_dragImage->Move(event.GetPosition(), this);
63 m_dragImage->Show(this);
66 Eventually we end the drag and delete the drag image.
68 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
72 // End the drag and delete the drag image
75 m_dragImage->EndDrag(this);
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
95 class WXDLLEXPORT wxDragImage
: public wxObject
100 ////////////////////////////////////////////////////////////////////////////
103 wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
)
107 Create(image
, cursor
);
110 // Deprecated form of the above
111 wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
)
115 Create(image
, cursor
, cursorHotspot
);
118 wxDragImage(const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
)
122 Create(image
, cursor
);
125 // Deprecated form of the above
126 wxDragImage(const wxIcon
& image
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
)
130 Create(image
, cursor
, cursorHotspot
);
133 wxDragImage(const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
)
140 // Deprecated form of the above
141 wxDragImage(const wxString
& str
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
)
145 Create(str
, cursor
, cursorHotspot
);
149 wxDragImage(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
)
153 Create(treeCtrl
, id
);
158 wxDragImage(const wxListCtrl
& listCtrl
, long id
)
162 Create(listCtrl
, id
);
169 ////////////////////////////////////////////////////////////////////////////
172 ////////////////////////////////////////////////////////////////////////////
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
))
178 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
179 return Create(image
, cursor
);
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
))
186 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
187 return Create(image
, cursor
);
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
))
194 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
195 return Create(str
, cursor
);
199 // Create a drag image for the given tree control item
200 bool Create(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
);
204 // Create a drag image for the given list control item
205 bool Create(const wxListCtrl
& listCtrl
, long id
);
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
);
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
);
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
);
231 ////////////////////////////////////////////////////////////////////////////
233 // Initialize variables
236 // Returns the native image list handle
237 WXHIMAGELIST
GetHIMAGELIST() const { return m_hImageList
; }
239 #if !wxUSE_SIMPLER_DRAGIMAGE
240 // Returns the native image list handle for the cursor
241 WXHIMAGELIST
GetCursorHIMAGELIST() const { return m_hCursorImageList
; }
245 WXHIMAGELIST m_hImageList
;
247 #if wxUSE_SIMPLER_DRAGIMAGE
248 wxCursor m_oldCursor
;
250 WXHIMAGELIST m_hCursorImageList
;
254 // wxPoint m_cursorHotspot; // Obsolete
257 wxRect m_boundingRect
;
261 DECLARE_DYNAMIC_CLASS(wxDragImage
)
262 DECLARE_NO_COPY_CLASS(wxDragImage
)