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