]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/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
42 wxDataFormat( wxDataFormatId type
);
43 wxDataFormat( const wxString
&id
);
44 wxDataFormat( const wxChar
*id
);
45 wxDataFormat( const wxDataFormat
&format
);
46 wxDataFormat( const GdkAtom atom
);
48 void SetType( wxDataFormatId type
);
49 wxDataFormatId
GetType() const;
51 /* the string Id identifies the format of clipboard or DnD data. a word
52 * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
53 * to the clipboard - the latter with the Id "application/wxword", an
54 * image manipulation program would put a wxBitmapDataObject and a
55 * wxPrivateDataObject to the clipboard - the latter with "image/png". */
57 wxString
GetId() const;
58 void SetId( const wxChar
*id
);
61 void SetAtom(GdkAtom atom
) { m_hasAtom
= TRUE
; m_atom
= atom
; }
63 // implicit conversion to wxDataFormatId
64 operator wxDataFormatId() const { return m_type
; }
66 bool operator==(wxDataFormatId type
) const { return m_type
== type
; }
67 bool operator!=(wxDataFormatId type
) const { return m_type
!= type
; }
70 wxDataFormatId m_type
;
75 void PrepareFormats();
78 DECLARE_CLASS( wxDataFormat
)
81 //-------------------------------------------------------------------------
82 // wxDataBroker (internal)
83 //-------------------------------------------------------------------------
85 class wxDataBroker
: public wxObject
92 void Add( wxDataObject
*dataObject
, bool preferred
= FALSE
);
95 /* OLE implementation, the methods don't need to be overridden */
97 /* get number of supported formats */
98 virtual size_t GetFormatCount() const;
100 /* return nth supported format */
101 virtual wxDataFormat
&GetNthFormat( size_t nth
) const;
103 /* return preferrd/best supported format */
104 virtual wxDataFormatId
GetPreferredFormat() const;
106 /* search through m_dataObjects, return TRUE if found */
107 virtual bool IsSupportedFormat( wxDataFormat
&format
) const;
109 /* search through m_dataObjects and call child's GetSize() */
110 virtual size_t GetSize( wxDataFormat
& format
) const;
112 /* search through m_dataObjects and call child's WriteData(dest) */
113 virtual void WriteData( wxDataFormat
& format
, void *dest
) const;
117 wxList m_dataObjects
;
121 DECLARE_CLASS( wxDataBroker
)
124 //----------------------------------------------------------------------------
125 // wxDataObject to be placed in wxDataBroker
126 //----------------------------------------------------------------------------
128 class wxDataObject
: public wxObject
137 /* write data to dest */
138 virtual void WriteData( void *dest
) const = 0;
140 /* get size of data */
141 virtual size_t GetSize() const = 0;
145 wxDataFormat m_format
;
147 wxDataFormat
&GetFormat();
149 wxDataFormatId
GetFormatType() const;
150 wxString
GetFormatId() const;
151 GdkAtom
GetFormatAtom() const;
154 DECLARE_DYNAMIC_CLASS( wxDataObject
)
157 //----------------------------------------------------------------------------
158 // wxTextDataObject is a specialization of wxDataObject for text data
159 //----------------------------------------------------------------------------
161 class wxTextDataObject
: public wxDataObject
164 /* default constructor. call SetText() later or override
165 WriteData() and GetSize() for working on-demand */
169 wxTextDataObject( const wxString
& data
);
171 /* set current text data */
172 void SetText( const wxString
& data
);
174 /* get current text data */
175 wxString
GetText() const;
177 /* by default calls WriteString() with string set by constructor or
178 by SetText(). can be overridden for working on-demand */
179 virtual void WriteData( void *dest
) const;
181 /* by default, returns length of string as set by constructor or
182 by SetText(). can be overridden for working on-demand */
183 virtual size_t GetSize() const;
185 /* write string to dest */
186 void WriteString( const wxString
&str
, void *dest
) const;
193 DECLARE_DYNAMIC_CLASS( wxTextDataObject
)
196 //----------------------------------------------------------------------------
197 // wxFileDataObject is a specialization of wxDataObject for file names
198 //----------------------------------------------------------------------------
200 class wxFileDataObject
: public wxDataObject
203 /* default constructor */
206 /* add file name to list */
207 void AddFile( const wxString
&file
);
209 /* get all filename as one string. each file name is 0 terminated,
210 the list is double zero terminated */
211 wxString
GetFiles() const;
213 /* write list of filenames */
214 virtual void WriteData( void *dest
) const;
216 /* return length of list of filenames */
217 virtual size_t GetSize() const;
224 DECLARE_DYNAMIC_CLASS( wxFileDataObject
)
227 //----------------------------------------------------------------------------
228 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
229 //----------------------------------------------------------------------------
231 class wxBitmapDataObject
: public wxDataObject
234 /* see wxTextDataObject for explanation */
235 wxBitmapDataObject();
236 wxBitmapDataObject( const wxBitmap
& bitmap
);
237 ~wxBitmapDataObject();
239 void SetBitmap( const wxBitmap
&bitmap
);
240 wxBitmap
GetBitmap() const;
242 virtual void WriteData( void *dest
) const;
243 virtual size_t GetSize() const;
244 void *GetData() const { return (void*)m_pngData
; }
246 void WriteBitmap( const wxBitmap
&bitmap
, void *dest
) const;
248 void SetPngData( const char *pngData
, size_t pngSize
);
255 void DoConvertToPng();
258 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject
);