]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/metafile.h
more socket cleanup to allow using wxSocket from both wxBase and wxCore (replaces...
[wxWidgets.git] / include / wx / msw / metafile.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/metafile.h
3 // Purpose: wxMetaFile, wxMetaFileDC and wxMetaFileDataObject classes
4 // Author: Julian Smart
5 // Modified by: VZ 07.01.00: implemented wxMetaFileDataObject
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_METAFIILE_H_
13 #define _WX_METAFIILE_H_
14
15 #include "wx/dc.h"
16 #include "wx/gdiobj.h"
17
18 #if wxUSE_DRAG_AND_DROP
19 #include "wx/dataobj.h"
20 #endif
21
22 // ----------------------------------------------------------------------------
23 // Metafile and metafile device context classes
24 // ----------------------------------------------------------------------------
25
26 class WXDLLIMPEXP_FWD_CORE wxMetafile;
27
28 class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData
29 {
30 public:
31 wxMetafileRefData();
32 virtual ~wxMetafileRefData();
33
34 virtual bool IsOk() const { return m_metafile != 0; }
35
36 public:
37 WXHANDLE m_metafile;
38 int m_windowsMappingMode;
39 int m_width, m_height;
40
41 friend class WXDLLIMPEXP_FWD_CORE wxMetafile;
42 };
43
44 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
45
46 class WXDLLEXPORT wxMetafile: public wxGDIObject
47 {
48 public:
49 wxMetafile(const wxString& file = wxEmptyString);
50 virtual ~wxMetafile();
51
52 // After this is called, the metafile cannot be used for anything
53 // since it is now owned by the clipboard.
54 virtual bool SetClipboard(int width = 0, int height = 0);
55
56 virtual bool Play(wxDC *dc);
57
58 // set/get the size of metafile for clipboard operations
59 wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); }
60 int GetWidth() const { return M_METAFILEDATA->m_width; }
61 int GetHeight() const { return M_METAFILEDATA->m_height; }
62
63 void SetWidth(int width) { M_METAFILEDATA->m_width = width; }
64 void SetHeight(int height) { M_METAFILEDATA->m_height = height; }
65
66 // Implementation
67 WXHANDLE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; }
68 void SetHMETAFILE(WXHANDLE mf) ;
69 int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; }
70 void SetWindowsMappingMode(int mm);
71
72 private:
73 DECLARE_DYNAMIC_CLASS(wxMetafile)
74 };
75
76 class WXDLLEXPORT wxMetafileDCImpl: public wxMSWDCImpl
77 {
78 public:
79 wxMetafileDCImpl(const wxString& file = wxEmptyString);
80 wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
81 virtual ~wxMetafileDCImpl();
82
83 virtual wxMetafile *Close();
84 virtual void SetMapMode(int mode);
85 virtual void DoGetTextExtent(const wxString& string,
86 wxCoord *x, wxCoord *y,
87 wxCoord *descent = NULL,
88 wxCoord *externalLeading = NULL,
89 const wxFont *theFont = NULL) const;
90
91 // Implementation
92 wxMetafile *GetMetaFile() const { return m_metaFile; }
93 void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
94 int GetWindowsMappingMode() const { return m_windowsMappingMode; }
95 void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
96
97 protected:
98 virtual void DoGetSize(int *width, int *height) const;
99
100 virtual wxGDIRefData *CreateGDIRefData() const;
101 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
102
103 int m_windowsMappingMode;
104 wxMetafile* m_metaFile;
105
106 private:
107 DECLARE_CLASS(wxMetafileDCImpl)
108 DECLARE_NO_COPY_CLASS(wxMetafileDCImpl)
109 };
110
111 class WXDLLEXPORT wxMetafileDC: public wxDC
112 {
113 public:
114 // Don't supply origin and extent
115 // Supply them to wxMakeMetaFilePlaceable instead.
116 wxMetafileDC(const wxString& file);
117 { m_pimpl = new wxMetafileDCImpl( this, file ); }
118
119 // Supply origin and extent (recommended).
120 // Then don't need to supply them to wxMakeMetaFilePlaceable.
121 wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
122 { m_pimpl = new wxMetafileDCImpl( this, file, xext, yext, xorg, yorg ); }
123
124 wxMetafile *GetMetafile() const
125 { return ((wxMetafileDCImpl*)m_pimpl)->GetMetaFile(); }
126
127 wxMetafile *Close()
128 { return ((wxMetafileDCImpl*)m_pimpl)->Close(); }
129
130 private:
131 DECLARE_CLASS(wxMetafileDC)
132 DECLARE_NO_COPY_CLASS(wxMetafileDC)
133 };
134
135
136
137
138 /*
139 * Pass filename of existing non-placeable metafile, and bounding box.
140 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
141 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
142 *
143 */
144
145 // No origin or extent
146 bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
147
148 // Optional origin and extent
149 bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = true);
150
151 // ----------------------------------------------------------------------------
152 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
153 // ----------------------------------------------------------------------------
154
155 #if wxUSE_DRAG_AND_DROP
156
157 class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple
158 {
159 public:
160 // ctors
161 wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE)
162 { }
163 wxMetafileDataObject(const wxMetafile& metafile)
164 : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { }
165
166 // virtual functions which you may override if you want to provide data on
167 // demand only - otherwise, the trivial default versions will be used
168 virtual void SetMetafile(const wxMetafile& metafile)
169 { m_metafile = metafile; }
170 virtual wxMetafile GetMetafile() const
171 { return m_metafile; }
172
173 // implement base class pure virtuals
174 virtual size_t GetDataSize() const;
175 virtual bool GetDataHere(void *buf) const;
176 virtual bool SetData(size_t len, const void *buf);
177
178 protected:
179 wxMetafile m_metafile;
180 };
181
182 #endif // wxUSE_DRAG_AND_DROP
183
184 #endif
185 // _WX_METAFIILE_H_
186