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