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