1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/metafile.h
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
9 // Copyright: (c) David Webster
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_METAFIILE_H_
15 #define _WX_METAFIILE_H_
18 #include "wx/gdiobj.h"
19 #include "wx/os2/dc.h"
21 #if wxUSE_DRAG_AND_DROP
22 #include "wx/dataobj.h"
26 * Metafile and metafile device context classes
30 #define wxMetaFile wxMetafile
31 #define wxMetaFileDC wxMetafileDC
33 class WXDLLIMPEXP_FWD_CORE wxMetafile
;
35 class WXDLLIMPEXP_CORE wxMetafileRefData
: public wxGDIRefData
37 friend class WXDLLIMPEXP_FWD_CORE wxMetafile
;
39 wxMetafileRefData(void);
40 virtual ~wxMetafileRefData(void);
42 virtual bool IsOk() const { return m_metafile
!= 0; }
46 int m_windowsMappingMode
;
49 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
51 class WXDLLIMPEXP_CORE wxMetafile
: public wxGDIObject
53 DECLARE_DYNAMIC_CLASS(wxMetafile
)
55 wxMetafile(const wxString
& file
= wxEmptyString
);
56 virtual ~wxMetafile(void);
58 // After this is called, the metafile cannot be used for anything
59 // since it is now owned by the clipboard.
60 virtual bool SetClipboard(int width
= 0, int height
= 0);
62 virtual bool Play(wxDC
*dc
);
65 inline WXHANDLE
GetHMETAFILE(void) { return M_METAFILEDATA
->m_metafile
; }
66 void SetHMETAFILE(WXHANDLE mf
) ;
67 inline int GetWindowsMappingMode(void) { return M_METAFILEDATA
->m_windowsMappingMode
; }
68 void SetWindowsMappingMode(int mm
);
71 virtual wxGDIRefData
*CreateGDIRefData() const;
72 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
75 class WXDLLIMPEXP_CORE wxMetafileDCImpl
: public wxPMDCImpl
78 wxMetafileDCImpl(wxDC
*owner
, const wxString
& file
= wxEmptyString
);
79 wxMetafileDCImpl(wxDC
*owner
, const wxString
& file
,
80 int xext
, int yext
, int xorg
, int yorg
);
81 virtual ~wxMetafileDCImpl();
83 virtual wxMetafile
*Close();
84 virtual void SetMapMode(wxMappingMode mode
);
85 virtual void DoGetTextExtent(const wxString
& string
,
86 wxCoord
*x
, wxCoord
*y
,
87 wxCoord
*descent
= NULL
,
88 wxCoord
*externalLeading
= NULL
,
89 const wxFont
*theFont
= NULL
) const;
92 wxMetafile
*GetMetaFile() const { return m_metaFile
; }
93 void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
94 int GetWindowsMappingMode() const { return m_windowsMappingMode
; }
95 void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
98 virtual void DoGetSize(int *width
, int *height
) const;
100 int m_windowsMappingMode
;
101 wxMetafile
* m_metaFile
;
104 DECLARE_CLASS(wxMetafileDCImpl
)
105 wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl
);
108 class WXDLLIMPEXP_CORE wxMetafileDC
: public wxDC
111 // Don't supply origin and extent
112 // Supply them to wxMakeMetaFilePlaceable instead.
113 wxMetafileDC(const wxString
& file
= wxEmptyString
)
114 :wxDC(new wxMetafileDCImpl( this, file
))
117 // Supply origin and extent (recommended).
118 // Then don't need to supply them to wxMakeMetaFilePlaceable.
119 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
120 : wxDC(new wxMetafileDCImpl( this, file
, xext
, yext
, xorg
, yorg
))
123 wxMetafile
*GetMetafile() const
124 { return ((wxMetafileDCImpl
*)m_pimpl
)->GetMetaFile(); }
126 virtual ~wxMetafileDC(void)
129 // Should be called at end of drawing
130 virtual wxMetafile
*Close(void)
131 { return ((wxMetafileDCImpl
*)m_pimpl
)->Close(); }
133 inline void SetMetaFile(wxMetafile
*mf
)
134 { ((wxMetafileDCImpl
*)m_pimpl
)->SetMetaFile(mf
); }
137 DECLARE_CLASS(wxMetafileDC
)
138 wxDECLARE_NO_COPY_CLASS(wxMetafileDC
);
142 * Pass filename of existing non-placeable metafile, and bounding box.
143 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
144 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
148 // No origin or extent
149 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
150 bool WXDLLIMPEXP_CORE
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
152 // Optional origin and extent
153 bool WXDLLIMPEXP_CORE
wxMakeMetaFilePlaceable( const wxString
& filename
159 ,bool useOriginAndExtent
= true
162 // ----------------------------------------------------------------------------
163 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
164 // ----------------------------------------------------------------------------
166 // TODO: implement OLE side of things. At present, it's just for clipboard
169 #if wxUSE_DRAG_AND_DROP
170 class WXDLLIMPEXP_CORE wxMetafileDataObject
: public wxDataObject
174 wxMetafileDataObject() { m_width
= 0; m_height
= 0; }
175 wxMetafileDataObject(const wxMetafile
& metafile
, int width
= 0,int height
= 0)
176 :m_metafile(metafile
)
178 ,m_height(height
) { }
180 void SetMetafile(const wxMetafile
& metafile
, int w
= 0, int h
= 0)
181 { m_metafile
= metafile
; m_width
= w
; m_height
= h
; }
182 wxMetafile
GetMetafile() const { return m_metafile
; }
183 int GetWidth() const { return m_width
; }
184 int GetHeight() const { return m_height
; }
186 virtual wxDataFormat
GetFormat() const { return wxDF_METAFILE
; }
189 // implement base class pure virtuals
190 virtual wxDataFormat GetPreferredFormat() const
191 { return (wxDataFormat) wxDataObject::Text; }
192 virtual bool IsSupportedFormat(wxDataFormat format) const
193 { return format == wxDataObject::Text || format == wxDataObject::Locale; }
194 virtual size_t GetDataSize() const
195 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
196 virtual void GetDataHere(void *pBuf) const
197 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
201 wxMetafile m_metafile
;