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_
19 #include "wx/gdiobj.h"
21 #if wxUSE_DRAG_AND_DROP
22 #include "wx/dataobj.h"
26 * Metafile and metafile device context classes
30 #define wxMetaFile wxMetafile
31 #define wxMetaFileDC wxMetafileDC
33 class WXDLLEXPORT wxMetafile
;
35 class WXDLLEXPORT wxMetafileRefData
: public wxGDIRefData
37 friend class WXDLLEXPORT wxMetafile
;
39 wxMetafileRefData(void);
40 ~wxMetafileRefData(void);
44 int m_windowsMappingMode
;
47 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
49 class WXDLLEXPORT wxMetafile
: public wxGDIObject
51 DECLARE_DYNAMIC_CLASS(wxMetafile
)
54 inline wxMetafile(const wxMetafile
& metafile
)
57 wxMetafile(const wxString
& file
= wxEmptyString
);
60 // After this is called, the metafile cannot be used for anything
61 // since it is now owned by the clipboard.
62 virtual bool SetClipboard(int width
= 0, int height
= 0);
64 virtual bool Play(wxDC
*dc
);
65 inline bool Ok(void) const { return (M_METAFILEDATA
&& (M_METAFILEDATA
->m_metafile
!= 0)); };
68 inline WXHANDLE
GetHMETAFILE(void) { return M_METAFILEDATA
->m_metafile
; }
69 void SetHMETAFILE(WXHANDLE mf
) ;
70 inline int GetWindowsMappingMode(void) { return M_METAFILEDATA
->m_windowsMappingMode
; }
71 void SetWindowsMappingMode(int mm
);
74 inline wxMetafile
& operator = (const wxMetafile
& metafile
)
75 { if (*this == metafile
) return (*this); Ref(metafile
); return *this; }
76 inline bool operator== (const wxMetafile
& metafile
) const
77 { return m_refData
== metafile
.m_refData
; }
78 inline bool operator!= (const wxMetafile
& metafile
) const
79 { return m_refData
!= metafile
.m_refData
; }
82 class WXDLLEXPORT wxMetafileDC
: public wxDC
84 DECLARE_DYNAMIC_CLASS(wxMetafileDC
)
87 // Don't supply origin and extent
88 // Supply them to wxMakeMetaFilePlaceable instead.
89 wxMetafileDC(const wxString
& file
= wxEmptyString
);
91 // Supply origin and extent (recommended).
92 // Then don't need to supply them to wxMakeMetaFilePlaceable.
93 wxMetafileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
);
97 // Should be called at end of drawing
98 virtual wxMetafile
*Close(void);
99 virtual void SetMapMode(int mode
);
100 virtual void GetTextExtent(const wxString
& string
, long *x
, long *y
,
101 long *descent
= NULL
, long *externalLeading
= NULL
,
102 wxFont
*theFont
= NULL
, bool use16bit
= false) const;
105 inline wxMetafile
*GetMetaFile(void) const { return m_metaFile
; }
106 inline void SetMetaFile(wxMetafile
*mf
) { m_metaFile
= mf
; }
107 inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode
; }
108 inline void SetWindowsMappingMode(int mm
) { m_windowsMappingMode
= mm
; }
111 int m_windowsMappingMode
;
112 wxMetafile
* m_metaFile
;
116 // function hiding warning supression
118 inline virtual void GetTextExtent( const wxString
& string
121 ,long* descent
= NULL
122 ,long* externalLeading
= NULL
123 ,wxFont
* theFont
= NULL
125 { GetTextExtent( string
, width
, height
, descent
, externalLeading
, theFont
, false);};
130 * Pass filename of existing non-placeable metafile, and bounding box.
131 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
132 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
136 // No origin or extent
137 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
138 bool WXDLLEXPORT
wxMakeMetafilePlaceable(const wxString
& filename
, float scale
= 1.0);
140 // Optional origin and extent
141 bool WXDLLEXPORT
wxMakeMetaFilePlaceable( const wxString
& filename
147 ,bool useOriginAndExtent
= true
150 // ----------------------------------------------------------------------------
151 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
152 // ----------------------------------------------------------------------------
154 // TODO: implement OLE side of things. At present, it's just for clipboard
157 #if wxUSE_DRAG_AND_DROP
158 class WXDLLEXPORT wxMetafileDataObject
: public wxDataObject
162 wxMetafileDataObject() { m_width
= 0; m_height
= 0; };
163 wxMetafileDataObject(const wxMetafile
& metafile
, int width
= 0,int height
= 0)
164 :m_metafile(metafile
)
166 ,m_height(height
) { }
168 void SetMetafile(const wxMetafile
& metafile
, int w
= 0, int h
= 0)
169 { m_metafile
= metafile
; m_width
= w
; m_height
= h
; }
170 wxMetafile
GetMetafile() const { return m_metafile
; }
171 int GetWidth() const { return m_width
; }
172 int GetHeight() const { return m_height
; }
174 virtual wxDataFormat
GetFormat() const { return wxDF_METAFILE
; }
177 // implement base class pure virtuals
178 virtual wxDataFormat GetPreferredFormat() const
179 { return (wxDataFormat) wxDataObject::Text; }
180 virtual bool IsSupportedFormat(wxDataFormat format) const
181 { return format == wxDataObject::Text || format == wxDataObject::Locale; }
182 virtual size_t GetDataSize() const
183 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
184 virtual void GetDataHere(void *pBuf) const
185 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
189 wxMetafile m_metafile
;