]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/dataobj.h
wxCALLBACK added, wxCOMPFUNC_CONV moved to defs.h
[wxWidgets.git] / include / wx / msw / ole / dataobj.h
CommitLineData
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 14
7dee726c 15#include "wx/bitmap.h"
da175b2c
RR
16// ----------------------------------------------------------------------------
17// wxDataFormat identifies the single format of data
18// ----------------------------------------------------------------------------
19
20class WXDLLEXPORT wxDataFormat
21{
22public:
23 // the clipboard formats under Win32 are UINTs
24 typedef unsigned int NativeFormat;
25
26 wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; }
27 wxDataFormat& operator=(NativeFormat format)
28 { m_format = format; return *this; }
29
30 // defautl copy ctor/assignment operators ok
31
32 // comparison (must have both versions)
33 bool operator==(wxDataFormatId format) const
34 { return m_format == (NativeFormat)format; }
35 bool operator!=(wxDataFormatId format) const
36 { return m_format != (NativeFormat)format; }
37 bool operator==(const wxDataFormat& format) const
38 { return m_format == format.m_format; }
39 bool operator!=(const wxDataFormat& format) const
40 { return m_format != format.m_format; }
41
42 // explicit and implicit conversions to NativeFormat which is one of
43 // standard data types (implicit conversion is useful for preserving the
44 // compatibility with old code)
45 NativeFormat GetFormatId() const { return m_format; }
46 operator NativeFormat() const { return m_format; }
47
48 // this only works with standard ids
49 void SetId(wxDataFormatId format) { m_format = format; }
50
51 // string ids are used for custom types - this SetId() must be used for
52 // application-specific formats
53 wxString GetId() const;
54 void SetId(const wxChar *format);
55
56private:
57 // returns TRUE if the format is one of those defined in wxDataFormatId
58 bool IsStandard() const { return m_format > 0 && m_format < wxDF_MAX; }
59
60 NativeFormat m_format;
61};
62
1737035f
VZ
63// ----------------------------------------------------------------------------
64// forward declarations
65// ----------------------------------------------------------------------------
66struct IDataObject;
67
68// ----------------------------------------------------------------------------
69// wxDataObject is a "smart" and polymorphic piece of data.
70//
3f480da3
VZ
71// TODO it's currently "read-only" from COM point of view, i.e. we don't support
72// SetData. We don't support all advise functions neither (but it's easy to
73// do if we really want them)
1737035f
VZ
74// ----------------------------------------------------------------------------
75
8853b9a8 76class WXDLLEXPORT wxDataObject
1737035f
VZ
77{
78public:
40e1a9c0
JS
79 // function to return symbolic name of clipboard format (debug messages)
80 static const char *GetFormatName(wxDataFormat format);
1737035f
VZ
81
82 // ctor & dtor
83 wxDataObject();
25889d3c 84 virtual ~wxDataObject();
1737035f
VZ
85
86 // pure virtuals to override
87 // get the best suited format for our data
88 virtual wxDataFormat GetPreferredFormat() const = 0;
89 // decide if we support this format (should be one of values of
3f480da3 90 // wxDataFormatId enumerations or a user-defined format)
1737035f
VZ
91 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
92 // get the (total) size of data
3cda6353 93 virtual size_t GetDataSize() const = 0;
1737035f
VZ
94 // copy raw data to provided pointer
95 virtual void GetDataHere(void *pBuf) const = 0;
96
97 // accessors
98 // retrieve IDataObject interface (for other OLE related classes)
99 IDataObject *GetInterface() const { return m_pIDataObject; }
100
06e43511
JS
101 ////// wxGTK compatibility: hopefully to become the preferred API.
102 virtual wxDataFormat GetFormat() const { return GetPreferredFormat(); }
103
1737035f
VZ
104private:
105 IDataObject *m_pIDataObject; // pointer to the COM interface
106};
107
108// ----------------------------------------------------------------------------
109// wxTextDataObject is a specialization of wxDataObject for text data
110// ----------------------------------------------------------------------------
8853b9a8 111class WXDLLEXPORT wxTextDataObject : public wxDataObject
1737035f
VZ
112{
113public:
114 // ctors
26f86486 115 wxTextDataObject() { }
1737035f
VZ
116 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
117 void Init(const wxString& strText) { m_strText = strText; }
118
119 // implement base class pure virtuals
120 virtual wxDataFormat GetPreferredFormat() const
3f480da3 121 { return wxDF_TEXT; }
1737035f 122 virtual bool IsSupportedFormat(wxDataFormat format) const
3f480da3 123 { return format == wxDF_TEXT || format == wxDF_LOCALE; }
3cda6353 124 virtual size_t GetDataSize() const
1737035f
VZ
125 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
126 virtual void GetDataHere(void *pBuf) const
127 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
128
06e43511
JS
129 ////// wxGTK compatibility: hopefully to become the preferred API.
130 void SetText(const wxString& strText) { m_strText = strText; }
131 wxString GetText() const { return m_strText; }
132 virtual wxDataFormat GetFormat() const { return wxDF_TEXT; }
133
1737035f
VZ
134private:
135 wxString m_strText;
136};
137
138// ----------------------------------------------------------------------------
139// @@@ TODO: wx{Bitmap|Metafile|...}DataObject
140// ----------------------------------------------------------------------------
141
06e43511
JS
142// ----------------------------------------------------------------------------
143// wxBitmapDataObject is a specialization of wxDataObject for bitmap data
144// ----------------------------------------------------------------------------
145
146// TODO: implement OLE side of things. At present, it's just for clipboard
147// use.
148class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
149{
150public:
151 // ctors
7dee726c 152 wxBitmapDataObject() {}
06e43511
JS
153 wxBitmapDataObject(const wxBitmap& bitmap): m_bitmap(bitmap) {}
154 void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
155 wxBitmap GetBitmap() const { return m_bitmap; }
156
157 virtual wxDataFormat GetFormat() const { return wxDF_BITMAP; }
158
06e43511
JS
159 // implement base class pure virtuals
160 virtual wxDataFormat GetPreferredFormat() const
3f480da3 161 { return wxDF_BITMAP; }
06e43511 162 virtual bool IsSupportedFormat(wxDataFormat format) const
3f480da3 163 { return format == wxDF_BITMAP; }
06e43511 164 virtual size_t GetDataSize() const
25889d3c 165 { wxASSERT(FALSE); return 0; } // BEMIMP
06e43511 166 virtual void GetDataHere(void *pBuf) const
25889d3c 167 { wxASSERT(FALSE); } // BEMIMP
06e43511
JS
168
169private:
170 wxBitmap m_bitmap;
171};
172
173// ----------------------------------------------------------------------------
174// wxMetaFileDataObject: see metafile.h is a specialization of wxDataObject for bitmap data
175// ----------------------------------------------------------------------------
176
657865d2 177// TODO: wxFileDataObject.
2845ddc2 178
bbcdf8bc 179#endif //_WX_OLEDATAOBJ_H
06e43511 180