]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dataobj.h
Added support for extra bitmap for toggled tool.
[wxWidgets.git] / include / wx / gtk1 / 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( const 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 // 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 bool m_hasAtom;
75 GdkAtom m_atom;
76 };
77
78 //-------------------------------------------------------------------------
79 // wxDataBroker (internal)
80 //-------------------------------------------------------------------------
81
82 class wxDataBroker : public wxObject
83 {
84 DECLARE_CLASS( wxDataBroker )
85
86 public:
87
88 /* constructor */
89 wxDataBroker();
90
91 /* add data object */
92 void Add( wxDataObject *dataObject, bool preferred = FALSE );
93
94 private:
95
96 /* OLE implementation, the methods don't need to be overridden */
97
98 /* get number of supported formats */
99 virtual size_t GetFormatCount() const;
100
101 /* return nth supported format */
102 virtual wxDataFormat &GetNthFormat( size_t nth ) const;
103
104 /* return preferrd/best supported format */
105 virtual wxDataFormatId GetPreferredFormat() const;
106
107 /* search through m_dataObjects, return TRUE if found */
108 virtual bool IsSupportedFormat( wxDataFormat &format ) const;
109
110 /* search through m_dataObjects and call child's GetSize() */
111 virtual size_t GetSize( wxDataFormat& format ) const;
112
113 /* search through m_dataObjects and call child's WriteData(dest) */
114 virtual void WriteData( wxDataFormat& format, void *dest ) const;
115
116 /* implementation */
117
118 public:
119
120 wxList m_dataObjects;
121 size_t m_preferred;
122 };
123
124 //----------------------------------------------------------------------------
125 // wxDataObject to be placed in wxDataBroker
126 //----------------------------------------------------------------------------
127
128 class wxDataObject : public wxObject
129 {
130 DECLARE_DYNAMIC_CLASS( wxDataObject )
131
132 public:
133
134 /* constructor */
135 wxDataObject();
136
137 /* destructor */
138 ~wxDataObject();
139
140 /* write data to dest */
141 virtual void WriteData( void *dest ) const = 0;
142
143 /* get size of data */
144 virtual size_t GetSize() const = 0;
145
146 /* implementation */
147
148 wxDataFormat &GetFormat();
149
150 wxDataFormatId GetFormatType() const;
151 wxString GetFormatId() const;
152 GdkAtom GetFormatAtom() const;
153
154 wxDataFormat m_format;
155 };
156
157 //----------------------------------------------------------------------------
158 // wxTextDataObject is a specialization of wxDataObject for text data
159 //----------------------------------------------------------------------------
160
161 class wxTextDataObject : public wxDataObject
162 {
163 DECLARE_DYNAMIC_CLASS( wxTextDataObject )
164
165 public:
166
167 /* default constructor. call SetText() later or override
168 WriteData() and GetSize() for working on-demand */
169 wxTextDataObject();
170
171 /* constructor */
172 wxTextDataObject( const wxString& data );
173
174 /* set current text data */
175 void SetText( const wxString& data );
176
177 /* get current text data */
178 wxString GetText() const;
179
180 /* by default calls WriteString() with string set by constructor or
181 by SetText(). can be overridden for working on-demand */
182 virtual void WriteData( void *dest ) const;
183
184 /* by default, returns length of string as set by constructor or
185 by SetText(). can be overridden for working on-demand */
186 virtual size_t GetSize() const;
187
188 /* write string to dest */
189 void WriteString( const wxString &str, void *dest ) const;
190
191 /* implementation */
192
193 wxString m_data;
194 };
195
196 //----------------------------------------------------------------------------
197 // wxFileDataObject is a specialization of wxDataObject for file names
198 //----------------------------------------------------------------------------
199
200 class wxFileDataObject : public wxDataObject
201 {
202 DECLARE_DYNAMIC_CLASS( wxFileDataObject )
203
204 public:
205
206 /* default constructor */
207 wxFileDataObject();
208
209 /* add file name to list */
210 void AddFile( const wxString &file );
211
212 /* get all filename as one string. each file name is 0 terminated,
213 the list is double zero terminated */
214 wxString GetFiles() const;
215
216 /* write list of filenames */
217 virtual void WriteData( void *dest ) const;
218
219 /* return length of list of filenames */
220 virtual size_t GetSize() const;
221
222 /* implementation */
223
224 wxString m_files;
225 };
226
227 //----------------------------------------------------------------------------
228 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
229 //----------------------------------------------------------------------------
230
231 class wxBitmapDataObject : public wxDataObject
232 {
233 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
234
235 public:
236
237 /* see wxTextDataObject for explanation */
238
239 wxBitmapDataObject();
240 wxBitmapDataObject( const wxBitmap& bitmap );
241
242 void SetBitmap( const wxBitmap &bitmap );
243 wxBitmap GetBitmap() const;
244
245 virtual void WriteData( void *dest ) const;
246 virtual size_t GetSize() const;
247
248 void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
249
250 // implementation
251
252 wxBitmap m_bitmap;
253
254 };
255
256 #endif
257 //__GTKDNDH__
258