1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dragimgg.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_DRAGIMGG_H_
14 #define _WX_DRAGIMGG_H_
17 #pragma interface "dragimgg.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);
93 class WXDLLEXPORT wxGenericDragImage
: public wxObject
98 ////////////////////////////////////////////////////////////////////////////
100 wxGenericDragImage();
101 wxGenericDragImage(const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0))
105 Create(image
, cursor
, hotspot
);
107 wxGenericDragImage(const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0))
111 Create(image
, cursor
, hotspot
);
113 wxGenericDragImage(const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0))
117 Create(str
, cursor
, hotspot
);
119 wxGenericDragImage(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
)
123 Create(treeCtrl
, id
);
125 wxGenericDragImage(const wxListCtrl
& listCtrl
, long id
)
129 Create(listCtrl
, id
);
131 ~wxGenericDragImage();
134 ////////////////////////////////////////////////////////////////////////////
137 ////////////////////////////////////////////////////////////////////////////
139 // Create a drag image from a bitmap and optional cursor
140 bool Create(const wxBitmap
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0));
142 // Create a drag image from an icon and optional cursor
143 bool Create(const wxIcon
& image
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0));
145 // Create a drag image from a string and optional cursor
146 bool Create(const wxString
& str
, const wxCursor
& cursor
= wxNullCursor
, const wxPoint
& hotspot
= wxPoint(0, 0));
148 // Create a drag image for the given tree control item
149 bool Create(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
);
151 // Create a drag image for the given list control item
152 bool Create(const wxListCtrl
& listCtrl
, long id
);
154 // Begin drag. hotspot is the location of the drag position relative to the upper-left
155 // corner of the image.
156 bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
, bool fullScreen
= FALSE
, wxRect
* rect
= (wxRect
*) NULL
);
158 // Begin drag. hotspot is the location of the drag position relative to the upper-left
159 // corner of the image. This is full screen only. fullScreenRect gives the
160 // position of the window on the screen, to restrict the drag to.
161 bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
, wxWindow
* fullScreenRect
);
166 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
167 // is non-NULL, or in screen coordinates if NULL.
168 bool Move(const wxPoint
& pt
);
177 ////////////////////////////////////////////////////////////////////////////
181 wxRect
GetImageRect(const wxPoint
& pos
) const;
183 // Erase and redraw simultaneously if possible
184 bool RedrawImage(const wxPoint
& oldPos
, const wxPoint
& newPos
, bool eraseOld
, bool drawNew
);
190 wxCursor m_oldCursor
;
198 // Stores the window contents while we're dragging the image around
199 wxBitmap m_backingBitmap
;
200 // A temporary bitmap for repairing/redrawing
201 wxBitmap m_repairBitmap
;
203 wxRect m_boundingRect
;
207 DECLARE_DYNAMIC_CLASS(wxGenericDragImage
)