]>
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 | ||
82 | // implementation | |
8e193f38 | 83 | |
d6086ea6 RR |
84 | void RegisterWidget( GtkWidget *widget ); |
85 | void UnregisterWidget( GtkWidget *widget ); | |
8e193f38 | 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 */ | |
8e193f38 | 92 | |
d6086ea6 | 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 | ||
103 | class wxTextDropTarget: public wxDropTarget | |
104 | { | |
105 | public: | |
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 ); | |
8e193f38 | 112 | |
d6086ea6 | 113 | /* you have to override OnDropData to get at the text */ |
8dbf4589 | 114 | virtual bool OnDropText( long x, long y, const wxChar *text ) = 0; |
8e193f38 | 115 | |
d6086ea6 RR |
116 | }; |
117 | ||
118 | //------------------------------------------------------------------------- | |
119 | // wxPrivateDropTarget | |
120 | //------------------------------------------------------------------------- | |
121 | ||
1dd989e1 | 122 | /* |
d6086ea6 RR |
123 | class wxPrivateDropTarget: public wxDropTarget |
124 | { | |
125 | public: | |
126 | ||
d6086ea6 | 127 | wxPrivateDropTarget(); |
d6086ea6 | 128 | wxPrivateDropTarget( const wxString &id ); |
8e193f38 | 129 | |
8dbf4589 RR |
130 | virtual bool OnMove( long x, long y ); |
131 | virtual bool OnDrop( long x, long y ); | |
132 | virtual bool OnData( long x, long y ); | |
8e193f38 | 133 | |
8dbf4589 | 134 | virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0; |
8e193f38 | 135 | |
d6086ea6 RR |
136 | void SetId( const wxString& id ) { m_id = id; } |
137 | wxString GetId() { return m_id; } | |
8e193f38 | 138 | |
d6086ea6 RR |
139 | private: |
140 | ||
141 | wxString m_id; | |
142 | }; | |
1dd989e1 | 143 | */ |
d6086ea6 RR |
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: | |
8e193f38 | 152 | |
d6086ea6 | 153 | wxFileDropTarget() {} |
8e193f38 | 154 | |
8dbf4589 RR |
155 | virtual bool OnMove( long x, long y ); |
156 | virtual bool OnDrop( long x, long y ); | |
157 | virtual bool OnData( long x, long y ); | |
8e193f38 | 158 | |
8dbf4589 | 159 | virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; |
d6086ea6 RR |
160 | }; |
161 | ||
c801d85f | 162 | //------------------------------------------------------------------------- |
8a126fcc | 163 | // wxDropSource |
c801d85f KB |
164 | //------------------------------------------------------------------------- |
165 | ||
8a126fcc | 166 | enum wxDragResult |
c801d85f | 167 | { |
8a126fcc RR |
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) | |
c801d85f KB |
173 | }; |
174 | ||
8a126fcc | 175 | class wxDropSource: public wxObject |
ab8884ac RR |
176 | { |
177 | public: | |
178 | ||
8a126fcc RR |
179 | /* constructor. set data later with SetData() */ |
180 | wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); | |
8e193f38 | 181 | |
8e193f38 | 182 | wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); |
8a126fcc | 183 | ~wxDropSource(); |
8e193f38 | 184 | |
8e193f38 VZ |
185 | void SetData( wxDataObject& data ); |
186 | ||
8a126fcc RR |
187 | /* start drag action */ |
188 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); | |
8e193f38 | 189 | |
8a126fcc RR |
190 | /* override to give feedback */ |
191 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } | |
8e193f38 | 192 | |
8a126fcc | 193 | /* GTK implementation */ |
8e193f38 | 194 | |
8a126fcc RR |
195 | void RegisterWindow(); |
196 | void UnregisterWindow(); | |
8e193f38 | 197 | |
8a126fcc RR |
198 | GtkWidget *m_widget; |
199 | wxWindow *m_window; | |
200 | wxDragResult m_retValue; | |
1dd989e1 | 201 | wxDataObject *m_data; |
8e193f38 | 202 | |
8a126fcc RR |
203 | wxCursor m_defaultCursor; |
204 | wxCursor m_goaheadCursor; | |
8e193f38 | 205 | |
8a126fcc RR |
206 | wxIcon m_goIcon; |
207 | wxIcon m_stopIcon; | |
8e193f38 | 208 | |
8a126fcc | 209 | bool m_waiting; |
c801d85f KB |
210 | }; |
211 | ||
ac57418f RR |
212 | #endif |
213 | ||
214 | // wxUSE_DRAG_AND_DROP | |
215 | ||
8e193f38 | 216 | #endif |
c801d85f KB |
217 | //__GTKDNDH__ |
218 |