]> git.saurik.com Git - wxWidgets.git/blame - src/msw/fontenum.cpp
additions for wxFileDataObject from Ricky Gonzales <gonzales@pyramid3.net>
[wxWidgets.git] / src / msw / fontenum.cpp
CommitLineData
a1d58ddc
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/fontenum.cpp
543f08a6
JS
3// Purpose: wxFontEnumerator class for Windows
4// Author: Julian Smart
a1d58ddc 5// Modified by: Vadim Zeitlin to add support for font encodings
543f08a6
JS
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
a1d58ddc
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "fontenum.h"
22#endif
543f08a6
JS
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/font.h"
33#endif
34
a1d58ddc 35#include "wx/fontenum.h"
543f08a6 36
a1d58ddc
VZ
37#include "wx/msw/private.h"
38
39// ----------------------------------------------------------------------------
40// private classes
41// ----------------------------------------------------------------------------
42
43class wxFontEnumeratorHelper
543f08a6 44{
a1d58ddc
VZ
45public:
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
59private:
60 // the object we forward calls to OnFont() to
61 wxFontEnumerator *m_fontEnum;
543f08a6 62
a1d58ddc
VZ
63 // if != -1, enum only fonts which have this encoding
64 int m_charset;
543f08a6 65
a1d58ddc
VZ
66 // if TRUE, enum only fixed fonts
67 bool m_fixedOnly;
68};
543f08a6 69
a1d58ddc
VZ
70// ----------------------------------------------------------------------------
71// private functions
72// ----------------------------------------------------------------------------
73
74int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
75 DWORD dwStyle, LONG lParam);
76
77// ============================================================================
78// implementation
79// ============================================================================
80
81// ----------------------------------------------------------------------------
82// wxFontEnumeratorHelper
83// ----------------------------------------------------------------------------
84
85wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
86{
87 m_fontEnum = fontEnum;
88 m_charset = -1;
89 m_fixedOnly = FALSE;
543f08a6
JS
90}
91
a1d58ddc
VZ
92bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
93{
94 bool exact;
95 m_charset = wxCharsetFromEncoding(encoding, &exact);
96#ifdef __WIN32__
97 if ( !exact )
98 {
99 m_charset = DEFAULT_CHARSET;
100 }
101#endif // Win32
543f08a6 102
a1d58ddc
VZ
103 return exact;
104}
105
106void wxFontEnumeratorHelper::DoEnumerate()
543f08a6 107{
a1d58ddc 108 HDC hDC = ::GetDC(NULL);
543f08a6 109
543f08a6 110#ifdef __WIN32__
a1d58ddc
VZ
111 LOGFONT lf;
112 lf.lfCharSet = m_charset;
113 lf.lfFaceName[0] = _T('\0');
114 lf.lfPitchAndFamily = 0;
115 ::EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC)wxFontEnumeratorProc,
116 (LPARAM)this, 0 /* reserved */) ;
117#else // Win16
118 ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc,
119 (LPARAM) (void*) this) ;
120#endif // Win32/16
543f08a6 121
a1d58ddc
VZ
122 ::ReleaseDC(NULL, hDC);
123}
124
125bool wxFontEnumeratorHelper::OnFont(const LPLOGFONT lf,
126 const LPTEXTMETRIC tm) const
127{
128 if ( m_fixedOnly )
129 {
130 // check that it's a fixed pitch font (there is *no* error here, the
131 // flag name is misleading!)
132 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
133 {
134 // not a fixed pitch font
135 return TRUE;
136 }
137 }
138
139 if ( m_charset != -1 )
140 {
141 // check that we have the right encoding
142 if ( lf->lfCharSet != m_charset )
143 {
144 return TRUE;
145 }
146 }
147
148 return m_fontEnum->OnFontFamily(lf->lfFaceName);
149}
150
151// ----------------------------------------------------------------------------
152// wxFontEnumerator
153// ----------------------------------------------------------------------------
154
155bool wxFontEnumerator::EnumerateFamilies(wxFontEncoding encoding,
156 bool fixedWidthOnly)
543f08a6 157{
a1d58ddc
VZ
158 wxFontEnumeratorHelper fe(this);
159 if ( fe.SetEncoding(encoding) )
160 {
161 fe.SetFixedOnly(fixedWidthOnly);
162
163 fe.DoEnumerate();
164 }
165 // else: no such fonts, unknown encoding
166
543f08a6
JS
167 return TRUE;
168}
169
a1d58ddc
VZ
170bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
171{
172 wxFAIL_MSG(wxT("TODO"));
173
174 return TRUE;
175}
176
177// ----------------------------------------------------------------------------
178// Windows callbacks
179// ----------------------------------------------------------------------------
180
181int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
182 DWORD dwStyle, LONG lParam)
183{
184 // Get rid of any fonts that we don't want...
185 if ( dwStyle != TRUETYPE_FONTTYPE )
186 {
187 // continue enumeration
188 return TRUE;
189 }
190
191 wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam;
192
193 return fontEnum->OnFont(lplf, lptm);
194}
195