]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dnd.h
This is the way to go (well, close enough).
[wxWidgets.git] / include / wx / gtk1 / dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dnd.h
3 // Purpose: declaration of the wxDropTarget class
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
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"
19
20 #if wxUSE_DRAG_AND_DROP
21
22 #include "wx/object.h"
23 #include "wx/string.h"
24 #include "wx/dataobj.h"
25 #include "wx/cursor.h"
26 #include "wx/icon.h"
27 #include "wx/gdicmn.h"
28
29 //-------------------------------------------------------------------------
30 // classes
31 //-------------------------------------------------------------------------
32
33 class wxWindow;
34
35 class wxDropTarget;
36 class wxTextDropTarget;
37 class wxFileDropTarget;
38 class wxPrivateDropTarget;
39
40 class wxDropSource;
41
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 bool m_waiting;
99 };
100
101 #include "gtk/gtk.h"
102 #if (GTK_MINOR_VERSION > 0)
103
104 //-------------------------------------------------------------------------
105 // wxDropTarget
106 //-------------------------------------------------------------------------
107
108 class wxDropTarget: public wxObject
109 {
110 public:
111
112 wxDropTarget();
113 ~wxDropTarget();
114
115 /* may be overridden to react to events */
116 virtual void OnEnter();
117 virtual void OnLeave();
118
119 /* may be overridden to reject certain formats or drops
120 on certain areas */
121 virtual bool OnMove( int x, int y );
122
123 /* has to be overridden to accept drop. call GetData() to
124 indicate the format you request and get the data. */
125 virtual bool OnDrop( int x, int y );
126
127 /* called to query what formats are available */
128 bool IsSupported( wxDataFormat format );
129
130 /* fill data with data from the dragging source */
131 bool GetData( wxDataObject *data );
132
133 // implementation
134
135 void RegisterWidget( GtkWidget *widget );
136 void UnregisterWidget( GtkWidget *widget );
137
138 GdkDragContext *m_dragContext;
139 GtkWidget *m_dragWidget;
140 guint m_dragTime;
141 bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
142 bool m_waiting; /* asynchronous process */
143 bool m_dataRetrieveSuccess;
144 wxDataObject *m_currentDataObject;
145
146 void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
147 void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
148 void SetDragTime( guint time ) { m_dragTime = time; }
149 };
150
151 //-------------------------------------------------------------------------
152 // wxTextDropTarget
153 //-------------------------------------------------------------------------
154
155 class wxTextDropTarget: public wxDropTarget
156 {
157 public:
158
159 wxTextDropTarget() {}
160
161 virtual bool OnMove( int x, int y );
162 virtual bool OnDrop( int x, int y );
163
164 /* you have to override OnDropData to get at the text */
165 virtual bool OnDropText( int x, int y, const char *text ) = 0;
166
167 };
168
169 //-------------------------------------------------------------------------
170 // wxPrivateDropTarget
171 //-------------------------------------------------------------------------
172
173 class wxPrivateDropTarget: public wxDropTarget
174 {
175 public:
176
177 /* sets id to "application/myprogram" where "myprogram" is the
178 same as wxApp->GetAppName() */
179 wxPrivateDropTarget();
180 /* see SetId() below for explanation */
181 wxPrivateDropTarget( const wxString &id );
182
183 virtual bool OnMove( int x, int y );
184 virtual bool OnDrop( int x, int y );
185
186 /* you have to override OnDropData to get at the data */
187 virtual bool OnDropData( int x, int y, void *data, size_t size ) = 0;
188
189 /* the string ID identifies the format of clipboard or DnD data. a word
190 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
191 to the clipboard - the latter with the Id "application/wxword" or
192 "image/png". */
193 void SetId( const wxString& id ) { m_id = id; }
194 wxString GetId() { return m_id; }
195
196 private:
197
198 wxString m_id;
199 };
200
201 //----------------------------------------------------------------------------
202 // A drop target which accepts files (dragged from File Manager or Explorer)
203 //----------------------------------------------------------------------------
204
205 class wxFileDropTarget: public wxDropTarget
206 {
207 public:
208
209 wxFileDropTarget() {}
210
211 virtual bool OnMove( int x, int y );
212 virtual bool OnDrop( int x, int y );
213 virtual void OnData( int x, int y );
214
215 /* you have to override OnDropFiles to get at the file names */
216 virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0;
217
218 };
219
220 #else
221
222 //-------------------------------------------------------------------------
223 // wxDropTarget
224 //-------------------------------------------------------------------------
225
226 class wxDropTarget: public wxObject
227 {
228 public:
229
230 wxDropTarget();
231 ~wxDropTarget();
232
233 virtual void OnEnter() { }
234 virtual void OnLeave() { }
235 virtual void OnMouseMove( long WXUNUSED(x), long WXUNUSED(y) ) { }
236 virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0;
237
238 // Override these to indicate what kind of data you support:
239
240 virtual size_t GetFormatCount() const = 0;
241 virtual wxDataFormat &GetFormat(size_t n) const;
242
243 // implementation
244
245 void RegisterWidget( GtkWidget *widget );
246 void UnregisterWidget( GtkWidget *widget );
247
248 wxDataFormat *m_format;
249 };
250
251 //-------------------------------------------------------------------------
252 // wxTextDropTarget
253 //-------------------------------------------------------------------------
254
255 class wxTextDropTarget: public wxDropTarget
256 {
257 public:
258
259 wxTextDropTarget();
260 virtual bool OnDrop( long x, long y, const void *data, size_t size );
261 virtual bool OnDropText( long x, long y, const char *psz );
262
263 protected:
264
265 virtual size_t GetFormatCount() const;
266 };
267
268 //-------------------------------------------------------------------------
269 // wxPrivateDropTarget
270 //-------------------------------------------------------------------------
271
272 class wxPrivateDropTarget: public wxDropTarget
273 {
274 public:
275
276 wxPrivateDropTarget();
277
278 // you have to override OnDrop to get at the data
279
280 // the string ID identifies the format of clipboard or DnD data. a word
281 // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
282 // to the clipboard - the latter with the Id "application/wxword" or
283 // "image/png".
284
285 void SetId( const wxString& id );
286
287 wxString GetId()
288 { return m_id; }
289
290 private:
291
292 virtual size_t GetFormatCount() const;
293
294 wxString m_id;
295 };
296
297 //----------------------------------------------------------------------------
298 // A drop target which accepts files (dragged from File Manager or Explorer)
299 //----------------------------------------------------------------------------
300
301 class wxFileDropTarget: public wxDropTarget
302 {
303 public:
304
305 wxFileDropTarget();
306
307 virtual bool OnDrop( long x, long y, const void *data, size_t size );
308 virtual bool OnDropFiles( long x, long y,
309 size_t nFiles, const char * const aszFiles[] );
310
311 protected:
312
313 virtual size_t GetFormatCount() const;
314 };
315
316 #endif
317
318
319 #endif
320
321 // wxUSE_DRAG_AND_DROP
322
323 #endif
324 //__GTKDNDH__
325