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
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_METAFIILE_H_
13 #define _WX_METAFIILE_H_
16 #include "wx/gdiobj.h"
18 #if wxUSE_DRAG_AND_DROP
19 #include "wx/dataobj.h"
22 // ----------------------------------------------------------------------------
23 // Metafile and metafile device context classes
24 // ----------------------------------------------------------------------------
26 class WXDLLEXPORT wxMetafile
;
28 class WXDLLEXPORT wxMetafileRefData
: public wxGDIRefData
30 friend class WXDLLEXPORT wxMetafile
;
33 virtual ~wxMetafileRefData();
37 int m_windowsMappingMode
;
38 int m_width
, m_height
;
41 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
43 class WXDLLEXPORT wxMetafile
: public wxGDIObject
46 wxMetafile(const wxString
& file
= wxEmptyString
);
47 virtual ~wxMetafile();
49 // After this is called, the metafile cannot be used for anything
50 // since it is now owned by the clipboard.
51 virtual bool SetClipboard(int width
= 0, int height
= 0);
53 virtual bool Play(wxDC
*dc
);
54 bool Ok() const { return IsOk(); }
55 bool IsOk() const { return (M_METAFILEDATA
&& (M_METAFILEDATA
->m_metafile
!= 0)); };
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 DECLARE_DYNAMIC_CLASS(wxMetafile
)
75 class WXDLLEXPORT wxMetafileDC
: public wxDC
78 // Don't supply origin and extent
79 // Supply them to wxMakeMetaFilePlaceable instead.
80 wxMetafileDC(const wxString
& file
= wxEmptyString
);
82 // Supply origin and extent (recommended).
83 // Then don't need to supply them to wxMakeMetaFilePlaceable.
84 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
);
86 virtual ~wxMetafileDC();
88 // Should be called at end of drawing
89 virtual wxMetafile
*Close();
90 virtual void SetMapMode(int mode
);
91 virtual void DoGetTextExtent(const wxString
& string
,
92 wxCoord
*x
, wxCoord
*y
,
93 wxCoord
*descent
= NULL
,
94 wxCoord
*externalLeading
= NULL
,
95 const wxFont
*theFont
= NULL
) const;
98 wxMetafile
*GetMetaFile() const { return m_metaFile
; }
99 void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
100 int GetWindowsMappingMode() const { return m_windowsMappingMode
; }
101 void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
104 virtual void DoGetSize(int *width
, int *height
) const;
106 int m_windowsMappingMode
;
107 wxMetafile
* m_metaFile
;
110 DECLARE_DYNAMIC_CLASS(wxMetafileDC
)
114 * Pass filename of existing non-placeable metafile, and bounding box.
115 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
116 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
120 // No origin or extent
121 bool WXDLLEXPORT
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
123 // Optional origin and extent
124 bool WXDLLEXPORT
wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
= 1.0, bool useOriginAndExtent
= true);
126 // ----------------------------------------------------------------------------
127 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
128 // ----------------------------------------------------------------------------
130 #if wxUSE_DRAG_AND_DROP
132 class WXDLLEXPORT wxMetafileDataObject
: public wxDataObjectSimple
136 wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE
)
138 wxMetafileDataObject(const wxMetafile
& metafile
)
139 : wxDataObjectSimple(wxDF_METAFILE
), m_metafile(metafile
) { }
141 // virtual functions which you may override if you want to provide data on
142 // demand only - otherwise, the trivial default versions will be used
143 virtual void SetMetafile(const wxMetafile
& metafile
)
144 { m_metafile
= metafile
; }
145 virtual wxMetafile
GetMetafile() const
146 { return m_metafile
; }
148 // implement base class pure virtuals
149 virtual size_t GetDataSize() const;
150 virtual bool GetDataHere(void *buf
) const;
151 virtual bool SetData(size_t len
, const void *buf
);
154 wxMetafile m_metafile
;
157 #endif // wxUSE_DRAG_AND_DROP