]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
265b0c07 VZ |
2 | // Name: wx/msw/metafile.h |
3 | // Purpose: wxMetaFile, wxMetaFileDC and wxMetaFileDataObject classes | |
2bda0e17 | 4 | // Author: Julian Smart |
265b0c07 | 5 | // Modified by: VZ 07.01.00: implemented wxMetaFileDataObject |
2bda0e17 KB |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
bbcdf8bc | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_METAFIILE_H_ |
13 | #define _WX_METAFIILE_H_ | |
2bda0e17 | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
265b0c07 | 16 | #pragma interface "metafile.h" |
2bda0e17 KB |
17 | #endif |
18 | ||
2bda0e17 | 19 | #include "wx/dc.h" |
06e43511 JS |
20 | #include "wx/gdiobj.h" |
21 | ||
22 | #if wxUSE_DRAG_AND_DROP | |
265b0c07 | 23 | #include "wx/dataobj.h" |
06e43511 | 24 | #endif |
2bda0e17 | 25 | |
265b0c07 VZ |
26 | // ---------------------------------------------------------------------------- |
27 | // Metafile and metafile device context classes | |
28 | // ---------------------------------------------------------------------------- | |
06e43511 JS |
29 | |
30 | class WXDLLEXPORT wxMetafile; | |
31 | ||
32 | class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData | |
2bda0e17 | 33 | { |
06e43511 JS |
34 | friend class WXDLLEXPORT wxMetafile; |
35 | public: | |
265b0c07 VZ |
36 | wxMetafileRefData(); |
37 | ~wxMetafileRefData(); | |
06e43511 JS |
38 | |
39 | public: | |
40 | WXHANDLE m_metafile; | |
41 | int m_windowsMappingMode; | |
265b0c07 | 42 | int m_width, m_height; |
06e43511 JS |
43 | }; |
44 | ||
45 | #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) | |
46 | ||
47 | class WXDLLEXPORT wxMetafile: public wxGDIObject | |
48 | { | |
265b0c07 VZ |
49 | public: |
50 | wxMetafile(const wxString& file = wxEmptyString); | |
51 | wxMetafile(const wxMetafile& metafile) { Ref(metafile); } | |
52 | virtual ~wxMetafile(); | |
53 | ||
54 | // After this is called, the metafile cannot be used for anything | |
55 | // since it is now owned by the clipboard. | |
56 | virtual bool SetClipboard(int width = 0, int height = 0); | |
57 | ||
58 | virtual bool Play(wxDC *dc); | |
59 | bool Ok() const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); }; | |
60 | ||
61 | // set/get the size of metafile for clipboard operations | |
d9317fd4 | 62 | wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); } |
265b0c07 VZ |
63 | int GetWidth() const { return M_METAFILEDATA->m_width; } |
64 | int GetHeight() const { return M_METAFILEDATA->m_height; } | |
65 | ||
66 | void SetWidth(int width) { M_METAFILEDATA->m_width = width; } | |
67 | void SetHeight(int height) { M_METAFILEDATA->m_height = height; } | |
68 | ||
69 | // Implementation | |
70 | WXHANDLE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; } | |
71 | void SetHMETAFILE(WXHANDLE mf) ; | |
72 | int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; } | |
73 | void SetWindowsMappingMode(int mm); | |
74 | ||
75 | // Operators | |
76 | wxMetafile& operator=(const wxMetafile& metafile) | |
77 | { if (*this != metafile) Ref(metafile); return *this; } | |
78 | bool operator==(const wxMetafile& metafile) const | |
79 | { return m_refData == metafile.m_refData; } | |
80 | bool operator!=(const wxMetafile& metafile) const | |
81 | { return m_refData != metafile.m_refData; } | |
2bda0e17 | 82 | |
265b0c07 VZ |
83 | private: |
84 | DECLARE_DYNAMIC_CLASS(wxMetafile) | |
2bda0e17 KB |
85 | }; |
86 | ||
06e43511 | 87 | class WXDLLEXPORT wxMetafileDC: public wxDC |
2bda0e17 | 88 | { |
265b0c07 VZ |
89 | public: |
90 | // Don't supply origin and extent | |
91 | // Supply them to wxMakeMetaFilePlaceable instead. | |
d9317fd4 | 92 | wxMetafileDC(const wxString& file = wxEmptyString); |
2bda0e17 | 93 | |
265b0c07 VZ |
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); | |
2bda0e17 | 97 | |
265b0c07 | 98 | virtual ~wxMetafileDC(); |
2bda0e17 | 99 | |
265b0c07 VZ |
100 | // Should be called at end of drawing |
101 | virtual wxMetafile *Close(); | |
102 | virtual void SetMapMode(int mode); | |
103 | virtual void GetTextExtent(const wxString& string, long *x, long *y, | |
104 | long *descent = NULL, long *externalLeading = NULL, | |
598ddd96 | 105 | wxFont *theFont = NULL, bool use16bit = false) const; |
2bda0e17 | 106 | |
265b0c07 VZ |
107 | // Implementation |
108 | wxMetafile *GetMetaFile() const { return m_metaFile; } | |
109 | void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; } | |
110 | int GetWindowsMappingMode() const { return m_windowsMappingMode; } | |
111 | void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; } | |
2bda0e17 KB |
112 | |
113 | protected: | |
265b0c07 VZ |
114 | int m_windowsMappingMode; |
115 | wxMetafile* m_metaFile; | |
116 | ||
117 | private: | |
118 | DECLARE_DYNAMIC_CLASS(wxMetafileDC) | |
2bda0e17 KB |
119 | }; |
120 | ||
121 | /* | |
122 | * Pass filename of existing non-placeable metafile, and bounding box. | |
123 | * Adds a placeable metafile header, sets the mapping mode to anisotropic, | |
e3065973 | 124 | * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode. |
2bda0e17 KB |
125 | * |
126 | */ | |
127 | ||
128 | // No origin or extent | |
06e43511 | 129 | bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0); |
2bda0e17 KB |
130 | |
131 | // Optional origin and extent | |
598ddd96 | 132 | bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = true); |
2bda0e17 | 133 | |
06e43511 JS |
134 | // ---------------------------------------------------------------------------- |
135 | // wxMetafileDataObject is a specialization of wxDataObject for metafile data | |
136 | // ---------------------------------------------------------------------------- | |
137 | ||
06e43511 | 138 | #if wxUSE_DRAG_AND_DROP |
265b0c07 VZ |
139 | |
140 | class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple | |
06e43511 JS |
141 | { |
142 | public: | |
265b0c07 VZ |
143 | // ctors |
144 | wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE) | |
145 | { } | |
146 | wxMetafileDataObject(const wxMetafile& metafile) | |
147 | : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { } | |
148 | ||
149 | // virtual functions which you may override if you want to provide data on | |
150 | // demand only - otherwise, the trivial default versions will be used | |
151 | virtual void SetMetafile(const wxMetafile& metafile) | |
152 | { m_metafile = metafile; } | |
153 | virtual wxMetafile GetMetafile() const | |
154 | { return m_metafile; } | |
155 | ||
156 | // implement base class pure virtuals | |
157 | virtual size_t GetDataSize() const; | |
158 | virtual bool GetDataHere(void *buf) const; | |
159 | virtual bool SetData(size_t len, const void *buf); | |
06e43511 | 160 | |
265b0c07 VZ |
161 | protected: |
162 | wxMetafile m_metafile; | |
06e43511 | 163 | }; |
265b0c07 VZ |
164 | |
165 | #endif // wxUSE_DRAG_AND_DROP | |
06e43511 | 166 | |
2bda0e17 | 167 | #endif |
bbcdf8bc | 168 | // _WX_METAFIILE_H_ |
2845ddc2 | 169 |