]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dnd.h
Added size hints to dialog,
[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 // wxDropTarget
44 //-------------------------------------------------------------------------
45
46 class wxDropTarget: public wxObject
47 {
48 public:
49
50 wxDropTarget();
51 ~wxDropTarget();
52
53 /* may be overridden to react to events */
54 virtual void OnEnter();
55 virtual void OnLeave();
56
57 /* may be overridden to reject certain formats or drops
58 on certain areas. always returns TRUE by default
59 indicating that you'd accept the data from the drag. */
60 virtual bool OnMove( long x, long y );
61
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. */
66 virtual bool OnDrop( long x, long y );
67
68 /* this gets called once the data has actually arrived. get
69 it with GetData(). this has to be overridden. */
70 virtual bool OnData( long x, long y );
71
72 /* called from within OnDrop() to request a certain format
73 from the drop event. */
74 bool RequestData( wxDataFormat format );
75
76 /* called to query what formats are available */
77 bool IsSupported( wxDataFormat format );
78
79 /* fill data with data from the dragging source */
80 bool GetData( wxDataObject *data );
81
82 // implementation
83
84 void RegisterWidget( GtkWidget *widget );
85 void UnregisterWidget( GtkWidget *widget );
86
87 GdkDragContext *m_dragContext;
88 GtkWidget *m_dragWidget;
89 GtkSelectionData *m_dragData;
90 guint m_dragTime;
91 bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
92
93 void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
94 void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
95 void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
96 void SetDragTime( guint time ) { m_dragTime = time; }
97 };
98
99 //-------------------------------------------------------------------------
100 // wxTextDropTarget
101 //-------------------------------------------------------------------------
102
103 class wxTextDropTarget: public wxDropTarget
104 {
105 public:
106
107 wxTextDropTarget() {}
108
109 virtual bool OnMove( long x, long y );
110 virtual bool OnDrop( long x, long y );
111 virtual bool OnData( long x, long y );
112
113 /* you have to override OnDropData to get at the text */
114 virtual bool OnDropText( long x, long y, const wxChar *text ) = 0;
115
116 };
117
118 //-------------------------------------------------------------------------
119 // wxPrivateDropTarget
120 //-------------------------------------------------------------------------
121
122 /*
123 class wxPrivateDropTarget: public wxDropTarget
124 {
125 public:
126
127 wxPrivateDropTarget();
128 wxPrivateDropTarget( const wxString &id );
129
130 virtual bool OnMove( long x, long y );
131 virtual bool OnDrop( long x, long y );
132 virtual bool OnData( long x, long y );
133
134 virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
135
136 void SetId( const wxString& id ) { m_id = id; }
137 wxString GetId() { return m_id; }
138
139 private:
140
141 wxString m_id;
142 };
143 */
144
145 //----------------------------------------------------------------------------
146 // A drop target which accepts files (dragged from File Manager or Explorer)
147 //----------------------------------------------------------------------------
148
149 class wxFileDropTarget: public wxDropTarget
150 {
151 public:
152
153 wxFileDropTarget() {}
154
155 virtual bool OnMove( long x, long y );
156 virtual bool OnDrop( long x, long y );
157 virtual bool OnData( long x, long y );
158
159 virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
160 };
161
162 //-------------------------------------------------------------------------
163 // wxDropSource
164 //-------------------------------------------------------------------------
165
166 enum wxDragResult
167 {
168 wxDragError, // error prevented the d&d operation from completing
169 wxDragNone, // drag target didn't accept the data
170 wxDragCopy, // the data was successfully copied
171 wxDragMove, // the data was successfully moved (MSW only)
172 wxDragCancel // the operation was cancelled by user (not an error)
173 };
174
175 class wxDropSource: public wxObject
176 {
177 public:
178
179 /* constructor. set data later with SetData() */
180 wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
181
182 wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
183 ~wxDropSource();
184
185 void SetData( wxDataObject& data );
186
187 /* start drag action */
188 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
189
190 /* override to give feedback */
191 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
192
193 /* GTK implementation */
194
195 void RegisterWindow();
196 void UnregisterWindow();
197
198 GtkWidget *m_widget;
199 wxWindow *m_window;
200 wxDragResult m_retValue;
201 wxDataObject *m_data;
202
203 wxCursor m_defaultCursor;
204 wxCursor m_goaheadCursor;
205
206 wxIcon m_goIcon;
207 wxIcon m_stopIcon;
208
209 bool m_waiting;
210 };
211
212 #endif
213
214 // wxUSE_DRAG_AND_DROP
215
216 #endif
217 //__GTKDNDH__
218