]>
git.saurik.com Git - wxWidgets.git/blob - interface/dragimag.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDragImage
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 This class is used when you wish to drag an object on the screen,
14 and a simple cursor is not enough.
16 On Windows, the Win32 API is used to achieve smooth dragging. On other
18 wxGenericDragImage is used. Applications may also prefer to use
19 wxGenericDragImage on Windows, too.
21 @b wxPython note: wxPython uses wxGenericDragImage on all platforms, but
22 uses the wxDragImage name.
24 To use this class, when you wish to start dragging an image, create a
26 object and store it somewhere you can access it as the drag progresses.
27 Call BeginDrag to start, and EndDrag to stop the drag. To move the image,
28 initially call Show and then Move. If you wish to update the screen contents
29 during the drag (for example, highlight an item as in the dragimag sample),
31 update the screen, call Move, and then call Show.
33 You can drag within one window, or you can use full-screen dragging
34 either across the whole screen, or just restricted to one area
35 of the screen to save resources. If you want the user to drag between
36 two windows, then you will need to use full-screen dragging.
38 If you wish to draw the image yourself, use wxGenericDragImage and
39 override wxDragImage::DoDrawImage and
40 wxDragImage::GetImageRect.
42 Please see @c samples/dragimag for an example.
47 class wxDragImage
: public wxObject
53 Constructs a drag image an optional cursor. This constructor is only available
55 wxGenericDragImage, and can be used when the application
56 supplies DoDrawImage() and GetImageRect().
59 Icon or bitmap to be used as the drag image. The bitmap can
62 Text used to construct a drag image.
64 Optional cursor to combine with the image.
66 This parameter is deprecated.
68 Tree control for constructing a tree drag image.
70 List control for constructing a list drag image.
72 Tree or list control item id.
75 wxDragImage(const wxBitmap
& image
,
76 const wxCursor
& cursor
= wxNullCursor
);
77 wxDragImage(const wxIcon
& image
,
78 const wxCursor
& cursor
= wxNullCursor
);
79 wxDragImage(const wxString
& text
,
80 const wxCursor
& cursor
= wxNullCursor
);
81 wxDragImage(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
);
82 wxDragImage(const wxListCtrl
& treeCtrl
, long id
);
83 wxDragImage(const wxCursor
& cursor
= wxNullCursor
);
88 Start dragging the image, using the first window to capture the mouse and the
90 to specify the bounding area. This form is equivalent to using the first form,
91 but more convenient than working out the bounding rectangle explicitly.
92 You need to then call Show()
93 and Move() to show the image on the screen.
94 Call EndDrag() when the drag has finished.
95 Note that this call automatically calls CaptureMouse.
98 The location of the drag position relative to the upper-left corner
101 The window that captures the mouse, and within which the dragging
102 is limited unless fullScreen is @true.
103 @param boundingWindow
104 In the second form of the function, specifies the
105 area within which the drag occurs.
107 If @true, specifies that the drag will be visible over the full
108 screen, or over as much of the screen as is specified by rect. Note that
110 still be captured in window.
112 If non-@NULL, specifies the rectangle (in screen coordinates) that
113 bounds the dragging operation. Specifying this can make the operation more
115 by cutting down on the area under consideration, and it can also make a
117 since the drag is clipped to this area.
119 bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
,
120 bool fullScreen
= false,
121 wxRect
* rect
= NULL
);
122 bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
,
123 wxWindow
* boundingWindow
);
127 Draws the image on the device context with top-left corner at the given
129 This function is only available with wxGenericDragImage, to allow applications
131 draw their own image instead of using an actual bitmap. If you override this
133 you must also override GetImageRect().
135 virtual bool DoDrawImage(wxDC
& dc
, const wxPoint
& pos
);
138 Call this when the drag has finished.
139 Note that this call automatically calls ReleaseMouse.
144 Returns the rectangle enclosing the image, assuming that the image is drawn
146 top-left corner at the given point.
147 This function is available in wxGenericDragImage only, and may be overridden
149 wxDragImage::DoDrawImage) to provide a virtual drawing capability.
151 virtual wxRect
GetImageRect(const wxPoint
& pos
) const;
154 Hides the image. You may wish to call this before updating the window
155 contents (perhaps highlighting an item). Then call Move()
161 Call this to move the image to a new position. The image will only be shown if
162 Show() has been called previously (for example
163 at the start of the drag).
164 @a pt is the position in client coordinates (relative to the window specified
166 You can move the image either when the image is hidden or shown, but in general
168 will be smoother if you move the image when it is shown.
170 bool Move(const wxPoint
& pt
);
173 Shows the image. Call this at least once when dragging.
178 Override this if you wish to draw the window contents to the backing bitmap
179 yourself. This can be desirable if you wish to avoid flicker by not having to
180 redraw the updated window itself just before dragging, which can cause a
182 as the drag starts. Instead, paint the drag image's backing bitmap to show the
184 graphic @e minus the objects to be dragged, and leave the window itself to be
186 by the drag image. This can provide eerily smooth, flicker-free drag behaviour.
187 The default implementation copies the window contents to the backing bitmap. A
189 implementation will normally copy information from another source, such as from
191 own backing bitmap if it has one, or directly from internal data structures.
192 This function is available in wxGenericDragImage only.
194 bool UpdateBackingFromWindow(wxDC
& windowDC
, wxMemoryDC
& destDC
,
195 const wxRect
& sourceRect
,
196 const wxRect
& destRect
) const;