]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dragimag.h
Augmented version to b5
[wxWidgets.git] / include / wx / msw / dragimag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dragimag.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: 08/04/99
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_DRAGIMAG_H_
14 #define _WX_DRAGIMAG_H_
15
16 #ifdef __GNUG__
17 #pragma interface "dragimag.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
26 /*
27 To use this class, create a wxDragImage when you start dragging, for example:
28
29 void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
30 {
31 #ifdef __WXMSW__
32 ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWindows
33 #endif
34
35 CaptureMouse();
36
37 m_dragImage = new wxDragImage(* this, itemId);
38 m_dragImage->BeginDrag(wxPoint(0, 0), this);
39 m_dragImage->Move(pt, this);
40 m_dragImage->Show(this);
41 ...
42 }
43
44 In your OnMouseMove function, hide the image, do any display updating required,
45 then move and show the image again:
46
47 void MyTreeCtrl::OnMouseMove(wxMouseEvent& event)
48 {
49 if (m_dragMode == MY_TREE_DRAG_NONE)
50 {
51 event.Skip();
52 return;
53 }
54
55 // Prevent screen corruption by hiding the image
56 if (m_dragImage)
57 m_dragImage->Hide(this);
58
59 // Do some updating of the window, such as highlighting the drop target
60 ...
61
62 #ifdef __WXMSW__
63 if (updateWindow)
64 ::UpdateWindow((HWND) GetHWND());
65 #endif
66
67 // Move and show the image again
68 m_dragImage->Move(event.GetPosition(), this);
69 m_dragImage->Show(this);
70 }
71
72 Eventually we end the drag and delete the drag image.
73
74 void MyTreeCtrl::OnLeftUp(wxMouseEvent& event)
75 {
76 ...
77
78 // End the drag and delete the drag image
79 if (m_dragImage)
80 {
81 m_dragImage->EndDrag(this);
82 delete m_dragImage;
83 m_dragImage = NULL;
84 }
85 ReleaseMouse();
86 }
87 */
88
89 /*
90 Notes for Unix version:
91 Can we simply use cursors instead, creating a cursor dynamically, setting it into the window
92 in BeginDrag, and restoring the old cursor in EndDrag?
93 For a really bog-standard implementation, we could simply use a normal dragging cursor
94 and ignore the image.
95 */
96
97 /*
98 * wxDragImage
99 */
100
101 class WXDLLEXPORT wxDragImage: public wxObject
102 {
103 DECLARE_DYNAMIC_CLASS(wxDragImage)
104 public:
105
106 // Ctors & dtor
107 ////////////////////////////////////////////////////////////////////////////
108
109 wxDragImage();
110 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
111 {
112 m_hImageList = 0;
113 Create(image, cursor);
114 }
115 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
116 {
117 m_hImageList = 0;
118 Create(image, cursor);
119 }
120 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
121 {
122 m_hImageList = 0;
123 Create(str, cursor);
124 }
125 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
126 {
127 m_hImageList = 0;
128 Create(treeCtrl, id);
129 }
130 wxDragImage(const wxListCtrl& listCtrl, long id)
131 {
132 m_hImageList = 0;
133 Create(listCtrl, id);
134 }
135 ~wxDragImage();
136
137 // Attributes
138 ////////////////////////////////////////////////////////////////////////////
139
140 // Operations
141 ////////////////////////////////////////////////////////////////////////////
142
143 // Create a drag image from a bitmap and optional cursor
144 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
145
146 // Create a drag image from an icon and optional cursor
147 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
148
149 // Create a drag image from a string and optional cursor
150 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
151
152 // Create a drag image for the given tree control item
153 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
154
155 // Create a drag image for the given list control item
156 bool Create(const wxListCtrl& listCtrl, long id);
157
158 // Begin drag. hotspot is the location of the drag position relative to the upper-left
159 // corner of the image.
160 bool BeginDrag(const wxPoint& hotspot, wxWindow* window);
161
162 // End drag
163 bool EndDrag(wxWindow* window);
164
165 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
166 // is non-NULL, or in screen coordinates if NULL.
167 bool Move(const wxPoint& pt, wxWindow* window);
168
169 // Show the image
170 bool Show(wxWindow* window);
171
172 // Hide the image
173 bool Hide(wxWindow* window);
174
175 // Implementation
176 ////////////////////////////////////////////////////////////////////////////
177
178 // Returns the native image list handle
179 inline WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
180
181 protected:
182 WXHIMAGELIST m_hImageList;
183 wxCursor m_cursor;
184 wxPoint m_hotspot;
185 wxPoint m_position;
186 };
187
188 #endif
189 // _WX_DRAGIMAG_H_