Version: 3.1.0
wxDragImage Class Reference

#include <wx/dragimag.h>

+ Inheritance diagram for wxDragImage:

Detailed Description

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 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.

If you wish to draw the image yourself, use wxGenericDragImage and override DoDrawImage() and GetImageRect().

Library:  wxCore
Category:  Clipboard and Drag & Drop
See Also
Drag Image Sample

Public Member Functions

 wxDragImage ()
 Default constructor.
 
 wxDragImage (const wxBitmap &image, const wxCursor &cursor=wxNullCursor)
 Constructs a drag image from a bitmap and optional cursor.
 
 wxDragImage (const wxIcon &image, const wxCursor &cursor=wxNullCursor)
 Constructs a drag image from an icon and optional cursor.
 
 wxDragImage (const wxString &text, const wxCursor &cursor=wxNullCursor)
 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 &listCtrl, long id)
 Constructs a drag image from the text in the given list control item, and optional cursor.
 
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.
 
virtual bool DoDrawImage (wxDC &dc, const wxPoint &pos) const
 Draws the image on the device context with top-left corner at the given position.
 
bool EndDrag ()
 Call this when the drag has finished.
 
virtual wxRect GetImageRect (const wxPoint &pos) const
 Returns the rectangle enclosing the image, assuming that the image is drawn with its top-left corner at the given point.
 
bool Hide ()
 Hides the image.
 
bool Move (const wxPoint &pt)
 Call this to move the image to a new position.
 
bool Show ()
 Shows the image.
 
virtual bool UpdateBackingFromWindow (wxDC &windowDC, wxMemoryDC &destDC, const wxRect &sourceRect, const wxRect &destRect) const
 Override this if you wish to draw the window contents to the backing bitmap yourself.
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data.
 
 wxObject (const wxObject &other)
 Copy ctor.
 
virtual ~wxObject ()
 Destructor.
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class.
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj.
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone.
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer.
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data.
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public.
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object.
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it.
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data.
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data.
 

Constructor & Destructor Documentation

wxDragImage::wxDragImage ( )

Default constructor.

wxDragImage::wxDragImage ( const wxBitmap image,
const wxCursor cursor = wxNullCursor 
)

Constructs a drag image from a bitmap and optional cursor.

Parameters
imageBitmap to be used as the drag image. The bitmap can have a mask.
cursorOptional cursor to combine with the image.
wxDragImage::wxDragImage ( const wxIcon image,
const wxCursor cursor = wxNullCursor 
)

Constructs a drag image from an icon and optional cursor.

Parameters
imageIcon to be used as the drag image.
cursorOptional cursor to combine with the image.
wxDragImage::wxDragImage ( const wxString text,
const wxCursor cursor = wxNullCursor 
)

Constructs a drag image from a text string and optional cursor.

Parameters
textText used to construct a drag image.
cursorOptional cursor to combine with the image.
wxDragImage::wxDragImage ( const wxTreeCtrl treeCtrl,
wxTreeItemId id 
)

Constructs a drag image from the text in the given tree control item, and optional cursor.

Parameters
treeCtrlTree control for constructing a tree drag image.
idTree control item id.
wxDragImage::wxDragImage ( const wxListCtrl listCtrl,
long  id 
)

Constructs a drag image from the text in the given list control item, and optional cursor.

Parameters
listCtrlList control for constructing a list drag image.
idList control item id.

Member Function Documentation

bool wxDragImage::BeginDrag ( const wxPoint hotspot,
wxWindow window,
bool  fullScreen = false,
wxRect rect = NULL 
)

Start dragging the image, in a window or full screen.

You need to then call Show() and Move() to show the image on the screen. Call EndDrag() when the drag has finished.

Note that this call automatically calls CaptureMouse().

Parameters
hotspotThe location of the drag position relative to the upper-left corner of the image.
windowThe window that captures the mouse, and within which the dragging is limited unless fullScreen is true.
fullScreenIf true, specifies that the drag will be visible over the full screen, or over as much of the screen as is specified by rect. Note that the mouse will still be captured in window.
rectIf non-NULL, specifies the rectangle (in screen coordinates) that bounds the dragging operation. Specifying this can make the operation more efficient by cutting down on the area under consideration, and it can also make a visual difference since the drag is clipped to this area.
bool wxDragImage::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 Show() and Move() to show the image on the screen. Call EndDrag() when the drag has finished.

Note that this call automatically calls CaptureMouse().

Parameters
hotspotThe location of the drag position relative to the upper-left corner of the image.
windowThe window that captures the mouse, and within which the dragging is limited.
boundingWindowSpecifies the area within which the drag occurs.
virtual bool wxDragImage::DoDrawImage ( wxDC dc,
const wxPoint pos 
) const
virtual

Draws the image on the device context with top-left corner at the given position.

This function is only available with wxGenericDragImage, to allow applications to draw their own image instead of using an actual bitmap. If you override this function, you must also override GetImageRect().

bool wxDragImage::EndDrag ( )

Call this when the drag has finished.

Note
This function automatically releases mouse capture.
virtual wxRect wxDragImage::GetImageRect ( const wxPoint pos) const
virtual

Returns the rectangle enclosing the image, assuming that the image is drawn with its top-left corner at the given point.

This function is available in wxGenericDragImage only, and may be overridden (together with DoDrawImage()) to provide a virtual drawing capability.

bool wxDragImage::Hide ( )

Hides the image.

You may wish to call this before updating the window contents (perhaps highlighting an item). Then call Move() and Show().

bool wxDragImage::Move ( const wxPoint pt)

Call this to move the image to a new position.

The image will only be shown if Show() has been called previously (for example at the start of the drag).

Parameters
ptThe position in client coordinates (relative to the window specified in 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 wxDragImage::Show ( )

Shows the image.

Call this at least once when dragging.

virtual bool wxDragImage::UpdateBackingFromWindow ( wxDC windowDC,
wxMemoryDC destDC,
const wxRect sourceRect,
const wxRect destRect 
) const
virtual

Override this if you wish to draw the window contents to the backing bitmap yourself.

This can be desirable if you wish to avoid flicker by not having to redraw the updated window itself just before dragging, which can cause a flicker just as the drag starts. Instead, paint the drag image's backing bitmap to show the appropriate graphic minus the objects to be dragged, and leave the window itself to be updated by the drag image. This can provide eerily smooth, flicker-free drag behaviour.

The default implementation copies the window contents to the backing bitmap. A new implementation will normally copy information from another source, such as from its own backing bitmap if it has one, or directly from internal data structures.

This function is available in wxGenericDragImage only.