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