1///////////////////////////////////////////////////////////////////////////////
2// Name:        wx/msw/enhmeta.h
3// Purpose:     wxEnhMetaFile class for Win32
4// Author:      Vadim Zeitlin
5// Modified by:
6// Created:     13.01.00
7// RCS-ID:      $Id: enhmeta.h 60850 2009-06-01 10:16:13Z JS $
8// Copyright:   (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence:     wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MSW_ENHMETA_H_
13#define _WX_MSW_ENHMETA_H_
14
15#include "wx/dc.h"
16
17#if wxUSE_DRAG_AND_DROP
18    #include "wx/dataobj.h"
19#endif
20
21// Change this to 1 if you set wxUSE_HIGH_QUALITY_PREVIEW_IN_WXMSW to 1 in prntbase.cpp
22#define wxUSE_ENH_METAFILE_FROM_DC 0
23
24// ----------------------------------------------------------------------------
25// wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE
26// ----------------------------------------------------------------------------
27
28class WXDLLEXPORT wxEnhMetaFile : public wxObject
29{
30public:
31    wxEnhMetaFile(const wxString& file = wxEmptyString) : m_filename(file)
32        { Init(); }
33    wxEnhMetaFile(const wxEnhMetaFile& metafile) : wxObject()
34        { Init(); Assign(metafile); }
35    wxEnhMetaFile& operator=(const wxEnhMetaFile& metafile)
36        { Free(); Assign(metafile); return *this; }
37
38    virtual ~wxEnhMetaFile()
39        { Free(); }
40
41    // display the picture stored in the metafile on the given DC
42    bool Play(wxDC *dc, wxRect *rectBound = (wxRect *)NULL);
43
44    // accessors
45    bool Ok() const { return IsOk(); }
46    bool IsOk() const { return m_hMF != 0; }
47
48    wxSize GetSize() const;
49    int GetWidth() const { return GetSize().x; }
50    int GetHeight() const { return GetSize().y; }
51
52    const wxString& GetFileName() const { return m_filename; }
53
54    // copy the metafile to the clipboard: the width and height parameters are
55    // for backwards compatibility (with wxMetaFile) only, they are ignored by
56    // this method
57    bool SetClipboard(int width = 0, int height = 0);
58
59    // implementation
60    WXHANDLE GetHENHMETAFILE() const { return m_hMF; }
61    void SetHENHMETAFILE(WXHANDLE hMF) { Free(); m_hMF = hMF; }
62
63protected:
64    void Init();
65    void Free();
66    void Assign(const wxEnhMetaFile& mf);
67
68private:
69    wxString m_filename;
70    WXHANDLE m_hMF;
71
72    DECLARE_DYNAMIC_CLASS(wxEnhMetaFile)
73};
74
75// ----------------------------------------------------------------------------
76// wxEnhMetaFileDC: allows to create a wxEnhMetaFile
77// ----------------------------------------------------------------------------
78
79class WXDLLEXPORT wxEnhMetaFileDC : public wxDC
80{
81public:
82    // the ctor parameters specify the filename (empty for memory metafiles),
83    // the metafile picture size and the optional description/comment
84    wxEnhMetaFileDC(const wxString& filename = wxEmptyString,
85                    int width = 0, int height = 0,
86                    const wxString& description = wxEmptyString);
87
88#if wxUSE_ENH_METAFILE_FROM_DC
89    // as above, but takes reference DC as first argument to take resolution,
90    // size, font metrics etc. from
91    wxEnhMetaFileDC(const wxDC& referenceDC,
92                    const wxString& filename = wxEmptyString,
93                    int width = 0, int height = 0,
94                    const wxString& description = wxEmptyString);
95#endif
96
97    virtual ~wxEnhMetaFileDC();
98
99    // obtain a pointer to the new metafile (caller should delete it)
100    wxEnhMetaFile *Close();
101
102protected:
103    virtual void DoGetSize(int *width, int *height) const;
104
105private:
106    // size passed to ctor and returned by DoGetSize()
107    int m_width,
108        m_height;
109
110    DECLARE_DYNAMIC_CLASS_NO_COPY(wxEnhMetaFileDC)
111};
112
113#if wxUSE_DRAG_AND_DROP
114
115// ----------------------------------------------------------------------------
116// wxEnhMetaFileDataObject is a specialization of wxDataObject for enh metafile
117// ----------------------------------------------------------------------------
118
119// notice that we want to support both CF_METAFILEPICT and CF_ENHMETAFILE and
120// so we derive from wxDataObject and not from wxDataObjectSimple
121class WXDLLEXPORT wxEnhMetaFileDataObject : public wxDataObject
122{
123public:
124    // ctors
125    wxEnhMetaFileDataObject() { }
126    wxEnhMetaFileDataObject(const wxEnhMetaFile& metafile)
127        : m_metafile(metafile) { }
128
129    // virtual functions which you may override if you want to provide data on
130    // demand only - otherwise, the trivial default versions will be used
131    virtual void SetMetafile(const wxEnhMetaFile& metafile)
132        { m_metafile = metafile; }
133    virtual wxEnhMetaFile GetMetafile() const
134        { return m_metafile; }
135
136    // implement base class pure virtuals
137    virtual wxDataFormat GetPreferredFormat(Direction dir) const;
138    virtual size_t GetFormatCount(Direction dir) const;
139    virtual void GetAllFormats(wxDataFormat *formats, Direction dir) const;
140    virtual size_t GetDataSize(const wxDataFormat& format) const;
141    virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
142    virtual bool SetData(const wxDataFormat& format, size_t len,
143                         const void *buf);
144
145protected:
146    wxEnhMetaFile m_metafile;
147
148    DECLARE_NO_COPY_CLASS(wxEnhMetaFileDataObject)
149};
150
151
152// ----------------------------------------------------------------------------
153// wxEnhMetaFileSimpleDataObject does derive from wxDataObjectSimple which
154// makes it more convenient to use (it can be used with wxDataObjectComposite)
155// at the price of not supoprting any more CF_METAFILEPICT but only
156// CF_ENHMETAFILE
157// ----------------------------------------------------------------------------
158
159class WXDLLEXPORT wxEnhMetaFileSimpleDataObject : public wxDataObjectSimple
160{
161public:
162    // ctors
163    wxEnhMetaFileSimpleDataObject() : wxDataObjectSimple(wxDF_ENHMETAFILE) { }
164    wxEnhMetaFileSimpleDataObject(const wxEnhMetaFile& metafile)
165        : wxDataObjectSimple(wxDF_ENHMETAFILE), m_metafile(metafile) { }
166
167    // virtual functions which you may override if you want to provide data on
168    // demand only - otherwise, the trivial default versions will be used
169    virtual void SetEnhMetafile(const wxEnhMetaFile& metafile)
170        { m_metafile = metafile; }
171    virtual wxEnhMetaFile GetEnhMetafile() const
172        { return m_metafile; }
173
174    // implement base class pure virtuals
175    virtual size_t GetDataSize() const;
176    virtual bool GetDataHere(void *buf) const;
177    virtual bool SetData(size_t len, const void *buf);
178
179    virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const
180        { return GetDataSize(); }
181    virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
182                             void *buf) const
183        { return GetDataHere(buf); }
184    virtual bool SetData(const wxDataFormat& WXUNUSED(format),
185                         size_t len, const void *buf)
186        { return SetData(len, buf); }
187
188protected:
189    wxEnhMetaFile m_metafile;
190
191    DECLARE_NO_COPY_CLASS(wxEnhMetaFileSimpleDataObject)
192};
193
194#endif // wxUSE_DRAG_AND_DROP
195
196#endif // _WX_MSW_ENHMETA_H_
197