]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/dnd.h
1. wxTimer::Start() returns bool in wxGTK too (other minor corrections
[wxWidgets.git] / include / wx / gtk / dnd.h
CommitLineData
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
27class wxWindow;
28
e3e65dac
RR
29class wxDataObject;
30class wxTextDataObject;
31class wxFileDataObject;
32
c801d85f
KB
33class wxDropTarget;
34class wxTextDropTarget;
e3e65dac
RR
35class wxFileDropTarget;
36
37class wxDropSource;
38
39//-------------------------------------------------------------------------
40// wxDataObject
41//-------------------------------------------------------------------------
42
43class wxDataObject: public wxObject
44{
45public:
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
c86f1403 83 virtual size_t GetDataSize() const = 0;
e3e65dac
RR
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
93class wxTextDataObject : public wxDataObject
94{
95public:
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; }
c86f1403 106 virtual size_t GetDataSize() const
e3e65dac
RR
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
111private:
112 wxString m_strText;
113
114};
c801d85f 115
e3e65dac
RR
116// ----------------------------------------------------------------------------
117// wxFileDataObject is a specialization of wxDataObject for file names
118// ----------------------------------------------------------------------------
119
120class wxFileDataObject : public wxDataObject
121{
122public:
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; }
c86f1403 133 virtual size_t GetDataSize() const
e3e65dac
RR
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
138private:
139 wxString m_files;
140
141};
c801d85f
KB
142//-------------------------------------------------------------------------
143// wxDropTarget
144//-------------------------------------------------------------------------
145
46dc76ba 146class 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
175class 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 193class 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
46ccb510
JS
213 enum wxDragResult
214 {
215 wxDragError, // error prevented the d&d operation from completing
216 wxDragNone, // drag target didn't accept the data
217 wxDragCopy, // the data was successfully copied
218 wxDragMove, // the data was successfully moved
219 wxDragCancel // the operation was cancelled by user (not an error)
220 };
221
e3e65dac 222class wxDropSource: public wxObject
c801d85f
KB
223{
224 public:
225
e3e65dac
RR
226 wxDropSource( wxWindow *win );
227 wxDropSource( wxDataObject &data, wxWindow *win );
228
229 ~wxDropSource(void);
c801d85f 230
e3e65dac 231 void SetData( wxDataObject &data );
46ccb510 232 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
e3e65dac 233
46ccb510 234 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
e3e65dac
RR
235
236 protected:
c801d85f 237
b6af8d80
RR
238 friend void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source );
239
e3e65dac
RR
240 void RegisterWindow(void);
241 void UnregisterWindow(void);
242
243 GtkWidget *m_widget;
244 wxWindow *m_window;
46ccb510 245 wxDragResult m_retValue;
e3e65dac
RR
246 wxDataObject *m_data;
247
248 wxCursor m_defaultCursor;
249 wxCursor m_goaheadCursor;
c801d85f
KB
250};
251
252#endif
253 //__GTKDNDH__
254