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_
17 #if wxUSE_DRAG_AND_DROP
18 #include "wx/dataobj.h"
21 // ----------------------------------------------------------------------------
22 // wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE
23 // ----------------------------------------------------------------------------
25 class WXDLLEXPORT wxEnhMetaFile
: public wxObject
28 wxEnhMetaFile(const wxString
& file
= wxEmptyString
) : m_filename(file
)
30 wxEnhMetaFile(const wxEnhMetaFile
& metafile
) : wxObject()
31 { Init(); Assign(metafile
); }
32 wxEnhMetaFile
& operator=(const wxEnhMetaFile
& metafile
)
33 { Free(); Assign(metafile
); return *this; }
35 virtual ~wxEnhMetaFile()
38 // display the picture stored in the metafile on the given DC
39 bool Play(wxDC
*dc
, wxRect
*rectBound
= (wxRect
*)NULL
);
42 bool Ok() const { return IsOk(); }
43 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
);
69 DECLARE_DYNAMIC_CLASS(wxEnhMetaFile
)
72 // ----------------------------------------------------------------------------
73 // wxEnhMetaFileDC: allows to create a wxEnhMetaFile
74 // ----------------------------------------------------------------------------
76 class WXDLLEXPORT wxEnhMetaFileDC
: public wxDC
79 // the ctor parameters specify the filename (empty for memory metafiles),
80 // the metafile picture size and the optional description/comment
81 wxEnhMetaFileDC(const wxString
& filename
= wxEmptyString
,
82 int width
= 0, int height
= 0,
83 const wxString
& description
= wxEmptyString
);
85 DECLARE_DYNAMIC_CLASS_NO_COPY(wxEnhMetaFileDC
)
88 #if wxUSE_DRAG_AND_DROP
90 // ----------------------------------------------------------------------------
91 // wxEnhMetaFileDataObject is a specialization of wxDataObject for enh metafile
92 // ----------------------------------------------------------------------------
94 // notice that we want to support both CF_METAFILEPICT and CF_ENHMETAFILE and
95 // so we derive from wxDataObject and not from wxDataObjectSimple
96 class WXDLLEXPORT wxEnhMetaFileDataObject
: public wxDataObject
100 wxEnhMetaFileDataObject() { }
101 wxEnhMetaFileDataObject(const wxEnhMetaFile
& metafile
)
102 : m_metafile(metafile
) { }
104 // virtual functions which you may override if you want to provide data on
105 // demand only - otherwise, the trivial default versions will be used
106 virtual void SetMetafile(const wxEnhMetaFile
& metafile
)
107 { m_metafile
= metafile
; }
108 virtual wxEnhMetaFile
GetMetafile() const
109 { return m_metafile
; }
111 // implement base class pure virtuals
112 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
113 virtual size_t GetFormatCount(Direction dir
) const;
114 virtual void GetAllFormats(wxDataFormat
*formats
, Direction dir
) const;
115 virtual size_t GetDataSize(const wxDataFormat
& format
) const;
116 virtual bool GetDataHere(const wxDataFormat
& format
, void *buf
) const;
117 virtual bool SetData(const wxDataFormat
& format
, size_t len
,
121 wxEnhMetaFile m_metafile
;
123 DECLARE_NO_COPY_CLASS(wxEnhMetaFileDataObject
)
127 // ----------------------------------------------------------------------------
128 // wxEnhMetaFileSimpleDataObject does derive from wxDataObjectSimple which
129 // makes it more convenient to use (it can be used with wxDataObjectComposite)
130 // at the price of not supoprting any more CF_METAFILEPICT but only
132 // ----------------------------------------------------------------------------
134 class WXDLLEXPORT wxEnhMetaFileSimpleDataObject
: public wxDataObjectSimple
138 wxEnhMetaFileSimpleDataObject() : wxDataObjectSimple(wxDF_ENHMETAFILE
) { }
139 wxEnhMetaFileSimpleDataObject(const wxEnhMetaFile
& metafile
)
140 : wxDataObjectSimple(wxDF_ENHMETAFILE
), m_metafile(metafile
) { }
142 // virtual functions which you may override if you want to provide data on
143 // demand only - otherwise, the trivial default versions will be used
144 virtual void SetEnhMetafile(const wxEnhMetaFile
& metafile
)
145 { m_metafile
= metafile
; }
146 virtual wxEnhMetaFile
GetEnhMetafile() const
147 { return m_metafile
; }
149 // implement base class pure virtuals
150 virtual size_t GetDataSize() const;
151 virtual bool GetDataHere(void *buf
) const;
152 virtual bool SetData(size_t len
, const void *buf
);
154 virtual size_t GetDataSize(const wxDataFormat
& WXUNUSED(format
)) const
155 { return GetDataSize(); }
156 virtual bool GetDataHere(const wxDataFormat
& WXUNUSED(format
),
158 { return GetDataHere(buf
); }
159 virtual bool SetData(const wxDataFormat
& WXUNUSED(format
),
160 size_t len
, const void *buf
)
161 { return SetData(len
, buf
); }
164 wxEnhMetaFile m_metafile
;
166 DECLARE_NO_COPY_CLASS(wxEnhMetaFileSimpleDataObject
)
169 #endif // wxUSE_DRAG_AND_DROP
171 #endif // _WX_MSW_ENHMETA_H_