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