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