]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dragimgg.h
Added m_isOpened variable to simulate opening/closing
[wxWidgets.git] / include / wx / generic / dragimgg.h
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 #if defined(__GNUG__) && !defined(__APPLE__)
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 #include "wx/log.h"
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__
33 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWindows
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
94 class WXDLLEXPORT wxGenericDragImage: public wxObject
95 {
96 public:
97
98 // Ctors & dtor
99 ////////////////////////////////////////////////////////////////////////////
100
101 wxGenericDragImage(const wxCursor& cursor = wxNullCursor)
102 {
103 Init();
104 Create(cursor);
105 }
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)
138 {
139 Init();
140
141 Create(image, cursor, cursorHotspot);
142 }
143
144 wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
145 {
146 Init();
147
148 Create(str, cursor);
149 }
150
151 // Deprecated version of the above
152 wxGenericDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
153 {
154 Init();
155
156 Create(str, cursor, cursorHotspot);
157 }
158
159 wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
160 {
161 Init();
162
163 Create(treeCtrl, id);
164 }
165
166 wxGenericDragImage(const wxListCtrl& listCtrl, long id)
167 {
168 Init();
169
170 Create(listCtrl, id);
171 }
172 ~wxGenericDragImage();
173
174 // Attributes
175 ////////////////////////////////////////////////////////////////////////////
176
177 // For efficiency, tell wxGenericDragImage to use a bitmap that's already
178 // created (e.g. from last drag)
179 void SetBackingBitmap(wxBitmap* bitmap) { m_pBackingBitmap = bitmap; }
180
181 // Operations
182 ////////////////////////////////////////////////////////////////////////////
183
184 // Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
185 bool Create(const wxCursor& cursor = wxNullCursor);
186 bool Create(const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
187 {
188 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
189 return Create(cursor);
190 }
191
192 // Create a drag image from a bitmap and optional cursor
193 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
194 bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
195 {
196 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
197 return Create(image, cursor);
198 }
199
200 // Create a drag image from an icon and optional cursor
201 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
202 bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
203 {
204 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
205 return Create(image, cursor);
206 }
207
208 // Create a drag image from a string and optional cursor
209 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
210 bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
211 {
212 wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
213 return Create(str, cursor);
214 }
215
216 // Create a drag image for the given tree control item
217 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
218
219 // Create a drag image for the given list control item
220 bool Create(const wxListCtrl& listCtrl, long id);
221
222 // Begin drag. hotspot is the location of the drag position relative to the upper-left
223 // corner of the image.
224 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = FALSE, wxRect* rect = (wxRect*) NULL);
225
226 // Begin drag. hotspot is the location of the drag position relative to the upper-left
227 // corner of the image. This is full screen only. fullScreenRect gives the
228 // position of the window on the screen, to restrict the drag to.
229 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
230
231 // End drag
232 bool EndDrag();
233
234 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
235 // is non-NULL, or in screen coordinates if NULL.
236 bool Move(const wxPoint& pt);
237
238 // Show the image
239 bool Show();
240
241 // Hide the image
242 bool Hide();
243
244 // Implementation
245 ////////////////////////////////////////////////////////////////////////////
246
247 void Init();
248
249 // Override this if you are using a virtual image (drawing your own image)
250 virtual wxRect GetImageRect(const wxPoint& pos) const;
251
252 // Override this if you are using a virtual image (drawing your own image)
253 virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
254
255 // Override this if you wish to draw the window contents to the backing bitmap
256 // yourself. This can be desirable if you wish to avoid flicker by not having to
257 // redraw the window itself before dragging in order to be graphic-minus-dragged-objects.
258 // Instead, paint the drag image's backing bitmap to be correct, and leave the window
259 // to be updated only when dragging the objects away (thus giving a smoother appearance).
260 virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
261 const wxRect& sourceRect, const wxRect& destRect) const;
262
263 // Erase and redraw simultaneously if possible
264 virtual bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew);
265
266 protected:
267 wxBitmap m_bitmap;
268 wxIcon m_icon;
269 wxCursor m_cursor;
270 wxCursor m_oldCursor;
271 // wxPoint m_hotspot;
272 wxPoint m_offset; // The hostpot value passed to BeginDrag
273 wxPoint m_position;
274 bool m_isDirty;
275 bool m_isShown;
276 wxWindow* m_window;
277 wxDC* m_windowDC;
278
279 // Stores the window contents while we're dragging the image around
280 wxBitmap m_backingBitmap;
281 wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap
282 // (pass to wxGenericDragImage as an efficiency measure)
283 // A temporary bitmap for repairing/redrawing
284 wxBitmap m_repairBitmap;
285
286 wxRect m_boundingRect;
287 bool m_fullScreen;
288
289 private:
290 DECLARE_DYNAMIC_CLASS(wxGenericDragImage)
291 DECLARE_NO_COPY_CLASS(wxGenericDragImage)
292 };
293
294 #endif
295 // _WX_DRAGIMGG_H_