]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.h | |
3 | // Purpose: declaration of the wxDropTarget class | |
4 | // Author: Robert Roebling | |
58614078 | 5 | // RCS-ID: $Id$ |
c801d85f KB |
6 | // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling |
7 | // Licence: wxWindows license | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifndef __GTKDNDH__ | |
12 | #define __GTKDNDH__ | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "wx/defs.h" | |
ac57418f | 19 | |
06cfab17 | 20 | #if wxUSE_DRAG_AND_DROP |
ac57418f | 21 | |
c801d85f KB |
22 | #include "wx/object.h" |
23 | #include "wx/string.h" | |
8b53e5a2 | 24 | #include "wx/dataobj.h" |
c801d85f | 25 | #include "wx/cursor.h" |
e4677d31 RR |
26 | #include "wx/icon.h" |
27 | #include "wx/gdicmn.h" | |
c801d85f KB |
28 | |
29 | //------------------------------------------------------------------------- | |
30 | // classes | |
31 | //------------------------------------------------------------------------- | |
32 | ||
33 | class wxWindow; | |
34 | ||
35 | class wxDropTarget; | |
36 | class wxTextDropTarget; | |
e3e65dac | 37 | class wxFileDropTarget; |
ab8884ac | 38 | class wxPrivateDropTarget; |
e3e65dac RR |
39 | |
40 | class wxDropSource; | |
41 | ||
d6086ea6 RR |
42 | //------------------------------------------------------------------------- |
43 | // wxDropSource | |
44 | //------------------------------------------------------------------------- | |
45 | ||
46 | enum wxDragResult | |
47 | { | |
48 | wxDragError, // error prevented the d&d operation from completing | |
49 | wxDragNone, // drag target didn't accept the data | |
50 | wxDragCopy, // the data was successfully copied | |
51 | wxDragMove, // the data was successfully moved (MSW only) | |
52 | wxDragCancel // the operation was cancelled by user (not an error) | |
53 | }; | |
54 | ||
55 | class wxDropSource: public wxObject | |
56 | { | |
57 | public: | |
58 | ||
59 | /* constructor. set data later with SetData() */ | |
60 | wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); | |
61 | ||
62 | /* constructor for setting one data object */ | |
63 | wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); | |
64 | ||
65 | /* constructor for setting several data objects via wxDataBroker */ | |
66 | wxDropSource( wxDataBroker *data, wxWindow *win ); | |
67 | ||
68 | ~wxDropSource(); | |
69 | ||
70 | /* set several dataobjects via wxDataBroker */ | |
71 | void SetData( wxDataBroker *data ); | |
72 | ||
73 | /* set one dataobject */ | |
74 | void SetData( wxDataObject *data ); | |
75 | ||
76 | /* start drag action */ | |
77 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); | |
78 | ||
79 | /* override to give feedback */ | |
80 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } | |
81 | ||
82 | /* GTK implementation */ | |
83 | ||
84 | void RegisterWindow(); | |
85 | void UnregisterWindow(); | |
86 | ||
87 | GtkWidget *m_widget; | |
88 | wxWindow *m_window; | |
89 | wxDragResult m_retValue; | |
90 | wxDataBroker *m_data; | |
91 | ||
92 | wxCursor m_defaultCursor; | |
93 | wxCursor m_goaheadCursor; | |
94 | ||
95 | wxIcon m_goIcon; | |
96 | wxIcon m_stopIcon; | |
97 | }; | |
98 | ||
99 | #include "gtk/gtk.h" | |
100 | #if (GTK_MINOR_VERSION > 0) | |
101 | ||
102 | //------------------------------------------------------------------------- | |
103 | // wxDropTarget | |
104 | //------------------------------------------------------------------------- | |
105 | ||
106 | class wxDropTarget: public wxObject | |
107 | { | |
108 | public: | |
109 | ||
110 | wxDropTarget(); | |
111 | ~wxDropTarget(); | |
112 | ||
113 | /* may be overridden to react to events */ | |
114 | virtual void OnEnter(); | |
115 | virtual void OnLeave(); | |
829e3e8d RR |
116 | |
117 | /* may be overridden to reject certain formats or drops | |
118 | on certain areas */ | |
d6086ea6 RR |
119 | virtual bool OnMove( int x, int y ); |
120 | ||
829e3e8d RR |
121 | /* has to be overridden to accept drop. call GetData() to |
122 | indicate the format you request and get the data. */ | |
d6086ea6 RR |
123 | virtual bool OnDrop( int x, int y ); |
124 | ||
829e3e8d | 125 | /* called to query what formats are available */ |
d6086ea6 RR |
126 | bool IsSupported( wxDataFormat format ); |
127 | ||
829e3e8d | 128 | /* fill data with data from the dragging source */ |
d6086ea6 RR |
129 | bool GetData( wxDataObject *data ); |
130 | ||
131 | // implementation | |
132 | ||
133 | void RegisterWidget( GtkWidget *widget ); | |
134 | void UnregisterWidget( GtkWidget *widget ); | |
135 | ||
829e3e8d RR |
136 | GdkDragContext *m_dragContext; |
137 | GtkWidget *m_dragWidget; | |
138 | guint m_dragTime; | |
139 | bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ | |
140 | bool m_waiting; /* asynchronous process */ | |
141 | bool m_dataRetrieveSuccess; | |
142 | wxDataObject *m_currentDataObject; | |
d6086ea6 RR |
143 | |
144 | void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } | |
829e3e8d RR |
145 | void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } |
146 | void SetDragTime( guint time ) { m_dragTime = time; } | |
d6086ea6 RR |
147 | }; |
148 | ||
149 | //------------------------------------------------------------------------- | |
150 | // wxTextDropTarget | |
151 | //------------------------------------------------------------------------- | |
152 | ||
153 | class wxTextDropTarget: public wxDropTarget | |
154 | { | |
155 | public: | |
156 | ||
157 | wxTextDropTarget() {} | |
158 | ||
159 | virtual bool OnMove( int x, int y ); | |
160 | virtual bool OnDrop( int x, int y ); | |
161 | ||
162 | /* you have to override OnDropData to get at the text */ | |
163 | virtual bool OnDropText( int x, int y, const char *text ) = 0; | |
164 | ||
165 | }; | |
166 | ||
167 | //------------------------------------------------------------------------- | |
168 | // wxPrivateDropTarget | |
169 | //------------------------------------------------------------------------- | |
170 | ||
171 | class wxPrivateDropTarget: public wxDropTarget | |
172 | { | |
173 | public: | |
174 | ||
175 | /* sets id to "application/myprogram" where "myprogram" is the | |
176 | same as wxApp->GetAppName() */ | |
177 | wxPrivateDropTarget(); | |
178 | /* see SetId() below for explanation */ | |
179 | wxPrivateDropTarget( const wxString &id ); | |
180 | ||
181 | virtual bool OnMove( int x, int y ); | |
182 | virtual bool OnDrop( int x, int y ); | |
183 | ||
184 | /* you have to override OnDropData to get at the data */ | |
185 | virtual bool OnDropData( int x, int y, void *data, size_t size ) = 0; | |
186 | ||
187 | /* the string ID identifies the format of clipboard or DnD data. a word | |
188 | processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
189 | to the clipboard - the latter with the Id "application/wxword" or | |
190 | "image/png". */ | |
191 | void SetId( const wxString& id ) { m_id = id; } | |
192 | wxString GetId() { return m_id; } | |
193 | ||
194 | private: | |
195 | ||
196 | wxString m_id; | |
197 | }; | |
198 | ||
199 | //---------------------------------------------------------------------------- | |
200 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
201 | //---------------------------------------------------------------------------- | |
202 | ||
203 | class wxFileDropTarget: public wxDropTarget | |
204 | { | |
205 | public: | |
206 | ||
207 | wxFileDropTarget() {} | |
208 | ||
209 | virtual bool OnMove( int x, int y ); | |
210 | virtual bool OnDrop( int x, int y ); | |
829e3e8d | 211 | virtual void OnData( int x, int y ); |
d6086ea6 RR |
212 | |
213 | /* you have to override OnDropFiles to get at the file names */ | |
214 | virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0; | |
215 | ||
216 | }; | |
217 | ||
218 | #else | |
219 | ||
c801d85f KB |
220 | //------------------------------------------------------------------------- |
221 | // wxDropTarget | |
222 | //------------------------------------------------------------------------- | |
223 | ||
46dc76ba | 224 | class wxDropTarget: public wxObject |
c801d85f KB |
225 | { |
226 | public: | |
227 | ||
228 | wxDropTarget(); | |
229 | ~wxDropTarget(); | |
e3e65dac | 230 | |
c801d85f KB |
231 | virtual void OnEnter() { } |
232 | virtual void OnLeave() { } | |
5b077d48 | 233 | virtual void OnMouseMove( long WXUNUSED(x), long WXUNUSED(y) ) { } |
dc86cb34 | 234 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; |
c801d85f | 235 | |
e3e65dac RR |
236 | // Override these to indicate what kind of data you support: |
237 | ||
238 | virtual size_t GetFormatCount() const = 0; | |
0d2a2b60 | 239 | virtual wxDataFormat &GetFormat(size_t n) const; |
e3e65dac | 240 | |
dc86cb34 RR |
241 | // implementation |
242 | ||
e3e65dac | 243 | void RegisterWidget( GtkWidget *widget ); |
c801d85f | 244 | void UnregisterWidget( GtkWidget *widget ); |
0d2a2b60 RR |
245 | |
246 | wxDataFormat *m_format; | |
c801d85f KB |
247 | }; |
248 | ||
249 | //------------------------------------------------------------------------- | |
250 | // wxTextDropTarget | |
251 | //------------------------------------------------------------------------- | |
252 | ||
253 | class wxTextDropTarget: public wxDropTarget | |
254 | { | |
255 | public: | |
256 | ||
0d2a2b60 | 257 | wxTextDropTarget(); |
dc86cb34 | 258 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
c801d85f | 259 | virtual bool OnDropText( long x, long y, const char *psz ); |
e3e65dac RR |
260 | |
261 | protected: | |
262 | ||
263 | virtual size_t GetFormatCount() const; | |
c801d85f KB |
264 | }; |
265 | ||
ab8884ac RR |
266 | //------------------------------------------------------------------------- |
267 | // wxPrivateDropTarget | |
268 | //------------------------------------------------------------------------- | |
269 | ||
270 | class wxPrivateDropTarget: public wxDropTarget | |
271 | { | |
272 | public: | |
273 | ||
274 | wxPrivateDropTarget(); | |
275 | ||
276 | // you have to override OnDrop to get at the data | |
277 | ||
278 | // the string ID identifies the format of clipboard or DnD data. a word | |
279 | // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
0d2a2b60 RR |
280 | // to the clipboard - the latter with the Id "application/wxword" or |
281 | // "image/png". | |
ab8884ac | 282 | |
0d2a2b60 | 283 | void SetId( const wxString& id ); |
ab8884ac RR |
284 | |
285 | wxString GetId() | |
286 | { return m_id; } | |
287 | ||
288 | private: | |
289 | ||
290 | virtual size_t GetFormatCount() const; | |
ab8884ac RR |
291 | |
292 | wxString m_id; | |
293 | }; | |
294 | ||
0d2a2b60 | 295 | //---------------------------------------------------------------------------- |
e3e65dac | 296 | // A drop target which accepts files (dragged from File Manager or Explorer) |
0d2a2b60 | 297 | //---------------------------------------------------------------------------- |
c801d85f | 298 | |
e3e65dac | 299 | class wxFileDropTarget: public wxDropTarget |
c801d85f KB |
300 | { |
301 | public: | |
e3e65dac | 302 | |
0d2a2b60 | 303 | wxFileDropTarget(); |
e3e65dac | 304 | |
dc86cb34 | 305 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
e3e65dac | 306 | virtual bool OnDropFiles( long x, long y, |
dc86cb34 | 307 | size_t nFiles, const char * const aszFiles[] ); |
c801d85f | 308 | |
e3e65dac | 309 | protected: |
c801d85f | 310 | |
e3e65dac | 311 | virtual size_t GetFormatCount() const; |
c801d85f KB |
312 | }; |
313 | ||
d6086ea6 | 314 | #endif |
c801d85f | 315 | |
c801d85f | 316 | |
ac57418f RR |
317 | #endif |
318 | ||
319 | // wxUSE_DRAG_AND_DROP | |
320 | ||
c801d85f KB |
321 | #endif |
322 | //__GTKDNDH__ | |
323 |