]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.h | |
3 | // Purpose: declaration of the wxDropTarget class | |
4 | // Author: Robert Roebling | |
5 | // RCS-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 | #include "wx/object.h" | |
20 | #include "wx/string.h" | |
21 | #include "wx/cursor.h" | |
22 | ||
23 | //------------------------------------------------------------------------- | |
24 | // classes | |
25 | //------------------------------------------------------------------------- | |
26 | ||
27 | class wxWindow; | |
28 | ||
e3e65dac RR |
29 | class wxDataObject; |
30 | class wxTextDataObject; | |
31 | class wxFileDataObject; | |
32 | ||
c801d85f KB |
33 | class wxDropTarget; |
34 | class wxTextDropTarget; | |
e3e65dac RR |
35 | class wxFileDropTarget; |
36 | ||
37 | class wxDropSource; | |
38 | ||
39 | //------------------------------------------------------------------------- | |
40 | // wxDataObject | |
41 | //------------------------------------------------------------------------- | |
42 | ||
43 | class wxDataObject: public wxObject | |
44 | { | |
45 | public: | |
46 | // all data formats (values are the same as in windows.h, do not change!) | |
47 | enum StdFormat | |
48 | { | |
49 | Invalid, | |
50 | Text, | |
51 | Bitmap, | |
52 | MetafilePict, | |
53 | Sylk, | |
54 | Dif, | |
55 | Tiff, | |
56 | OemText, | |
57 | Dib, | |
58 | Palette, | |
59 | Pendata, | |
60 | Riff, | |
61 | Wave, | |
62 | UnicodeText, | |
63 | EnhMetafile, | |
64 | Hdrop, | |
65 | Locale, | |
66 | Max | |
67 | }; | |
68 | ||
69 | // function to return symbolic name of clipboard format (debug messages) | |
70 | static const char *GetFormatName(wxDataFormat format); | |
71 | ||
72 | // ctor & dtor | |
73 | wxDataObject() {}; | |
74 | ~wxDataObject() {}; | |
75 | ||
76 | // pure virtuals to override | |
77 | // get the best suited format for our data | |
78 | virtual wxDataFormat GetPreferredFormat() const = 0; | |
79 | // decide if we support this format (should be one of values of | |
80 | // StdFormat enumerations or a user-defined format) | |
81 | virtual bool IsSupportedFormat(wxDataFormat format) const = 0; | |
82 | // get the (total) size of data | |
83 | virtual uint GetDataSize() const = 0; | |
84 | // copy raw data to provided pointer | |
85 | virtual void GetDataHere(void *pBuf) const = 0; | |
86 | ||
87 | }; | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // wxTextDataObject is a specialization of wxDataObject for text data | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | class wxTextDataObject : public wxDataObject | |
94 | { | |
95 | public: | |
96 | // ctors | |
97 | wxTextDataObject() { } | |
98 | wxTextDataObject(const wxString& strText) : m_strText(strText) { } | |
99 | void Init(const wxString& strText) { m_strText = strText; } | |
100 | ||
101 | // implement base class pure virtuals | |
102 | virtual wxDataFormat GetPreferredFormat() const | |
103 | { return wxDF_TEXT; } | |
104 | virtual bool IsSupportedFormat(wxDataFormat format) const | |
105 | { return format == wxDF_TEXT; } | |
106 | virtual uint GetDataSize() const | |
107 | { return m_strText.Len() + 1; } // +1 for trailing '\0'of course | |
108 | virtual void GetDataHere(void *pBuf) const | |
109 | { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } | |
110 | ||
111 | private: | |
112 | wxString m_strText; | |
113 | ||
114 | }; | |
c801d85f | 115 | |
e3e65dac RR |
116 | // ---------------------------------------------------------------------------- |
117 | // wxFileDataObject is a specialization of wxDataObject for file names | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | class wxFileDataObject : public wxDataObject | |
121 | { | |
122 | public: | |
123 | ||
124 | wxFileDataObject(void) { } | |
125 | void AddFile( const wxString &file ) | |
126 | { m_files += file; m_files += ";"; } | |
127 | ||
128 | // implement base class pure virtuals | |
129 | virtual wxDataFormat GetPreferredFormat() const | |
130 | { return wxDF_FILENAME; } | |
131 | virtual bool IsSupportedFormat(wxDataFormat format) const | |
132 | { return format == wxDF_FILENAME; } | |
133 | virtual uint GetDataSize() const | |
134 | { return m_files.Len() + 1; } // +1 for trailing '\0'of course | |
135 | virtual void GetDataHere(void *pBuf) const | |
136 | { memcpy(pBuf, m_files.c_str(), GetDataSize()); } | |
137 | ||
138 | private: | |
139 | wxString m_files; | |
140 | ||
141 | }; | |
c801d85f KB |
142 | //------------------------------------------------------------------------- |
143 | // wxDropTarget | |
144 | //------------------------------------------------------------------------- | |
145 | ||
46dc76ba | 146 | class wxDropTarget: public wxObject |
c801d85f KB |
147 | { |
148 | public: | |
149 | ||
150 | wxDropTarget(); | |
151 | ~wxDropTarget(); | |
e3e65dac | 152 | |
c801d85f KB |
153 | virtual void OnEnter() { } |
154 | virtual void OnLeave() { } | |
155 | virtual bool OnDrop( long x, long y, const void *pData ) = 0; | |
156 | ||
e3e65dac RR |
157 | // protected: |
158 | ||
159 | friend wxWindow; | |
160 | ||
161 | // Override these to indicate what kind of data you support: | |
162 | ||
163 | virtual size_t GetFormatCount() const = 0; | |
164 | virtual wxDataFormat GetFormat(size_t n) const = 0; | |
165 | ||
c801d85f | 166 | void Drop( GdkEvent *event, int x, int y ); |
e3e65dac | 167 | void RegisterWidget( GtkWidget *widget ); |
c801d85f KB |
168 | void UnregisterWidget( GtkWidget *widget ); |
169 | }; | |
170 | ||
171 | //------------------------------------------------------------------------- | |
172 | // wxTextDropTarget | |
173 | //------------------------------------------------------------------------- | |
174 | ||
175 | class wxTextDropTarget: public wxDropTarget | |
176 | { | |
177 | public: | |
178 | ||
179 | wxTextDropTarget() {}; | |
180 | virtual bool OnDrop( long x, long y, const void *pData ); | |
181 | virtual bool OnDropText( long x, long y, const char *psz ); | |
e3e65dac RR |
182 | |
183 | protected: | |
184 | ||
185 | virtual size_t GetFormatCount() const; | |
186 | virtual wxDataFormat GetFormat(size_t n) const; | |
c801d85f KB |
187 | }; |
188 | ||
e3e65dac RR |
189 | // ---------------------------------------------------------------------------- |
190 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
191 | // ---------------------------------------------------------------------------- | |
c801d85f | 192 | |
e3e65dac | 193 | class wxFileDropTarget: public wxDropTarget |
c801d85f KB |
194 | { |
195 | public: | |
e3e65dac RR |
196 | |
197 | wxFileDropTarget() {}; | |
198 | ||
199 | virtual bool OnDrop(long x, long y, const void *pData); | |
200 | virtual bool OnDropFiles( long x, long y, | |
201 | size_t nFiles, const char * const aszFiles[]); | |
c801d85f | 202 | |
e3e65dac | 203 | protected: |
c801d85f | 204 | |
e3e65dac RR |
205 | virtual size_t GetFormatCount() const; |
206 | virtual wxDataFormat GetFormat(size_t n) const; | |
c801d85f KB |
207 | }; |
208 | ||
209 | //------------------------------------------------------------------------- | |
e3e65dac | 210 | // wxDropSource |
c801d85f KB |
211 | //------------------------------------------------------------------------- |
212 | ||
e3e65dac | 213 | class wxDropSource: public wxObject |
c801d85f KB |
214 | { |
215 | public: | |
216 | ||
e3e65dac RR |
217 | enum DragResult |
218 | { | |
219 | Error, // error prevented the d&d operation from completing | |
220 | None, // drag target didn't accept the data | |
221 | Copy, // the data was successfully copied | |
222 | Move, // the data was successfully moved | |
223 | Cancel // the operation was cancelled by user (not an error) | |
224 | }; | |
225 | ||
226 | wxDropSource( wxWindow *win ); | |
227 | wxDropSource( wxDataObject &data, wxWindow *win ); | |
228 | ||
229 | ~wxDropSource(void); | |
c801d85f | 230 | |
e3e65dac RR |
231 | void SetData( wxDataObject &data ); |
232 | DragResult DoDragDrop( bool bAllowMove = FALSE ); | |
233 | ||
234 | virtual bool GiveFeedback( DragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }; | |
235 | ||
236 | protected: | |
c801d85f | 237 | |
e3e65dac RR |
238 | void RegisterWindow(void); |
239 | void UnregisterWindow(void); | |
240 | ||
241 | GtkWidget *m_widget; | |
242 | wxWindow *m_window; | |
243 | ||
244 | wxDataObject *m_data; | |
245 | ||
246 | wxCursor m_defaultCursor; | |
247 | wxCursor m_goaheadCursor; | |
c801d85f KB |
248 | }; |
249 | ||
250 | #endif | |
251 | //__GTKDNDH__ | |
252 |