]>
Commit | Line | Data |
---|---|---|
1737035f VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: ole/dataobj.h | |
3 | // Purpose: declaration of the wxDataObject class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 10.05.98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
bbcdf8bc | 9 | // Licence: wxWindows licence |
1737035f VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_OLEDATAOBJ_H |
13 | #define _WX_OLEDATAOBJ_H | |
1737035f VZ |
14 | |
15 | // ---------------------------------------------------------------------------- | |
16 | // forward declarations | |
17 | // ---------------------------------------------------------------------------- | |
18 | struct IDataObject; | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // wxDataObject is a "smart" and polymorphic piece of data. | |
22 | // | |
23 | // @@@ it's currently "read-only" from COM point of view, i.e. we don't support | |
24 | // SetData. We don't support all advise functions neither (but it's easy to | |
25 | // do if we really want them) | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
8853b9a8 | 28 | class WXDLLEXPORT wxDataObject |
1737035f VZ |
29 | { |
30 | public: | |
31 | // all data formats (values are the same as in windows.h, do not change!) | |
32 | enum StdFormat | |
33 | { | |
34 | Invalid, | |
35 | Text, | |
36 | Bitmap, | |
37 | MetafilePict, | |
38 | Sylk, | |
39 | Dif, | |
40 | Tiff, | |
41 | OemText, | |
42 | Dib, | |
43 | Palette, | |
44 | Pendata, | |
45 | Riff, | |
46 | Wave, | |
47 | UnicodeText, | |
48 | EnhMetafile, | |
49 | Hdrop, | |
50 | Locale, | |
51 | Max | |
52 | }; | |
53 | ||
40e1a9c0 JS |
54 | // function to return symbolic name of clipboard format (debug messages) |
55 | static const char *GetFormatName(wxDataFormat format); | |
1737035f VZ |
56 | |
57 | // ctor & dtor | |
58 | wxDataObject(); | |
59 | ~wxDataObject(); | |
60 | ||
61 | // pure virtuals to override | |
62 | // get the best suited format for our data | |
63 | virtual wxDataFormat GetPreferredFormat() const = 0; | |
64 | // decide if we support this format (should be one of values of | |
65 | // StdFormat enumerations or a user-defined format) | |
66 | virtual bool IsSupportedFormat(wxDataFormat format) const = 0; | |
67 | // get the (total) size of data | |
3cda6353 | 68 | virtual size_t GetDataSize() const = 0; |
1737035f VZ |
69 | // copy raw data to provided pointer |
70 | virtual void GetDataHere(void *pBuf) const = 0; | |
71 | ||
72 | // accessors | |
73 | // retrieve IDataObject interface (for other OLE related classes) | |
74 | IDataObject *GetInterface() const { return m_pIDataObject; } | |
75 | ||
06e43511 JS |
76 | ////// wxGTK compatibility: hopefully to become the preferred API. |
77 | virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); } | |
78 | ||
1737035f VZ |
79 | private: |
80 | IDataObject *m_pIDataObject; // pointer to the COM interface | |
81 | }; | |
82 | ||
83 | // ---------------------------------------------------------------------------- | |
84 | // wxTextDataObject is a specialization of wxDataObject for text data | |
85 | // ---------------------------------------------------------------------------- | |
8853b9a8 | 86 | class WXDLLEXPORT wxTextDataObject : public wxDataObject |
1737035f VZ |
87 | { |
88 | public: | |
89 | // ctors | |
90 | wxTextDataObject(); | |
91 | wxTextDataObject(const wxString& strText) : m_strText(strText) { } | |
92 | void Init(const wxString& strText) { m_strText = strText; } | |
93 | ||
94 | // implement base class pure virtuals | |
95 | virtual wxDataFormat GetPreferredFormat() const | |
b3324be2 | 96 | { return (wxDataFormat) wxDataObject::Text; } |
1737035f VZ |
97 | virtual bool IsSupportedFormat(wxDataFormat format) const |
98 | { return format == wxDataObject::Text || format == wxDataObject::Locale; } | |
3cda6353 | 99 | virtual size_t GetDataSize() const |
1737035f VZ |
100 | { return m_strText.Len() + 1; } // +1 for trailing '\0'of course |
101 | virtual void GetDataHere(void *pBuf) const | |
102 | { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } | |
103 | ||
06e43511 JS |
104 | ////// wxGTK compatibility: hopefully to become the preferred API. |
105 | void SetText(const wxString& strText) { m_strText = strText; } | |
106 | wxString GetText() const { return m_strText; } | |
107 | virtual wxDataFormat GetFormat() const { return wxDF_TEXT; } | |
108 | ||
1737035f VZ |
109 | private: |
110 | wxString m_strText; | |
111 | }; | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
114 | // @@@ TODO: wx{Bitmap|Metafile|...}DataObject | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
06e43511 JS |
117 | // ---------------------------------------------------------------------------- |
118 | // wxBitmapDataObject is a specialization of wxDataObject for bitmap data | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | // TODO: implement OLE side of things. At present, it's just for clipboard | |
122 | // use. | |
123 | class WXDLLEXPORT wxBitmapDataObject : public wxDataObject | |
124 | { | |
125 | public: | |
126 | // ctors | |
127 | wxBitmapDataObject() {}; | |
128 | wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) {} | |
129 | void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } | |
130 | wxBitmap GetBitmap() const { return m_bitmap; } | |
131 | ||
132 | virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; } | |
133 | ||
134 | /* ?? | |
135 | // implement base class pure virtuals | |
136 | virtual wxDataFormat GetPreferredFormat() const | |
137 | { return (wxDataFormat) wxDataObject::Text; } | |
138 | virtual bool IsSupportedFormat(wxDataFormat format) const | |
139 | { return format == wxDataObject::Text || format == wxDataObject::Locale; } | |
140 | virtual size_t GetDataSize() const | |
141 | { return m_strText.Len() + 1; } // +1 for trailing '\0'of course | |
142 | virtual void GetDataHere(void *pBuf) const | |
143 | { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } | |
144 | */ | |
145 | ||
146 | private: | |
147 | wxBitmap m_bitmap; | |
148 | }; | |
149 | ||
150 | // ---------------------------------------------------------------------------- | |
151 | // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
2845ddc2 JS |
154 | TODO: wxFileDataObject. |
155 | ||
bbcdf8bc | 156 | #endif //_WX_OLEDATAOBJ_H |
06e43511 | 157 |