]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/dnd.h
Added function GetDefaultSize
[wxWidgets.git] / include / wx / os2 / 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 class WXDLLEXPORT wxDataObject;
29 class WXDLLEXPORT wxTextDataObject;
30 class WXDLLEXPORT wxFileDataObject;
31
32 class WXDLLEXPORT wxDropTarget;
33 class WXDLLEXPORT wxTextDropTarget;
34 class WXDLLEXPORT wxFileDropTarget;
35
36 class WXDLLEXPORT wxDropSource;
37
38 //-------------------------------------------------------------------------
39 // wxDataFormat (internal)
40 //-------------------------------------------------------------------------
41
42 class wxDataFormat : public wxObject
43 {
44 DECLARE_CLASS( wxDataFormat )
45
46 public:
47 wxDataFormat();
48 wxDataFormat( wxDataFormatId type );
49 wxDataFormat( const wxString &id );
50 wxDataFormat( const wxChar *id );
51 wxDataFormat( const wxDataFormat &format );
52
53 void SetType( wxDataFormatId type );
54 wxDataFormatId GetType() const;
55
56 /* the string Id identifies the format of clipboard or DnD data. a word
57 * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
58 * to the clipboard - the latter with the Id "application/wxword", an
59 * image manipulation program would put a wxBitmapDataObject and a
60 * wxPrivateDataObject to the clipboard - the latter with "image/png". */
61
62 wxString GetId() const;
63 void SetId( const wxChar *id );
64
65 // implicit conversion to wxDataFormatId
66 operator wxDataFormatId() const { return m_type; }
67
68 bool operator==(wxDataFormatId type) const { return m_type == type; }
69 bool operator!=(wxDataFormatId type) const { return m_type != type; }
70
71 private:
72 wxDataFormatId m_type;
73 wxString m_id;
74 };
75 //-------------------------------------------------------------------------
76 // wxDataObject
77 //-------------------------------------------------------------------------
78
79 class WXDLLEXPORT wxDataObject: public wxObject
80 {
81 public:
82 // all data formats (values are the same as in windows.h, do not change!)
83 enum StdFormat
84 {
85 Invalid,
86 Text,
87 Bitmap,
88 MetafilePict,
89 Sylk,
90 Dif,
91 Tiff,
92 OemText,
93 Dib,
94 Palette,
95 Pendata,
96 Riff,
97 Wave,
98 UnicodeText,
99 EnhMetafile,
100 Hdrop,
101 Locale,
102 Max
103 };
104
105 // function to return symbolic name of clipboard format (debug messages)
106 static const char *GetFormatName(wxDataFormat format);
107
108 // ctor & dtor
109 wxDataObject() {};
110 ~wxDataObject() {};
111
112 // pure virtuals to override
113 // get the best suited format for our data
114 virtual wxDataFormat GetPreferredFormat() const = 0;
115 // decide if we support this format (should be one of values of
116 // StdFormat enumerations or a user-defined format)
117 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
118 // get the (total) size of data
119 virtual size_t GetDataSize() const = 0;
120 // copy raw data to provided pointer
121 virtual void GetDataHere(void *pBuf) const = 0;
122
123 };
124
125 // ----------------------------------------------------------------------------
126 // wxTextDataObject is a specialization of wxDataObject for text data
127 // ----------------------------------------------------------------------------
128
129 class WXDLLEXPORT wxTextDataObject : public wxDataObject
130 {
131 public:
132 // ctors
133 wxTextDataObject() { }
134 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
135 void Init(const wxString& strText) { m_strText = strText; }
136
137 // implement base class pure virtuals
138 virtual wxDataFormat GetPreferredFormat() const
139 { return wxDF_TEXT; }
140 virtual bool IsSupportedFormat(wxDataFormat format) const
141 { return format == wxDF_TEXT; }
142 virtual size_t GetDataSize() const
143 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
144 virtual void GetDataHere(void *pBuf) const
145 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
146
147 private:
148 wxString m_strText;
149
150 };
151
152 // ----------------------------------------------------------------------------
153 // wxFileDataObject is a specialization of wxDataObject for file names
154 // ----------------------------------------------------------------------------
155
156 class WXDLLEXPORT wxFileDataObject : public wxDataObject
157 {
158 public:
159
160 wxFileDataObject(void) { }
161 void AddFile( const wxString &file )
162 { m_files += file; m_files += ";"; }
163
164 // implement base class pure virtuals
165 virtual wxDataFormat GetPreferredFormat() const
166 { return wxDF_FILENAME; }
167 virtual bool IsSupportedFormat(wxDataFormat format) const
168 { return format == wxDF_FILENAME; }
169 virtual size_t GetDataSize() const
170 { return m_files.Len() + 1; } // +1 for trailing '\0'of course
171 virtual void GetDataHere(void *pBuf) const
172 { memcpy(pBuf, m_files.c_str(), GetDataSize()); }
173
174 private:
175 wxString m_files;
176
177 };
178 //-------------------------------------------------------------------------
179 // wxDropTarget
180 //-------------------------------------------------------------------------
181
182 class WXDLLEXPORT wxDropTarget: public wxObject
183 {
184 public:
185
186 wxDropTarget();
187 ~wxDropTarget();
188
189 virtual void OnEnter() { }
190 virtual void OnLeave() { }
191 virtual bool OnDrop( long x, long y, const void *pData ) = 0;
192
193 // protected:
194
195 friend wxWindow;
196
197 // Override these to indicate what kind of data you support:
198
199 virtual size_t GetFormatCount() const = 0;
200 virtual wxDataFormat GetFormat(size_t n) const = 0;
201 };
202
203 //-------------------------------------------------------------------------
204 // wxTextDropTarget
205 //-------------------------------------------------------------------------
206
207 class WXDLLEXPORT wxTextDropTarget: public wxDropTarget
208 {
209 public:
210
211 wxTextDropTarget() {};
212 virtual bool OnDrop( long x, long y, const void *pData );
213 virtual bool OnDropText( long x, long y, const char *psz );
214
215 protected:
216
217 virtual size_t GetFormatCount() const;
218 virtual wxDataFormat GetFormat(size_t n) const;
219 };
220
221 // ----------------------------------------------------------------------------
222 // A drop target which accepts files (dragged from File Manager or Explorer)
223 // ----------------------------------------------------------------------------
224
225 class WXDLLEXPORT wxFileDropTarget: public wxDropTarget
226 {
227 public:
228
229 wxFileDropTarget() {};
230
231 virtual bool OnDrop(long x, long y, const void *pData);
232 virtual bool OnDropFiles( long x, long y,
233 size_t nFiles, const char * const aszFiles[]);
234
235 protected:
236
237 virtual size_t GetFormatCount() const;
238 virtual wxDataFormat GetFormat(size_t n) const;
239 };
240
241 //-------------------------------------------------------------------------
242 // wxDropSource
243 //-------------------------------------------------------------------------
244
245 enum wxDragResult
246 {
247 wxDragError, // error prevented the d&d operation from completing
248 wxDragNone, // drag target didn't accept the data
249 wxDragCopy, // the data was successfully copied
250 wxDragMove, // the data was successfully moved
251 wxDragCancel // the operation was cancelled by user (not an error)
252 };
253
254 class WXDLLEXPORT wxDropSource: public wxObject
255 {
256 public:
257
258 wxDropSource( wxWindow *win );
259 wxDropSource( wxDataObject &data, wxWindow *win );
260
261 ~wxDropSource(void);
262
263 void SetData( wxDataObject &data );
264 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
265
266 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
267
268 protected:
269
270 wxDataObject *m_data;
271 };
272
273 #endif
274 //_WX_DND_H_
275