]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataobj.h
wxPrivateDataObject works under MSW as well (hopefully it still does under
[wxWidgets.git] / include / wx / gtk / dataobj.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dataobj.h
3 // Purpose: declaration of the wxDataObject class
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
7 // Licence: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __GTKDATAOBJECTH__
11 #define __GTKDATAOBJECTH__
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include "wx/defs.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/bitmap.h"
21
22 //-------------------------------------------------------------------------
23 // classes
24 //-------------------------------------------------------------------------
25
26 class wxDataFormat;
27 class wxDataBroker;
28 class wxDataObject;
29 class wxTextDataObject;
30 class wxBitmapDataObject;
31 class wxPrivateDataObject;
32 class wxFileDataObject;
33
34 //-------------------------------------------------------------------------
35 // wxDataFormat (internal)
36 //-------------------------------------------------------------------------
37
38 class wxDataFormat : public wxObject
39 {
40 DECLARE_CLASS( wxDataFormat )
41
42 public:
43 wxDataFormat();
44 wxDataFormat( wxDataFormatId type );
45 wxDataFormat( const wxString &id );
46 wxDataFormat( const wxChar *id );
47 wxDataFormat( wxDataFormat &format );
48 wxDataFormat( const GdkAtom atom );
49
50 void SetType( wxDataFormatId type );
51 wxDataFormatId GetType() const;
52
53 /* the string Id identifies the format of clipboard or DnD data. a word
54 * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
55 * to the clipboard - the latter with the Id "application/wxword", an
56 * image manipulation program would put a wxBitmapDataObject and a
57 * wxPrivateDataObject to the clipboard - the latter with "image/png". */
58
59 wxString GetId() const;
60 void SetId( const wxChar *id );
61
62 GdkAtom GetAtom();
63 void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; }
64
65 private:
66 wxDataFormatId m_type;
67 wxString m_id;
68 bool m_hasAtom;
69 GdkAtom m_atom;
70 };
71
72 //-------------------------------------------------------------------------
73 // wxDataBroker (internal)
74 //-------------------------------------------------------------------------
75
76 class wxDataBroker : public wxObject
77 {
78 DECLARE_CLASS( wxDataBroker )
79
80 public:
81
82 /* constructor */
83 wxDataBroker();
84
85 /* add data object */
86 void Add( wxDataObject *dataObject, bool preferred = FALSE );
87
88 private:
89
90 /* OLE implementation, the methods don't need to be overridden */
91
92 /* get number of supported formats */
93 virtual size_t GetFormatCount() const;
94
95 /* return nth supported format */
96 virtual wxDataFormat &GetNthFormat( size_t nth ) const;
97
98 /* return preferrd/best supported format */
99 virtual wxDataFormat &GetPreferredFormat() const;
100
101 /* search through m_dataObjects, return TRUE if found */
102 virtual bool IsSupportedFormat( wxDataFormat &format ) const;
103
104 /* search through m_dataObjects and call child's GetSize() */
105 virtual size_t GetSize( wxDataFormat& format ) const;
106
107 /* search through m_dataObjects and call child's WriteData(dest) */
108 virtual void WriteData( wxDataFormat& format, void *dest ) const;
109
110 /* implementation */
111
112 public:
113
114 wxList m_dataObjects;
115 size_t m_preferred;
116 };
117
118 //----------------------------------------------------------------------------
119 // wxDataObject to be placed in wxDataBroker
120 //----------------------------------------------------------------------------
121
122 class wxDataObject : public wxObject
123 {
124 DECLARE_DYNAMIC_CLASS( wxDataObject )
125
126 public:
127
128 /* constructor */
129 wxDataObject();
130
131 /* destructor */
132 ~wxDataObject();
133
134 /* write data to dest */
135 virtual void WriteData( void *dest ) const = 0;
136
137 /* get size of data */
138 virtual size_t GetSize() const = 0;
139
140 /* implementation */
141
142 wxDataFormat &GetFormat();
143
144 wxDataFormatId GetFormatType() const;
145 wxString GetFormatId() const;
146 GdkAtom GetFormatAtom() const;
147
148 wxDataFormat m_format;
149 };
150
151 //----------------------------------------------------------------------------
152 // wxTextDataObject is a specialization of wxDataObject for text data
153 //----------------------------------------------------------------------------
154
155 class wxTextDataObject : public wxDataObject
156 {
157 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
158
159 public:
160
161 /* default constructor. call SetText() later or override
162 WriteData() and GetSize() for working on-demand */
163 wxTextDataObject();
164
165 /* constructor */
166 wxTextDataObject( const wxString& data );
167
168 /* set current text data */
169 void SetText( const wxString& data );
170
171 /* get current text data */
172 wxString GetText() const;
173
174 /* by default calls WriteString() with string set by constructor or
175 by SetText(). can be overridden for working on-demand */
176 virtual void WriteData( void *dest ) const;
177
178 /* by default, returns length of string as set by constructor or
179 by SetText(). can be overridden for working on-demand */
180 virtual size_t GetSize() const;
181
182 /* write string to dest */
183 void WriteString( const wxString &str, void *dest ) const;
184
185 /* implementation */
186
187 wxString m_data;
188 };
189
190 //----------------------------------------------------------------------------
191 // wxFileDataObject is a specialization of wxDataObject for file names
192 //----------------------------------------------------------------------------
193
194 class wxFileDataObject : public wxDataObject
195 {
196 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
197
198 public:
199
200 /* default constructor */
201 wxFileDataObject();
202
203 /* add file name to list */
204 void AddFile( const wxString &file );
205
206 /* get all filename as one string. each file name is 0 terminated,
207 the list is double zero terminated */
208 wxString GetFiles() const;
209
210 /* write list of filenames */
211 virtual void WriteData( void *dest ) const;
212
213 /* return length of list of filenames */
214 virtual size_t GetSize() const;
215
216 /* implementation */
217
218 wxString m_files;
219 };
220
221 //----------------------------------------------------------------------------
222 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
223 //----------------------------------------------------------------------------
224
225 class wxBitmapDataObject : public wxDataObject
226 {
227 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
228
229 public:
230
231 /* see wxTextDataObject for explanation */
232
233 wxBitmapDataObject();
234 wxBitmapDataObject( const wxBitmap& bitmap );
235
236 void SetBitmap( const wxBitmap &bitmap );
237 wxBitmap GetBitmap() const;
238
239 virtual void WriteData( void *dest ) const;
240 virtual size_t GetSize() const;
241
242 void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
243
244 // implementation
245
246 wxBitmap m_bitmap;
247
248 };
249
250 #endif
251 //__GTKDNDH__
252