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 #pragma interface "metafile.h"
24 #include "wx/gdiobj.h"
26 #if wxUSE_DRAG_AND_DROP
27 #include "wx/dataobj.h"
30 // provide synonyms for all metafile classes
31 #define wxMetaFile wxMetafile
32 #define wxMetaFileDC wxMetafileDC
33 #define wxMetaFileDataObject wxMetafileDataObject
35 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
37 // ----------------------------------------------------------------------------
38 // Metafile and metafile device context classes
39 // ----------------------------------------------------------------------------
41 class WXDLLEXPORT wxMetafile
;
43 class WXDLLEXPORT wxMetafileRefData
: public wxGDIRefData
45 friend class WXDLLEXPORT wxMetafile
;
52 int m_windowsMappingMode
;
53 int m_width
, m_height
;
56 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
58 class WXDLLEXPORT wxMetafile
: public wxGDIObject
61 wxMetafile(const wxString
& file
= wxEmptyString
);
62 wxMetafile(const wxMetafile
& metafile
) { Ref(metafile
); }
63 virtual ~wxMetafile();
65 // After this is called, the metafile cannot be used for anything
66 // since it is now owned by the clipboard.
67 virtual bool SetClipboard(int width
= 0, int height
= 0);
69 virtual bool Play(wxDC
*dc
);
70 bool Ok() const { return (M_METAFILEDATA
&& (M_METAFILEDATA
->m_metafile
!= 0)); };
72 // set/get the size of metafile for clipboard operations
73 int GetWidth() const { return M_METAFILEDATA
->m_width
; }
74 int GetHeight() const { return M_METAFILEDATA
->m_height
; }
76 void SetWidth(int width
) { M_METAFILEDATA
->m_width
= width
; }
77 void SetHeight(int height
) { M_METAFILEDATA
->m_height
= height
; }
80 WXHANDLE
GetHMETAFILE() const { return M_METAFILEDATA
->m_metafile
; }
81 void SetHMETAFILE(WXHANDLE mf
) ;
82 int GetWindowsMappingMode() const { return M_METAFILEDATA
->m_windowsMappingMode
; }
83 void SetWindowsMappingMode(int mm
);
86 wxMetafile
& operator=(const wxMetafile
& metafile
)
87 { if (*this != metafile
) Ref(metafile
); return *this; }
88 bool operator==(const wxMetafile
& metafile
) const
89 { return m_refData
== metafile
.m_refData
; }
90 bool operator!=(const wxMetafile
& metafile
) const
91 { return m_refData
!= metafile
.m_refData
; }
94 DECLARE_DYNAMIC_CLASS(wxMetafile
)
97 class WXDLLEXPORT wxMetafileDC
: public wxDC
100 // Don't supply origin and extent
101 // Supply them to wxMakeMetaFilePlaceable instead.
102 wxMetafileDC(const wxString
& file
= "");
104 // Supply origin and extent (recommended).
105 // Then don't need to supply them to wxMakeMetaFilePlaceable.
106 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
);
108 virtual ~wxMetafileDC();
110 // Should be called at end of drawing
111 virtual wxMetafile
*Close();
112 virtual void SetMapMode(int mode
);
113 virtual void GetTextExtent(const wxString
& string
, long *x
, long *y
,
114 long *descent
= NULL
, long *externalLeading
= NULL
,
115 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const;
118 wxMetafile
*GetMetaFile() const { return m_metaFile
; }
119 void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
120 int GetWindowsMappingMode() const { return m_windowsMappingMode
; }
121 void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
124 int m_windowsMappingMode
;
125 wxMetafile
* m_metaFile
;
128 DECLARE_DYNAMIC_CLASS(wxMetafileDC
)
132 * Pass filename of existing non-placeable metafile, and bounding box.
133 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
134 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
138 // No origin or extent
139 bool WXDLLEXPORT
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
141 // Optional origin and extent
142 bool WXDLLEXPORT
wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
= 1.0, bool useOriginAndExtent
= TRUE
);
144 // ----------------------------------------------------------------------------
145 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
146 // ----------------------------------------------------------------------------
148 #if wxUSE_DRAG_AND_DROP
150 class WXDLLEXPORT wxMetafileDataObject
: public wxDataObjectSimple
154 wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE
)
156 wxMetafileDataObject(const wxMetafile
& metafile
)
157 : wxDataObjectSimple(wxDF_METAFILE
), m_metafile(metafile
) { }
159 // virtual functions which you may override if you want to provide data on
160 // demand only - otherwise, the trivial default versions will be used
161 virtual void SetMetafile(const wxMetafile
& metafile
)
162 { m_metafile
= metafile
; }
163 virtual wxMetafile
GetMetafile() const
164 { return m_metafile
; }
166 // implement base class pure virtuals
167 virtual size_t GetDataSize() const;
168 virtual bool GetDataHere(void *buf
) const;
169 virtual bool SetData(size_t len
, const void *buf
);
172 wxMetafile m_metafile
;
175 #endif // wxUSE_DRAG_AND_DROP
177 #endif // wxUSE_METAFILE