]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/dnd.h
many changes; major ones:
[wxWidgets.git] / include / wx / gtk / dnd.h
CommitLineData
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
33class wxWindow;
34
35class wxDropTarget;
36class wxTextDropTarget;
e3e65dac 37class wxFileDropTarget;
ab8884ac 38class wxPrivateDropTarget;
e3e65dac
RR
39
40class wxDropSource;
41
d6086ea6
RR
42//-------------------------------------------------------------------------
43// wxDropTarget
44//-------------------------------------------------------------------------
45
46class wxDropTarget: public wxObject
47{
48public:
49
50 wxDropTarget();
51 ~wxDropTarget();
52
53 /* may be overridden to react to events */
54 virtual void OnEnter();
55 virtual void OnLeave();
829e3e8d
RR
56
57 /* may be overridden to reject certain formats or drops
5af019af
RR
58 on certain areas. always returns TRUE by default
59 indicating that you'd accept the data from the drag. */
8dbf4589 60 virtual bool OnMove( long x, long y );
d6086ea6 61
5af019af
RR
62 /* has to be overridden to accept a drop event. call
63 IsSupported() to ask which formats are available
64 and then call RequestData() to indicate the format
65 you request. */
8dbf4589 66 virtual bool OnDrop( long x, long y );
5af019af
RR
67
68 /* this gets called once the data has actually arrived. get
69 it with GetData(). this has to be overridden. */
8dbf4589 70 virtual bool OnData( long x, long y );
5af019af
RR
71
72 /* called from within OnDrop() to request a certain format
73 from the drop event. */
74 bool RequestData( wxDataFormat format );
d6086ea6 75
829e3e8d 76 /* called to query what formats are available */
d6086ea6
RR
77 bool IsSupported( wxDataFormat format );
78
829e3e8d 79 /* fill data with data from the dragging source */
d6086ea6
RR
80 bool GetData( wxDataObject *data );
81
82// implementation
83
84 void RegisterWidget( GtkWidget *widget );
85 void UnregisterWidget( GtkWidget *widget );
86
829e3e8d
RR
87 GdkDragContext *m_dragContext;
88 GtkWidget *m_dragWidget;
5af019af 89 GtkSelectionData *m_dragData;
829e3e8d
RR
90 guint m_dragTime;
91 bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
d6086ea6
RR
92
93 void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
829e3e8d 94 void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
5af019af 95 void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
829e3e8d 96 void SetDragTime( guint time ) { m_dragTime = time; }
d6086ea6
RR
97};
98
99//-------------------------------------------------------------------------
100// wxTextDropTarget
101//-------------------------------------------------------------------------
102
103class wxTextDropTarget: public wxDropTarget
104{
105public:
106
107 wxTextDropTarget() {}
108
8dbf4589
RR
109 virtual bool OnMove( long x, long y );
110 virtual bool OnDrop( long x, long y );
111 virtual bool OnData( long x, long y );
d6086ea6
RR
112
113 /* you have to override OnDropData to get at the text */
8dbf4589 114 virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
d6086ea6
RR
115
116};
117
118//-------------------------------------------------------------------------
119// wxPrivateDropTarget
120//-------------------------------------------------------------------------
121
122class wxPrivateDropTarget: public wxDropTarget
123{
124public:
125
126 /* sets id to "application/myprogram" where "myprogram" is the
127 same as wxApp->GetAppName() */
128 wxPrivateDropTarget();
129 /* see SetId() below for explanation */
130 wxPrivateDropTarget( const wxString &id );
131
8dbf4589
RR
132 virtual bool OnMove( long x, long y );
133 virtual bool OnDrop( long x, long y );
134 virtual bool OnData( long x, long y );
d6086ea6
RR
135
136 /* you have to override OnDropData to get at the data */
8dbf4589 137 virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
d6086ea6
RR
138
139 /* the string ID identifies the format of clipboard or DnD data. a word
140 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
141 to the clipboard - the latter with the Id "application/wxword" or
142 "image/png". */
143 void SetId( const wxString& id ) { m_id = id; }
144 wxString GetId() { return m_id; }
145
146private:
147
148 wxString m_id;
149};
150
151//----------------------------------------------------------------------------
152// A drop target which accepts files (dragged from File Manager or Explorer)
153//----------------------------------------------------------------------------
154
155class wxFileDropTarget: public wxDropTarget
156{
157public:
158
159 wxFileDropTarget() {}
160
8dbf4589
RR
161 virtual bool OnMove( long x, long y );
162 virtual bool OnDrop( long x, long y );
163 virtual bool OnData( long x, long y );
d6086ea6
RR
164
165 /* you have to override OnDropFiles to get at the file names */
8dbf4589 166 virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
d6086ea6
RR
167
168};
169
c801d85f 170//-------------------------------------------------------------------------
8a126fcc 171// wxDropSource
c801d85f
KB
172//-------------------------------------------------------------------------
173
8a126fcc 174enum wxDragResult
c801d85f 175{
8a126fcc
RR
176 wxDragError, // error prevented the d&d operation from completing
177 wxDragNone, // drag target didn't accept the data
178 wxDragCopy, // the data was successfully copied
179 wxDragMove, // the data was successfully moved (MSW only)
180 wxDragCancel // the operation was cancelled by user (not an error)
c801d85f
KB
181};
182
8a126fcc 183class wxDropSource: public wxObject
ab8884ac
RR
184{
185public:
186
8a126fcc
RR
187 /* constructor. set data later with SetData() */
188 wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
ab8884ac 189
8a126fcc
RR
190 /* constructor for setting one data object */
191 wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
ab8884ac 192
8a126fcc
RR
193 /* constructor for setting several data objects via wxDataBroker */
194 wxDropSource( wxDataBroker *data, wxWindow *win );
ab8884ac 195
8a126fcc 196 ~wxDropSource();
ab8884ac 197
8a126fcc
RR
198 /* set several dataobjects via wxDataBroker */
199 void SetData( wxDataBroker *data );
ab8884ac 200
8a126fcc
RR
201 /* set one dataobject */
202 void SetData( wxDataObject *data );
c801d85f 203
8a126fcc
RR
204 /* start drag action */
205 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
e3e65dac 206
8a126fcc
RR
207 /* override to give feedback */
208 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
c801d85f 209
8a126fcc
RR
210 /* GTK implementation */
211
212 void RegisterWindow();
213 void UnregisterWindow();
214
215 GtkWidget *m_widget;
216 wxWindow *m_window;
217 wxDragResult m_retValue;
218 wxDataBroker *m_data;
219
220 wxCursor m_defaultCursor;
221 wxCursor m_goaheadCursor;
222
223 wxIcon m_goIcon;
224 wxIcon m_stopIcon;
225
226 bool m_waiting;
c801d85f
KB
227};
228
ac57418f
RR
229#endif
230
231 // wxUSE_DRAG_AND_DROP
232
c801d85f
KB
233#endif
234 //__GTKDNDH__
235