]>
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 //-------------------------------------------------------------------------
36 //-------------------------------------------------------------------------
41 // the clipboard formats under GDK are GdkAtoms
42 typedef GdkAtom NativeFormat
;
45 wxDataFormat( wxDataFormatId type
);
46 wxDataFormat( const wxString
&id
);
47 wxDataFormat( const wxChar
*id
);
48 wxDataFormat( NativeFormat format
);
50 wxDataFormat
& operator=(NativeFormat format
)
51 { SetId(format
); return *this; }
52 wxDataFormat
& operator=(const wxDataFormat
& format
)
53 { SetId(format
); return *this; }
55 // comparison (must have both versions)
56 bool operator==(wxDataFormatId type
) const
57 { return m_type
== (wxDataFormatId
)type
; }
58 bool operator!=(wxDataFormatId type
) const
59 { return m_type
!= (wxDataFormatId
)type
; }
60 bool operator==(NativeFormat format
) const
61 { return m_format
== (NativeFormat
)format
; }
62 bool operator!=(NativeFormat format
) const
63 { return m_format
!= (NativeFormat
)format
; }
64 bool operator==(const wxDataFormat
& format
) const
65 { return m_format
== format
.m_format
; }
66 bool operator!=(const wxDataFormat
& format
) const
67 { return m_format
!= format
.m_format
; }
69 // explicit and implicit conversions to NativeFormat which is one of
70 // standard data types (implicit conversion is useful for preserving the
71 // compatibility with old code)
72 NativeFormat
GetFormatId() const { return m_format
; }
73 operator NativeFormat() const { return m_format
; }
75 // this only works with standard ids
76 void SetId( wxDataFormatId type
);
78 // this only works with standard ids
79 void SetId( NativeFormat format
);
81 // string ids are used for custom types - this SetId() must be used for
82 // application-specific formats
83 wxString
GetId() const;
84 void SetId( const wxChar
*id
);
87 wxDataFormatId
GetType() const;
90 wxDataFormatId m_type
;
91 NativeFormat m_format
;
93 void PrepareFormats();
94 void SetType( wxDataFormatId type
);
97 //----------------------------------------------------------------------------
99 //----------------------------------------------------------------------------
101 class wxDataObject
: public wxObject
107 virtual wxDataFormat
GetPreferredFormat() const = 0;
109 // get the number of formats we support: it is understood that if we
110 // can accept data in some format, then we can render data in this
111 // format as well, but the contrary is not necessarily true. For the
112 // default value of the argument, all formats we support should be
113 // returned, but if outputOnlyToo == FALSE, then we should only return
114 // the formats which our SetData() understands
115 virtual size_t GetFormatCount(bool outputOnlyToo
= TRUE
) const
118 // return all formats in the provided array (of size GetFormatCount())
119 virtual void GetAllFormats(wxDataFormat
*formats
,
120 bool outputOnlyToo
= TRUE
) const
121 { formats
[0] = GetPreferredFormat(); }
123 // get the (total) size of data for the given format
124 virtual size_t GetDataSize(const wxDataFormat
& format
) const = 0;
126 // copy raw data (in the specified format) to provided pointer
127 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const = 0;
129 // get data from the buffer (in the given format)
130 virtual bool SetData(const wxDataFormat
& format
, const void *buf
) = 0;
132 // a simpler name which makes more sense for data objects supporting
134 wxDataFormat
GetFormat() const { return GetPreferredFormat(); }
137 // decide if we support this format (can be either standard or custom
138 // format) -- now uses GetAllFormats()
139 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const;
142 DECLARE_DYNAMIC_CLASS( wxDataObject
)
145 //----------------------------------------------------------------------------
146 // wxTextDataObject is a specialization of wxDataObject for text data
147 //----------------------------------------------------------------------------
149 class wxTextDataObject
: public wxDataObject
154 wxTextDataObject(const wxString
& strText
);
155 void Init(const wxString
& strText
) { m_strText
= strText
; }
157 virtual wxDataFormat
GetPreferredFormat() const
158 { return wxDF_TEXT
; }
159 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
160 { return format
== wxDF_TEXT
; }
162 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
163 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
164 virtual bool SetData(const wxDataFormat
& format
, const void *buf
);
166 // additional helpers
167 void SetText(const wxString
& strText
) { m_strText
= strText
; }
168 wxString
GetText() const { return m_strText
; }
174 DECLARE_DYNAMIC_CLASS( wxTextDataObject
)
177 //----------------------------------------------------------------------------
178 // wxFileDataObject is a specialization of wxDataObject for file names
179 //----------------------------------------------------------------------------
181 class wxFileDataObject
: public wxDataObject
186 void AddFile( const wxString
&file
);
187 void SetFiles( const wxString
&files
)
189 wxString
GetFiles() const;
191 virtual wxDataFormat
GetPreferredFormat() const
192 { return wxDF_FILENAME
; }
193 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
194 { return format
== wxDF_FILENAME
; }
196 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
197 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
198 virtual bool SetData(const wxDataFormat
& format
, const void *buf
);
204 DECLARE_DYNAMIC_CLASS( wxFileDataObject
)
207 //----------------------------------------------------------------------------
208 // wxBitmapDataObject is a specialization of wxDataObject for bitmaps
209 //----------------------------------------------------------------------------
211 class wxBitmapDataObject
: public wxDataObject
215 wxBitmapDataObject();
216 wxBitmapDataObject(const wxBitmap
& bitmap
);
219 ~wxBitmapDataObject();
221 // set/get our bitmap
222 void SetBitmap(const wxBitmap
& bitmap
);
223 const wxBitmap
GetBitmap() const { return m_bitmap
; }
225 virtual wxDataFormat
GetPreferredFormat() const
226 { return wxDF_BITMAP
; }
227 virtual bool IsSupportedFormat(const wxDataFormat
& format
) const
228 { return format
== wxDF_BITMAP
; }
230 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
231 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
234 virtual bool SetData(const wxDataFormat
& format
, const void *buf
);
237 virtual void SetPngData(const void *buf
, size_t size
);
240 { return m_pngData
; }
247 void DoConvertToPng();
250 DECLARE_DYNAMIC_CLASS( wxBitmapDataObject
);