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