]>
Commit | Line | Data |
---|---|---|
dc63c944 JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dataobj.h | |
3 | // Purpose: declaration of the wxDataObject class | |
4 | // Author: Julian Smart | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 1998 Julian Smart | |
7 | // Licence: wxWindows licence | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_DATAOBJ_H_ | |
11 | #define _WX_DATAOBJ_H_ | |
12 | ||
13 | #ifdef __GNUG__ | |
aed0ed3c | 14 | #pragma interface "dataobj.h" |
dc63c944 JS |
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 | ||
da175b2c RR |
26 | class wxDataFormat; |
27 | class wxDataObject; | |
28 | class wxTextDataObject; | |
dc63c944 JS |
29 | |
30 | //------------------------------------------------------------------------- | |
da175b2c | 31 | // wxDataFormat |
dc63c944 JS |
32 | //------------------------------------------------------------------------- |
33 | ||
da175b2c | 34 | class wxDataFormat : public wxObject |
dc63c944 | 35 | { |
da175b2c | 36 | DECLARE_CLASS( wxDataFormat ) |
dc63c944 JS |
37 | |
38 | public: | |
da175b2c RR |
39 | wxDataFormat(); |
40 | wxDataFormat( wxDataFormatId type ); | |
41 | wxDataFormat( const wxString &id ); | |
42 | wxDataFormat( const wxChar *id ); | |
43 | wxDataFormat( const wxDataFormat &format ); | |
44 | wxDataFormat( const Atom atom ); | |
dc63c944 | 45 | |
da175b2c RR |
46 | void SetType( wxDataFormatId type ); |
47 | wxDataFormatId GetType() const; | |
dc63c944 | 48 | |
da175b2c RR |
49 | /* the string Id identifies the format of clipboard or DnD data. a word |
50 | * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
51 | * to the clipboard - the latter with the Id "application/wxword", an | |
52 | * image manipulation program would put a wxBitmapDataObject and a | |
53 | * wxPrivateDataObject to the clipboard - the latter with "image/png". */ | |
dc63c944 | 54 | |
da175b2c RR |
55 | wxString GetId() const; |
56 | void SetId( const wxChar *id ); | |
dc63c944 | 57 | |
da175b2c RR |
58 | Atom GetAtom(); |
59 | void SetAtom(Atom atom) { m_hasAtom = TRUE; m_atom = atom; } | |
dc63c944 | 60 | |
da175b2c RR |
61 | // implicit conversion to wxDataFormatId |
62 | operator wxDataFormatId() const { return m_type; } | |
dc63c944 | 63 | |
da175b2c RR |
64 | bool operator==(wxDataFormatId type) const { return m_type == type; } |
65 | bool operator!=(wxDataFormatId type) const { return m_type != type; } | |
dc63c944 JS |
66 | |
67 | private: | |
da175b2c RR |
68 | wxDataFormatId m_type; |
69 | wxString m_id; | |
70 | bool m_hasAtom; | |
71 | Atom m_atom; | |
dc63c944 JS |
72 | }; |
73 | ||
da175b2c RR |
74 | //---------------------------------------------------------------------------- |
75 | // wxDataObject to be placed in wxDataBroker | |
76 | //---------------------------------------------------------------------------- | |
dc63c944 | 77 | |
da175b2c | 78 | class wxDataObject : public wxObject |
dc63c944 | 79 | { |
da175b2c | 80 | DECLARE_DYNAMIC_CLASS( wxDataObject ) |
dc63c944 JS |
81 | |
82 | public: | |
83 | ||
da175b2c RR |
84 | /* constructor */ |
85 | wxDataObject(); | |
dc63c944 | 86 | |
da175b2c RR |
87 | /* destructor */ |
88 | ~wxDataObject(); | |
dc63c944 | 89 | |
da175b2c RR |
90 | /* write data to dest */ |
91 | virtual void WriteData( void *dest ) const = 0; | |
dc63c944 | 92 | |
da175b2c RR |
93 | /* get size of data */ |
94 | virtual size_t GetSize() const = 0; | |
dc63c944 | 95 | |
da175b2c RR |
96 | /* implementation */ |
97 | ||
98 | wxDataFormat &GetFormat(); | |
99 | ||
100 | wxDataFormatId GetFormatType() const; | |
101 | wxString GetFormatId() const; | |
102 | Atom GetFormatAtom() const; | |
103 | ||
104 | wxDataFormat m_format; | |
dc63c944 JS |
105 | }; |
106 | ||
da175b2c RR |
107 | //---------------------------------------------------------------------------- |
108 | // wxTextDataObject is a specialization of wxDataObject for text data | |
109 | //---------------------------------------------------------------------------- | |
dc63c944 | 110 | |
da175b2c | 111 | class wxTextDataObject : public wxDataObject |
dc63c944 | 112 | { |
da175b2c | 113 | DECLARE_DYNAMIC_CLASS( wxTextDataObject ) |
dc63c944 JS |
114 | |
115 | public: | |
116 | ||
da175b2c RR |
117 | /* default constructor. call SetText() later or override |
118 | WriteData() and GetSize() for working on-demand */ | |
119 | wxTextDataObject(); | |
120 | ||
121 | /* constructor */ | |
122 | wxTextDataObject( const wxString& data ); | |
123 | ||
124 | /* set current text data */ | |
125 | void SetText( const wxString& data ); | |
126 | ||
127 | /* get current text data */ | |
128 | wxString GetText() const; | |
129 | ||
130 | /* by default calls WriteString() with string set by constructor or | |
131 | by SetText(). can be overridden for working on-demand */ | |
132 | virtual void WriteData( void *dest ) const; | |
133 | ||
134 | /* by default, returns length of string as set by constructor or | |
135 | by SetText(). can be overridden for working on-demand */ | |
136 | virtual size_t GetSize() const; | |
137 | ||
138 | /* write string to dest */ | |
139 | void WriteString( const wxString &str, void *dest ) const; | |
140 | ||
141 | /* implementation */ | |
142 | ||
143 | wxString m_data; | |
dc63c944 JS |
144 | }; |
145 | ||
146 | ||
147 | #endif | |
148 | //_WX_DATAOBJ_H_ | |
149 |