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