]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dragimag.h
(blind) fixes for Motif compilation
[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
23f681ec 10// Licence: wxWindows licence
7cf83330
JS
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
101class WXDLLEXPORT wxDragImage: public wxObject
102{
7cf83330 103public:
23f681ec 104
7cf83330
JS
105 // Ctors & dtor
106 ////////////////////////////////////////////////////////////////////////////
107
108 wxDragImage();
109 wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
110 {
68be9f09
JS
111 Init();
112
113 Create(image, cursor, hotspot);
7cf83330
JS
114 }
115 wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
116 {
68be9f09
JS
117 Init();
118
119 Create(image, cursor, hotspot);
7cf83330
JS
120 }
121 wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
122 {
68be9f09
JS
123 Init();
124
125 Create(str, cursor, hotspot);
7cf83330
JS
126 }
127 wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
128 {
68be9f09
JS
129 Init();
130
7cf83330
JS
131 Create(treeCtrl, id);
132 }
133 wxDragImage(const wxListCtrl& listCtrl, long id)
134 {
68be9f09
JS
135 Init();
136
7cf83330
JS
137 Create(listCtrl, id);
138 }
139 ~wxDragImage();
23f681ec 140
7cf83330
JS
141 // Attributes
142 ////////////////////////////////////////////////////////////////////////////
23f681ec 143
7cf83330
JS
144 // Operations
145 ////////////////////////////////////////////////////////////////////////////
23f681ec 146
7cf83330
JS
147 // Create a drag image from a bitmap and optional cursor
148 bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
23f681ec 149
7cf83330
JS
150 // Create a drag image from an icon and optional cursor
151 bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
23f681ec 152
7cf83330
JS
153 // Create a drag image from a string and optional cursor
154 bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
155
156 // Create a drag image for the given tree control item
157 bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
158
159 // Create a drag image for the given list control item
160 bool Create(const wxListCtrl& listCtrl, long id);
161
162 // Begin drag. hotspot is the location of the drag position relative to the upper-left
163 // corner of the image.
68be9f09
JS
164 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullScreen = FALSE, wxRect* rect = (wxRect*) NULL);
165
166 // Begin drag. hotspot is the location of the drag position relative to the upper-left
167 // corner of the image. This is full screen only. fullScreenRect gives the
168 // position of the window on the screen, to restrict the drag to.
169 bool BeginDrag(const wxPoint& hotspot, wxWindow* window, wxWindow* fullScreenRect);
23f681ec 170
7cf83330 171 // End drag
68be9f09 172 bool EndDrag();
23f681ec 173
7cf83330
JS
174 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
175 // is non-NULL, or in screen coordinates if NULL.
68be9f09 176 bool Move(const wxPoint& pt);
7cf83330
JS
177
178 // Show the image
68be9f09 179 bool Show();
7cf83330
JS
180
181 // Hide the image
68be9f09 182 bool Hide();
23f681ec 183
7cf83330
JS
184 // Implementation
185 ////////////////////////////////////////////////////////////////////////////
23f681ec 186
68be9f09
JS
187 // Initialize variables
188 void Init();
189
7cf83330 190 // Returns the native image list handle
23f681ec
VZ
191 WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
192
68be9f09
JS
193 // Returns the native image list handle for the cursor
194 WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
195
7cf83330
JS
196protected:
197 WXHIMAGELIST m_hImageList;
68be9f09 198 WXHIMAGELIST m_hCursorImageList;
7cf83330
JS
199 wxCursor m_cursor;
200 wxPoint m_hotspot;
201 wxPoint m_position;
68be9f09
JS
202 wxWindow* m_window;
203 wxRect m_boundingRect;
204 bool m_fullScreen;
23f681ec
VZ
205
206private:
207 DECLARE_DYNAMIC_CLASS(wxDragImage)
7cf83330
JS
208};
209
210#endif
211 // _WX_DRAGIMAG_H_