1 /////////////////////////////////////////////////////////////////////////////
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
10 // Copyright: (c) David Webster
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
15 #ifndef _WX_METAFIILE_H_
16 #define _WX_METAFIILE_H_
22 #include "wx/gdiobj.h"
24 #if wxUSE_DRAG_AND_DROP
25 #include "wx/dataobj.h"
29 * Metafile and metafile device context classes
33 #define wxMetaFile wxMetafile
34 #define wxMetaFileDC wxMetafileDC
36 class WXDLLEXPORT wxMetafile
;
38 class WXDLLEXPORT wxMetafileRefData
: public wxGDIRefData
40 friend class WXDLLEXPORT wxMetafile
;
42 wxMetafileRefData(void);
43 ~wxMetafileRefData(void);
47 int m_windowsMappingMode
;
50 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
52 class WXDLLEXPORT wxMetafile
: public wxGDIObject
54 DECLARE_DYNAMIC_CLASS(wxMetafile
)
57 inline wxMetafile(const wxMetafile
& metafile
)
60 wxMetafile(const wxString
& file
= "");
63 // After this is called, the metafile cannot be used for anything
64 // since it is now owned by the clipboard.
65 virtual bool SetClipboard(int width
= 0, int height
= 0);
67 virtual bool Play(wxDC
*dc
);
68 inline bool Ok(void) const { return (M_METAFILEDATA
&& (M_METAFILEDATA
->m_metafile
!= 0)); };
71 inline WXHANDLE
GetHMETAFILE(void) { return M_METAFILEDATA
->m_metafile
; }
72 void SetHMETAFILE(WXHANDLE mf
) ;
73 inline int GetWindowsMappingMode(void) { return M_METAFILEDATA
->m_windowsMappingMode
; }
74 void SetWindowsMappingMode(int mm
);
77 inline wxMetafile
& operator = (const wxMetafile
& metafile
)
78 { if (*this == metafile
) return (*this); Ref(metafile
); return *this; }
79 inline bool operator== (const wxMetafile
& metafile
) const
80 { return m_refData
== metafile
.m_refData
; }
81 inline bool operator!= (const wxMetafile
& metafile
) const
82 { return m_refData
!= metafile
.m_refData
; }
87 class WXDLLEXPORT wxMetafileDC
: public wxDC
89 DECLARE_DYNAMIC_CLASS(wxMetafileDC
)
92 // Don't supply origin and extent
93 // Supply them to wxMakeMetaFilePlaceable instead.
94 wxMetafileDC(const wxString
& file
= "");
96 // Supply origin and extent (recommended).
97 // Then don't need to supply them to wxMakeMetaFilePlaceable.
98 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
);
102 // Should be called at end of drawing
103 virtual wxMetafile
*Close(void);
104 virtual void SetMapMode(int mode
);
105 virtual void GetTextExtent(const wxString
& string
, long *x
, long *y
,
106 long *descent
= NULL
, long *externalLeading
= NULL
,
107 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const;
110 inline wxMetafile
*GetMetaFile(void) const { return m_metaFile
; }
111 inline void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
112 inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode
; }
113 inline void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
116 int m_windowsMappingMode
;
117 wxMetafile
* m_metaFile
;
120 // function hiding warning supression
121 inline virtual void GetTextExtent( const wxString
& string
124 ,long* descent
= NULL
125 ,long* externalLeading
= NULL
126 ,wxFont
* theFont
= NULL
128 { GetTextExtent( string
, width
, height
, descent
, externalLeading
, theFont
, FALSE
);};
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 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
140 bool WXDLLEXPORT
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
142 // Optional origin and extent
143 bool WXDLLEXPORT
wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
= 1.0, bool useOriginAndExtent
= TRUE
);
145 // ----------------------------------------------------------------------------
146 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
147 // ----------------------------------------------------------------------------
149 // TODO: implement OLE side of things. At present, it's just for clipboard
152 #if wxUSE_DRAG_AND_DROP
153 class WXDLLEXPORT wxMetafileDataObject
: public wxDataObject
157 wxMetafileDataObject() { m_width
= 0; m_height
= 0; };
158 wxMetafileDataObject(const wxMetafile
& metafile
, int width
= 0, int height
= 0):
159 m_metafile(metafile
), m_width(width
), m_height(height
) { }
161 void SetMetafile(const wxMetafile
& metafile
, int w
= 0, int h
= 0)
162 { m_metafile
= metafile
; m_width
= w
; m_height
= h
; }
163 wxMetafile
GetMetafile() const { return m_metafile
; }
164 int GetWidth() const { return m_width
; }
165 int GetHeight() const { return m_height
; }
167 virtual wxDataFormat
GetFormat() const { return wxDF_METAFILE
; }
170 // implement base class pure virtuals
171 virtual wxDataFormat GetPreferredFormat() const
172 { return (wxDataFormat) wxDataObject::Text; }
173 virtual bool IsSupportedFormat(wxDataFormat format) const
174 { return format == wxDataObject::Text || format == wxDataObject::Locale; }
175 virtual size_t GetDataSize() const
176 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
177 virtual void GetDataHere(void *pBuf) const
178 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
182 wxMetafile m_metafile
;
188 #endif // wxUSE_METAFILE