1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/dragimag.h
3 // Purpose: wxDragImage class: a kind of a cursor, that can cope
4 // with more sophisticated images
5 // Author: Julian Smart
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_DRAGIMAG_H_
14 #define _WX_DRAGIMAG_H_
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"
27 To use this class, create a wxDragImage when you start dragging, for example:
29 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
32 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWindows
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);
44 In your OnMouseMove function, hide the image, do any display updating required,
45 then move and show the image again:
47 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
49 if (m_dragMode == MY_TREE_DRAG_NONE)
55 // Prevent screen corruption by hiding the image
57 m_dragImage->Hide(this);
59 // Do some updating of the window, such as highlighting the drop target
64 ::UpdateWindow((HWND) GetHWND());
67 // Move and show the image again
68 m_dragImage->Move(event.GetPosition(), this);
69 m_dragImage->Show(this);
72 Eventually we end the drag and delete the drag image.
74 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
78 // End the drag and delete the drag image
81 m_dragImage->EndDrag(this);
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
101 class WXDLLEXPORT wxDragImage
: public wxObject
106 ////////////////////////////////////////////////////////////////////////////
109 wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0))
112 Create(image
, cursor
);
114 wxDragImage(const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0))
117 Create(image
, cursor
);
119 wxDragImage(const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0))
124 wxDragImage(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
)
127 Create(treeCtrl
, id
);
129 wxDragImage(const wxListCtrl
& listCtrl
, long id
)
132 Create(listCtrl
, id
);
137 ////////////////////////////////////////////////////////////////////////////
140 ////////////////////////////////////////////////////////////////////////////
142 // Create a drag image from a bitmap and optional cursor
143 bool Create(const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0));
145 // Create a drag image from an icon and optional cursor
146 bool Create(const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0));
148 // Create a drag image from a string and optional cursor
149 bool Create(const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0));
151 // Create a drag image for the given tree control item
152 bool Create(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
);
154 // Create a drag image for the given list control item
155 bool Create(const wxListCtrl
& listCtrl
, long id
);
157 // Begin drag. hotspot is the location of the drag position relative to the upper-left
158 // corner of the image.
159 bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
);
162 bool EndDrag(wxWindow
* window
);
164 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
165 // is non-NULL, or in screen coordinates if NULL.
166 bool Move(const wxPoint
& pt
, wxWindow
* window
);
169 bool Show(wxWindow
* window
);
172 bool Hide(wxWindow
* window
);
175 ////////////////////////////////////////////////////////////////////////////
177 // Returns the native image list handle
178 WXHIMAGELIST
GetHIMAGELIST() const { return m_hImageList
; }
181 WXHIMAGELIST m_hImageList
;
187 DECLARE_DYNAMIC_CLASS(wxDragImage
)