]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataobj.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxDataObject class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
7 // Licence: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef __GTKDATAOBJECTH__
11 #define __GTKDATAOBJECTH__
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/bitmap.h"
22 //-------------------------------------------------------------------------
24 //-------------------------------------------------------------------------
29 class wxTextDataObject
;
30 class wxBitmapDataObject
;
31 class wxPrivateDataObject
;
32 class wxFileDataObject
;
34 //-------------------------------------------------------------------------
35 // wxDataFormat (internal)
36 //-------------------------------------------------------------------------
38 class wxDataFormat
: public wxObject
40 DECLARE_CLASS( 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
);
50 void SetType( wxDataFormatId type
);
51 wxDataFormatId
GetType() const;
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". */
59 wxString
GetId() const;
60 void SetId( const wxChar
*id
);
63 void SetAtom(GdkAtom atom
) { m_hasAtom
= TRUE
; m_atom
= atom
; }
65 // implicit conversion to wxDataFormatId
66 operator wxDataFormatId() const { return m_type
; }
68 bool operator==(wxDataFormatId type
) const { return m_type
== type
; }
69 bool operator!=(wxDataFormatId type
) const { return m_type
!= type
; }
72 wxDataFormatId m_type
;
78 //-------------------------------------------------------------------------
79 // wxDataBroker (internal)
80 //-------------------------------------------------------------------------
82 class wxDataBroker
: public wxObject
84 DECLARE_CLASS( wxDataBroker
)
92 void Add( wxDataObject
*dataObject
, bool preferred
= FALSE
);
96 /* OLE implementation, the methods don't need to be overridden */
98 /* get number of supported formats */
99 virtual size_t GetFormatCount() const;
101 /* return nth supported format */
102 virtual wxDataFormat
&GetNthFormat( size_t nth
) const;
104 /* return preferrd/best supported format */
105 virtual wxDataFormatId
GetPreferredFormat() const;
107 /* search through m_dataObjects, return TRUE if found */
108 virtual bool IsSupportedFormat( wxDataFormat
&format
) const;
110 /* search through m_dataObjects and call child's GetSize() */
111 virtual size_t GetSize( wxDataFormat
& format
) const;
113 /* search through m_dataObjects and call child's WriteData(dest) */
114 virtual void WriteData( wxDataFormat
& format
, void *dest
) const;
120 wxList m_dataObjects
;
124 //----------------------------------------------------------------------------
125 // wxDataObject to be placed in wxDataBroker
126 //----------------------------------------------------------------------------
128 class wxDataObject
: public wxObject
130 DECLARE_DYNAMIC_CLASS( wxDataObject
)
140 /* write data to dest */
141 virtual void WriteData( void *dest
) const = 0;
143 /* get size of data */
144 virtual size_t GetSize() const = 0;
148 wxDataFormat
&GetFormat();
150 wxDataFormatId
GetFormatType() const;
151 wxString
GetFormatId() const;
152 GdkAtom
GetFormatAtom() const;
154 wxDataFormat m_format
;
157 //----------------------------------------------------------------------------
158 // wxTextDataObject is a specialization of wxDataObject for text data
159 //----------------------------------------------------------------------------
161 class wxTextDataObject
: public wxDataObject
163 DECLARE_DYNAMIC_CLASS( wxTextDataObject
)
167 /* default constructor. call SetText() later or override
168 WriteData() and GetSize() for working on-demand */
172 wxTextDataObject( const wxString
& data
);
174 /* set current text data */
175 void SetText( const wxString
& data
);
177 /* get current text data */
178 wxString
GetText() const;
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;
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;
188 /* write string to dest */
189 void WriteString( const wxString
&str
, void *dest
) const;
196 //----------------------------------------------------------------------------
197 // wxFileDataObject is a specialization of wxDataObject for file names
198 //----------------------------------------------------------------------------
200 class wxFileDataObject
: public wxDataObject
202 DECLARE_DYNAMIC_CLASS( wxFileDataObject
)
206 /* default constructor */
209 /* add file name to list */
210 void AddFile( const wxString
&file
);
212 /* get all filename as one string. each file name is 0 terminated,
213 the list is double zero terminated */
214 wxString
GetFiles() const;
216 /* write list of filenames */
217 virtual void WriteData( void *dest
) const;
219 /* return length of list of filenames */
220 virtual size_t GetSize() const;
227 //----------------------------------------------------------------------------
228 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
229 //----------------------------------------------------------------------------
231 class wxBitmapDataObject
: public wxDataObject
233 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject
)
237 /* see wxTextDataObject for explanation */
239 wxBitmapDataObject();
240 wxBitmapDataObject( const wxBitmap
& bitmap
);
242 void SetBitmap( const wxBitmap
&bitmap
);
243 wxBitmap
GetBitmap() const;
245 virtual void WriteData( void *dest
) const;
246 virtual size_t GetSize() const;
248 void WriteBitmap( const wxBitmap
&bitmap
, void *dest
) const;