]>
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 KB |
25 | #include "wx/cursor.h" |
26 | ||
fed46e72 RR |
27 | //------------------------------------------------------------------------- |
28 | // conditional compilation | |
29 | //------------------------------------------------------------------------- | |
30 | ||
31 | #if (GTK_MINOR_VERSION == 1) | |
32 | #if (GTK_MICRO_VERSION >= 3) | |
33 | #define NEW_GTK_DND_CODE | |
34 | #endif | |
35 | #endif | |
36 | ||
c801d85f KB |
37 | //------------------------------------------------------------------------- |
38 | // classes | |
39 | //------------------------------------------------------------------------- | |
40 | ||
41 | class wxWindow; | |
42 | ||
43 | class wxDropTarget; | |
44 | class wxTextDropTarget; | |
e3e65dac | 45 | class wxFileDropTarget; |
ab8884ac | 46 | class wxPrivateDropTarget; |
e3e65dac RR |
47 | |
48 | class wxDropSource; | |
49 | ||
c801d85f KB |
50 | //------------------------------------------------------------------------- |
51 | // wxDropTarget | |
52 | //------------------------------------------------------------------------- | |
53 | ||
46dc76ba | 54 | class wxDropTarget: public wxObject |
c801d85f KB |
55 | { |
56 | public: | |
57 | ||
58 | wxDropTarget(); | |
59 | ~wxDropTarget(); | |
e3e65dac | 60 | |
c801d85f KB |
61 | virtual void OnEnter() { } |
62 | virtual void OnLeave() { } | |
dc86cb34 | 63 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; |
c801d85f | 64 | |
e3e65dac RR |
65 | // Override these to indicate what kind of data you support: |
66 | ||
67 | virtual size_t GetFormatCount() const = 0; | |
0d2a2b60 | 68 | virtual wxDataFormat &GetFormat(size_t n) const; |
e3e65dac | 69 | |
dc86cb34 RR |
70 | // implementation |
71 | ||
e3e65dac | 72 | void RegisterWidget( GtkWidget *widget ); |
c801d85f | 73 | void UnregisterWidget( GtkWidget *widget ); |
0d2a2b60 RR |
74 | |
75 | wxDataFormat *m_format; | |
c801d85f KB |
76 | }; |
77 | ||
78 | //------------------------------------------------------------------------- | |
79 | // wxTextDropTarget | |
80 | //------------------------------------------------------------------------- | |
81 | ||
82 | class wxTextDropTarget: public wxDropTarget | |
83 | { | |
84 | public: | |
85 | ||
0d2a2b60 | 86 | wxTextDropTarget(); |
dc86cb34 | 87 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
c801d85f | 88 | virtual bool OnDropText( long x, long y, const char *psz ); |
e3e65dac RR |
89 | |
90 | protected: | |
91 | ||
92 | virtual size_t GetFormatCount() const; | |
c801d85f KB |
93 | }; |
94 | ||
ab8884ac RR |
95 | //------------------------------------------------------------------------- |
96 | // wxPrivateDropTarget | |
97 | //------------------------------------------------------------------------- | |
98 | ||
99 | class wxPrivateDropTarget: public wxDropTarget | |
100 | { | |
101 | public: | |
102 | ||
103 | wxPrivateDropTarget(); | |
104 | ||
105 | // you have to override OnDrop to get at the data | |
106 | ||
107 | // the string ID identifies the format of clipboard or DnD data. a word | |
108 | // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
0d2a2b60 RR |
109 | // to the clipboard - the latter with the Id "application/wxword" or |
110 | // "image/png". | |
ab8884ac | 111 | |
0d2a2b60 | 112 | void SetId( const wxString& id ); |
ab8884ac RR |
113 | |
114 | wxString GetId() | |
115 | { return m_id; } | |
116 | ||
117 | private: | |
118 | ||
119 | virtual size_t GetFormatCount() const; | |
ab8884ac RR |
120 | |
121 | wxString m_id; | |
122 | }; | |
123 | ||
0d2a2b60 | 124 | //---------------------------------------------------------------------------- |
e3e65dac | 125 | // A drop target which accepts files (dragged from File Manager or Explorer) |
0d2a2b60 | 126 | //---------------------------------------------------------------------------- |
c801d85f | 127 | |
e3e65dac | 128 | class wxFileDropTarget: public wxDropTarget |
c801d85f KB |
129 | { |
130 | public: | |
e3e65dac | 131 | |
0d2a2b60 | 132 | wxFileDropTarget(); |
e3e65dac | 133 | |
dc86cb34 | 134 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
e3e65dac | 135 | virtual bool OnDropFiles( long x, long y, |
dc86cb34 | 136 | size_t nFiles, const char * const aszFiles[] ); |
c801d85f | 137 | |
e3e65dac | 138 | protected: |
c801d85f | 139 | |
e3e65dac | 140 | virtual size_t GetFormatCount() const; |
c801d85f KB |
141 | }; |
142 | ||
143 | //------------------------------------------------------------------------- | |
e3e65dac | 144 | // wxDropSource |
c801d85f KB |
145 | //------------------------------------------------------------------------- |
146 | ||
dc86cb34 RR |
147 | enum wxDragResult |
148 | { | |
149 | wxDragError, // error prevented the d&d operation from completing | |
150 | wxDragNone, // drag target didn't accept the data | |
151 | wxDragCopy, // the data was successfully copied | |
0d2a2b60 | 152 | wxDragMove, // the data was successfully moved (MSW only) |
dc86cb34 RR |
153 | wxDragCancel // the operation was cancelled by user (not an error) |
154 | }; | |
46ccb510 | 155 | |
e3e65dac | 156 | class wxDropSource: public wxObject |
c801d85f KB |
157 | { |
158 | public: | |
159 | ||
0d2a2b60 | 160 | /* constructor. set data later with SetData() */ |
e3e65dac | 161 | wxDropSource( wxWindow *win ); |
0d2a2b60 RR |
162 | |
163 | /* constructor for setting one data object */ | |
164 | wxDropSource( wxDataObject *data, wxWindow *win ); | |
165 | ||
166 | /* constructor for setting several data objects via wxDataBroker */ | |
167 | wxDropSource( wxDataBroker *data, wxWindow *win ); | |
e3e65dac RR |
168 | |
169 | ~wxDropSource(void); | |
c801d85f | 170 | |
0d2a2b60 RR |
171 | /* set one dataobject */ |
172 | void SetData( wxDataBroker *data ); | |
173 | ||
174 | /* set severa dataobjects via wxDataBroker */ | |
175 | void SetData( wxDataObject *data ); | |
176 | ||
177 | /* start drag action */ | |
46ccb510 | 178 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); |
e3e65dac | 179 | |
0d2a2b60 RR |
180 | /* override to give feedback */ |
181 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } | |
b6af8d80 | 182 | |
0d2a2b60 | 183 | /* GTK implementation */ |
dc86cb34 | 184 | |
e3e65dac RR |
185 | void RegisterWindow(void); |
186 | void UnregisterWindow(void); | |
187 | ||
188 | GtkWidget *m_widget; | |
189 | wxWindow *m_window; | |
46ccb510 | 190 | wxDragResult m_retValue; |
0d2a2b60 | 191 | wxDataBroker *m_data; |
e3e65dac RR |
192 | |
193 | wxCursor m_defaultCursor; | |
194 | wxCursor m_goaheadCursor; | |
c801d85f KB |
195 | }; |
196 | ||
ac57418f RR |
197 | #endif |
198 | ||
199 | // wxUSE_DRAG_AND_DROP | |
200 | ||
c801d85f KB |
201 | #endif |
202 | //__GTKDNDH__ | |
203 |