]>
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 | // wxDropTarget | |
44 | //------------------------------------------------------------------------- | |
45 | ||
46 | class wxDropTarget: public wxObject | |
47 | { | |
48 | public: | |
49 | ||
50 | wxDropTarget(); | |
51 | ~wxDropTarget(); | |
8e193f38 | 52 | |
d6086ea6 RR |
53 | /* may be overridden to react to events */ |
54 | virtual void OnEnter(); | |
55 | virtual void OnLeave(); | |
8e193f38 | 56 | |
829e3e8d | 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 ); |
8e193f38 VZ |
61 | |
62 | /* has to be overridden to accept a drop event. call | |
5af019af | 63 | IsSupported() to ask which formats are available |
8e193f38 | 64 | and then call RequestData() to indicate the format |
5af019af | 65 | you request. */ |
8dbf4589 | 66 | virtual bool OnDrop( long x, long y ); |
8e193f38 | 67 | |
5af019af RR |
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 | 77 | bool IsSupported( wxDataFormat format ); |
8e193f38 | 78 | |
829e3e8d | 79 | /* fill data with data from the dragging source */ |
d6086ea6 RR |
80 | bool GetData( wxDataObject *data ); |
81 | ||
a3e7d24d RR |
82 | virtual size_t GetFormatCount() const = 0; |
83 | virtual wxDataFormat GetFormat(size_t n) const = 0; | |
84 | ||
d6086ea6 | 85 | // implementation |
8e193f38 | 86 | |
d6086ea6 RR |
87 | void RegisterWidget( GtkWidget *widget ); |
88 | void UnregisterWidget( GtkWidget *widget ); | |
8e193f38 | 89 | |
829e3e8d RR |
90 | GdkDragContext *m_dragContext; |
91 | GtkWidget *m_dragWidget; | |
5af019af | 92 | GtkSelectionData *m_dragData; |
829e3e8d RR |
93 | guint m_dragTime; |
94 | bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ | |
8e193f38 | 95 | |
d6086ea6 | 96 | void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } |
829e3e8d | 97 | void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } |
5af019af | 98 | void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; } |
829e3e8d | 99 | void SetDragTime( guint time ) { m_dragTime = time; } |
d6086ea6 RR |
100 | }; |
101 | ||
102 | //------------------------------------------------------------------------- | |
103 | // wxTextDropTarget | |
104 | //------------------------------------------------------------------------- | |
105 | ||
106 | class wxTextDropTarget: public wxDropTarget | |
107 | { | |
108 | public: | |
109 | ||
110 | wxTextDropTarget() {} | |
111 | ||
8dbf4589 | 112 | virtual bool OnData( long x, long y ); |
8e193f38 | 113 | |
d6086ea6 | 114 | /* you have to override OnDropData to get at the text */ |
8dbf4589 | 115 | virtual bool OnDropText( long x, long y, const wxChar *text ) = 0; |
8e193f38 | 116 | |
a3e7d24d RR |
117 | virtual size_t GetFormatCount() const |
118 | { return 1; } | |
119 | virtual wxDataFormat GetFormat(size_t n) const | |
120 | { return wxDF_TEXT; } | |
d6086ea6 RR |
121 | }; |
122 | ||
123 | //------------------------------------------------------------------------- | |
124 | // wxPrivateDropTarget | |
125 | //------------------------------------------------------------------------- | |
126 | ||
1dd989e1 | 127 | /* |
d6086ea6 RR |
128 | class wxPrivateDropTarget: public wxDropTarget |
129 | { | |
130 | public: | |
131 | ||
d6086ea6 | 132 | wxPrivateDropTarget(); |
d6086ea6 | 133 | wxPrivateDropTarget( const wxString &id ); |
8e193f38 | 134 | |
8dbf4589 RR |
135 | virtual bool OnMove( long x, long y ); |
136 | virtual bool OnDrop( long x, long y ); | |
137 | virtual bool OnData( long x, long y ); | |
8e193f38 | 138 | |
8dbf4589 | 139 | virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0; |
8e193f38 | 140 | |
d6086ea6 RR |
141 | void SetId( const wxString& id ) { m_id = id; } |
142 | wxString GetId() { return m_id; } | |
8e193f38 | 143 | |
d6086ea6 RR |
144 | private: |
145 | ||
146 | wxString m_id; | |
147 | }; | |
1dd989e1 | 148 | */ |
d6086ea6 RR |
149 | |
150 | //---------------------------------------------------------------------------- | |
151 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
152 | //---------------------------------------------------------------------------- | |
153 | ||
154 | class wxFileDropTarget: public wxDropTarget | |
155 | { | |
156 | public: | |
8e193f38 | 157 | |
d6086ea6 | 158 | wxFileDropTarget() {} |
8e193f38 | 159 | |
8dbf4589 | 160 | virtual bool OnData( long x, long y ); |
8e193f38 | 161 | |
8dbf4589 | 162 | virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; |
a3e7d24d RR |
163 | |
164 | virtual size_t GetFormatCount() const | |
165 | { return 1; } | |
166 | virtual wxDataFormat GetFormat(size_t n) const | |
167 | { return wxDF_FILENAME; } | |
d6086ea6 RR |
168 | }; |
169 | ||
c801d85f | 170 | //------------------------------------------------------------------------- |
8a126fcc | 171 | // wxDropSource |
c801d85f KB |
172 | //------------------------------------------------------------------------- |
173 | ||
8a126fcc | 174 | enum 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 | 183 | class wxDropSource: public wxObject |
ab8884ac RR |
184 | { |
185 | public: | |
186 | ||
8a126fcc RR |
187 | /* constructor. set data later with SetData() */ |
188 | wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); | |
8e193f38 | 189 | |
8e193f38 | 190 | wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); |
8a126fcc | 191 | ~wxDropSource(); |
8e193f38 | 192 | |
8e193f38 VZ |
193 | void SetData( wxDataObject& data ); |
194 | ||
8a126fcc RR |
195 | /* start drag action */ |
196 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); | |
8e193f38 | 197 | |
8a126fcc RR |
198 | /* override to give feedback */ |
199 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } | |
8e193f38 | 200 | |
8a126fcc | 201 | /* GTK implementation */ |
8e193f38 | 202 | |
8a126fcc RR |
203 | void RegisterWindow(); |
204 | void UnregisterWindow(); | |
8e193f38 | 205 | |
8a126fcc RR |
206 | GtkWidget *m_widget; |
207 | wxWindow *m_window; | |
208 | wxDragResult m_retValue; | |
1dd989e1 | 209 | wxDataObject *m_data; |
8e193f38 | 210 | |
8a126fcc RR |
211 | wxCursor m_defaultCursor; |
212 | wxCursor m_goaheadCursor; | |
8e193f38 | 213 | |
8a126fcc RR |
214 | wxIcon m_goIcon; |
215 | wxIcon m_stopIcon; | |
8e193f38 | 216 | |
8a126fcc | 217 | bool m_waiting; |
c801d85f KB |
218 | }; |
219 | ||
ac57418f RR |
220 | #endif |
221 | ||
222 | // wxUSE_DRAG_AND_DROP | |
223 | ||
8e193f38 | 224 | #endif |
c801d85f KB |
225 | //__GTKDNDH__ |
226 |