]>
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: Stefan Csomor | |
7 | // Modified by: | |
8 | // Created: 1998-01-01 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Stefan Csomor | |
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_DATAOBJ | |
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 | class wxMetafileRefData ; | |
35 | ||
36 | #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) | |
37 | ||
38 | class WXDLLEXPORT wxMetafile: public wxGDIObject | |
39 | { | |
40 | DECLARE_DYNAMIC_CLASS(wxMetafile) | |
41 | public: | |
42 | // Copy constructor | |
43 | wxMetafile(const wxMetafile& metafile) | |
44 | : wxGDIObject() | |
45 | { Ref(metafile); } | |
46 | ||
47 | wxMetafile(const wxString& file = wxEmptyString); | |
48 | ~wxMetafile(void); | |
49 | ||
50 | // After this is called, the metafile cannot be used for anything | |
51 | // since it is now owned by the clipboard. | |
52 | virtual bool SetClipboard(int width = 0, int height = 0); | |
53 | ||
54 | virtual bool Play(wxDC *dc); | |
55 | bool Ok() const ; | |
56 | ||
57 | wxSize GetSize() const; | |
58 | int GetWidth() const { return GetSize().x; } | |
59 | int GetHeight() const { return GetSize().y; } | |
60 | ||
61 | // Implementation | |
62 | WXHMETAFILE GetHMETAFILE() const ; | |
63 | void SetHMETAFILE(WXHMETAFILE mf) ; | |
64 | ||
65 | // Operators | |
66 | inline wxMetafile& operator = (const wxMetafile& metafile) { if (*this == metafile) return (*this); Ref(metafile); return *this; } | |
67 | inline bool operator == (const wxMetafile& metafile) { return m_refData == metafile.m_refData; } | |
68 | inline bool operator != (const wxMetafile& metafile) { return m_refData != metafile.m_refData; } | |
69 | ||
70 | protected: | |
71 | }; | |
72 | ||
73 | class WXDLLEXPORT wxMetafileDC: public wxDC | |
74 | { | |
75 | DECLARE_DYNAMIC_CLASS(wxMetafileDC) | |
76 | ||
77 | public: | |
78 | // the ctor parameters specify the filename (empty for memory metafiles), | |
79 | // the metafile picture size and the optional description/comment | |
80 | wxMetafileDC(const wxString& filename = wxEmptyString, | |
81 | int width = 0, int height = 0, | |
82 | const wxString& description = wxEmptyString); | |
83 | ||
84 | ~wxMetafileDC(void); | |
85 | ||
86 | // Should be called at end of drawing | |
87 | virtual wxMetafile *Close(void); | |
88 | virtual void DoGetSize(int *width, int *height) const ; | |
89 | ||
90 | // Implementation | |
91 | inline wxMetafile *GetMetaFile(void) const { return m_metaFile; } | |
92 | inline void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; } | |
93 | ||
94 | protected: | |
95 | wxMetafile* m_metaFile; | |
96 | }; | |
97 | ||
98 | /* | |
99 | * Pass filename of existing non-placeable metafile, and bounding box. | |
100 | * Adds a placeable metafile header, sets the mapping mode to anisotropic, | |
101 | * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode. | |
102 | * | |
103 | */ | |
104 | ||
105 | // No origin or extent | |
106 | #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable | |
107 | bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0); | |
108 | ||
109 | // Optional origin and extent | |
110 | bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = TRUE); | |
111 | ||
112 | // ---------------------------------------------------------------------------- | |
113 | // wxMetafileDataObject is a specialization of wxDataObject for metafile data | |
114 | // ---------------------------------------------------------------------------- | |
115 | ||
116 | #if wxUSE_DATAOBJ | |
117 | class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple | |
118 | { | |
119 | public: | |
120 | // ctors | |
121 | wxMetafileDataObject() | |
122 | : wxDataObjectSimple(wxDF_METAFILE) { }; | |
123 | wxMetafileDataObject(const wxMetafile& metafile) | |
124 | : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { } | |
125 | ||
126 | // virtual functions which you may override if you want to provide data on | |
127 | // demand only - otherwise, the trivial default versions will be used | |
128 | virtual void SetMetafile(const wxMetafile& metafile) | |
129 | { m_metafile = metafile; } | |
130 | virtual wxMetafile GetMetafile() const | |
131 | { return m_metafile; } | |
132 | ||
133 | // implement base class pure virtuals | |
134 | virtual size_t GetDataSize() const; | |
135 | virtual bool GetDataHere(void *buf) const; | |
136 | virtual bool SetData(size_t len, const void *buf); | |
137 | ||
138 | virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const | |
139 | { return GetDataSize(); } | |
140 | virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format), | |
141 | void *buf) const | |
142 | { return GetDataHere(buf); } | |
143 | virtual bool SetData(const wxDataFormat& WXUNUSED(format), | |
144 | size_t len, const void *buf) | |
145 | { return SetData(len, buf); } | |
146 | protected: | |
147 | wxMetafile m_metafile; | |
148 | }; | |
149 | #endif | |
150 | ||
151 | #endif | |
152 | // _WX_METAFIILE_H_ |