]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dnd.h
Small fixes to wxChoice, wxComboBox and wxListBox
[wxWidgets.git] / include / wx / gtk1 / dnd.h
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
29 class wxDataObject;
30 class wxTextDataObject;
31 class wxFileDataObject;
32
33 class wxDropTarget;
34 class wxTextDropTarget;
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 size_t 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 size_t 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 };
115
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 size_t 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 };
142 //-------------------------------------------------------------------------
143 // wxDropTarget
144 //-------------------------------------------------------------------------
145
146 class wxDropTarget: public wxObject
147 {
148 public:
149
150 wxDropTarget();
151 ~wxDropTarget();
152
153 virtual void OnEnter() { }
154 virtual void OnLeave() { }
155 virtual bool OnDrop( long x, long y, const void *pData ) = 0;
156
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
166 void Drop( GdkEvent *event, int x, int y );
167 void RegisterWidget( GtkWidget *widget );
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 );
182
183 protected:
184
185 virtual size_t GetFormatCount() const;
186 virtual wxDataFormat GetFormat(size_t n) const;
187 };
188
189 // ----------------------------------------------------------------------------
190 // A drop target which accepts files (dragged from File Manager or Explorer)
191 // ----------------------------------------------------------------------------
192
193 class wxFileDropTarget: public wxDropTarget
194 {
195 public:
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[]);
202
203 protected:
204
205 virtual size_t GetFormatCount() const;
206 virtual wxDataFormat GetFormat(size_t n) const;
207 };
208
209 //-------------------------------------------------------------------------
210 // wxDropSource
211 //-------------------------------------------------------------------------
212
213 class wxDropSource: public wxObject
214 {
215 public:
216
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);
230
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:
237
238 friend void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source );
239
240 void RegisterWindow(void);
241 void UnregisterWindow(void);
242
243 GtkWidget *m_widget;
244 wxWindow *m_window;
245 DragResult m_retValue;
246 wxDataObject *m_data;
247
248 wxCursor m_defaultCursor;
249 wxCursor m_goaheadCursor;
250 };
251
252 #endif
253 //__GTKDNDH__
254