]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dragimgg.h
I don't think anylonger that DrawHeaderButton() should
[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 22
e412f892
SC
23#if defined(wxMAC_USE_CORE_GRAPHICS) && wxMAC_USE_CORE_GRAPHICS
24#include "wx/dc.h"
25#endif
26
68be9f09
JS
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 106
aa2d25a5
JS
107 wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
108 {
109 Init();
110
111 Create(image, cursor);
112 }
113
aa2d25a5
JS
114 wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
115 {
116 Init();
117
118 Create(image, cursor);
119 }
120
aa2d25a5 121 wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
68be9f09
JS
122 {
123 Init();
124
aa2d25a5 125 Create(str, cursor);
68be9f09 126 }
aa2d25a5 127
ca3e85cf
WS
128#if WXWIN_COMPATIBILITY_2_6
129 // don't use in new code, use versions without hot spot parameter
130 wxDEPRECATED( wxGenericDragImage(const wxCursor& cursor, const wxPoint& cursorHotspot) );
131 wxDEPRECATED( wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
132 wxDEPRECATED( wxGenericDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
133 wxDEPRECATED( wxGenericDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot) );
134 wxDEPRECATED( bool Create(const wxCursor& cursor, const wxPoint& cursorHotspot) );
135 wxDEPRECATED( bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
136 wxDEPRECATED( bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
137 wxDEPRECATED( bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot) );
138#endif // WXWIN_COMPATIBILITY_2_6
aa2d25a5 139
3080bf59 140#if wxUSE_TREECTRL
68be9f09
JS
141 wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
142 {
143 Init();
144
145 Create(treeCtrl, id);
146 }
3080bf59 147#endif
aa2d25a5 148
3080bf59 149#if wxUSE_LISTCTRL
68be9f09
JS
150 wxGenericDragImage(const wxListCtrl& listCtrl, long id)
151 {
152 Init();
153
154 Create(listCtrl, id);
155 }
3080bf59
VZ
156#endif
157
d3c7fc99 158 virtual ~wxGenericDragImage();
68be9f09
JS
159
160 // Attributes
161 ////////////////////////////////////////////////////////////////////////////
162
f6bcfd97
BP
163 // For efficiency, tell wxGenericDragImage to use a bitmap that's already
164 // created (e.g. from last drag)
e412f892
SC
165 void SetBackingBitmap(wxBitmap* bitmap) {
166#if defined(wxMAC_USE_CORE_GRAPHICS) && wxMAC_USE_CORE_GRAPHICS
167#else
168 m_pBackingBitmap = bitmap;
169#endif
170 }
f6bcfd97 171
68be9f09
JS
172 // Operations
173 ////////////////////////////////////////////////////////////////////////////
174
f6bcfd97 175 // Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
aa2d25a5 176 bool Create(const wxCursor& cursor = wxNullCursor);
f6bcfd97 177
68be9f09 178 // Create a drag image from a bitmap and optional cursor
aa2d25a5 179 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
68be9f09
JS
180
181 // Create a drag image from an icon and optional cursor
aa2d25a5 182 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
68be9f09
JS
183
184 // Create a drag image from a string and optional cursor
aa2d25a5 185 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
68be9f09 186
3080bf59 187#if wxUSE_TREECTRL
68be9f09
JS
188 // Create a drag image for the given tree control item
189 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
3080bf59 190#endif
68be9f09 191
3080bf59 192#if wxUSE_LISTCTRL
68be9f09
JS
193 // Create a drag image for the given list control item
194 bool Create(const wxListCtrl& listCtrl, long id);
3080bf59 195#endif
68be9f09
JS
196
197 // Begin drag. hotspot is the location of the drag position relative to the upper-left
198 // corner of the image.
ca65c044 199 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = (wxRect*) NULL);
68be9f09
JS
200
201 // Begin drag. hotspot is the location of the drag position relative to the upper-left
202 // corner of the image. This is full screen only. fullScreenRect gives the
203 // position of the window on the screen, to restrict the drag to.
204 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
205
206 // End drag
207 bool EndDrag();
208
209 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
210 // is non-NULL, or in screen coordinates if NULL.
211 bool Move(const wxPoint& pt);
212
213 // Show the image
214 bool Show();
215
216 // Hide the image
217 bool Hide();
218
219 // Implementation
220 ////////////////////////////////////////////////////////////////////////////
221
222 void Init();
223
f6bcfd97
BP
224 // Override this if you are using a virtual image (drawing your own image)
225 virtual wxRect GetImageRect(const wxPoint& pos) const;
226
227 // Override this if you are using a virtual image (drawing your own image)
228 virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
229
230 // Override this if you wish to draw the window contents to the backing bitmap
231 // yourself. This can be desirable if you wish to avoid flicker by not having to
232 // redraw the window itself before dragging in order to be graphic-minus-dragged-objects.
233 // Instead, paint the drag image's backing bitmap to be correct, and leave the window
234 // to be updated only when dragging the objects away (thus giving a smoother appearance).
235 virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
ca3e85cf 236 const wxRect& sourceRect, const wxRect& destRect) const;
68be9f09
JS
237
238 // Erase and redraw simultaneously if possible
f6bcfd97 239 virtual bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew);
68be9f09
JS
240
241protected:
242 wxBitmap m_bitmap;
243 wxIcon m_icon;
244 wxCursor m_cursor;
245 wxCursor m_oldCursor;
aa2d25a5 246// wxPoint m_hotspot;
f6bcfd97 247 wxPoint m_offset; // The hostpot value passed to BeginDrag
68be9f09
JS
248 wxPoint m_position;
249 bool m_isDirty;
250 bool m_isShown;
251 wxWindow* m_window;
252 wxDC* m_windowDC;
253
e412f892
SC
254#if defined(wxMAC_USE_CORE_GRAPHICS) && wxMAC_USE_CORE_GRAPHICS
255 wxOverlay m_overlay;
256 wxDCOverlay* m_dcOverlay;
257#else
68be9f09
JS
258 // Stores the window contents while we're dragging the image around
259 wxBitmap m_backingBitmap;
f6bcfd97
BP
260 wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap
261 // (pass to wxGenericDragImage as an efficiency measure)
68be9f09
JS
262 // A temporary bitmap for repairing/redrawing
263 wxBitmap m_repairBitmap;
e412f892 264#endif
68be9f09
JS
265
266 wxRect m_boundingRect;
267 bool m_fullScreen;
268
269private:
270 DECLARE_DYNAMIC_CLASS(wxGenericDragImage)
22f3361e 271 DECLARE_NO_COPY_CLASS(wxGenericDragImage)
68be9f09
JS
272};
273
274#endif
275 // _WX_DRAGIMGG_H_