1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/enhmeta.h
3 // Purpose: wxEnhMetaFile class for Win32
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MSW_ENHMETA_H_
13 #define _WX_MSW_ENHMETA_H_
16 #include "wx/gdiobj.h"
18 #if wxUSE_DRAG_AND_DROP
19 #include "wx/dataobj.h"
22 // ----------------------------------------------------------------------------
23 // wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE
24 // ----------------------------------------------------------------------------
26 class WXDLLIMPEXP_CORE wxEnhMetaFile
: public wxGDIObject
29 wxEnhMetaFile(const wxString
& file
= wxEmptyString
) : m_filename(file
)
31 wxEnhMetaFile(const wxEnhMetaFile
& metafile
) : wxGDIObject()
32 { Init(); Assign(metafile
); }
33 wxEnhMetaFile
& operator=(const wxEnhMetaFile
& metafile
)
34 { Free(); Assign(metafile
); return *this; }
36 virtual ~wxEnhMetaFile()
39 // display the picture stored in the metafile on the given DC
40 bool Play(wxDC
*dc
, wxRect
*rectBound
= NULL
);
43 virtual bool IsOk() const { return m_hMF
!= 0; }
45 wxSize
GetSize() const;
46 int GetWidth() const { return GetSize().x
; }
47 int GetHeight() const { return GetSize().y
; }
49 const wxString
& GetFileName() const { return m_filename
; }
51 // copy the metafile to the clipboard: the width and height parameters are
52 // for backwards compatibility (with wxMetaFile) only, they are ignored by
54 bool SetClipboard(int width
= 0, int height
= 0);
57 WXHANDLE
GetHENHMETAFILE() const { return m_hMF
; }
58 void SetHENHMETAFILE(WXHANDLE hMF
) { Free(); m_hMF
= hMF
; }
63 void Assign(const wxEnhMetaFile
& mf
);
65 // we don't use these functions (but probably should) but have to implement
66 // them as they're pure virtual in the base class
67 virtual wxGDIRefData
*CreateGDIRefData() const;
68 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
74 DECLARE_DYNAMIC_CLASS(wxEnhMetaFile
)
77 // ----------------------------------------------------------------------------
78 // wxEnhMetaFileDC: allows to create a wxEnhMetaFile
79 // ----------------------------------------------------------------------------
81 class WXDLLIMPEXP_CORE wxEnhMetaFileDC
: public wxDC
84 // the ctor parameters specify the filename (empty for memory metafiles),
85 // the metafile picture size and the optional description/comment
86 wxEnhMetaFileDC(const wxString
& filename
= wxEmptyString
,
87 int width
= 0, int height
= 0,
88 const wxString
& description
= wxEmptyString
);
90 // as above, but takes reference DC as first argument to take resolution,
91 // size, font metrics etc. from
92 wxEnhMetaFileDC(const wxDC
& referenceDC
,
93 const wxString
& filename
= wxEmptyString
,
94 int width
= 0, int height
= 0,
95 const wxString
& description
= wxEmptyString
);
97 // obtain a pointer to the new metafile (caller should delete it)
98 wxEnhMetaFile
*Close();
101 DECLARE_DYNAMIC_CLASS_NO_COPY(wxEnhMetaFileDC
)
104 #if wxUSE_DRAG_AND_DROP
106 // ----------------------------------------------------------------------------
107 // wxEnhMetaFileDataObject is a specialization of wxDataObject for enh metafile
108 // ----------------------------------------------------------------------------
110 // notice that we want to support both CF_METAFILEPICT and CF_ENHMETAFILE and
111 // so we derive from wxDataObject and not from wxDataObjectSimple
112 class WXDLLIMPEXP_CORE wxEnhMetaFileDataObject
: public wxDataObject
116 wxEnhMetaFileDataObject() { }
117 wxEnhMetaFileDataObject(const wxEnhMetaFile
& metafile
)
118 : m_metafile(metafile
) { }
120 // virtual functions which you may override if you want to provide data on
121 // demand only - otherwise, the trivial default versions will be used
122 virtual void SetMetafile(const wxEnhMetaFile
& metafile
)
123 { m_metafile
= metafile
; }
124 virtual wxEnhMetaFile
GetMetafile() const
125 { return m_metafile
; }
127 // implement base class pure virtuals
128 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
129 virtual size_t GetFormatCount(Direction dir
) const;
130 virtual void GetAllFormats(wxDataFormat
*formats
, Direction dir
) const;
131 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
132 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
133 virtual bool SetData(const wxDataFormat
& format
, size_t len
,
137 wxEnhMetaFile m_metafile
;
139 wxDECLARE_NO_COPY_CLASS(wxEnhMetaFileDataObject
);
143 // ----------------------------------------------------------------------------
144 // wxEnhMetaFileSimpleDataObject does derive from wxDataObjectSimple which
145 // makes it more convenient to use (it can be used with wxDataObjectComposite)
146 // at the price of not supoprting any more CF_METAFILEPICT but only
148 // ----------------------------------------------------------------------------
150 class WXDLLIMPEXP_CORE wxEnhMetaFileSimpleDataObject
: public wxDataObjectSimple
154 wxEnhMetaFileSimpleDataObject() : wxDataObjectSimple(wxDF_ENHMETAFILE
) { }
155 wxEnhMetaFileSimpleDataObject(const wxEnhMetaFile
& metafile
)
156 : wxDataObjectSimple(wxDF_ENHMETAFILE
), m_metafile(metafile
) { }
158 // virtual functions which you may override if you want to provide data on
159 // demand only - otherwise, the trivial default versions will be used
160 virtual void SetEnhMetafile(const wxEnhMetaFile
& metafile
)
161 { m_metafile
= metafile
; }
162 virtual wxEnhMetaFile
GetEnhMetafile() const
163 { return m_metafile
; }
165 // implement base class pure virtuals
166 virtual size_t GetDataSize() const;
167 virtual bool GetDataHere(void *buf
) const;
168 virtual bool SetData(size_t len
, const void *buf
);
170 virtual size_t GetDataSize(const wxDataFormat
& WXUNUSED(format
)) const
171 { return GetDataSize(); }
172 virtual bool GetDataHere(const wxDataFormat
& WXUNUSED(format
),
174 { return GetDataHere(buf
); }
175 virtual bool SetData(const wxDataFormat
& WXUNUSED(format
),
176 size_t len
, const void *buf
)
177 { return SetData(len
, buf
); }
180 wxEnhMetaFile m_metafile
;
182 wxDECLARE_NO_COPY_CLASS(wxEnhMetaFileSimpleDataObject
);
185 #endif // wxUSE_DRAG_AND_DROP
187 #endif // _WX_MSW_ENHMETA_H_