]> git.saurik.com Git - wxWidgets.git/blob - src/os2/fontenum.cpp
Add virtual ~wxAnyScrollHelperBase() to fix compiler warning.
[wxWidgets.git] / src / os2 / fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/fontenum.cpp
3 // Purpose: wxFontEnumerator class for Windows
4 // Author: Julian Smart
5 // Modified by: David Webster to add support for font encodings
6 // Created: 01/03/00
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #if wxUSE_FONTMAP
23
24 #include "wx/fontenum.h"
25
26 #ifndef WX_PRECOMP
27 #include "wx/font.h"
28 #endif
29
30 #include "wx/fontmap.h"
31 #include "wx/encinfo.h"
32
33 #include "wx/os2/private.h"
34
35 // ----------------------------------------------------------------------------
36 // private classes
37 // ----------------------------------------------------------------------------
38
39 class wxFontEnumeratorHelper
40 {
41 public:
42 wxFontEnumeratorHelper(wxFontEnumerator *fontEnum);
43
44 // control what exactly are we enumerating
45 bool SetEncoding(wxFontEncoding encoding);
46 void SetFixedOnly(bool fixedOnly)
47 { m_fixedOnly = fixedOnly; }
48
49 // call to start enumeration
50 void DoEnumerate();
51
52 // called by our font enumeration proc
53 bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const;
54
55 private:
56 // the object we forward calls to OnFont() to
57 wxFontEnumerator *m_fontEnum;
58
59 // if != -1, enum only fonts which have this encoding
60 int m_charset;
61
62 // if not empty, enum only the fonts with this facename
63 wxString m_facename;
64
65 // if true, enum only fixed fonts
66 bool m_fixedOnly;
67 };
68
69 // ----------------------------------------------------------------------------
70 // private functions
71 // ----------------------------------------------------------------------------
72
73 // TODO:
74 /*
75 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
76 DWORD dwStyle, LONG lParam);
77 */
78
79 // ============================================================================
80 // implementation
81 // ============================================================================
82
83 // ----------------------------------------------------------------------------
84 // wxFontEnumeratorHelper
85 // ----------------------------------------------------------------------------
86
87 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
88 {
89 m_fontEnum = fontEnum;
90 m_charset = -1;
91 m_fixedOnly = FALSE;
92 }
93
94 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
95 {
96 wxNativeEncodingInfo info;
97 if ( !wxGetNativeFontEncoding(encoding, &info) )
98 {
99 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
100 {
101 // no such encodings at all
102 return FALSE;
103 }
104 }
105 m_charset = info.charset;
106 m_facename = info.facename;
107
108 return true;
109 }
110
111 #define wxFONTENUMPROC FONTENUMPROC
112
113 void wxFontEnumeratorHelper::DoEnumerate()
114 {
115 // TODO:
116 /*
117 HDC hDC = ::GetDC(NULL);
118
119 #ifdef __WIN32__
120 LOGFONT lf;
121 lf.lfCharSet = m_charset;
122 wxStrlcpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName));
123 lf.lfPitchAndFamily = 0;
124 ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc,
125 (LPARAM)this, 0) ;
126 #else // Win16
127 ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc,
128 #ifdef STRICT
129 (LPARAM)
130 #else
131 (LPSTR)
132 #endif
133 this);
134 #endif // Win32/16
135
136 ::ReleaseDC(NULL, hDC);
137 */
138 }
139
140 bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf,
141 const LPTEXTMETRIC tm */) const
142 {
143 // TODO:
144 /*
145 if ( m_fixedOnly )
146 {
147 // check that it's a fixed pitch font (there is *no* error here, the
148 // flag name is misleading!)
149 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
150 {
151 // not a fixed pitch font
152 return true;
153 }
154 }
155
156 if ( m_charset != -1 )
157 {
158 // check that we have the right encoding
159 if ( lf->lfCharSet != m_charset )
160 {
161 return true;
162 }
163 }
164
165 return m_fontEnum->OnFacename(lf->lfFaceName);
166 */
167 return true;
168 }
169
170 // ----------------------------------------------------------------------------
171 // wxFontEnumerator
172 // ----------------------------------------------------------------------------
173
174 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
175 bool fixedWidthOnly)
176 {
177 wxFontEnumeratorHelper fe(this);
178 if ( fe.SetEncoding(encoding) )
179 {
180 fe.SetFixedOnly(fixedWidthOnly);
181
182 fe.DoEnumerate();
183 }
184 // else: no such fonts, unknown encoding
185
186 return true;
187 }
188
189 bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
190 {
191 wxFAIL_MSG(wxT("TODO"));
192
193 return true;
194 }
195
196 // ----------------------------------------------------------------------------
197 // Windows callbacks
198 // ----------------------------------------------------------------------------
199
200 // TODO:
201 /*
202 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
203 DWORD dwStyle, LONG lParam)
204 {
205 // Get rid of any fonts that we don't want...
206 if ( dwStyle != TRUETYPE_FONTTYPE )
207 {
208 // continue enumeration
209 return TRUE;
210 }
211
212 wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam;
213
214 return fontEnum->OnFont(lplf, lptm);
215 }
216 */
217
218 #endif // wxUSE_FONTMAP