]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dragimag.h
Always provide wxMenuItem bitmap-related methods in wxMSW.
[wxWidgets.git] / include / wx / msw / dragimag.h
CommitLineData
7cf83330 1/////////////////////////////////////////////////////////////////////////////
23f681ec 2// Name: wx/msw/dragimag.h
7cf83330
JS
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: 08/04/99
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart
65571936 10// Licence: wxWindows licence
7cf83330
JS
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_DRAGIMAG_H_
14#define _WX_DRAGIMAG_H_
15
93344f25
PC
16#if wxUSE_DRAGIMAGE
17
7cf83330
JS
18#include "wx/bitmap.h"
19#include "wx/icon.h"
20#include "wx/cursor.h"
21#include "wx/treectrl.h"
22#include "wx/listctrl.h"
23
aa2d25a5
JS
24// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
25#define wxUSE_SIMPLER_DRAGIMAGE 0
6ea5c52d 26
7cf83330
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
7cf83330
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 Notes for Unix version:
92 Can we simply use cursors instead, creating a cursor dynamically, setting it into the window
93 in BeginDrag, and restoring the old cursor in EndDrag?
94 For a really bog-standard implementation, we could simply use a normal dragging cursor
95 and ignore the image.
96*/
97
98/*
99 * wxDragImage
100 */
101
53a2db12 102class WXDLLIMPEXP_CORE wxDragImage: public wxObject
7cf83330 103{
7cf83330 104public:
23f681ec 105
7cf83330
JS
106 // Ctors & dtor
107 ////////////////////////////////////////////////////////////////////////////
108
109 wxDragImage();
aa2d25a5
JS
110 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
111 {
112 Init();
113
114 Create(image, cursor);
115 }
116
aa2d25a5
JS
117 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
118 {
119 Init();
120
121 Create(image, cursor);
122 }
123
aa2d25a5
JS
124 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
125 {
126 Init();
127
128 Create(str, cursor);
129 }
130
3080bf59 131#if wxUSE_TREECTRL
7cf83330
JS
132 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
133 {
68be9f09
JS
134 Init();
135
7cf83330
JS
136 Create(treeCtrl, id);
137 }
3080bf59 138#endif
aa2d25a5 139
3080bf59 140#if wxUSE_LISTCTRL
7cf83330
JS
141 wxDragImage(const wxListCtrl& listCtrl, long id)
142 {
68be9f09
JS
143 Init();
144
7cf83330
JS
145 Create(listCtrl, id);
146 }
3080bf59 147#endif
aa2d25a5 148
d3c7fc99 149 virtual ~wxDragImage();
23f681ec 150
7cf83330
JS
151 // Attributes
152 ////////////////////////////////////////////////////////////////////////////
23f681ec 153
7cf83330
JS
154 // Operations
155 ////////////////////////////////////////////////////////////////////////////
23f681ec 156
7cf83330 157 // Create a drag image from a bitmap and optional cursor
aa2d25a5 158 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
23f681ec 159
7cf83330 160 // Create a drag image from an icon and optional cursor
aa2d25a5 161 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
23f681ec 162
7cf83330 163 // Create a drag image from a string and optional cursor
aa2d25a5 164 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
7cf83330 165
3080bf59 166#if wxUSE_TREECTRL
7cf83330
JS
167 // Create a drag image for the given tree control item
168 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
3080bf59 169#endif
7cf83330 170
3080bf59 171#if wxUSE_LISTCTRL
7cf83330
JS
172 // Create a drag image for the given list control item
173 bool Create(const wxListCtrl& listCtrl, long id);
3080bf59 174#endif
7cf83330
JS
175
176 // Begin drag. hotspot is the location of the drag position relative to the upper-left
177 // corner of the image.
d3b9f782 178 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = false, wxRect* rect = NULL);
68be9f09
JS
179
180 // Begin drag. hotspot is the location of the drag position relative to the upper-left
181 // corner of the image. This is full screen only. fullScreenRect gives the
182 // position of the window on the screen, to restrict the drag to.
183 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
23f681ec 184
7cf83330 185 // End drag
68be9f09 186 bool EndDrag();
23f681ec 187
7cf83330
JS
188 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
189 // is non-NULL, or in screen coordinates if NULL.
68be9f09 190 bool Move(const wxPoint& pt);
7cf83330
JS
191
192 // Show the image
68be9f09 193 bool Show();
7cf83330
JS
194
195 // Hide the image
68be9f09 196 bool Hide();
23f681ec 197
7cf83330
JS
198 // Implementation
199 ////////////////////////////////////////////////////////////////////////////
23f681ec 200
68be9f09
JS
201 // Initialize variables
202 void Init();
203
7cf83330 204 // Returns the native image list handle
23f681ec
VZ
205 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
206
6ea5c52d 207#if !wxUSE_SIMPLER_DRAGIMAGE
68be9f09
JS
208 // Returns the native image list handle for the cursor
209 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
6ea5c52d 210#endif
68be9f09 211
82b30473
VZ
212 // don't use in new code, use versions without hot spot parameter
213#if WXWIN_COMPATIBILITY_2_8
214 wxDEPRECATED_CONSTRUCTOR( wxDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
215 wxDEPRECATED_CONSTRUCTOR( wxDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot) );
216 wxDEPRECATED_CONSTRUCTOR( wxDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
217 wxDEPRECATED( bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
218 wxDEPRECATED( bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot) );
219 wxDEPRECATED( bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot) );
220#endif // WXWIN_COMPATIBILITY_2_8
221
7cf83330
JS
222protected:
223 WXHIMAGELIST m_hImageList;
6ea5c52d
JS
224
225#if wxUSE_SIMPLER_DRAGIMAGE
226 wxCursor m_oldCursor;
227#else
68be9f09 228 WXHIMAGELIST m_hCursorImageList;
6ea5c52d
JS
229#endif
230
7cf83330 231 wxCursor m_cursor;
aa2d25a5 232// wxPoint m_cursorHotspot; // Obsolete
7cf83330 233 wxPoint m_position;
68be9f09
JS
234 wxWindow* m_window;
235 wxRect m_boundingRect;
236 bool m_fullScreen;
23f681ec
VZ
237
238private:
239 DECLARE_DYNAMIC_CLASS(wxDragImage)
c0c133e1 240 wxDECLARE_NO_COPY_CLASS(wxDragImage);
7cf83330
JS
241};
242
93344f25 243#endif // wxUSE_DRAGIMAGE
7cf83330
JS
244#endif
245 // _WX_DRAGIMAG_H_