]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dnd.h
Added wxPoem sample; fixed some Dialog Editor problems; wxStaticBitmap and wxBitmapButton
[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: $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 // 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
33 //-------------------------------------------------------------------------
34 // classes
35 //-------------------------------------------------------------------------
36
37 class wxWindow;
38
39 class wxDataObject;
40 class wxTextDataObject;
41 class wxFileDataObject;
42
43 class wxDropTarget;
44 class wxTextDropTarget;
45 class wxFileDropTarget;
46
47 class wxDropSource;
48
49 //-------------------------------------------------------------------------
50 // wxDataObject
51 //-------------------------------------------------------------------------
52
53 class wxDataObject: public wxObject
54 {
55 public:
56
57 wxDataObject() {};
58 ~wxDataObject() {};
59
60 virtual wxDataFormat GetPreferredFormat() const = 0;
61 virtual bool IsSupportedFormat( wxDataFormat format ) const = 0;
62 virtual size_t GetDataSize() const = 0;
63 virtual void GetDataHere( void *data ) const = 0;
64
65 };
66
67 // ----------------------------------------------------------------------------
68 // wxTextDataObject is a specialization of wxDataObject for text data
69 // ----------------------------------------------------------------------------
70
71 class wxTextDataObject : public wxDataObject
72 {
73 public:
74
75 wxTextDataObject() { }
76 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
77 void Init(const wxString& strText) { m_strText = strText; }
78
79 virtual wxDataFormat GetPreferredFormat() const
80 { return wxDF_TEXT; }
81
82 virtual bool IsSupportedFormat(wxDataFormat format) const
83 { return format == wxDF_TEXT; }
84
85 virtual size_t GetDataSize() const
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()); }
90
91 private:
92 wxString m_strText;
93
94 };
95
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 )
106 { m_files += file; m_files += '\0'; }
107
108 virtual wxDataFormat GetPreferredFormat() const
109 { return wxDF_FILENAME; }
110
111 virtual bool IsSupportedFormat( wxDataFormat format ) const
112 { return format == wxDF_FILENAME; }
113
114 virtual size_t GetDataSize() const
115 { return m_files.Len(); } // no trailing '\0'
116
117 virtual void GetDataHere( void *data ) const
118 { memcpy(data, m_files.c_str(), GetDataSize()); }
119
120 private:
121 wxString m_files;
122
123 };
124 //-------------------------------------------------------------------------
125 // wxDropTarget
126 //-------------------------------------------------------------------------
127
128 class wxDropTarget: public wxObject
129 {
130 public:
131
132 wxDropTarget();
133 ~wxDropTarget();
134
135 virtual void OnEnter() { }
136 virtual void OnLeave() { }
137 virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0;
138
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
144 // implementation
145
146 void RegisterWidget( GtkWidget *widget );
147 void UnregisterWidget( GtkWidget *widget );
148 };
149
150 //-------------------------------------------------------------------------
151 // wxTextDropTarget
152 //-------------------------------------------------------------------------
153
154 class wxTextDropTarget: public wxDropTarget
155 {
156 public:
157
158 wxTextDropTarget() {};
159 virtual bool OnDrop( long x, long y, const void *data, size_t size );
160 virtual bool OnDropText( long x, long y, const char *psz );
161
162 protected:
163
164 virtual size_t GetFormatCount() const;
165 virtual wxDataFormat GetFormat(size_t n) const;
166 };
167
168 // ----------------------------------------------------------------------------
169 // A drop target which accepts files (dragged from File Manager or Explorer)
170 // ----------------------------------------------------------------------------
171
172 class wxFileDropTarget: public wxDropTarget
173 {
174 public:
175
176 wxFileDropTarget() {};
177
178 virtual bool OnDrop( long x, long y, const void *data, size_t size );
179 virtual bool OnDropFiles( long x, long y,
180 size_t nFiles, const char * const aszFiles[] );
181
182 protected:
183
184 virtual size_t GetFormatCount() const;
185 virtual wxDataFormat GetFormat(size_t n) const;
186 };
187
188 //-------------------------------------------------------------------------
189 // wxDropSource
190 //-------------------------------------------------------------------------
191
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 };
200
201 class wxDropSource: public wxObject
202 {
203 public:
204
205 wxDropSource( wxWindow *win );
206 wxDropSource( wxDataObject &data, wxWindow *win );
207
208 ~wxDropSource(void);
209
210 void SetData( wxDataObject &data );
211 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
212
213 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
214
215 // implementation
216
217 void RegisterWindow(void);
218 void UnregisterWindow(void);
219
220 GtkWidget *m_widget;
221 wxWindow *m_window;
222 wxDragResult m_retValue;
223 wxDataObject *m_data;
224
225 wxCursor m_defaultCursor;
226 wxCursor m_goaheadCursor;
227 };
228
229 #endif
230 //__GTKDNDH__
231