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: David Webster
10 // Copyright: (c) David Webster
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_METAFIILE_H_
16 #define _WX_METAFIILE_H_
19 #include "wx/gdiobj.h"
20 #include "wx/os2/dc.h"
22 #if wxUSE_DRAG_AND_DROP
23 #include "wx/dataobj.h"
27 * Metafile and metafile device context classes
31 #define wxMetaFile wxMetafile
32 #define wxMetaFileDC wxMetafileDC
34 class WXDLLIMPEXP_FWD_CORE wxMetafile
;
36 class WXDLLIMPEXP_CORE wxMetafileRefData
: public wxGDIRefData
38 friend class WXDLLIMPEXP_FWD_CORE wxMetafile
;
40 wxMetafileRefData(void);
41 virtual ~wxMetafileRefData(void);
43 virtual bool IsOk() const { return m_metafile
!= 0; }
47 int m_windowsMappingMode
;
50 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
52 class WXDLLIMPEXP_CORE wxMetafile
: public wxGDIObject
54 DECLARE_DYNAMIC_CLASS(wxMetafile
)
56 wxMetafile(const wxString
& file
= wxEmptyString
);
57 virtual ~wxMetafile(void);
59 // After this is called, the metafile cannot be used for anything
60 // since it is now owned by the clipboard.
61 virtual bool SetClipboard(int width
= 0, int height
= 0);
63 virtual bool Play(wxDC
*dc
);
66 inline WXHANDLE
GetHMETAFILE(void) { return M_METAFILEDATA
->m_metafile
; }
67 void SetHMETAFILE(WXHANDLE mf
) ;
68 inline int GetWindowsMappingMode(void) { return M_METAFILEDATA
->m_windowsMappingMode
; }
69 void SetWindowsMappingMode(int mm
);
72 virtual wxGDIRefData
*CreateGDIRefData() const;
73 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
76 class WXDLLIMPEXP_CORE wxMetafileDCImpl
: public wxPMDCImpl
79 wxMetafileDCImpl(wxDC
*owner
, const wxString
& file
= wxEmptyString
);
80 wxMetafileDCImpl(wxDC
*owner
, const wxString
& file
,
81 int xext
, int yext
, int xorg
, int yorg
);
82 virtual ~wxMetafileDCImpl();
84 virtual wxMetafile
*Close();
85 virtual void SetMapMode(wxMappingMode mode
);
86 virtual void DoGetTextExtent(const wxString
& string
,
87 wxCoord
*x
, wxCoord
*y
,
88 wxCoord
*descent
= NULL
,
89 wxCoord
*externalLeading
= NULL
,
90 const wxFont
*theFont
= NULL
) const;
93 wxMetafile
*GetMetaFile() const { return m_metaFile
; }
94 void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
95 int GetWindowsMappingMode() const { return m_windowsMappingMode
; }
96 void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
99 virtual void DoGetSize(int *width
, int *height
) const;
101 int m_windowsMappingMode
;
102 wxMetafile
* m_metaFile
;
105 DECLARE_CLASS(wxMetafileDCImpl
)
106 wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl
);
109 class WXDLLIMPEXP_CORE wxMetafileDC
: public wxDC
112 // Don't supply origin and extent
113 // Supply them to wxMakeMetaFilePlaceable instead.
114 wxMetafileDC(const wxString
& file
= wxEmptyString
)
115 :wxDC(new wxMetafileDCImpl( this, file
))
118 // Supply origin and extent (recommended).
119 // Then don't need to supply them to wxMakeMetaFilePlaceable.
120 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
121 : wxDC(new wxMetafileDCImpl( this, file
, xext
, yext
, xorg
, yorg
))
124 wxMetafile
*GetMetafile() const
125 { return ((wxMetafileDCImpl
*)m_pimpl
)->GetMetaFile(); }
127 virtual ~wxMetafileDC(void)
130 // Should be called at end of drawing
131 virtual wxMetafile
*Close(void)
132 { return ((wxMetafileDCImpl
*)m_pimpl
)->Close(); }
134 inline void SetMetaFile(wxMetafile
*mf
)
135 { ((wxMetafileDCImpl
*)m_pimpl
)->SetMetaFile(mf
); }
138 DECLARE_CLASS(wxMetafileDC
)
139 wxDECLARE_NO_COPY_CLASS(wxMetafileDC
);
143 * Pass filename of existing non-placeable metafile, and bounding box.
144 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
145 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
149 // No origin or extent
150 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
151 bool WXDLLIMPEXP_CORE
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
153 // Optional origin and extent
154 bool WXDLLIMPEXP_CORE
wxMakeMetaFilePlaceable( const wxString
& filename
160 ,bool useOriginAndExtent
= true
163 // ----------------------------------------------------------------------------
164 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
165 // ----------------------------------------------------------------------------
167 // TODO: implement OLE side of things. At present, it's just for clipboard
170 #if wxUSE_DRAG_AND_DROP
171 class WXDLLIMPEXP_CORE wxMetafileDataObject
: public wxDataObject
175 wxMetafileDataObject() { m_width
= 0; m_height
= 0; };
176 wxMetafileDataObject(const wxMetafile
& metafile
, int width
= 0,int height
= 0)
177 :m_metafile(metafile
)
179 ,m_height(height
) { }
181 void SetMetafile(const wxMetafile
& metafile
, int w
= 0, int h
= 0)
182 { m_metafile
= metafile
; m_width
= w
; m_height
= h
; }
183 wxMetafile
GetMetafile() const { return m_metafile
; }
184 int GetWidth() const { return m_width
; }
185 int GetHeight() const { return m_height
; }
187 virtual wxDataFormat
GetFormat() const { return wxDF_METAFILE
; }
190 // implement base class pure virtuals
191 virtual wxDataFormat GetPreferredFormat() const
192 { return (wxDataFormat) wxDataObject::Text; }
193 virtual bool IsSupportedFormat(wxDataFormat format) const
194 { return format == wxDataObject::Text || format == wxDataObject::Locale; }
195 virtual size_t GetDataSize() const
196 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
197 virtual void GetDataHere(void *pBuf) const
198 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
202 wxMetafile m_metafile
;