]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dnd.h
Tcl regex lib
[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 #if wxUSE_DRAG_AND_DROP
19
20 #include "wx/object.h"
21 #include "wx/string.h"
22 #include "wx/dataobj.h"
23 #include "wx/cursor.h"
24 #include "wx/icon.h"
25 #include "wx/gdicmn.h"
26
27 //-------------------------------------------------------------------------
28 // classes
29 //-------------------------------------------------------------------------
30
31 class wxWindow;
32
33 class wxDropTarget;
34 class wxTextDropTarget;
35 class wxFileDropTarget;
36 class wxPrivateDropTarget;
37
38 class wxDropSource;
39
40 //-------------------------------------------------------------------------
41 // wxDropTarget
42 //-------------------------------------------------------------------------
43
44 class wxDropTarget: public wxObject
45 {
46 public:
47
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 );
65
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 );
69
70 /* called from within OnDrop() to request a certain format
71 from the drop event. */
72 bool RequestData( wxDataFormat format );
73
74 /* called to query what formats are available */
75 bool IsSupported( wxDataFormat format );
76
77 /* fill data with data from the dragging source */
78 bool GetData( wxDataObject *data );
79
80 virtual size_t GetFormatCount() const = 0;
81 virtual wxDataFormat GetFormat(size_t n) const = 0;
82
83 // implementation
84
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 //-------------------------------------------------------------------------
103
104 class wxTextDropTarget: public wxDropTarget
105 {
106 public:
107
108 wxTextDropTarget() {}
109
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; }
119 };
120
121 //-------------------------------------------------------------------------
122 // wxPrivateDropTarget
123 //-------------------------------------------------------------------------
124
125 /*
126 class wxPrivateDropTarget: public wxDropTarget
127 {
128 public:
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
142 private:
143
144 wxString m_id;
145 };
146 */
147
148 //----------------------------------------------------------------------------
149 // A drop target which accepts files (dragged from File Manager or Explorer)
150 //----------------------------------------------------------------------------
151
152 class wxFileDropTarget: public wxDropTarget
153 {
154 public:
155
156 wxFileDropTarget() {}
157
158 virtual bool OnData( long x, long y );
159
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 };
167
168 //-------------------------------------------------------------------------
169 // wxDropSource
170 //-------------------------------------------------------------------------
171
172 class wxDropSource: public wxObject
173 {
174 public:
175 /* constructor. set data later with SetData() */
176 wxDropSource( wxWindow *win,
177 const wxIcon &go = wxNullIcon,
178 const wxIcon &stop = wxNullIcon );
179
180 /* constructor for setting one data object */
181 wxDropSource( wxDataObject& data,
182 wxWindow *win,
183 const wxIcon &go = wxNullIcon,
184 const wxIcon &stop = wxNullIcon );
185
186 ~wxDropSource();
187
188 /* start drag action */
189 virtual wxDragResult DoDragDrop( bool bAllowMove = FALSE );
190
191 /* GTK implementation */
192 void RegisterWindow();
193 void UnregisterWindow();
194
195 GtkWidget *m_widget;
196 wxWindow *m_window;
197 wxDragResult m_retValue;
198 wxDataObject *m_data;
199
200 wxCursor m_defaultCursor;
201 wxCursor m_goaheadCursor;
202
203 wxIcon m_goIcon;
204 wxIcon m_stopIcon;
205
206 bool m_waiting;
207 };
208
209 #endif
210
211 // wxUSE_DRAG_AND_DROP
212
213 #endif
214 //__GTKDNDH__
215