2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dragimag.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxDragImage
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDragImage
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
This class is used when you wish to drag an object on the screen, and a
|
|
|
|
simple cursor is not enough.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
On Windows, the Win32 API is used to achieve smooth dragging. On other
|
2008-04-21 21:38:12 -04:00
|
|
|
platforms, wxGenericDragImage is used. Applications may also prefer to use
|
2008-03-08 08:52:38 -05:00
|
|
|
wxGenericDragImage on Windows, too.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
@beginWxPythonOnly
|
|
|
|
wxPython uses wxGenericDragImage on all platforms, but uses the wxDragImage
|
|
|
|
name.
|
|
|
|
@endWxPythonOnly
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
To use this class, when you wish to start dragging an image, create a
|
2008-04-21 21:38:12 -04:00
|
|
|
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().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
If you wish to draw the image yourself, use wxGenericDragImage and override
|
|
|
|
DoDrawImage() and GetImageRect().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
2008-04-21 21:38:12 -04:00
|
|
|
@category{dnd}
|
|
|
|
|
|
|
|
@see @ref page_samples_dragimag
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxDragImage : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxDragImage();
|
|
|
|
/**
|
|
|
|
Constructs a drag image from a bitmap and optional cursor.
|
|
|
|
|
|
|
|
@param image
|
|
|
|
Bitmap to be used as the drag image. The bitmap can have a mask.
|
|
|
|
@param cursor
|
|
|
|
Optional cursor to combine with the image.
|
|
|
|
@param cursorHotspot
|
|
|
|
This parameter is deprecated.
|
|
|
|
*/
|
|
|
|
wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor,
|
|
|
|
const wxPoint& cursorHotspot = wxPoint(0, 0));
|
|
|
|
/**
|
|
|
|
Constructs a drag image from an icon and optional cursor.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param image
|
2008-04-21 21:38:12 -04:00
|
|
|
Icon to be used as the drag image.
|
|
|
|
@param cursor
|
|
|
|
Optional cursor to combine with the image.
|
|
|
|
@param cursorHotspot
|
|
|
|
This parameter is deprecated.
|
|
|
|
|
|
|
|
@beginWxPythonOnly
|
|
|
|
This constructor is called wxDragIcon in wxPython.
|
|
|
|
@endWxPythonOnly
|
|
|
|
*/
|
|
|
|
wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor,
|
|
|
|
const wxPoint& cursorHotspot = wxPoint(0, 0));
|
|
|
|
/**
|
|
|
|
Constructs a drag image from a text string and optional cursor.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param text
|
2008-03-09 08:33:59 -04:00
|
|
|
Text used to construct a drag image.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param cursor
|
2008-03-09 08:33:59 -04:00
|
|
|
Optional cursor to combine with the image.
|
2008-04-21 21:38:12 -04:00
|
|
|
@param cursorHotspot
|
2008-03-09 08:33:59 -04:00
|
|
|
This parameter is deprecated.
|
2008-04-21 21:38:12 -04:00
|
|
|
|
|
|
|
@beginWxPythonOnly
|
|
|
|
This constructor is called wxDragString in wxPython.
|
|
|
|
@endWxPythonOnly
|
|
|
|
*/
|
|
|
|
wxDragImage(const wxString& text, const wxCursor& cursor = wxNullCursor,
|
|
|
|
const wxPoint& cursorHotspot = wxPoint(0, 0));
|
|
|
|
/**
|
|
|
|
Constructs a drag image from the text in the given tree control item,
|
|
|
|
and optional cursor.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param treeCtrl
|
2008-03-09 08:33:59 -04:00
|
|
|
Tree control for constructing a tree drag image.
|
2008-04-21 21:38:12 -04:00
|
|
|
@param id
|
|
|
|
Tree control item id.
|
|
|
|
|
|
|
|
@beginWxPythonOnly
|
|
|
|
This constructor is called wxDragTreeItem in wxPython.
|
|
|
|
@endWxPythonOnly
|
|
|
|
*/
|
|
|
|
wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
|
|
|
|
/**
|
|
|
|
Constructs a drag image from the text in the given list control item,
|
|
|
|
and optional cursor.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param listCtrl
|
2008-03-09 08:33:59 -04:00
|
|
|
List control for constructing a list drag image.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param id
|
2008-04-21 21:38:12 -04:00
|
|
|
List control item id.
|
|
|
|
|
|
|
|
@beginWxPythonOnly
|
|
|
|
This constructor is called wxDragListItem in wxPython.
|
|
|
|
@endWxPythonOnly
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-21 21:38:12 -04:00
|
|
|
wxDragImage(const wxListCtrl& listCtrl, long id);
|
|
|
|
/**
|
|
|
|
Constructs a drag image an optional cursor. This constructor is only
|
|
|
|
available for wxGenericDragImage, and can be used when the application
|
|
|
|
supplies DoDrawImage() and GetImageRect().
|
|
|
|
|
|
|
|
@param cursor
|
|
|
|
Optional cursor to combine with the image.
|
|
|
|
@param cursorHotspot
|
|
|
|
This parameter is deprecated.
|
|
|
|
*/
|
|
|
|
wxDragImage(const wxCursor& cursor = wxNullCursor,
|
|
|
|
const wxPoint& cursorHotspot = wxPoint(0, 0));
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
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().
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param hotspot
|
2008-03-09 08:33:59 -04:00
|
|
|
The location of the drag position relative to the upper-left corner
|
|
|
|
of the image.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param window
|
2008-03-09 08:33:59 -04:00
|
|
|
The window that captures the mouse, and within which the dragging
|
|
|
|
is limited unless fullScreen is @true.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param fullScreen
|
2008-03-09 08:33:59 -04:00
|
|
|
If @true, specifies that the drag will be visible over the full
|
2008-04-21 21:38:12 -04:00
|
|
|
screen, or over as much of the screen as is specified by rect. Note
|
|
|
|
that the mouse will still be captured in window.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param rect
|
2008-03-09 08:33:59 -04:00
|
|
|
If non-@NULL, specifies the rectangle (in screen coordinates) that
|
2008-04-21 21:38:12 -04:00
|
|
|
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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
|
2008-04-21 21:38:12 -04:00
|
|
|
bool fullScreen = false, wxRect* rect = NULL);
|
|
|
|
/**
|
|
|
|
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().
|
|
|
|
|
|
|
|
@param hotspot
|
|
|
|
The location of the drag position relative to the upper-left corner
|
|
|
|
of the image.
|
|
|
|
@param window
|
|
|
|
The window that captures the mouse, and within which the dragging
|
|
|
|
is limited.
|
|
|
|
@param boundingWindow
|
|
|
|
Specifies the area within which the drag occurs.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
|
|
|
|
wxWindow* boundingWindow);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Draws the image on the device context with top-left corner at the given
|
|
|
|
position.
|
2008-04-21 21:38:12 -04:00
|
|
|
|
|
|
|
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().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Call this when the drag has finished.
|
2008-04-21 21:38:12 -04:00
|
|
|
|
|
|
|
@note This function automatically releases mouse capture.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool EndDrag();
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual wxRect GetImageRect(const wxPoint& pos) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Hides the image. You may wish to call this before updating the window
|
2008-04-21 21:38:12 -04:00
|
|
|
contents (perhaps highlighting an item). Then call Move() and Show().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Hide();
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
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).
|
|
|
|
|
|
|
|
@param pt
|
|
|
|
The 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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Move(const wxPoint& pt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Shows the image. Call this at least once when dragging.
|
|
|
|
*/
|
|
|
|
bool Show();
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
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 @e 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.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This function is available in wxGenericDragImage only.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
|
|
|
|
const wxRect& sourceRect,
|
|
|
|
const wxRect& destRect) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|