]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/metafile.h
New scrolling code.
[wxWidgets.git] / include / wx / msw / metafile.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: metafile.h
3 // Purpose: wxMetaFile, wxMetaFileDC classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 #ifndef _WX_METAFIILE_H_
14 #define _WX_METAFIILE_H_
15
16 #ifdef __GNUG__
17 #pragma interface "metafile.h"
18 #endif
19
20 #include "wx/setup.h"
21
22 #if wxUSE_METAFILE
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 /*
31 * Metafile and metafile device context classes
32 *
33 */
34
35 #define wxMetaFile wxMetafile
36 #define wxMetaFileDC wxMetafileDC
37
38 class WXDLLEXPORT wxMetafile;
39
40 class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData
41 {
42 friend class WXDLLEXPORT wxMetafile;
43 public:
44 wxMetafileRefData(void);
45 ~wxMetafileRefData(void);
46
47 public:
48 WXHANDLE m_metafile;
49 int m_windowsMappingMode;
50 };
51
52 #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
53
54 class WXDLLEXPORT wxMetafile: public wxGDIObject
55 {
56 DECLARE_DYNAMIC_CLASS(wxMetafile)
57 public:
58 // Copy constructor
59 inline wxMetafile(const wxMetafile& metafile)
60 { Ref(metafile); }
61
62 wxMetafile(const wxString& file = "");
63 ~wxMetafile(void);
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 inline bool Ok(void) const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); };
71
72 // Implementation
73 inline WXHANDLE GetHMETAFILE(void) { return M_METAFILEDATA->m_metafile; }
74 void SetHMETAFILE(WXHANDLE mf) ;
75 inline int GetWindowsMappingMode(void) { return M_METAFILEDATA->m_windowsMappingMode; }
76 void SetWindowsMappingMode(int mm);
77
78 // Operators
79 inline wxMetafile& operator = (const wxMetafile& metafile) { if (*this == metafile) return (*this); Ref(metafile); return *this; }
80 inline bool operator == (const wxMetafile& metafile) { return m_refData == metafile.m_refData; }
81 inline bool operator != (const wxMetafile& metafile) { return m_refData != metafile.m_refData; }
82
83 protected:
84 };
85
86 class WXDLLEXPORT wxMetafileDC: public wxDC
87 {
88 DECLARE_DYNAMIC_CLASS(wxMetafileDC)
89
90 public:
91 // Don't supply origin and extent
92 // Supply them to wxMakeMetaFilePlaceable instead.
93 wxMetafileDC(const wxString& file = "");
94
95 // Supply origin and extent (recommended).
96 // Then don't need to supply them to wxMakeMetaFilePlaceable.
97 wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
98
99 ~wxMetafileDC(void);
100
101 // Should be called at end of drawing
102 virtual wxMetafile *Close(void);
103 virtual void SetMapMode(int mode);
104 virtual void GetTextExtent(const wxString& string, long *x, long *y,
105 long *descent = NULL, long *externalLeading = NULL,
106 wxFont *theFont = NULL, bool use16bit = FALSE) const;
107
108 // Implementation
109 inline wxMetafile *GetMetaFile(void) const { return m_metaFile; }
110 inline void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
111 inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode; }
112 inline void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
113
114 protected:
115 int m_windowsMappingMode;
116 wxMetafile* m_metaFile;
117 };
118
119 /*
120 * Pass filename of existing non-placeable metafile, and bounding box.
121 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
122 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
123 *
124 */
125
126 // No origin or extent
127 #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
128 bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
129
130 // Optional origin and extent
131 bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = TRUE);
132
133 // ----------------------------------------------------------------------------
134 // wxMetafileDataObject is a specialization of wxDataObject for metafile data
135 // ----------------------------------------------------------------------------
136
137 // TODO: implement OLE side of things. At present, it's just for clipboard
138 // use.
139
140 #if wxUSE_DRAG_AND_DROP
141 class WXDLLEXPORT wxMetafileDataObject : public wxDataObject
142 {
143 public:
144 // ctors
145 wxMetafileDataObject() { m_width = 0; m_height = 0; };
146 wxMetafileDataObject(const wxMetafile& metafile, int width = 0, int height = 0):
147 m_metafile(metafile), m_width(width), m_height(height) { }
148
149 void SetMetafile(const wxMetafile& metafile, int w = 0, int h = 0)
150 { m_metafile = metafile; m_width = w; m_height = h; }
151 wxMetafile GetMetafile() const { return m_metafile; }
152 int GetWidth() const { return m_width; }
153 int GetHeight() const { return m_height; }
154
155 virtual wxDataFormat GetFormat() const { return wxDF_METAFILE; }
156
157 /* ??
158 // implement base class pure virtuals
159 virtual wxDataFormat GetPreferredFormat() const
160 { return (wxDataFormat) wxDataObject::Text; }
161 virtual bool IsSupportedFormat(wxDataFormat format) const
162 { return format == wxDataObject::Text || format == wxDataObject::Locale; }
163 virtual size_t GetDataSize() const
164 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
165 virtual void GetDataHere(void *pBuf) const
166 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
167 */
168
169 private:
170 wxMetafile m_metafile;
171 int m_width;
172 int m_height;
173 };
174 #endif
175
176 #endif // wxUSE_METAFILE
177 #endif
178 // _WX_METAFIILE_H_
179