1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMetaFile, wxMetaFileDC classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_METAFIILE_H_
14 #define _WX_METAFIILE_H_
17 #pragma interface "metafile.h"
24 #include "wx/gdiobj.h"
26 #if wxUSE_DRAG_AND_DROP
27 #include "wx/dataobj.h"
31 * Metafile and metafile device context classes
35 #define wxMetaFile wxMetafile
36 #define wxMetaFileDC wxMetafileDC
38 class WXDLLEXPORT wxMetafile
;
40 class WXDLLEXPORT wxMetafileRefData
: public wxGDIRefData
42 friend class WXDLLEXPORT wxMetafile
;
44 wxMetafileRefData(void);
45 ~wxMetafileRefData(void);
49 int m_windowsMappingMode
;
52 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
54 class WXDLLEXPORT wxMetafile
: public wxGDIObject
56 DECLARE_DYNAMIC_CLASS(wxMetafile
)
59 inline wxMetafile(const wxMetafile
& metafile
)
62 wxMetafile(const wxString
& file
= "");
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 inline bool Ok(void) const { return (M_METAFILEDATA
&& (M_METAFILEDATA
->m_metafile
!= 0)); };
73 inline WXHANDLE
GetHMETAFILE(void) { return M_METAFILEDATA
->m_metafile
; }
74 void SetHMETAFILE(WXHANDLE mf
) ;
75 inline int GetWindowsMappingMode(void) { return M_METAFILEDATA
->m_windowsMappingMode
; }
76 void SetWindowsMappingMode(int mm
);
79 inline wxMetafile
& operator = (const wxMetafile
& metafile
) { if (*this == metafile
) return (*this); Ref(metafile
); return *this; }
80 inline bool operator == (const wxMetafile
& metafile
) { return m_refData
== metafile
.m_refData
; }
81 inline bool operator != (const wxMetafile
& metafile
) { return m_refData
!= metafile
.m_refData
; }
86 class WXDLLEXPORT wxMetafileDC
: public wxDC
88 DECLARE_DYNAMIC_CLASS(wxMetafileDC
)
91 // Don't supply origin and extent
92 // Supply them to wxMakeMetaFilePlaceable instead.
93 wxMetafileDC(const wxString
& file
= "");
95 // Supply origin and extent (recommended).
96 // Then don't need to supply them to wxMakeMetaFilePlaceable.
97 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
);
101 // Should be called at end of drawing
102 virtual wxMetafile
*Close(void);
103 virtual void SetMapMode(int mode
);
104 virtual void GetTextExtent(const wxString
& string
, long *x
, long *y
,
105 long *descent
= NULL
, long *externalLeading
= NULL
,
106 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const;
109 inline wxMetafile
*GetMetaFile(void) const { return m_metaFile
; }
110 inline void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
111 inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode
; }
112 inline void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
115 int m_windowsMappingMode
;
116 wxMetafile
* m_metaFile
;
120 * Pass filename of existing non-placeable metafile, and bounding box.
121 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
122 * and sets the window origin and extent to mimic the MM_TEXT mapping mode.
126 // No origin or extent
127 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
128 bool WXDLLEXPORT
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
130 // Optional origin and extent
131 bool WXDLLEXPORT
wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
= 1.0, bool useOriginAndExtent
= TRUE
);
133 // ----------------------------------------------------------------------------
134 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
135 // ----------------------------------------------------------------------------
137 // TODO: implement OLE side of things. At present, it's just for clipboard
140 #if wxUSE_DRAG_AND_DROP
141 class WXDLLEXPORT wxMetafileDataObject
: public wxDataObject
145 wxMetafileDataObject() { m_width
= 0; m_height
= 0; };
146 wxMetafileDataObject(const wxMetafile
& metafile
, int width
= 0, int height
= 0):
147 m_metafile(metafile
), m_width(width
), m_height(height
) { }
149 void SetMetafile(const wxMetafile
& metafile
, int w
= 0, int h
= 0)
150 { m_metafile
= metafile
; m_width
= w
; m_height
= h
; }
151 wxMetafile
GetMetafile() const { return m_metafile
; }
152 int GetWidth() const { return m_width
; }
153 int GetHeight() const { return m_height
; }
155 virtual wxDataFormat
GetFormat() const { return wxDF_METAFILE
; }
158 // implement base class pure virtuals
159 virtual wxDataFormat GetPreferredFormat() const
160 { return (wxDataFormat) wxDataObject::Text; }
161 virtual bool IsSupportedFormat(wxDataFormat format) const
162 { return format == wxDataObject::Text || format == wxDataObject::Locale; }
163 virtual size_t GetDataSize() const
164 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
165 virtual void GetDataHere(void *pBuf) const
166 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
170 wxMetafile m_metafile
;
176 #endif // wxUSE_METAFILE