This class is used when you wish to drag an object on the screen, and a simple cursor is not enough.
On Windows, the WIN32 API is used to do achieve smooth dragging. On other platforms, wxGenericDragImage is used. Applications may also prefer to use wxGenericDragImage on Windows, too.
To use this class, when you wish to start dragging an image, create a wxDragImage object and store it somewhere you can access it as the drag progresses. Call BeginDrag to start, and EndDrag to stop the drag. To move the image, initially call Show and then Move. If you wish to update the screen contents during the drag (for example, highlight an item as in the dragimag sample), first call Hide, update the screen, call Move, and then call Show.
You can drag within one window, or you can use full-screen dragging either across the whole screen, or just restricted to one area of the screen to save resources. If you want the user to drag between two windows, then you will need to use full-screen dragging.
Please see samples/dragimag for an example.
Derived from
Include files
<wx/dragimag.h>
<wx/generic/dragimgg.h>
Members
wxDragImage::wxDragImage
wxDragImage::BeginDrag
wxDragImage::EndDrag
wxDragImage::Hide
wxDragImage::Move
wxDragImage::Show
wxDragImage()
Default constructor.
wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint&hotspot = wxPoint(0, 0))
Constructs a drag image from a bitmap and optional cursor.
wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint&hotspot = wxPoint(0, 0))
Constructs a drag image from an icon and optional cursor.
wxDragImage(const wxString& text, const wxCursor& cursor = wxNullCursor, const wxPoint&hotspot = wxPoint(0, 0))
Constructs a drag image from a text string and optional cursor.
wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
Constructs a drag image from the text in the given tree control item, and optional cursor.
wxDragImage(const wxListCtrl& treeCtrl, long id)
Constructs a drag image from the text in the given tree control item, and optional cursor.
Parameters
image
text
cursor
hotspot
treeCtrl
listCtrl
id
bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = FALSE, wxRect* rect = NULL)
Start dragging the image, in a window or full screen.
bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* boundingWindow)
Start dragging the image, using the first window to capture the mouse and the second to specify the bounding area. This form is equivalent to using the first form, but more convenient than working out the bounding rectangle explicitly.
You need to then call wxDragImage::Show and wxDragImage::Move to show the image on the screen.
Call wxDragImage::EndDrag when the drag has finished.
Note that this call automatically calls CaptureMouse.
Parameters
hotspot
window
boundingWindow
fullScreen
rect
bool EndDrag()
Call this when the drag has finished.
Note that this call automatically calls ReleaseMouse.
bool Hide()
Hides the image. You may wish to call this before updating the window contents (perhaps highlighting an item). Then call wxDragImage::Move and wxDragImage::Show.
bool Move(const wxPoint& pt)
Call this to move the image to a new position. The image will only be shown if wxDragImage::Show has been called previously (for example at the start of the drag).
pt is the position in window coordinates (or screen coordinates if no window was specified to BeginDrag.
You can move the image either when the image is hidden or shown, but in general dragging will be smoother if you move the image when it is shown.
bool Show()
Shows the image. Call this at least once when dragging.