]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/dragimag.h
Add NUM_CUSTOM
[wxWidgets.git] / interface / wx / dragimag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dragimag.h
3 // Purpose: interface of wxDragImage
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxDragImage
11
12 This class is used when you wish to drag an object on the screen, and a
13 simple cursor is not enough.
14
15 On Windows, the Win32 API is used to achieve smooth dragging. On other
16 platforms, wxGenericDragImage is used. Applications may also prefer to use
17 wxGenericDragImage on Windows, too.
18
19 @beginWxPythonOnly
20 wxPython uses wxGenericDragImage on all platforms, but uses the wxDragImage
21 name.
22 @endWxPythonOnly
23
24 To use this class, when you wish to start dragging an image, create a
25 wxDragImage object and store it somewhere you can access it as the drag
26 progresses. Call BeginDrag() to start, and EndDrag() to stop the drag. To
27 move the image, initially call Show() and then Move(). If you wish to
28 update the screen contents during the drag (for example, highlight an item
29 as in the dragimag sample), first call Hide(), update the screen, call
30 Move(), and then call Show().
31
32 You can drag within one window, or you can use full-screen dragging either
33 across the whole screen, or just restricted to one area of the screen to
34 save resources. If you want the user to drag between two windows, then you
35 will need to use full-screen dragging.
36
37 If you wish to draw the image yourself, use wxGenericDragImage and override
38 DoDrawImage() and GetImageRect().
39
40 @library{wxcore}
41 @category{dnd}
42
43 @see @ref page_samples_dragimag
44 */
45 class wxDragImage : public wxObject
46 {
47 public:
48 /**
49 Default constructor.
50 */
51 wxDragImage();
52 /**
53 Constructs a drag image from a bitmap and optional cursor.
54
55 @param image
56 Bitmap to be used as the drag image. The bitmap can have a mask.
57 @param cursor
58 Optional cursor to combine with the image.
59 */
60 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
61 /**
62 Constructs a drag image from an icon and optional cursor.
63
64 @param image
65 Icon to be used as the drag image.
66 @param cursor
67 Optional cursor to combine with the image.
68
69 @beginWxPythonOnly
70 This constructor is called wxDragIcon in wxPython.
71 @endWxPythonOnly
72 */
73 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
74 /**
75 Constructs a drag image from a text string and optional cursor.
76
77 @param text
78 Text used to construct a drag image.
79 @param cursor
80 Optional cursor to combine with the image.
81
82 @beginWxPythonOnly
83 This constructor is called wxDragString in wxPython.
84 @endWxPythonOnly
85 */
86 wxDragImage(const wxString& text, const wxCursor& cursor = wxNullCursor);
87 /**
88 Constructs a drag image from the text in the given tree control item,
89 and optional cursor.
90
91 @param treeCtrl
92 Tree control for constructing a tree drag image.
93 @param id
94 Tree control item id.
95
96 @beginWxPythonOnly
97 This constructor is called wxDragTreeItem in wxPython.
98 @endWxPythonOnly
99 */
100 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
101 /**
102 Constructs a drag image from the text in the given list control item,
103 and optional cursor.
104
105 @param listCtrl
106 List control for constructing a list drag image.
107 @param id
108 List control item id.
109
110 @beginWxPythonOnly
111 This constructor is called wxDragListItem in wxPython.
112 @endWxPythonOnly
113 */
114 wxDragImage(const wxListCtrl& listCtrl, long id);
115 /**
116 Start dragging the image, in a window or full screen.
117
118 You need to then call Show() and Move() to show the image on the
119 screen. Call EndDrag() when the drag has finished.
120
121 Note that this call automatically calls CaptureMouse().
122
123 @param hotspot
124 The location of the drag position relative to the upper-left corner
125 of the image.
126 @param window
127 The window that captures the mouse, and within which the dragging
128 is limited unless fullScreen is @true.
129 @param fullScreen
130 If @true, specifies that the drag will be visible over the full
131 screen, or over as much of the screen as is specified by rect. Note
132 that the mouse will still be captured in window.
133 @param rect
134 If non-@NULL, specifies the rectangle (in screen coordinates) that
135 bounds the dragging operation. Specifying this can make the
136 operation more efficient by cutting down on the area under
137 consideration, and it can also make a visual difference since the
138 drag is clipped to this area.
139 */
140 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
141 bool fullScreen = false, wxRect* rect = NULL);
142 /**
143 Start dragging the image, using the first window to capture the mouse
144 and the second to specify the bounding area. This form is equivalent to
145 using the first form, but more convenient than working out the bounding
146 rectangle explicitly.
147
148 You need to then call Show() and Move() to show the image on the
149 screen. Call EndDrag() when the drag has finished.
150
151 Note that this call automatically calls CaptureMouse().
152
153 @param hotspot
154 The location of the drag position relative to the upper-left corner
155 of the image.
156 @param window
157 The window that captures the mouse, and within which the dragging
158 is limited.
159 @param boundingWindow
160 Specifies the area within which the drag occurs.
161 */
162 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
163 wxWindow* boundingWindow);
164
165 /**
166 Draws the image on the device context with top-left corner at the given
167 position.
168
169 This function is only available with wxGenericDragImage, to allow
170 applications to draw their own image instead of using an actual bitmap.
171 If you override this function, you must also override GetImageRect().
172 */
173 virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
174
175 /**
176 Call this when the drag has finished.
177
178 @note This function automatically releases mouse capture.
179 */
180 bool EndDrag();
181
182 /**
183 Returns the rectangle enclosing the image, assuming that the image is
184 drawn with its top-left corner at the given point.
185
186 This function is available in wxGenericDragImage only, and may be
187 overridden (together with DoDrawImage()) to provide a virtual drawing
188 capability.
189 */
190 virtual wxRect GetImageRect(const wxPoint& pos) const;
191
192 /**
193 Hides the image. You may wish to call this before updating the window
194 contents (perhaps highlighting an item). Then call Move() and Show().
195 */
196 bool Hide();
197
198 /**
199 Call this to move the image to a new position. The image will only be
200 shown if Show() has been called previously (for example at the start of
201 the drag).
202
203 @param pt
204 The position in client coordinates (relative to the window
205 specified in BeginDrag()).
206
207 You can move the image either when the image is hidden or shown, but in
208 general dragging will be smoother if you move the image when it is
209 shown.
210 */
211 bool Move(const wxPoint& pt);
212
213 /**
214 Shows the image. Call this at least once when dragging.
215 */
216 bool Show();
217
218 /**
219 Override this if you wish to draw the window contents to the backing
220 bitmap yourself. This can be desirable if you wish to avoid flicker by
221 not having to redraw the updated window itself just before dragging,
222 which can cause a flicker just as the drag starts. Instead, paint the
223 drag image's backing bitmap to show the appropriate graphic @e minus
224 the objects to be dragged, and leave the window itself to be updated by
225 the drag image. This can provide eerily smooth, flicker-free drag
226 behaviour.
227
228 The default implementation copies the window contents to the backing
229 bitmap. A new implementation will normally copy information from
230 another source, such as from its own backing bitmap if it has one, or
231 directly from internal data structures.
232
233 This function is available in wxGenericDragImage only.
234 */
235 virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
236 const wxRect& sourceRect,
237 const wxRect& destRect) const;
238 };
239