]>
Commit | Line | Data |
---|---|---|
52479aef SC |
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: Stefan Csomor | |
7 | // Modified by: | |
8 | // Created: 1998-01-01 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Stefan Csomor | |
65571936 | 11 | // Licence: wxWindows licence |
52479aef SC |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | ||
14 | ||
15 | #ifndef _WX_METAFIILE_H_ | |
16 | #define _WX_METAFIILE_H_ | |
17 | ||
18 | #if wxUSE_METAFILE | |
19 | #include "wx/dc.h" | |
20 | #include "wx/gdiobj.h" | |
21 | ||
22 | #if wxUSE_DATAOBJ | |
23 | #include "wx/dataobj.h" | |
24 | #endif | |
25 | ||
26 | /* | |
27 | * Metafile and metafile device context classes | |
28 | * | |
29 | */ | |
30 | ||
31 | #define wxMetaFile wxMetafile | |
32 | #define wxMetaFileDC wxMetafileDC | |
33 | ||
34 | class WXDLLEXPORT wxMetafile; | |
35 | ||
36 | class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData | |
37 | { | |
38 | friend class WXDLLEXPORT wxMetafile; | |
39 | public: | |
40 | wxMetafileRefData(void); | |
d3c7fc99 | 41 | virtual ~wxMetafileRefData(void); |
52479aef SC |
42 | |
43 | public: | |
44 | WXHMETAFILE m_metafile; | |
45 | }; | |
46 | ||
47 | #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) | |
48 | ||
49 | class WXDLLEXPORT wxMetafile: public wxGDIObject | |
50 | { | |
51 | DECLARE_DYNAMIC_CLASS(wxMetafile) | |
52 | public: | |
52479aef | 53 | wxMetafile(const wxString& file = wxEmptyString); |
d3c7fc99 | 54 | virtual ~wxMetafile(void); |
52479aef SC |
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)); }; | |
52479aef SC |
63 | |
64 | wxSize GetSize() const; | |
65 | int GetWidth() const { return GetSize().x; } | |
66 | int GetHeight() const { return GetSize().y; } | |
67 | ||
68 | // Implementation | |
69 | inline WXHMETAFILE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; } | |
70 | void SetHMETAFILE(WXHMETAFILE mf) ; | |
71 | ||
72 | // Operators | |
fbfb8bcc VZ |
73 | inline bool operator == (const wxMetafile& metafile) const { return m_refData == metafile.m_refData; } |
74 | inline bool operator != (const wxMetafile& metafile) const { return m_refData != metafile.m_refData; } | |
52479aef SC |
75 | |
76 | protected: | |
77 | }; | |
78 | ||
79 | class WXDLLEXPORT wxMetafileDC: public wxDC | |
80 | { | |
81 | DECLARE_DYNAMIC_CLASS(wxMetafileDC) | |
82 | ||
83 | public: | |
84 | // the ctor parameters specify the filename (empty for memory metafiles), | |
85 | // the metafile picture size and the optional description/comment | |
86 | wxMetafileDC(const wxString& filename = wxEmptyString, | |
87 | int width = 0, int height = 0, | |
88 | const wxString& description = wxEmptyString); | |
89 | ||
d3c7fc99 | 90 | virtual ~wxMetafileDC(void); |
52479aef SC |
91 | |
92 | // Should be called at end of drawing | |
93 | virtual wxMetafile *Close(void); | |
94 | virtual void DoGetSize(int *width, int *height) const ; | |
95 | ||
96 | // Implementation | |
97 | inline wxMetafile *GetMetaFile(void) const { return m_metaFile; } | |
98 | inline void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; } | |
99 | ||
100 | protected: | |
101 | wxMetafile* m_metaFile; | |
102 | }; | |
103 | ||
104 | /* | |
105 | * Pass filename of existing non-placeable metafile, and bounding box. | |
106 | * Adds a placeable metafile header, sets the mapping mode to anisotropic, | |
107 | * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode. | |
108 | * | |
109 | */ | |
110 | ||
111 | // No origin or extent | |
112 | #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable | |
113 | bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0); | |
114 | ||
115 | // Optional origin and extent | |
116 | bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = TRUE); | |
117 | ||
118 | // ---------------------------------------------------------------------------- | |
119 | // wxMetafileDataObject is a specialization of wxDataObject for metafile data | |
120 | // ---------------------------------------------------------------------------- | |
121 | ||
122 | #if wxUSE_DATAOBJ | |
123 | class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple | |
124 | { | |
125 | public: | |
126 | // ctors | |
127 | wxMetafileDataObject() | |
128 | : wxDataObjectSimple(wxDF_METAFILE) { }; | |
129 | wxMetafileDataObject(const wxMetafile& metafile) | |
130 | : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { } | |
131 | ||
132 | // virtual functions which you may override if you want to provide data on | |
133 | // demand only - otherwise, the trivial default versions will be used | |
134 | virtual void SetMetafile(const wxMetafile& metafile) | |
135 | { m_metafile = metafile; } | |
136 | virtual wxMetafile GetMetafile() const | |
137 | { return m_metafile; } | |
138 | ||
139 | // implement base class pure virtuals | |
140 | virtual size_t GetDataSize() const; | |
141 | virtual bool GetDataHere(void *buf) const; | |
142 | virtual bool SetData(size_t len, const void *buf); | |
143 | ||
144 | virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const | |
145 | { return GetDataSize(); } | |
146 | virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format), | |
147 | void *buf) const | |
148 | { return GetDataHere(buf); } | |
149 | virtual bool SetData(const wxDataFormat& WXUNUSED(format), | |
150 | size_t len, const void *buf) | |
151 | { return SetData(len, buf); } | |
152 | protected: | |
153 | wxMetafile m_metafile; | |
154 | }; | |
155 | #endif | |
156 | ||
157 | #endif // wxUSE_METAFILE | |
158 | ||
159 | ||
160 | #endif | |
161 | // _WX_METAFIILE_H_ |