]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/dataobj.h
Correct some minor compile pbs with VC++1.52c & VC++4.1
[wxWidgets.git] / include / wx / msw / ole / dataobj.h
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>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_OLEDATAOBJ_H
13 #define _WX_OLEDATAOBJ_H
14
15 // ----------------------------------------------------------------------------
16 // forward declarations
17 // ----------------------------------------------------------------------------
18 struct IDataObject;
19
20 // ----------------------------------------------------------------------------
21 // wxDataObject is a "smart" and polymorphic piece of data.
22 //
23 // TODO 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
28 class WXDLLEXPORT wxDataObject
29 {
30 public:
31 // function to return symbolic name of clipboard format (debug messages)
32 static const char *GetFormatName(wxDataFormat format);
33
34 // ctor & dtor
35 wxDataObject();
36 virtual ~wxDataObject();
37
38 // pure virtuals to override
39 // get the best suited format for our data
40 virtual wxDataFormat GetPreferredFormat() const = 0;
41 // decide if we support this format (should be one of values of
42 // wxDataFormatId enumerations or a user-defined format)
43 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
44 // get the (total) size of data
45 virtual size_t GetDataSize() const = 0;
46 // copy raw data to provided pointer
47 virtual void GetDataHere(void *pBuf) const = 0;
48
49 // accessors
50 // retrieve IDataObject interface (for other OLE related classes)
51 IDataObject *GetInterface() const { return m_pIDataObject; }
52
53 ////// wxGTK compatibility: hopefully to become the preferred API.
54 virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); }
55
56 private:
57 IDataObject *m_pIDataObject; // pointer to the COM interface
58 };
59
60 // ----------------------------------------------------------------------------
61 // wxTextDataObject is a specialization of wxDataObject for text data
62 // ----------------------------------------------------------------------------
63 class WXDLLEXPORT wxTextDataObject : public wxDataObject
64 {
65 public:
66 // ctors
67 wxTextDataObject() { }
68 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
69 void Init(const wxString& strText) { m_strText = strText; }
70
71 // implement base class pure virtuals
72 virtual wxDataFormat GetPreferredFormat() const
73 { return wxDF_TEXT; }
74 virtual bool IsSupportedFormat(wxDataFormat format) const
75 { return format == wxDF_TEXT || format == wxDF_LOCALE; }
76 virtual size_t GetDataSize() const
77 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
78 virtual void GetDataHere(void *pBuf) const
79 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
80
81 ////// wxGTK compatibility: hopefully to become the preferred API.
82 void SetText(const wxString& strText) { m_strText = strText; }
83 wxString GetText() const { return m_strText; }
84 virtual wxDataFormat GetFormat() const { return wxDF_TEXT; }
85
86 private:
87 wxString m_strText;
88 };
89
90 // ----------------------------------------------------------------------------
91 // @@@ TODO: wx{Bitmap|Metafile|...}DataObject
92 // ----------------------------------------------------------------------------
93
94 // ----------------------------------------------------------------------------
95 // wxBitmapDataObject is a specialization of wxDataObject for bitmap data
96 // ----------------------------------------------------------------------------
97
98 // TODO: implement OLE side of things. At present, it's just for clipboard
99 // use.
100 class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
101 {
102 public:
103 // ctors
104 wxBitmapDataObject() {};
105 wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) {}
106 void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
107 wxBitmap GetBitmap() const { return m_bitmap; }
108
109 virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; }
110
111 // implement base class pure virtuals
112 virtual wxDataFormat GetPreferredFormat() const
113 { return wxDF_BITMAP; }
114 virtual bool IsSupportedFormat(wxDataFormat format) const
115 { return format == wxDF_BITMAP; }
116 virtual size_t GetDataSize() const
117 { wxASSERT(FALSE); return 0; } // BEMIMP
118 virtual void GetDataHere(void *pBuf) const
119 { wxASSERT(FALSE); } // BEMIMP
120
121 private:
122 wxBitmap m_bitmap;
123 };
124
125 // ----------------------------------------------------------------------------
126 // wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
127 // ----------------------------------------------------------------------------
128
129 // TODO: wxFileDataObject.
130
131 #endif //_WX_OLEDATAOBJ_H
132