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