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