]>
Commit | Line | Data |
---|---|---|
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. | |
6 | // Author: David Webster | |
7 | // Modified by: | |
8 | // Created: 10/10/99 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) David Webster | |
11 | // Licence: wxWindows licence | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | ||
15 | #ifndef _WX_METAFIILE_H_ | |
16 | #define _WX_METAFIILE_H_ | |
17 | ||
18 | #include "wx/dc.h" | |
19 | #include "wx/gdiobj.h" | |
20 | ||
21 | #if wxUSE_DRAG_AND_DROP | |
22 | #include "wx/dataobj.h" | |
23 | #endif | |
24 | ||
25 | /* | |
26 | * Metafile and metafile device context classes | |
27 | * | |
28 | */ | |
29 | ||
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); | |
40 | virtual ~wxMetafileRefData(void); | |
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 | |
50 | { | |
51 | DECLARE_DYNAMIC_CLASS(wxMetafile) | |
52 | public: | |
53 | wxMetafile(const wxString& file = wxEmptyString); | |
54 | virtual ~wxMetafile(void); | |
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); | |
61 | inline bool Ok() const { return IsOk(); } | |
62 | inline bool IsOk(void) const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); }; | |
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); | |
69 | ||
70 | // Operators | |
71 | inline bool operator== (const wxMetafile& metafile) const | |
72 | { return m_refData == metafile.m_refData; } | |
73 | inline bool operator!= (const wxMetafile& metafile) const | |
74 | { return m_refData != metafile.m_refData; } | |
75 | }; | |
76 | ||
77 | class WXDLLEXPORT wxMetafileDC: public wxDC | |
78 | { | |
79 | DECLARE_DYNAMIC_CLASS(wxMetafileDC) | |
80 | ||
81 | public: | |
82 | // Don't supply origin and extent | |
83 | // Supply them to wxMakeMetaFilePlaceable instead. | |
84 | wxMetafileDC(const wxString& file = wxEmptyString); | |
85 | ||
86 | // Supply origin and extent (recommended). | |
87 | // Then don't need to supply them to wxMakeMetaFilePlaceable. | |
88 | wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg); | |
89 | ||
90 | virtual ~wxMetafileDC(void); | |
91 | ||
92 | // Should be called at end of drawing | |
93 | virtual wxMetafile *Close(void); | |
94 | virtual void SetMapMode(int mode); | |
95 | virtual void GetTextExtent(const wxString& string, long *x, long *y, | |
96 | long *descent = NULL, long *externalLeading = NULL, | |
97 | wxFont *theFont = NULL, bool use16bit = false) const; | |
98 | ||
99 | // Implementation | |
100 | inline wxMetafile *GetMetaFile(void) const { return m_metaFile; } | |
101 | inline void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; } | |
102 | inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode; } | |
103 | inline void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; } | |
104 | ||
105 | protected: | |
106 | int m_windowsMappingMode; | |
107 | wxMetafile* m_metaFile; | |
108 | ||
109 | private: | |
110 | #ifndef __WATCOMC__ | |
111 | // function hiding warning supression | |
112 | // still required ?? | |
113 | inline virtual void GetTextExtent( const wxString& string | |
114 | ,long* width | |
115 | ,long* height | |
116 | ,long* descent = NULL | |
117 | ,long* externalLeading = NULL | |
118 | ,wxFont* theFont = NULL | |
119 | ) const | |
120 | { GetTextExtent( string, width, height, descent, externalLeading, theFont, false);}; | |
121 | #endif | |
122 | }; | |
123 | ||
124 | /* | |
125 | * Pass filename of existing non-placeable metafile, and bounding box. | |
126 | * Adds a placeable metafile header, sets the mapping mode to anisotropic, | |
127 | * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode. | |
128 | * | |
129 | */ | |
130 | ||
131 | // No origin or extent | |
132 | #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable | |
133 | bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0); | |
134 | ||
135 | // Optional origin and extent | |
136 | bool WXDLLEXPORT wxMakeMetaFilePlaceable( const wxString& filename | |
137 | ,int x1 | |
138 | ,int y1 | |
139 | ,int x2 | |
140 | ,int y2 | |
141 | ,float scale = 1.0 | |
142 | ,bool useOriginAndExtent = true | |
143 | ); | |
144 | ||
145 | // ---------------------------------------------------------------------------- | |
146 | // wxMetafileDataObject is a specialization of wxDataObject for metafile data | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
149 | // TODO: implement OLE side of things. At present, it's just for clipboard | |
150 | // use. | |
151 | ||
152 | #if wxUSE_DRAG_AND_DROP | |
153 | class WXDLLEXPORT wxMetafileDataObject : public wxDataObject | |
154 | { | |
155 | public: | |
156 | // ctors | |
157 | wxMetafileDataObject() { m_width = 0; m_height = 0; }; | |
158 | wxMetafileDataObject(const wxMetafile& metafile, int width = 0,int height = 0) | |
159 | :m_metafile(metafile) | |
160 | ,m_width(width) | |
161 | ,m_height(height) { } | |
162 | ||
163 | void SetMetafile(const wxMetafile& metafile, int w = 0, int h = 0) | |
164 | { m_metafile = metafile; m_width = w; m_height = h; } | |
165 | wxMetafile GetMetafile() const { return m_metafile; } | |
166 | int GetWidth() const { return m_width; } | |
167 | int GetHeight() const { return m_height; } | |
168 | ||
169 | virtual wxDataFormat GetFormat() const { return wxDF_METAFILE; } | |
170 | ||
171 | /* ?? | |
172 | // implement base class pure virtuals | |
173 | virtual wxDataFormat GetPreferredFormat() const | |
174 | { return (wxDataFormat) wxDataObject::Text; } | |
175 | virtual bool IsSupportedFormat(wxDataFormat format) const | |
176 | { return format == wxDataObject::Text || format == wxDataObject::Locale; } | |
177 | virtual size_t GetDataSize() const | |
178 | { return m_strText.Len() + 1; } // +1 for trailing '\0'of course | |
179 | virtual void GetDataHere(void *pBuf) const | |
180 | { memcpy(pBuf, m_strText.c_str(), GetDataSize()); } | |
181 | */ | |
182 | ||
183 | private: | |
184 | wxMetafile m_metafile; | |
185 | int m_width; | |
186 | int m_height; | |
187 | }; | |
188 | #endif | |
189 | ||
190 | #endif | |
191 | // _WX_METAFIILE_H_ |