]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: metafile.h | |
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. | |
75f11ad7 | 6 | // Author: David Webster |
0e320a79 | 7 | // Modified by: |
75f11ad7 | 8 | // Created: 10/10/99 |
0e320a79 | 9 | // RCS-ID: $Id$ |
75f11ad7 | 10 | // Copyright: (c) David Webster |
65571936 | 11 | // Licence: wxWindows licence |
0e320a79 DW |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | ||
14 | ||
15 | #ifndef _WX_METAFIILE_H_ | |
16 | #define _WX_METAFIILE_H_ | |
17 | ||
a419c3b1 | 18 | #include "wx/dc.h" |
75f11ad7 | 19 | #include "wx/gdiobj.h" |
4b3f61d1 | 20 | #include "wx/os2/dc.h" |
75f11ad7 DW |
21 | |
22 | #if wxUSE_DRAG_AND_DROP | |
23 | #include "wx/dataobj.h" | |
24 | #endif | |
0e320a79 DW |
25 | |
26 | /* | |
75f11ad7 | 27 | * Metafile and metafile device context classes |
0e320a79 DW |
28 | * |
29 | */ | |
30 | ||
75f11ad7 DW |
31 | #define wxMetaFile wxMetafile |
32 | #define wxMetaFileDC wxMetafileDC | |
33 | ||
b5dbe15d | 34 | class WXDLLIMPEXP_FWD_CORE wxMetafile; |
75f11ad7 | 35 | |
53a2db12 | 36 | class WXDLLIMPEXP_CORE wxMetafileRefData: public wxGDIRefData |
75f11ad7 | 37 | { |
b5dbe15d | 38 | friend class WXDLLIMPEXP_FWD_CORE wxMetafile; |
75f11ad7 DW |
39 | public: |
40 | wxMetafileRefData(void); | |
d3c7fc99 | 41 | virtual ~wxMetafileRefData(void); |
75f11ad7 | 42 | |
8f884a0d VZ |
43 | virtual bool IsOk() const { return m_metafile != 0; } |
44 | ||
75f11ad7 DW |
45 | public: |
46 | WXHANDLE m_metafile; | |
47 | int m_windowsMappingMode; | |
48 | }; | |
49 | ||
50 | #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) | |
51 | ||
53a2db12 | 52 | class WXDLLIMPEXP_CORE wxMetafile: public wxGDIObject |
0e320a79 | 53 | { |
c40158e4 WS |
54 | DECLARE_DYNAMIC_CLASS(wxMetafile) |
55 | public: | |
c40158e4 | 56 | wxMetafile(const wxString& file = wxEmptyString); |
d3c7fc99 | 57 | virtual ~wxMetafile(void); |
c40158e4 WS |
58 | |
59 | // After this is called, the metafile cannot be used for anything | |
60 | // since it is now owned by the clipboard. | |
61 | virtual bool SetClipboard(int width = 0, int height = 0); | |
62 | ||
63 | virtual bool Play(wxDC *dc); | |
c40158e4 WS |
64 | |
65 | // Implementation | |
66 | inline WXHANDLE GetHMETAFILE(void) { return M_METAFILEDATA->m_metafile; } | |
67 | void SetHMETAFILE(WXHANDLE mf) ; | |
68 | inline int GetWindowsMappingMode(void) { return M_METAFILEDATA->m_windowsMappingMode; } | |
69 | void SetWindowsMappingMode(int mm); | |
4b3f61d1 SN |
70 | |
71 | protected: | |
72 | virtual wxGDIRefData *CreateGDIRefData() const; | |
73 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; | |
0e320a79 DW |
74 | }; |
75 | ||
53a2db12 | 76 | class WXDLLIMPEXP_CORE wxMetafileDCImpl: public wxPMDCImpl |
0e320a79 | 77 | { |
4b3f61d1 SN |
78 | public: |
79 | wxMetafileDCImpl(wxDC *owner, const wxString& file = wxEmptyString); | |
80 | wxMetafileDCImpl(wxDC *owner, const wxString& file, | |
81 | int xext, int yext, int xorg, int yorg); | |
82 | virtual ~wxMetafileDCImpl(); | |
83 | ||
84 | virtual wxMetafile *Close(); | |
89efaf2b | 85 | virtual void SetMapMode(wxMappingMode mode); |
4b3f61d1 SN |
86 | virtual void DoGetTextExtent(const wxString& string, |
87 | wxCoord *x, wxCoord *y, | |
88 | wxCoord *descent = NULL, | |
89 | wxCoord *externalLeading = NULL, | |
90 | const wxFont *theFont = NULL) const; | |
91 | ||
92 | // Implementation | |
93 | wxMetafile *GetMetaFile() const { return m_metaFile; } | |
94 | void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; } | |
95 | int GetWindowsMappingMode() const { return m_windowsMappingMode; } | |
96 | void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; } | |
97 | ||
98 | protected: | |
99 | virtual void DoGetSize(int *width, int *height) const; | |
100 | ||
101 | int m_windowsMappingMode; | |
102 | wxMetafile* m_metaFile; | |
0e320a79 | 103 | |
4b3f61d1 SN |
104 | private: |
105 | DECLARE_CLASS(wxMetafileDCImpl) | |
c0c133e1 | 106 | wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl); |
4b3f61d1 SN |
107 | }; |
108 | ||
53a2db12 | 109 | class WXDLLIMPEXP_CORE wxMetafileDC: public wxDC |
4b3f61d1 | 110 | { |
c40158e4 WS |
111 | public: |
112 | // Don't supply origin and extent | |
113 | // Supply them to wxMakeMetaFilePlaceable instead. | |
4b3f61d1 SN |
114 | wxMetafileDC(const wxString& file = wxEmptyString) |
115 | :wxDC(new wxMetafileDCImpl( this, file )) | |
116 | { } | |
0e320a79 | 117 | |
c40158e4 WS |
118 | // Supply origin and extent (recommended). |
119 | // Then don't need to supply them to wxMakeMetaFilePlaceable. | |
4b3f61d1 | 120 | wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg) |
2c6dbc21 | 121 | : wxDC(new wxMetafileDCImpl( this, file, xext, yext, xorg, yorg )) |
4b3f61d1 | 122 | { } |
0e320a79 | 123 | |
2c6dbc21 | 124 | wxMetafile *GetMetafile() const |
4b3f61d1 | 125 | { return ((wxMetafileDCImpl*)m_pimpl)->GetMetaFile(); } |
0e320a79 | 126 | |
4b3f61d1 SN |
127 | virtual ~wxMetafileDC(void) |
128 | { delete m_pimpl; } | |
0e320a79 | 129 | |
4b3f61d1 SN |
130 | // Should be called at end of drawing |
131 | virtual wxMetafile *Close(void) | |
132 | { return ((wxMetafileDCImpl*)m_pimpl)->Close(); } | |
0e320a79 | 133 | |
4b3f61d1 SN |
134 | inline void SetMetaFile(wxMetafile *mf) |
135 | { ((wxMetafileDCImpl*)m_pimpl)->SetMetaFile(mf); } | |
75f11ad7 DW |
136 | |
137 | private: | |
4b3f61d1 | 138 | DECLARE_CLASS(wxMetafileDC) |
c0c133e1 | 139 | wxDECLARE_NO_COPY_CLASS(wxMetafileDC); |
0e320a79 DW |
140 | }; |
141 | ||
142 | /* | |
143 | * Pass filename of existing non-placeable metafile, and bounding box. | |
144 | * Adds a placeable metafile header, sets the mapping mode to anisotropic, | |
145 | * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode. | |
146 | * | |
147 | */ | |
148 | ||
149 | // No origin or extent | |
75f11ad7 | 150 | #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable |
53a2db12 | 151 | bool WXDLLIMPEXP_CORE wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0); |
0e320a79 DW |
152 | |
153 | // Optional origin and extent | |
53a2db12 | 154 | bool WXDLLIMPEXP_CORE wxMakeMetaFilePlaceable( const wxString& filename |
c40158e4 WS |
155 | ,int x1 |
156 | ,int y1 | |
157 | ,int x2 | |
158 | ,int y2 | |
159 | ,float scale = 1.0 | |
160 | ,bool useOriginAndExtent = true | |
161 | ); | |
0e320a79 | 162 | |
75f11ad7 DW |
163 | // ---------------------------------------------------------------------------- |
164 | // wxMetafileDataObject is a specialization of wxDataObject for metafile data | |
165 | // ---------------------------------------------------------------------------- | |
166 | ||
167 | // TODO: implement OLE side of things. At present, it's just for clipboard | |
168 | // use. | |
169 | ||
170 | #if wxUSE_DRAG_AND_DROP | |
53a2db12 | 171 | class WXDLLIMPEXP_CORE wxMetafileDataObject : public wxDataObject |
75f11ad7 DW |
172 | { |
173 | public: | |
c40158e4 WS |
174 | // ctors |
175 | wxMetafileDataObject() { m_width = 0; m_height = 0; }; | |
176 | wxMetafileDataObject(const wxMetafile& metafile, int width = 0,int height = 0) | |
177 | :m_metafile(metafile) | |
178 | ,m_width(width) | |
179 | ,m_height(height) { } | |
75f11ad7 | 180 | |
c40158e4 WS |
181 | void SetMetafile(const wxMetafile& metafile, int w = 0, int h = 0) |
182 | { m_metafile = metafile; m_width = w; m_height = h; } | |
183 | wxMetafile GetMetafile() const { return m_metafile; } | |
184 | int GetWidth() const { return m_width; } | |
185 | int GetHeight() const { return m_height; } | |
75f11ad7 | 186 | |
c40158e4 | 187 | virtual wxDataFormat GetFormat() const { return wxDF_METAFILE; } |
75f11ad7 DW |
188 | |
189 | /* ?? | |
c40158e4 WS |
190 | // implement base class pure virtuals |
191 | virtual wxDataFormat GetPreferredFormat() const | |
192 | { return (wxDataFormat) wxDataObject::Text; } | |
193 | virtual bool IsSupportedFormat(wxDataFormat format) const | |
194 | { return format == wxDataObject::Text || format == wxDataObject::Locale; } | |
195 | virtual size_t GetDataSize() const | |
196 | { return m_strText.Len() + 1; } // +1 for trailing '\0'of course | |
197 | virtual void GetDataHere(void *pBuf) const | |
198 | { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } | |
75f11ad7 DW |
199 | */ |
200 | ||
201 | private: | |
c40158e4 WS |
202 | wxMetafile m_metafile; |
203 | int m_width; | |
204 | int m_height; | |
75f11ad7 DW |
205 | }; |
206 | #endif | |
207 | ||
0e320a79 DW |
208 | #endif |
209 | // _WX_METAFIILE_H_ |