]>
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; | |
4ba47b40 RR |
97 | |
98 | bool m_waiting; | |
d6086ea6 RR |
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(); | |
829e3e8d RR |
118 | |
119 | /* may be overridden to reject certain formats or drops | |
5af019af RR |
120 | on certain areas. always returns TRUE by default |
121 | indicating that you'd accept the data from the drag. */ | |
d6086ea6 RR |
122 | virtual bool OnMove( int x, int y ); |
123 | ||
5af019af RR |
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. */ | |
d6086ea6 | 128 | virtual bool OnDrop( int x, int y ); |
5af019af RR |
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 ); | |
d6086ea6 | 137 | |
829e3e8d | 138 | /* called to query what formats are available */ |
d6086ea6 RR |
139 | bool IsSupported( wxDataFormat format ); |
140 | ||
829e3e8d | 141 | /* fill data with data from the dragging source */ |
d6086ea6 RR |
142 | bool GetData( wxDataObject *data ); |
143 | ||
144 | // implementation | |
145 | ||
146 | void RegisterWidget( GtkWidget *widget ); | |
147 | void UnregisterWidget( GtkWidget *widget ); | |
148 | ||
829e3e8d RR |
149 | GdkDragContext *m_dragContext; |
150 | GtkWidget *m_dragWidget; | |
5af019af | 151 | GtkSelectionData *m_dragData; |
829e3e8d RR |
152 | guint m_dragTime; |
153 | bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ | |
d6086ea6 RR |
154 | |
155 | void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } | |
829e3e8d | 156 | void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } |
5af019af | 157 | void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; } |
829e3e8d | 158 | void SetDragTime( guint time ) { m_dragTime = time; } |
d6086ea6 RR |
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 ); | |
5af019af | 173 | virtual bool OnData( int x, int y ); |
d6086ea6 RR |
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 ); | |
5af019af | 196 | virtual bool OnData( int x, int y ); |
d6086ea6 RR |
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 ); | |
5af019af | 225 | virtual bool OnData( int x, int y ); |
d6086ea6 RR |
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 | ||
c801d85f KB |
234 | //------------------------------------------------------------------------- |
235 | // wxDropTarget | |
236 | //------------------------------------------------------------------------- | |
237 | ||
46dc76ba | 238 | class wxDropTarget: public wxObject |
c801d85f KB |
239 | { |
240 | public: | |
241 | ||
242 | wxDropTarget(); | |
243 | ~wxDropTarget(); | |
e3e65dac | 244 | |
c801d85f KB |
245 | virtual void OnEnter() { } |
246 | virtual void OnLeave() { } | |
5b077d48 | 247 | virtual void OnMouseMove( long WXUNUSED(x), long WXUNUSED(y) ) { } |
dc86cb34 | 248 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; |
c801d85f | 249 | |
e3e65dac RR |
250 | // Override these to indicate what kind of data you support: |
251 | ||
252 | virtual size_t GetFormatCount() const = 0; | |
0d2a2b60 | 253 | virtual wxDataFormat &GetFormat(size_t n) const; |
e3e65dac | 254 | |
dc86cb34 RR |
255 | // implementation |
256 | ||
e3e65dac | 257 | void RegisterWidget( GtkWidget *widget ); |
c801d85f | 258 | void UnregisterWidget( GtkWidget *widget ); |
0d2a2b60 RR |
259 | |
260 | wxDataFormat *m_format; | |
c801d85f KB |
261 | }; |
262 | ||
263 | //------------------------------------------------------------------------- | |
264 | // wxTextDropTarget | |
265 | //------------------------------------------------------------------------- | |
266 | ||
267 | class wxTextDropTarget: public wxDropTarget | |
268 | { | |
269 | public: | |
270 | ||
0d2a2b60 | 271 | wxTextDropTarget(); |
dc86cb34 | 272 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
c801d85f | 273 | virtual bool OnDropText( long x, long y, const char *psz ); |
e3e65dac RR |
274 | |
275 | protected: | |
276 | ||
277 | virtual size_t GetFormatCount() const; | |
c801d85f KB |
278 | }; |
279 | ||
ab8884ac RR |
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 | |
0d2a2b60 RR |
294 | // to the clipboard - the latter with the Id "application/wxword" or |
295 | // "image/png". | |
ab8884ac | 296 | |
0d2a2b60 | 297 | void SetId( const wxString& id ); |
ab8884ac RR |
298 | |
299 | wxString GetId() | |
300 | { return m_id; } | |
301 | ||
302 | private: | |
303 | ||
304 | virtual size_t GetFormatCount() const; | |
ab8884ac RR |
305 | |
306 | wxString m_id; | |
307 | }; | |
308 | ||
0d2a2b60 | 309 | //---------------------------------------------------------------------------- |
e3e65dac | 310 | // A drop target which accepts files (dragged from File Manager or Explorer) |
0d2a2b60 | 311 | //---------------------------------------------------------------------------- |
c801d85f | 312 | |
e3e65dac | 313 | class wxFileDropTarget: public wxDropTarget |
c801d85f KB |
314 | { |
315 | public: | |
e3e65dac | 316 | |
0d2a2b60 | 317 | wxFileDropTarget(); |
e3e65dac | 318 | |
dc86cb34 | 319 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
e3e65dac | 320 | virtual bool OnDropFiles( long x, long y, |
dc86cb34 | 321 | size_t nFiles, const char * const aszFiles[] ); |
c801d85f | 322 | |
e3e65dac | 323 | protected: |
c801d85f | 324 | |
e3e65dac | 325 | virtual size_t GetFormatCount() const; |
c801d85f KB |
326 | }; |
327 | ||
d6086ea6 | 328 | #endif |
c801d85f | 329 | |
c801d85f | 330 | |
ac57418f RR |
331 | #endif |
332 | ||
333 | // wxUSE_DRAG_AND_DROP | |
334 | ||
c801d85f KB |
335 | #endif |
336 | //__GTKDNDH__ | |
337 |