]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/fontenum.cpp
3 // Purpose: wxFontEnumerator class for Windows
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin to add support for font encodings
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontenum.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/fontenum.h"
37 #include "wx/msw/private.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class wxFontEnumeratorHelper
46 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
48 // control what exactly are we enumerating
49 bool SetEncoding(wxFontEncoding encoding
);
50 void SetFixedOnly(bool fixedOnly
)
51 { m_fixedOnly
= fixedOnly
; }
53 // call to start enumeration
56 // called by our font enumeration proc
57 bool OnFont(const LPLOGFONT lf
, const LPTEXTMETRIC tm
) const;
60 // the object we forward calls to OnFont() to
61 wxFontEnumerator
*m_fontEnum
;
63 // if != -1, enum only fonts which have this encoding
66 // if TRUE, enum only fixed fonts
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 int CALLBACK
wxFontEnumeratorProc(LPLOGFONT lplf
, LPTEXTMETRIC lptm
,
75 DWORD dwStyle
, LONG lParam
);
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
82 // wxFontEnumeratorHelper
83 // ----------------------------------------------------------------------------
85 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
87 m_fontEnum
= fontEnum
;
92 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
95 m_charset
= wxCharsetFromEncoding(encoding
, &exact
);
99 m_charset
= DEFAULT_CHARSET
;
106 void wxFontEnumeratorHelper::DoEnumerate()
108 HDC hDC
= ::GetDC(NULL
);
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 */) ;
118 ::EnumFonts(hDC
, (LPTSTR
)NULL
, (FONTENUMPROC
)wxFontEnumeratorProc
,
119 (LPARAM
) (void*) this) ;
122 ::ReleaseDC(NULL
, hDC
);
125 bool wxFontEnumeratorHelper::OnFont(const LPLOGFONT lf
,
126 const LPTEXTMETRIC tm
) const
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
)
134 // not a fixed pitch font
139 if ( m_charset
!= -1 )
141 // check that we have the right encoding
142 if ( lf
->lfCharSet
!= m_charset
)
148 return m_fontEnum
->OnFontFamily(lf
->lfFaceName
);
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 bool wxFontEnumerator::EnumerateFamilies(wxFontEncoding encoding
,
158 wxFontEnumeratorHelper
fe(this);
159 if ( fe
.SetEncoding(encoding
) )
161 fe
.SetFixedOnly(fixedWidthOnly
);
165 // else: no such fonts, unknown encoding
170 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
172 wxFAIL_MSG(wxT("TODO"));
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 int CALLBACK
wxFontEnumeratorProc(LPLOGFONT lplf
, LPTEXTMETRIC lptm
,
182 DWORD dwStyle
, LONG lParam
)
184 // Get rid of any fonts that we don't want...
185 if ( dwStyle
!= TRUETYPE_FONTTYPE
)
187 // continue enumeration
191 wxFontEnumeratorHelper
*fontEnum
= (wxFontEnumeratorHelper
*)lParam
;
193 return fontEnum
->OnFont(lplf
, lptm
);