]>
Commit | Line | Data |
---|---|---|
d9317fd4 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/msw/enhmeta.h | |
3 | // Purpose: wxEnhMetaFile class for Win32 | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 13.01.00 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
d9317fd4 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_MSW_ENHMETA_H_ | |
13 | #define _WX_MSW_ENHMETA_H_ | |
14 | ||
d9317fd4 VZ |
15 | #include "wx/dc.h" |
16 | ||
17 | #if wxUSE_DRAG_AND_DROP | |
18 | #include "wx/dataobj.h" | |
19 | #endif | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | class WXDLLEXPORT wxEnhMetaFile : public wxObject | |
26 | { | |
27 | public: | |
28 | wxEnhMetaFile(const wxString& file = wxEmptyString) : m_filename(file) | |
29 | { Init(); } | |
252d21bd | 30 | wxEnhMetaFile(const wxEnhMetaFile& metafile) : wxObject() |
d9317fd4 VZ |
31 | { Init(); Assign(metafile); } |
32 | wxEnhMetaFile& operator=(const wxEnhMetaFile& metafile) | |
33 | { Free(); Assign(metafile); return *this; } | |
34 | ||
35 | virtual ~wxEnhMetaFile() | |
36 | { Free(); } | |
37 | ||
38 | // display the picture stored in the metafile on the given DC | |
39 | bool Play(wxDC *dc, wxRect *rectBound = (wxRect *)NULL); | |
40 | ||
41 | // accessors | |
b7cacb43 VZ |
42 | bool Ok() const { return IsOk(); } |
43 | bool IsOk() const { return m_hMF != 0; } | |
d9317fd4 VZ |
44 | |
45 | wxSize GetSize() const; | |
46 | int GetWidth() const { return GetSize().x; } | |
47 | int GetHeight() const { return GetSize().y; } | |
48 | ||
49 | const wxString& GetFileName() const { return m_filename; } | |
50 | ||
bfbd6dc1 VZ |
51 | // copy the metafile to the clipboard: the width and height parameters are |
52 | // for backwards compatibility (with wxMetaFile) only, they are ignored by | |
53 | // this method | |
54 | bool SetClipboard(int width = 0, int height = 0); | |
55 | ||
d9317fd4 VZ |
56 | // implementation |
57 | WXHANDLE GetHENHMETAFILE() const { return m_hMF; } | |
58 | void SetHENHMETAFILE(WXHANDLE hMF) { Free(); m_hMF = hMF; } | |
59 | ||
60 | protected: | |
7a295dfa | 61 | void Init(); |
d9317fd4 VZ |
62 | void Free(); |
63 | void Assign(const wxEnhMetaFile& mf); | |
64 | ||
65 | private: | |
66 | wxString m_filename; | |
67 | WXHANDLE m_hMF; | |
68 | ||
69 | DECLARE_DYNAMIC_CLASS(wxEnhMetaFile) | |
70 | }; | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // wxEnhMetaFileDC: allows to create a wxEnhMetaFile | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | class WXDLLEXPORT wxEnhMetaFileDC : public wxDC | |
77 | { | |
78 | public: | |
79 | // the ctor parameters specify the filename (empty for memory metafiles), | |
80 | // the metafile picture size and the optional description/comment | |
81 | wxEnhMetaFileDC(const wxString& filename = wxEmptyString, | |
82 | int width = 0, int height = 0, | |
83 | const wxString& description = wxEmptyString); | |
84 | ||
85 | virtual ~wxEnhMetaFileDC(); | |
86 | ||
87 | // obtain a pointer to the new metafile (caller should delete it) | |
88 | wxEnhMetaFile *Close(); | |
89 | ||
6f02a879 | 90 | protected: |
024026be VZ |
91 | virtual void DoGetSize(int *width, int *height) const; |
92 | ||
6f02a879 | 93 | private: |
024026be VZ |
94 | // size passed to ctor and returned by DoGetSize() |
95 | int m_width, | |
96 | m_height; | |
97 | ||
2eb10e2a | 98 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxEnhMetaFileDC) |
d9317fd4 VZ |
99 | }; |
100 | ||
7ba4fbeb VZ |
101 | #if wxUSE_DRAG_AND_DROP |
102 | ||
d9317fd4 VZ |
103 | // ---------------------------------------------------------------------------- |
104 | // wxEnhMetaFileDataObject is a specialization of wxDataObject for enh metafile | |
105 | // ---------------------------------------------------------------------------- | |
106 | ||
d9317fd4 | 107 | // notice that we want to support both CF_METAFILEPICT and CF_ENHMETAFILE and |
bfbd6dc1 | 108 | // so we derive from wxDataObject and not from wxDataObjectSimple |
d9317fd4 VZ |
109 | class WXDLLEXPORT wxEnhMetaFileDataObject : public wxDataObject |
110 | { | |
111 | public: | |
112 | // ctors | |
113 | wxEnhMetaFileDataObject() { } | |
114 | wxEnhMetaFileDataObject(const wxEnhMetaFile& metafile) | |
115 | : m_metafile(metafile) { } | |
116 | ||
117 | // virtual functions which you may override if you want to provide data on | |
118 | // demand only - otherwise, the trivial default versions will be used | |
119 | virtual void SetMetafile(const wxEnhMetaFile& metafile) | |
120 | { m_metafile = metafile; } | |
121 | virtual wxEnhMetaFile GetMetafile() const | |
122 | { return m_metafile; } | |
123 | ||
124 | // implement base class pure virtuals | |
125 | virtual wxDataFormat GetPreferredFormat(Direction dir) const; | |
126 | virtual size_t GetFormatCount(Direction dir) const; | |
127 | virtual void GetAllFormats(wxDataFormat *formats, Direction dir) const; | |
128 | virtual size_t GetDataSize(const wxDataFormat& format) const; | |
129 | virtual bool GetDataHere(const wxDataFormat& format, void *buf) const; | |
130 | virtual bool SetData(const wxDataFormat& format, size_t len, | |
131 | const void *buf); | |
132 | ||
133 | protected: | |
134 | wxEnhMetaFile m_metafile; | |
2eb10e2a VZ |
135 | |
136 | DECLARE_NO_COPY_CLASS(wxEnhMetaFileDataObject) | |
d9317fd4 VZ |
137 | }; |
138 | ||
7ba4fbeb VZ |
139 | |
140 | // ---------------------------------------------------------------------------- | |
141 | // wxEnhMetaFileSimpleDataObject does derive from wxDataObjectSimple which | |
142 | // makes it more convenient to use (it can be used with wxDataObjectComposite) | |
143 | // at the price of not supoprting any more CF_METAFILEPICT but only | |
144 | // CF_ENHMETAFILE | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
147 | class WXDLLEXPORT wxEnhMetaFileSimpleDataObject : public wxDataObjectSimple | |
148 | { | |
149 | public: | |
150 | // ctors | |
151 | wxEnhMetaFileSimpleDataObject() : wxDataObjectSimple(wxDF_ENHMETAFILE) { } | |
152 | wxEnhMetaFileSimpleDataObject(const wxEnhMetaFile& metafile) | |
153 | : wxDataObjectSimple(wxDF_ENHMETAFILE), m_metafile(metafile) { } | |
154 | ||
155 | // virtual functions which you may override if you want to provide data on | |
156 | // demand only - otherwise, the trivial default versions will be used | |
157 | virtual void SetEnhMetafile(const wxEnhMetaFile& metafile) | |
158 | { m_metafile = metafile; } | |
159 | virtual wxEnhMetaFile GetEnhMetafile() const | |
160 | { return m_metafile; } | |
161 | ||
162 | // implement base class pure virtuals | |
163 | virtual size_t GetDataSize() const; | |
164 | virtual bool GetDataHere(void *buf) const; | |
165 | virtual bool SetData(size_t len, const void *buf); | |
166 | ||
0e4acbd4 JS |
167 | virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const |
168 | { return GetDataSize(); } | |
169 | virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format), | |
170 | void *buf) const | |
171 | { return GetDataHere(buf); } | |
172 | virtual bool SetData(const wxDataFormat& WXUNUSED(format), | |
173 | size_t len, const void *buf) | |
174 | { return SetData(len, buf); } | |
175 | ||
7ba4fbeb VZ |
176 | protected: |
177 | wxEnhMetaFile m_metafile; | |
2eb10e2a VZ |
178 | |
179 | DECLARE_NO_COPY_CLASS(wxEnhMetaFileSimpleDataObject) | |
7ba4fbeb VZ |
180 | }; |
181 | ||
d9317fd4 VZ |
182 | #endif // wxUSE_DRAG_AND_DROP |
183 | ||
184 | #endif // _WX_MSW_ENHMETA_H_ |