]>
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" | |
19 | #include "wx/object.h" | |
20 | #include "wx/string.h" | |
21 | #include "wx/cursor.h" | |
22 | ||
fed46e72 RR |
23 | //------------------------------------------------------------------------- |
24 | // conditional compilation | |
25 | //------------------------------------------------------------------------- | |
26 | ||
27 | #if (GTK_MINOR_VERSION == 1) | |
28 | #if (GTK_MICRO_VERSION >= 3) | |
29 | #define NEW_GTK_DND_CODE | |
30 | #endif | |
31 | #endif | |
32 | ||
c801d85f KB |
33 | //------------------------------------------------------------------------- |
34 | // classes | |
35 | //------------------------------------------------------------------------- | |
36 | ||
37 | class wxWindow; | |
38 | ||
e3e65dac RR |
39 | class wxDataObject; |
40 | class wxTextDataObject; | |
41 | class wxFileDataObject; | |
42 | ||
c801d85f KB |
43 | class wxDropTarget; |
44 | class wxTextDropTarget; | |
e3e65dac RR |
45 | class wxFileDropTarget; |
46 | ||
47 | class wxDropSource; | |
48 | ||
49 | //------------------------------------------------------------------------- | |
50 | // wxDataObject | |
51 | //------------------------------------------------------------------------- | |
52 | ||
53 | class wxDataObject: public wxObject | |
54 | { | |
55 | public: | |
dc86cb34 | 56 | |
e3e65dac RR |
57 | wxDataObject() {}; |
58 | ~wxDataObject() {}; | |
59 | ||
e3e65dac | 60 | virtual wxDataFormat GetPreferredFormat() const = 0; |
dc86cb34 | 61 | virtual bool IsSupportedFormat( wxDataFormat format ) const = 0; |
c86f1403 | 62 | virtual size_t GetDataSize() const = 0; |
dc86cb34 | 63 | virtual void GetDataHere( void *data ) const = 0; |
e3e65dac RR |
64 | |
65 | }; | |
66 | ||
67 | // ---------------------------------------------------------------------------- | |
68 | // wxTextDataObject is a specialization of wxDataObject for text data | |
69 | // ---------------------------------------------------------------------------- | |
70 | ||
71 | class wxTextDataObject : public wxDataObject | |
72 | { | |
73 | public: | |
dc86cb34 | 74 | |
e3e65dac RR |
75 | wxTextDataObject() { } |
76 | wxTextDataObject(const wxString& strText) : m_strText(strText) { } | |
77 | void Init(const wxString& strText) { m_strText = strText; } | |
78 | ||
e3e65dac RR |
79 | virtual wxDataFormat GetPreferredFormat() const |
80 | { return wxDF_TEXT; } | |
dc86cb34 | 81 | |
e3e65dac RR |
82 | virtual bool IsSupportedFormat(wxDataFormat format) const |
83 | { return format == wxDF_TEXT; } | |
dc86cb34 | 84 | |
c86f1403 | 85 | virtual size_t GetDataSize() const |
dc86cb34 RR |
86 | { return m_strText.Len() + 1; } // +1 for trailing '\0' |
87 | ||
88 | virtual void GetDataHere( void *data ) const | |
89 | { memcpy(data, m_strText.c_str(), GetDataSize()); } | |
e3e65dac RR |
90 | |
91 | private: | |
92 | wxString m_strText; | |
93 | ||
94 | }; | |
c801d85f | 95 | |
e3e65dac RR |
96 | // ---------------------------------------------------------------------------- |
97 | // wxFileDataObject is a specialization of wxDataObject for file names | |
98 | // ---------------------------------------------------------------------------- | |
99 | ||
100 | class wxFileDataObject : public wxDataObject | |
101 | { | |
102 | public: | |
103 | ||
104 | wxFileDataObject(void) { } | |
105 | void AddFile( const wxString &file ) | |
e5403d7c | 106 | { m_files += file; m_files += '\0'; } |
e3e65dac | 107 | |
e3e65dac RR |
108 | virtual wxDataFormat GetPreferredFormat() const |
109 | { return wxDF_FILENAME; } | |
dc86cb34 RR |
110 | |
111 | virtual bool IsSupportedFormat( wxDataFormat format ) const | |
e3e65dac | 112 | { return format == wxDF_FILENAME; } |
dc86cb34 | 113 | |
c86f1403 | 114 | virtual size_t GetDataSize() const |
e5403d7c | 115 | { return m_files.Len(); } // no trailing '\0' |
dc86cb34 RR |
116 | |
117 | virtual void GetDataHere( void *data ) const | |
118 | { memcpy(data, m_files.c_str(), GetDataSize()); } | |
e3e65dac RR |
119 | |
120 | private: | |
121 | wxString m_files; | |
122 | ||
123 | }; | |
c801d85f KB |
124 | //------------------------------------------------------------------------- |
125 | // wxDropTarget | |
126 | //------------------------------------------------------------------------- | |
127 | ||
46dc76ba | 128 | class wxDropTarget: public wxObject |
c801d85f KB |
129 | { |
130 | public: | |
131 | ||
132 | wxDropTarget(); | |
133 | ~wxDropTarget(); | |
e3e65dac | 134 | |
c801d85f KB |
135 | virtual void OnEnter() { } |
136 | virtual void OnLeave() { } | |
dc86cb34 | 137 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; |
c801d85f | 138 | |
e3e65dac RR |
139 | // Override these to indicate what kind of data you support: |
140 | ||
141 | virtual size_t GetFormatCount() const = 0; | |
142 | virtual wxDataFormat GetFormat(size_t n) const = 0; | |
143 | ||
dc86cb34 RR |
144 | // implementation |
145 | ||
e3e65dac | 146 | void RegisterWidget( GtkWidget *widget ); |
c801d85f KB |
147 | void UnregisterWidget( GtkWidget *widget ); |
148 | }; | |
149 | ||
150 | //------------------------------------------------------------------------- | |
151 | // wxTextDropTarget | |
152 | //------------------------------------------------------------------------- | |
153 | ||
154 | class wxTextDropTarget: public wxDropTarget | |
155 | { | |
156 | public: | |
157 | ||
158 | wxTextDropTarget() {}; | |
dc86cb34 | 159 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
c801d85f | 160 | virtual bool OnDropText( long x, long y, const char *psz ); |
e3e65dac RR |
161 | |
162 | protected: | |
163 | ||
164 | virtual size_t GetFormatCount() const; | |
165 | virtual wxDataFormat GetFormat(size_t n) const; | |
c801d85f KB |
166 | }; |
167 | ||
e3e65dac RR |
168 | // ---------------------------------------------------------------------------- |
169 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
170 | // ---------------------------------------------------------------------------- | |
c801d85f | 171 | |
e3e65dac | 172 | class wxFileDropTarget: public wxDropTarget |
c801d85f KB |
173 | { |
174 | public: | |
e3e65dac RR |
175 | |
176 | wxFileDropTarget() {}; | |
177 | ||
dc86cb34 | 178 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
e3e65dac | 179 | virtual bool OnDropFiles( long x, long y, |
dc86cb34 | 180 | size_t nFiles, const char * const aszFiles[] ); |
c801d85f | 181 | |
e3e65dac | 182 | protected: |
c801d85f | 183 | |
e3e65dac RR |
184 | virtual size_t GetFormatCount() const; |
185 | virtual wxDataFormat GetFormat(size_t n) const; | |
c801d85f KB |
186 | }; |
187 | ||
188 | //------------------------------------------------------------------------- | |
e3e65dac | 189 | // wxDropSource |
c801d85f KB |
190 | //------------------------------------------------------------------------- |
191 | ||
dc86cb34 RR |
192 | enum wxDragResult |
193 | { | |
194 | wxDragError, // error prevented the d&d operation from completing | |
195 | wxDragNone, // drag target didn't accept the data | |
196 | wxDragCopy, // the data was successfully copied | |
197 | wxDragMove, // the data was successfully moved | |
198 | wxDragCancel // the operation was cancelled by user (not an error) | |
199 | }; | |
46ccb510 | 200 | |
e3e65dac | 201 | class wxDropSource: public wxObject |
c801d85f KB |
202 | { |
203 | public: | |
204 | ||
e3e65dac RR |
205 | wxDropSource( wxWindow *win ); |
206 | wxDropSource( wxDataObject &data, wxWindow *win ); | |
207 | ||
208 | ~wxDropSource(void); | |
c801d85f | 209 | |
e3e65dac | 210 | void SetData( wxDataObject &data ); |
46ccb510 | 211 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); |
e3e65dac | 212 | |
46ccb510 | 213 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }; |
b6af8d80 | 214 | |
dc86cb34 RR |
215 | // implementation |
216 | ||
e3e65dac RR |
217 | void RegisterWindow(void); |
218 | void UnregisterWindow(void); | |
219 | ||
220 | GtkWidget *m_widget; | |
221 | wxWindow *m_window; | |
46ccb510 | 222 | wxDragResult m_retValue; |
e3e65dac RR |
223 | wxDataObject *m_data; |
224 | ||
225 | wxCursor m_defaultCursor; | |
226 | wxCursor m_goaheadCursor; | |
c801d85f KB |
227 | }; |
228 | ||
229 | #endif | |
230 | //__GTKDNDH__ | |
231 |