]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dnd.h
This seems to be compiling.
[wxWidgets.git] / include / wx / gtk / 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. always returns TRUE by default
121 indicating that you'd accept the data from the drag. */
122 virtual bool OnMove( int x, int y );
123
124 /* has to be overridden to accept a drop event. call
125 IsSupported() to ask which formats are available
126 and then call RequestData() to indicate the format
127 you request. */
128 virtual bool OnDrop( int x, int y );
129
130 /* this gets called once the data has actually arrived. get
131 it with GetData(). this has to be overridden. */
132 virtual bool OnData( int x, int y );
133
134 /* called from within OnDrop() to request a certain format
135 from the drop event. */
136 bool RequestData( wxDataFormat format );
137
138 /* called to query what formats are available */
139 bool IsSupported( wxDataFormat format );
140
141 /* fill data with data from the dragging source */
142 bool GetData( wxDataObject *data );
143
144 // implementation
145
146 void RegisterWidget( GtkWidget *widget );
147 void UnregisterWidget( GtkWidget *widget );
148
149 GdkDragContext *m_dragContext;
150 GtkWidget *m_dragWidget;
151 GtkSelectionData *m_dragData;
152 guint m_dragTime;
153 bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
154
155 void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
156 void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
157 void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
158 void SetDragTime( guint time ) { m_dragTime = time; }
159 };
160
161 //-------------------------------------------------------------------------
162 // wxTextDropTarget
163 //-------------------------------------------------------------------------
164
165 class wxTextDropTarget: public wxDropTarget
166 {
167 public:
168
169 wxTextDropTarget() {}
170
171 virtual bool OnMove( int x, int y );
172 virtual bool OnDrop( int x, int y );
173 virtual bool OnData( int x, int y );
174
175 /* you have to override OnDropData to get at the text */
176 virtual bool OnDropText( int x, int y, const char *text ) = 0;
177
178 };
179
180 //-------------------------------------------------------------------------
181 // wxPrivateDropTarget
182 //-------------------------------------------------------------------------
183
184 class wxPrivateDropTarget: public wxDropTarget
185 {
186 public:
187
188 /* sets id to "application/myprogram" where "myprogram" is the
189 same as wxApp->GetAppName() */
190 wxPrivateDropTarget();
191 /* see SetId() below for explanation */
192 wxPrivateDropTarget( const wxString &id );
193
194 virtual bool OnMove( int x, int y );
195 virtual bool OnDrop( int x, int y );
196 virtual bool OnData( int x, int y );
197
198 /* you have to override OnDropData to get at the data */
199 virtual bool OnDropData( int x, int y, void *data, size_t size ) = 0;
200
201 /* the string ID identifies the format of clipboard or DnD data. a word
202 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
203 to the clipboard - the latter with the Id "application/wxword" or
204 "image/png". */
205 void SetId( const wxString& id ) { m_id = id; }
206 wxString GetId() { return m_id; }
207
208 private:
209
210 wxString m_id;
211 };
212
213 //----------------------------------------------------------------------------
214 // A drop target which accepts files (dragged from File Manager or Explorer)
215 //----------------------------------------------------------------------------
216
217 class wxFileDropTarget: public wxDropTarget
218 {
219 public:
220
221 wxFileDropTarget() {}
222
223 virtual bool OnMove( int x, int y );
224 virtual bool OnDrop( int x, int y );
225 virtual bool OnData( int x, int y );
226
227 /* you have to override OnDropFiles to get at the file names */
228 virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0;
229
230 };
231
232 #else
233
234 //-------------------------------------------------------------------------
235 // wxDropTarget
236 //-------------------------------------------------------------------------
237
238 class wxDropTarget: public wxObject
239 {
240 public:
241
242 wxDropTarget();
243 ~wxDropTarget();
244
245 virtual void OnEnter() { }
246 virtual void OnLeave() { }
247 virtual void OnMouseMove( long WXUNUSED(x), long WXUNUSED(y) ) { }
248 virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0;
249
250 // Override these to indicate what kind of data you support:
251
252 virtual size_t GetFormatCount() const = 0;
253 virtual wxDataFormat &GetFormat(size_t n) const;
254
255 // implementation
256
257 void RegisterWidget( GtkWidget *widget );
258 void UnregisterWidget( GtkWidget *widget );
259
260 wxDataFormat *m_format;
261 };
262
263 //-------------------------------------------------------------------------
264 // wxTextDropTarget
265 //-------------------------------------------------------------------------
266
267 class wxTextDropTarget: public wxDropTarget
268 {
269 public:
270
271 wxTextDropTarget();
272 virtual bool OnDrop( long x, long y, const void *data, size_t size );
273 virtual bool OnDropText( long x, long y, const char *psz );
274
275 protected:
276
277 virtual size_t GetFormatCount() const;
278 };
279
280 //-------------------------------------------------------------------------
281 // wxPrivateDropTarget
282 //-------------------------------------------------------------------------
283
284 class wxPrivateDropTarget: public wxDropTarget
285 {
286 public:
287
288 wxPrivateDropTarget();
289
290 // you have to override OnDrop to get at the data
291
292 // the string ID identifies the format of clipboard or DnD data. a word
293 // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
294 // to the clipboard - the latter with the Id "application/wxword" or
295 // "image/png".
296
297 void SetId( const wxString& id );
298
299 wxString GetId()
300 { return m_id; }
301
302 private:
303
304 virtual size_t GetFormatCount() const;
305
306 wxString m_id;
307 };
308
309 //----------------------------------------------------------------------------
310 // A drop target which accepts files (dragged from File Manager or Explorer)
311 //----------------------------------------------------------------------------
312
313 class wxFileDropTarget: public wxDropTarget
314 {
315 public:
316
317 wxFileDropTarget();
318
319 virtual bool OnDrop( long x, long y, const void *data, size_t size );
320 virtual bool OnDropFiles( long x, long y,
321 size_t nFiles, const char * const aszFiles[] );
322
323 protected:
324
325 virtual size_t GetFormatCount() const;
326 };
327
328 #endif
329
330
331 #endif
332
333 // wxUSE_DRAG_AND_DROP
334
335 #endif
336 //__GTKDNDH__
337