1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMetaFile, wxMetaFileDC classes.
4 // This probably should be restricted to Windows platforms,
5 // but if there is an equivalent on your platform, great.
6 // Author: Stefan Csomor
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_METAFIILE_H_
16 #define _WX_METAFIILE_H_
19 #include "wx/gdiobj.h"
22 #include "wx/dataobj.h"
25 #include "wx/mac/carbon/dcclient.h"
28 * Metafile and metafile device context classes
32 #define wxMetaFile wxMetafile
33 #define wxMetaFileDC wxMetafileDC
35 class WXDLLIMPEXP_FWD_CORE wxMetafile
;
36 class wxMetafileRefData
;
38 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
40 class WXDLLEXPORT wxMetafile
: public wxGDIObject
42 DECLARE_DYNAMIC_CLASS(wxMetafile
)
44 wxMetafile(const wxString
& file
= wxEmptyString
);
45 virtual ~wxMetafile(void);
47 // After this is called, the metafile cannot be used for anything
48 // since it is now owned by the clipboard.
49 virtual bool SetClipboard(int width
= 0, int height
= 0);
51 virtual bool Play(wxDC
*dc
);
52 bool Ok() const { return IsOk(); }
55 wxSize
GetSize() const;
56 int GetWidth() const { return GetSize().x
; }
57 int GetHeight() const { return GetSize().y
; }
60 WXHMETAFILE
GetHMETAFILE() const ;
61 void SetHMETAFILE(WXHMETAFILE mf
) ;
63 // Since the native metafile format is PDF for Quartz
64 // we need a call that allows setting PICT content for
65 // backwards compatibility
66 void SetPICT(void* pictHandle
) ;
71 class WXDLLEXPORT wxMetafileDCImpl
: public wxGCDCImpl
74 wxMetafileDCImpl( wxDC
*owner
,
75 const wxString
& filename
,
76 int width
, int height
,
77 const wxString
& description
);
79 virtual ~wxMetafileDCImpl();
81 // Should be called at end of drawing
82 virtual wxMetafile
*Close();
85 wxMetafile
*GetMetaFile(void) const { return m_metaFile
; }
86 void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
89 virtual void DoGetSize(int *width
, int *height
) const;
91 wxMetafile
* m_metaFile
;
94 DECLARE_CLASS(wxMetafileDCImpl
)
95 DECLARE_NO_COPY_CLASS(wxMetafileDCImpl
)
98 class WXDLLEXPORT wxMetafileDC
: public wxDC
101 // the ctor parameters specify the filename (empty for memory metafiles),
102 // the metafile picture size and the optional description/comment
103 wxMetafileDC( const wxString
& filename
= wxEmptyString
,
104 int width
= 0, int height
= 0,
105 const wxString
& description
= wxEmptyString
)
106 { m_pimpl
= new wxMetafileDCImpl( this, filename
, width
, height
, description
); }
108 wxMetafile
*GetMetafile() const
109 { return ((wxMetafileDCImpl
*)m_pimpl
)->GetMetaFile(); }
112 { return ((wxMetafileDCImpl
*)m_pimpl
)->Close(); }
115 DECLARE_CLASS(wxMetafileDC
)
116 DECLARE_NO_COPY_CLASS(wxMetafileDC
)
121 * Pass filename of existing non-placeable metafile, and bounding box.
122 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
123 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
127 // No origin or extent
128 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
129 bool WXDLLEXPORT
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
131 // Optional origin and extent
132 bool WXDLLEXPORT
wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
= 1.0, bool useOriginAndExtent
= TRUE
);
134 // ----------------------------------------------------------------------------
135 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
136 // ----------------------------------------------------------------------------
139 class WXDLLEXPORT wxMetafileDataObject
: public wxDataObjectSimple
143 wxMetafileDataObject()
144 : wxDataObjectSimple(wxDF_METAFILE
) { };
145 wxMetafileDataObject(const wxMetafile
& metafile
)
146 : wxDataObjectSimple(wxDF_METAFILE
), m_metafile(metafile
) { }
148 // virtual functions which you may override if you want to provide data on
149 // demand only - otherwise, the trivial default versions will be used
150 virtual void SetMetafile(const wxMetafile
& metafile
)
151 { m_metafile
= metafile
; }
152 virtual wxMetafile
GetMetafile() const
153 { return m_metafile
; }
155 // implement base class pure virtuals
156 virtual size_t GetDataSize() const;
157 virtual bool GetDataHere(void *buf
) const;
158 virtual bool SetData(size_t len
, const void *buf
);
160 virtual size_t GetDataSize(const wxDataFormat
& WXUNUSED(format
)) const
161 { return GetDataSize(); }
162 virtual bool GetDataHere(const wxDataFormat
& WXUNUSED(format
),
164 { return GetDataHere(buf
); }
165 virtual bool SetData(const wxDataFormat
& WXUNUSED(format
),
166 size_t len
, const void *buf
)
167 { return SetData(len
, buf
); }
169 wxMetafile m_metafile
;