]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dragimgg.h
fixed unused parameter warning
[wxWidgets.git] / include / wx / generic / dragimgg.h
CommitLineData
2b5f62a0 1//////////////////////////////////////////////////////////////////////////////
68be9f09
JS
2// Name: wx/generic/dragimgg.h
3// Purpose: wxDragImage class: a kind of a cursor, that can cope
4// with more sophisticated images
5// Author: Julian Smart
6// Modified by:
7// Created: 29/2/2000
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart
65571936 10// Licence: wxWindows licence
68be9f09
JS
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_DRAGIMGG_H_
14#define _WX_DRAGIMGG_H_
15
68be9f09
JS
16#include "wx/bitmap.h"
17#include "wx/icon.h"
18#include "wx/cursor.h"
19#include "wx/treectrl.h"
20#include "wx/listctrl.h"
2b5f62a0 21#include "wx/log.h"
68be9f09
JS
22
23/*
24 To use this class, create a wxDragImage when you start dragging, for example:
25
26 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
27 {
28#ifdef __WXMSW__
77ffb593 29 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWidgets
68be9f09
JS
30#endif
31
32 CaptureMouse();
33
34 m_dragImage = new wxDragImage(* this, itemId);
35 m_dragImage->BeginDrag(wxPoint(0, 0), this);
36 m_dragImage->Move(pt, this);
37 m_dragImage->Show(this);
38 ...
39 }
40
41 In your OnMouseMove function, hide the image, do any display updating required,
42 then move and show the image again:
43
44 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
45 {
46 if (m_dragMode == MY_TREE_DRAG_NONE)
47 {
48 event.Skip();
49 return;
50 }
51
52 // Prevent screen corruption by hiding the image
53 if (m_dragImage)
54 m_dragImage->Hide(this);
55
56 // Do some updating of the window, such as highlighting the drop target
57 ...
58
59#ifdef __WXMSW__
60 if (updateWindow)
61 ::UpdateWindow((HWND) GetHWND());
62#endif
63
64 // Move and show the image again
65 m_dragImage->Move(event.GetPosition(), this);
66 m_dragImage->Show(this);
67 }
68
69 Eventually we end the drag and delete the drag image.
70
71 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
72 {
73 ...
74
75 // End the drag and delete the drag image
76 if (m_dragImage)
77 {
78 m_dragImage->EndDrag(this);
79 delete m_dragImage;
80 m_dragImage = NULL;
81 }
82 ReleaseMouse();
83 }
84*/
85
86/*
87 * wxGenericDragImage
88 */
89
90class WXDLLEXPORT wxGenericDragImage: public wxObject
91{
92public:
93
94 // Ctors & dtor
95 ////////////////////////////////////////////////////////////////////////////
96
aa2d25a5 97 wxGenericDragImage(const wxCursor& cursor = wxNullCursor)
f6bcfd97
BP
98 {
99 Init();
aa2d25a5 100 Create(cursor);
f6bcfd97 101 }
aa2d25a5
JS
102
103 // Deprecated version of the above
104 wxGenericDragImage(const wxCursor& cursor, const wxPoint& cursorHotspot)
105 {
106 Init();
107 Create(cursor, cursorHotspot);
108 }
109
110 wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
111 {
112 Init();
113
114 Create(image, cursor);
115 }
116
117 // Deprecated version of the above
118 wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
119 {
120 Init();
121
122 Create(image, cursor, cursorHotspot);
123 }
124
125 wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
126 {
127 Init();
128
129 Create(image, cursor);
130 }
131
132 // Deprecated version of the above
133 wxGenericDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
68be9f09
JS
134 {
135 Init();
136
aa2d25a5 137 Create(image, cursor, cursorHotspot);
68be9f09 138 }
aa2d25a5
JS
139
140 wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
68be9f09
JS
141 {
142 Init();
143
aa2d25a5 144 Create(str, cursor);
68be9f09 145 }
aa2d25a5
JS
146
147 // Deprecated version of the above
148 wxGenericDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
68be9f09
JS
149 {
150 Init();
151
aa2d25a5 152 Create(str, cursor, cursorHotspot);
68be9f09 153 }
aa2d25a5 154
3080bf59 155#if wxUSE_TREECTRL
68be9f09
JS
156 wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
157 {
158 Init();
159
160 Create(treeCtrl, id);
161 }
3080bf59 162#endif
aa2d25a5 163
3080bf59 164#if wxUSE_LISTCTRL
68be9f09
JS
165 wxGenericDragImage(const wxListCtrl& listCtrl, long id)
166 {
167 Init();
168
169 Create(listCtrl, id);
170 }
3080bf59
VZ
171#endif
172
68be9f09
JS
173 ~wxGenericDragImage();
174
175 // Attributes
176 ////////////////////////////////////////////////////////////////////////////
177
f6bcfd97
BP
178 // For efficiency, tell wxGenericDragImage to use a bitmap that's already
179 // created (e.g. from last drag)
180 void SetBackingBitmap(wxBitmap* bitmap) { m_pBackingBitmap = bitmap; }
181
68be9f09
JS
182 // Operations
183 ////////////////////////////////////////////////////////////////////////////
184
f6bcfd97 185 // Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
aa2d25a5
JS
186 bool Create(const wxCursor& cursor = wxNullCursor);
187 bool Create(const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
188 {
189 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
190 return Create(cursor);
191 }
f6bcfd97 192
68be9f09 193 // Create a drag image from a bitmap and optional cursor
aa2d25a5 194 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
33ac7e6f 195 bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
aa2d25a5
JS
196 {
197 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
198 return Create(image, cursor);
199 }
68be9f09
JS
200
201 // Create a drag image from an icon and optional cursor
aa2d25a5 202 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
33ac7e6f 203 bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
aa2d25a5
JS
204 {
205 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
206 return Create(image, cursor);
207 }
68be9f09
JS
208
209 // Create a drag image from a string and optional cursor
aa2d25a5 210 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
33ac7e6f 211 bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
aa2d25a5
JS
212 {
213 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
214 return Create(str, cursor);
215 }
68be9f09 216
3080bf59 217#if wxUSE_TREECTRL
68be9f09
JS
218 // Create a drag image for the given tree control item
219 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
3080bf59 220#endif
68be9f09 221
3080bf59 222#if wxUSE_LISTCTRL
68be9f09
JS
223 // Create a drag image for the given list control item
224 bool Create(const wxListCtrl& listCtrl, long id);
3080bf59 225#endif
68be9f09
JS
226
227 // Begin drag. hotspot is the location of the drag position relative to the upper-left
228 // corner of the image.
ca65c044 229 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = (wxRect*) NULL);
68be9f09
JS
230
231 // Begin drag. hotspot is the location of the drag position relative to the upper-left
232 // corner of the image. This is full screen only. fullScreenRect gives the
233 // position of the window on the screen, to restrict the drag to.
234 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
235
236 // End drag
237 bool EndDrag();
238
239 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
240 // is non-NULL, or in screen coordinates if NULL.
241 bool Move(const wxPoint& pt);
242
243 // Show the image
244 bool Show();
245
246 // Hide the image
247 bool Hide();
248
249 // Implementation
250 ////////////////////////////////////////////////////////////////////////////
251
252 void Init();
253
f6bcfd97
BP
254 // Override this if you are using a virtual image (drawing your own image)
255 virtual wxRect GetImageRect(const wxPoint& pos) const;
256
257 // Override this if you are using a virtual image (drawing your own image)
258 virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
259
260 // Override this if you wish to draw the window contents to the backing bitmap
261 // yourself. This can be desirable if you wish to avoid flicker by not having to
262 // redraw the window itself before dragging in order to be graphic-minus-dragged-objects.
263 // Instead, paint the drag image's backing bitmap to be correct, and leave the window
264 // to be updated only when dragging the objects away (thus giving a smoother appearance).
265 virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
266 const wxRect& sourceRect, const wxRect& destRect) const;
68be9f09
JS
267
268 // Erase and redraw simultaneously if possible
f6bcfd97 269 virtual bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew);
68be9f09
JS
270
271protected:
272 wxBitmap m_bitmap;
273 wxIcon m_icon;
274 wxCursor m_cursor;
275 wxCursor m_oldCursor;
aa2d25a5 276// wxPoint m_hotspot;
f6bcfd97 277 wxPoint m_offset; // The hostpot value passed to BeginDrag
68be9f09
JS
278 wxPoint m_position;
279 bool m_isDirty;
280 bool m_isShown;
281 wxWindow* m_window;
282 wxDC* m_windowDC;
283
284 // Stores the window contents while we're dragging the image around
285 wxBitmap m_backingBitmap;
f6bcfd97
BP
286 wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap
287 // (pass to wxGenericDragImage as an efficiency measure)
68be9f09
JS
288 // A temporary bitmap for repairing/redrawing
289 wxBitmap m_repairBitmap;
290
291 wxRect m_boundingRect;
292 bool m_fullScreen;
293
294private:
295 DECLARE_DYNAMIC_CLASS(wxGenericDragImage)
22f3361e 296 DECLARE_NO_COPY_CLASS(wxGenericDragImage)
68be9f09
JS
297};
298
299#endif
300 // _WX_DRAGIMGG_H_