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