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