]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/dnd.h
*** empty log message ***
[wxWidgets.git] / include / wx / gtk1 / 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
06cfab17 18#if wxUSE_DRAG_AND_DROP
ac57418f 19
c801d85f
KB
20#include "wx/object.h"
21#include "wx/string.h"
8b53e5a2 22#include "wx/dataobj.h"
c801d85f 23#include "wx/cursor.h"
e4677d31
RR
24#include "wx/icon.h"
25#include "wx/gdicmn.h"
c801d85f
KB
26
27//-------------------------------------------------------------------------
28// classes
29//-------------------------------------------------------------------------
30
31class wxWindow;
32
33class wxDropTarget;
34class wxTextDropTarget;
e3e65dac 35class wxFileDropTarget;
ab8884ac 36class wxPrivateDropTarget;
e3e65dac
RR
37
38class wxDropSource;
39
d6086ea6
RR
40//-------------------------------------------------------------------------
41// wxDropTarget
42//-------------------------------------------------------------------------
43
44class wxDropTarget: public wxObject
45{
46public:
47
9e2896e5
VZ
48 wxDropTarget();
49 ~wxDropTarget();
50
51 /* may be overridden to react to events */
52 virtual void OnEnter();
53 virtual void OnLeave();
54
55 /* may be overridden to reject certain formats or drops
56 on certain areas. always returns TRUE by default
57 indicating that you'd accept the data from the drag. */
58 virtual bool OnMove( long x, long y );
59
60 /* has to be overridden to accept a drop event. call
61 IsSupported() to ask which formats are available
62 and then call RequestData() to indicate the format
63 you request. */
64 virtual bool OnDrop( long x, long y );
8e193f38 65
9e2896e5
VZ
66 /* this gets called once the data has actually arrived. get
67 it with GetData(). this has to be overridden. */
68 virtual bool OnData( long x, long y );
8e193f38 69
9e2896e5
VZ
70 /* called from within OnDrop() to request a certain format
71 from the drop event. */
72 bool RequestData( wxDataFormat format );
8e193f38 73
9e2896e5
VZ
74 /* called to query what formats are available */
75 bool IsSupported( wxDataFormat format );
d6086ea6 76
9e2896e5
VZ
77 /* fill data with data from the dragging source */
78 bool GetData( wxDataObject *data );
d6086ea6 79
9e2896e5
VZ
80 virtual size_t GetFormatCount() const = 0;
81 virtual wxDataFormat GetFormat(size_t n) const = 0;
82
8e00741d 83// implementation
d6086ea6 84
9e2896e5
VZ
85 void RegisterWidget( GtkWidget *widget );
86 void UnregisterWidget( GtkWidget *widget );
87
88 GdkDragContext *m_dragContext;
89 GtkWidget *m_dragWidget;
90 GtkSelectionData *m_dragData;
91 guint m_dragTime;
92 bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
93
94 void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
95 void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
96 void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
97 void SetDragTime( guint time ) { m_dragTime = time; }
98};
99
100//-------------------------------------------------------------------------
101// wxTextDropTarget
102//-------------------------------------------------------------------------
8e193f38 103
9e2896e5
VZ
104class wxTextDropTarget: public wxDropTarget
105{
106public:
8e193f38 107
9e2896e5 108 wxTextDropTarget() {}
8e193f38 109
9e2896e5
VZ
110 virtual bool OnData( long x, long y );
111
112 /* you have to override OnDropData to get at the text */
113 virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
114
115 virtual size_t GetFormatCount() const
116 { return 1; }
117 virtual wxDataFormat GetFormat(size_t n) const
118 { return wxDF_TEXT; }
d6086ea6
RR
119};
120
c801d85f 121//-------------------------------------------------------------------------
9e2896e5 122// wxPrivateDropTarget
c801d85f
KB
123//-------------------------------------------------------------------------
124
9e2896e5
VZ
125/*
126class wxPrivateDropTarget: public wxDropTarget
c801d85f 127{
9e2896e5
VZ
128public:
129
130 wxPrivateDropTarget();
131 wxPrivateDropTarget( const wxString &id );
132
133 virtual bool OnMove( long x, long y );
134 virtual bool OnDrop( long x, long y );
135 virtual bool OnData( long x, long y );
136
137 virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
138
139 void SetId( const wxString& id ) { m_id = id; }
140 wxString GetId() { return m_id; }
141
142private:
143
144 wxString m_id;
c801d85f 145};
9e2896e5 146*/
c801d85f 147
9e2896e5
VZ
148//----------------------------------------------------------------------------
149// A drop target which accepts files (dragged from File Manager or Explorer)
150//----------------------------------------------------------------------------
151
152class wxFileDropTarget: public wxDropTarget
ab8884ac
RR
153{
154public:
155
9e2896e5
VZ
156 wxFileDropTarget() {}
157
158 virtual bool OnData( long x, long y );
8e193f38 159
9e2896e5
VZ
160 virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
161
162 virtual size_t GetFormatCount() const
163 { return 1; }
164 virtual wxDataFormat GetFormat(size_t n) const
165 { return wxDF_FILENAME; }
166};
8e193f38 167
9e2896e5
VZ
168//-------------------------------------------------------------------------
169// wxDropSource
170//-------------------------------------------------------------------------
171
172class wxDropSource: public wxObject
173{
174public:
175 /* constructor. set data later with SetData() */
176 wxDropSource( wxWindow *win,
177 const wxIcon &go = wxNullIcon,
178 const wxIcon &stop = wxNullIcon );
8e193f38 179
9e2896e5
VZ
180 /* constructor for setting one data object */
181 wxDropSource( wxDataObject& data,
182 wxWindow *win,
183 const wxIcon &go = wxNullIcon,
184 const wxIcon &stop = wxNullIcon );
8e193f38 185
9e2896e5 186 ~wxDropSource();
8e193f38 187
9e2896e5
VZ
188 /* start drag action */
189 virtual wxDragResult DoDragDrop( bool bAllowMove = FALSE );
8e193f38 190
9e2896e5
VZ
191 /* GTK implementation */
192 void RegisterWindow();
193 void UnregisterWindow();
8e193f38 194
8a126fcc
RR
195 GtkWidget *m_widget;
196 wxWindow *m_window;
197 wxDragResult m_retValue;
1dd989e1 198 wxDataObject *m_data;
8e193f38 199
8a126fcc
RR
200 wxCursor m_defaultCursor;
201 wxCursor m_goaheadCursor;
8e193f38 202
8a126fcc
RR
203 wxIcon m_goIcon;
204 wxIcon m_stopIcon;
8e193f38 205
8a126fcc 206 bool m_waiting;
c801d85f
KB
207};
208
ac57418f
RR
209#endif
210
211 // wxUSE_DRAG_AND_DROP
212
8e193f38 213#endif
c801d85f
KB
214 //__GTKDNDH__
215