1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/metafile.h
3 // Purpose: wxMetaFile, wxMetaFileDC and wxMetaFileDataObject classes
4 // Author: Julian Smart
5 // Modified by: VZ 07.01.00: implemented wxMetaFileDataObject
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_METAFIILE_H_
12 #define _WX_METAFIILE_H_
15 #include "wx/gdiobj.h"
17 #if wxUSE_DRAG_AND_DROP
18 #include "wx/dataobj.h"
21 // ----------------------------------------------------------------------------
22 // Metafile and metafile device context classes
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_FWD_CORE wxMetafile
;
27 class WXDLLIMPEXP_CORE wxMetafileRefData
: public wxGDIRefData
31 virtual ~wxMetafileRefData();
33 virtual bool IsOk() const { return m_metafile
!= 0; }
37 int m_windowsMappingMode
;
38 int m_width
, m_height
;
40 friend class WXDLLIMPEXP_FWD_CORE wxMetafile
;
43 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
45 class WXDLLIMPEXP_CORE wxMetafile
: public wxGDIObject
48 wxMetafile(const wxString
& file
= wxEmptyString
);
49 virtual ~wxMetafile();
51 // After this is called, the metafile cannot be used for anything
52 // since it is now owned by the clipboard.
53 virtual bool SetClipboard(int width
= 0, int height
= 0);
55 virtual bool Play(wxDC
*dc
);
57 // set/get the size of metafile for clipboard operations
58 wxSize
GetSize() const { return wxSize(GetWidth(), GetHeight()); }
59 int GetWidth() const { return M_METAFILEDATA
->m_width
; }
60 int GetHeight() const { return M_METAFILEDATA
->m_height
; }
62 void SetWidth(int width
) { M_METAFILEDATA
->m_width
= width
; }
63 void SetHeight(int height
) { M_METAFILEDATA
->m_height
= height
; }
66 WXHANDLE
GetHMETAFILE() const { return M_METAFILEDATA
->m_metafile
; }
67 void SetHMETAFILE(WXHANDLE mf
) ;
68 int GetWindowsMappingMode() const { return M_METAFILEDATA
->m_windowsMappingMode
; }
69 void SetWindowsMappingMode(int mm
);
72 virtual wxGDIRefData
*CreateGDIRefData() const;
73 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
76 DECLARE_DYNAMIC_CLASS(wxMetafile
)
79 class WXDLLIMPEXP_CORE wxMetafileDCImpl
: public wxMSWDCImpl
82 wxMetafileDCImpl(wxDC
*owner
, const wxString
& file
= wxEmptyString
);
83 wxMetafileDCImpl(wxDC
*owner
, const wxString
& file
,
84 int xext
, int yext
, int xorg
, int yorg
);
85 virtual ~wxMetafileDCImpl();
87 virtual wxMetafile
*Close();
88 virtual void SetMapMode(wxMappingMode mode
);
89 virtual void DoGetTextExtent(const wxString
& string
,
90 wxCoord
*x
, wxCoord
*y
,
91 wxCoord
*descent
= NULL
,
92 wxCoord
*externalLeading
= NULL
,
93 const wxFont
*theFont
= NULL
) const;
96 wxMetafile
*GetMetaFile() const { return m_metaFile
; }
97 void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
98 int GetWindowsMappingMode() const { return m_windowsMappingMode
; }
99 void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
102 virtual void DoGetSize(int *width
, int *height
) const;
104 int m_windowsMappingMode
;
105 wxMetafile
* m_metaFile
;
108 DECLARE_CLASS(wxMetafileDCImpl
)
109 wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl
);
112 class WXDLLIMPEXP_CORE wxMetafileDC
: public wxDC
115 // Don't supply origin and extent
116 // Supply them to wxMakeMetaFilePlaceable instead.
117 wxMetafileDC(const wxString
& file
)
118 : wxDC(new wxMetafileDCImpl( this, file
))
121 // Supply origin and extent (recommended).
122 // Then don't need to supply them to wxMakeMetaFilePlaceable.
123 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
124 : wxDC(new wxMetafileDCImpl( this, file
, xext
, yext
, xorg
, yorg
))
127 wxMetafile
*GetMetafile() const
128 { return ((wxMetafileDCImpl
*)m_pimpl
)->GetMetaFile(); }
131 { return ((wxMetafileDCImpl
*)m_pimpl
)->Close(); }
134 DECLARE_CLASS(wxMetafileDC
)
135 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 bool WXDLLIMPEXP_CORE
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
151 // Optional origin and extent
152 bool WXDLLIMPEXP_CORE
wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
= 1.0, bool useOriginAndExtent
= true);
154 // ----------------------------------------------------------------------------
155 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
156 // ----------------------------------------------------------------------------
158 #if wxUSE_DRAG_AND_DROP
160 class WXDLLIMPEXP_CORE wxMetafileDataObject
: public wxDataObjectSimple
164 wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE
)
166 wxMetafileDataObject(const wxMetafile
& metafile
)
167 : wxDataObjectSimple(wxDF_METAFILE
), m_metafile(metafile
) { }
169 // virtual functions which you may override if you want to provide data on
170 // demand only - otherwise, the trivial default versions will be used
171 virtual void SetMetafile(const wxMetafile
& metafile
)
172 { m_metafile
= metafile
; }
173 virtual wxMetafile
GetMetafile() const
174 { return m_metafile
; }
176 // implement base class pure virtuals
177 virtual size_t GetDataSize() const;
178 virtual bool GetDataHere(void *buf
) const;
179 virtual bool SetData(size_t len
, const void *buf
);
182 wxMetafile m_metafile
;
185 #endif // wxUSE_DRAG_AND_DROP