]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/metafile.h
wxAPIENTRY fixes (?)
[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 #ifdef __GNUG__
16 #pragma interface "metafile.h"
17 #endif
18
19 #include "wx/setup.h"
20
21 #if wxUSE_METAFILE
22
23 #include "wx/dc.h"
24 #include "wx/gdiobj.h"
25
26 #if wxUSE_DRAG_AND_DROP
27 #include "wx/dataobj.h"
28 #endif
29
30 // provide synonyms for all metafile classes
31 #define wxMetaFile wxMetafile
32 #define wxMetaFileDC wxMetafileDC
33 #define wxMetaFileDataObject wxMetafileDataObject
34
35 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
36
37 // ----------------------------------------------------------------------------
38 // Metafile and metafile device context classes
39 // ----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxMetafile;
42
43 class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData
44 {
45 friend class WXDLLEXPORT wxMetafile;
46 public:
47 wxMetafileRefData();
48 ~wxMetafileRefData();
49
50 public:
51 WXHANDLE m_metafile;
52 int m_windowsMappingMode;
53 int m_width, m_height;
54 };
55
56 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
57
58 class WXDLLEXPORT wxMetafile: public wxGDIObject
59 {
60 public:
61 wxMetafile(const wxString& file = wxEmptyString);
62 wxMetafile(const wxMetafile& metafile) { Ref(metafile); }
63 virtual ~wxMetafile();
64
65 // After this is called, the metafile cannot be used for anything
66 // since it is now owned by the clipboard.
67 virtual bool SetClipboard(int width = 0, int height = 0);
68
69 virtual bool Play(wxDC *dc);
70 bool Ok() const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); };
71
72 // set/get the size of metafile for clipboard operations
73 int GetWidth() const { return M_METAFILEDATA->m_width; }
74 int GetHeight() const { return M_METAFILEDATA->m_height; }
75
76 void SetWidth(int width) { M_METAFILEDATA->m_width = width; }
77 void SetHeight(int height) { M_METAFILEDATA->m_height = height; }
78
79 // Implementation
80 WXHANDLE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; }
81 void SetHMETAFILE(WXHANDLE mf) ;
82 int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; }
83 void SetWindowsMappingMode(int mm);
84
85 // Operators
86 wxMetafile& operator=(const wxMetafile& metafile)
87 { if (*this != metafile) Ref(metafile); return *this; }
88 bool operator==(const wxMetafile& metafile) const
89 { return m_refData == metafile.m_refData; }
90 bool operator!=(const wxMetafile& metafile) const
91 { return m_refData != metafile.m_refData; }
92
93 private:
94 DECLARE_DYNAMIC_CLASS(wxMetafile)
95 };
96
97 class WXDLLEXPORT wxMetafileDC: public wxDC
98 {
99 public:
100 // Don't supply origin and extent
101 // Supply them to wxMakeMetaFilePlaceable instead.
102 wxMetafileDC(const wxString& file = "");
103
104 // Supply origin and extent (recommended).
105 // Then don't need to supply them to wxMakeMetaFilePlaceable.
106 wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
107
108 virtual ~wxMetafileDC();
109
110 // Should be called at end of drawing
111 virtual wxMetafile *Close();
112 virtual void SetMapMode(int mode);
113 virtual void GetTextExtent(const wxString& string, long *x, long *y,
114 long *descent = NULL, long *externalLeading = NULL,
115 wxFont *theFont = NULL, bool use16bit = FALSE) const;
116
117 // Implementation
118 wxMetafile *GetMetaFile() const { return m_metaFile; }
119 void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
120 int GetWindowsMappingMode() const { return m_windowsMappingMode; }
121 void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
122
123 protected:
124 int m_windowsMappingMode;
125 wxMetafile* m_metaFile;
126
127 private:
128 DECLARE_DYNAMIC_CLASS(wxMetafileDC)
129 };
130
131 /*
132 * Pass filename of existing non-placeable metafile, and bounding box.
133 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
134 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
135 *
136 */
137
138 // No origin or extent
139 bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
140
141 // Optional origin and extent
142 bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = TRUE);
143
144 // ----------------------------------------------------------------------------
145 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
146 // ----------------------------------------------------------------------------
147
148 #if wxUSE_DRAG_AND_DROP
149
150 class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple
151 {
152 public:
153 // ctors
154 wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE)
155 { }
156 wxMetafileDataObject(const wxMetafile& metafile)
157 : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { }
158
159 // virtual functions which you may override if you want to provide data on
160 // demand only - otherwise, the trivial default versions will be used
161 virtual void SetMetafile(const wxMetafile& metafile)
162 { m_metafile = metafile; }
163 virtual wxMetafile GetMetafile() const
164 { return m_metafile; }
165
166 // implement base class pure virtuals
167 virtual size_t GetDataSize() const;
168 virtual bool GetDataHere(void *buf) const;
169 virtual bool SetData(size_t len, const void *buf);
170
171 protected:
172 wxMetafile m_metafile;
173 };
174
175 #endif // wxUSE_DRAG_AND_DROP
176
177 #endif // wxUSE_METAFILE
178 #endif
179 // _WX_METAFIILE_H_
180