]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/dnd.h
corrected virtual function prototype
[wxWidgets.git] / include / wx / mac / dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dnd.h
3 // Purpose: Declaration of the wxDropTarget, wxDropSource class etc.
4 // Author: AUTHOR
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 AUTHOR
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_DND_H_
11 #define _WX_DND_H_
12
13 #ifdef __GNUG__
14 #pragma interface "dnd.h"
15 #endif
16
17 #include "wx/defs.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/cursor.h"
21
22 //-------------------------------------------------------------------------
23 // classes
24 //-------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxWindow;
27
28 #ifndef __WXMAC_X__
29 class WXDLLEXPORT wxDataObject;
30 class WXDLLEXPORT wxTextDataObject;
31 class WXDLLEXPORT wxFileDataObject;
32 #endif
33
34 class WXDLLEXPORT wxDropTarget;
35 class WXDLLEXPORT wxTextDropTarget;
36 class WXDLLEXPORT wxFileDropTarget;
37
38 class WXDLLEXPORT wxDropSource;
39
40 #ifndef __WXMAC_X__
41 //-------------------------------------------------------------------------
42 // wxDataObject
43 //-------------------------------------------------------------------------
44
45 class WXDLLEXPORT wxDataObject : public wxObject
46 {
47 public:
48 // all data formats (values are the same as in windows.h, do not change!)
49 enum StdFormat
50 {
51 Invalid,
52 Text,
53 Bitmap,
54 MetafilePict,
55 Sylk,
56 Dif,
57 Tiff,
58 OemText,
59 Dib,
60 Palette,
61 Pendata,
62 Riff,
63 Wave,
64 UnicodeText,
65 EnhMetafile,
66 Hdrop,
67 Locale,
68 Max
69 };
70
71 // function to return symbolic name of clipboard format (debug messages)
72 static const char *GetFormatName(wxDataFormat format);
73
74 // ctor & dtor
75 wxDataObject() {};
76 ~wxDataObject() {};
77
78 // pure virtuals to override
79 // get the best suited format for our data
80 virtual wxDataFormat GetPreferredFormat() const = 0;
81 // decide if we support this format (should be one of values of
82 // StdFormat enumerations or a user-defined format)
83 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
84 // get the (total) size of data
85 virtual size_t GetDataSize() const = 0;
86 // copy raw data to provided pointer
87 virtual void GetDataHere(void *pBuf) const = 0;
88
89 };
90
91 // ----------------------------------------------------------------------------
92 // wxTextDataObject is a specialization of wxDataObject for text data
93 // ----------------------------------------------------------------------------
94
95 class WXDLLEXPORT wxTextDataObject : public wxDataObject
96 {
97 public:
98 // ctors
99 wxTextDataObject() { }
100 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
101 void Init(const wxString& strText) { m_strText = strText; }
102
103 // implement base class pure virtuals
104 virtual wxDataFormat GetPreferredFormat() const
105 { return wxDF_TEXT; }
106 virtual bool IsSupportedFormat(wxDataFormat format) const
107 { return format == wxDF_TEXT; }
108 virtual size_t GetDataSize() const
109 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
110 virtual void GetDataHere(void *pBuf) const
111 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
112
113 private:
114 wxString m_strText;
115
116 };
117
118 // ----------------------------------------------------------------------------
119 // wxFileDataObject is a specialization of wxDataObject for file names
120 // ----------------------------------------------------------------------------
121
122 class WXDLLEXPORT wxFileDataObject : public wxDataObject
123 {
124 public:
125
126 wxFileDataObject(void) { }
127 void AddFile( const wxString &file )
128 { m_files += file; m_files += ";"; }
129
130 // implement base class pure virtuals
131 virtual wxDataFormat GetPreferredFormat() const
132 { return wxDF_FILENAME; }
133 virtual bool IsSupportedFormat(wxDataFormat format) const
134 { return format == wxDF_FILENAME; }
135 virtual size_t GetDataSize() const
136 { return m_files.Len() + 1; } // +1 for trailing '\0'of course
137 virtual void GetDataHere(void *pBuf) const
138 { memcpy(pBuf, m_files.c_str(), GetDataSize()); }
139
140 private:
141 wxString m_files;
142
143 };
144 #endif
145
146 //-------------------------------------------------------------------------
147 // wxDropTarget
148 //-------------------------------------------------------------------------
149
150 class WXDLLEXPORT wxDropTarget: public wxObject
151 {
152 public:
153
154 wxDropTarget();
155 ~wxDropTarget();
156
157 virtual void OnEnter() { }
158 virtual void OnLeave() { }
159 virtual bool OnDrop( wxCoord x, wxCoord y, const void *pData ) = 0;
160
161 // protected:
162
163 friend class wxWindow;
164
165 // Override these to indicate what kind of data you support:
166
167 virtual size_t GetFormatCount() const = 0;
168 virtual wxDataFormat GetFormat(size_t n) const = 0;
169 };
170
171 #ifndef __WXMAC_X__
172 //-------------------------------------------------------------------------
173 // wxTextDropTarget
174 //-------------------------------------------------------------------------
175
176 class WXDLLEXPORT wxTextDropTarget: public wxDropTarget
177 {
178 public:
179
180 wxTextDropTarget() {};
181 virtual bool OnDrop( wxCoord x, wxCoord y, const void *pData );
182 virtual bool OnDropText( wxCoord x, wxCoord y, const char *psz );
183
184 protected:
185
186 virtual size_t GetFormatCount() const;
187 virtual wxDataFormat GetFormat(size_t n) const;
188 };
189
190 // ----------------------------------------------------------------------------
191 // A drop target which accepts files (dragged from File Manager or Explorer)
192 // ----------------------------------------------------------------------------
193
194 class WXDLLEXPORT wxFileDropTarget: public wxDropTarget
195 {
196 public:
197
198 wxFileDropTarget() {};
199
200 virtual bool OnDrop(wxCoord x, wxCoord y, const void *pData);
201 virtual bool OnDropFiles( wxCoord x, wxCoord y,
202 size_t nFiles, const char * const aszFiles[]);
203
204 protected:
205
206 virtual size_t GetFormatCount() const;
207 virtual wxDataFormat GetFormat(size_t n) const;
208 };
209 #endif
210
211 //-------------------------------------------------------------------------
212 // wxDropSource
213 //-------------------------------------------------------------------------
214
215 class WXDLLEXPORT wxDropSource: public wxObject
216 {
217 public:
218
219 wxDropSource( wxWindow *win );
220 wxDropSource( wxDataObject &data, wxWindow *win );
221
222 ~wxDropSource(void);
223
224 void SetData( wxDataObject &data );
225 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
226
227 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
228
229 protected:
230
231 wxDataObject *m_data;
232 };
233
234 #endif
235 //_WX_DND_H_
236