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
6 // Created:     01/02/97
7 // RCS-ID:      $Id: metafile.h 46103 2007-05-18 15:14:44Z VZ $
8 // Copyright:   (c) Julian Smart
9 // Licence:     wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_METAFIILE_H_
13 #define _WX_METAFIILE_H_
14 
15 #include "wx/dc.h"
16 #include "wx/gdiobj.h"
17 
18 #if wxUSE_DRAG_AND_DROP
19     #include "wx/dataobj.h"
20 #endif
21 
22 // ----------------------------------------------------------------------------
23 // Metafile and metafile device context classes
24 // ----------------------------------------------------------------------------
25 
26 class WXDLLEXPORT wxMetafile;
27 
28 class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData
29 {
30     friend class WXDLLEXPORT wxMetafile;
31 public:
32     wxMetafileRefData();
33     virtual ~wxMetafileRefData();
34 
35 public:
36     WXHANDLE m_metafile;
37     int m_windowsMappingMode;
38     int m_width, m_height;
39 };
40 
41 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
42 
43 class WXDLLEXPORT wxMetafile: public wxGDIObject
44 {
45 public:
46     wxMetafile(const wxString& file = wxEmptyString);
47     virtual ~wxMetafile();
48 
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);
52 
53     virtual bool Play(wxDC *dc);
Ok()54     bool Ok() const { return IsOk(); }
IsOk()55     bool IsOk() const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); };
56 
57     // set/get the size of metafile for clipboard operations
GetSize()58     wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); }
GetWidth()59     int GetWidth() const { return M_METAFILEDATA->m_width; }
GetHeight()60     int GetHeight() const { return M_METAFILEDATA->m_height; }
61 
SetWidth(int width)62     void SetWidth(int width) { M_METAFILEDATA->m_width = width; }
SetHeight(int height)63     void SetHeight(int height) { M_METAFILEDATA->m_height = height; }
64 
65     // Implementation
GetHMETAFILE()66     WXHANDLE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; }
67     void SetHMETAFILE(WXHANDLE mf) ;
GetWindowsMappingMode()68     int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; }
69     void SetWindowsMappingMode(int mm);
70 
71 private:
72     DECLARE_DYNAMIC_CLASS(wxMetafile)
73 };
74 
75 class WXDLLEXPORT wxMetafileDC: public wxDC
76 {
77 public:
78     // Don't supply origin and extent
79     // Supply them to wxMakeMetaFilePlaceable instead.
80     wxMetafileDC(const wxString& file = wxEmptyString);
81 
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);
85 
86     virtual ~wxMetafileDC();
87 
88     // Should be called at end of drawing
89     virtual wxMetafile *Close();
90     virtual void SetMapMode(int mode);
91 
92 #if wxABI_VERSION >= 20805
93     virtual void DoGetTextExtent(const wxString& string,
94                                  wxCoord *x, wxCoord *y,
95                                  wxCoord *descent = NULL,
96                                  wxCoord *externalLeading = NULL,
97                                  const wxFont *theFont = NULL) const;
98 #endif // wx ABI 2.8.5+
99 
100     // this method shouldn't have been defined here (DoGetTextExtent() is the
101     // correct one) but keep it to avoid breaking binary backwards
102     // compatibility
103     virtual void GetTextExtent(const wxString& string, long *x, long *y,
104             long *descent = NULL, long *externalLeading = NULL,
105             wxFont *theFont = NULL, bool use16bit = false) const;
106 
107     // Implementation
GetMetaFile()108     wxMetafile *GetMetaFile() const { return m_metaFile; }
SetMetaFile(wxMetafile * mf)109     void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
GetWindowsMappingMode()110     int GetWindowsMappingMode() const { return m_windowsMappingMode; }
SetWindowsMappingMode(int mm)111     void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
112 
113 protected:
114     virtual void DoGetSize(int *width, int *height) const;
115 
116     int           m_windowsMappingMode;
117     wxMetafile*   m_metaFile;
118 
119 private:
120     DECLARE_DYNAMIC_CLASS(wxMetafileDC)
121 };
122 
123 /*
124  * Pass filename of existing non-placeable metafile, and bounding box.
125  * Adds a placeable metafile header, sets the mapping mode to anisotropic,
126  * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
127  *
128  */
129 
130 // No origin or extent
131 bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
132 
133 // Optional origin and extent
134 bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = true);
135 
136 // ----------------------------------------------------------------------------
137 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
138 // ----------------------------------------------------------------------------
139 
140 #if wxUSE_DRAG_AND_DROP
141 
142 class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple
143 {
144 public:
145     // ctors
wxMetafileDataObject()146     wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE)
147         { }
wxMetafileDataObject(const wxMetafile & metafile)148     wxMetafileDataObject(const wxMetafile& metafile)
149         : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { }
150 
151     // virtual functions which you may override if you want to provide data on
152     // demand only - otherwise, the trivial default versions will be used
SetMetafile(const wxMetafile & metafile)153     virtual void SetMetafile(const wxMetafile& metafile)
154         { m_metafile = metafile; }
GetMetafile()155     virtual wxMetafile GetMetafile() const
156         { return m_metafile; }
157 
158     // implement base class pure virtuals
159     virtual size_t GetDataSize() const;
160     virtual bool GetDataHere(void *buf) const;
161     virtual bool SetData(size_t len, const void *buf);
162 
163 protected:
164     wxMetafile m_metafile;
165 };
166 
167 #endif // wxUSE_DRAG_AND_DROP
168 
169 #endif
170     // _WX_METAFIILE_H_
171 
172