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