1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "fontenum.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/fontenum.h"
38 #include "wx/fontutil.h"
39 #include "wx/fontmap.h"
40 #include "wx/fontutil.h"
41 #include "wx/encinfo.h"
43 #include "wx/mac/private.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 class wxFontEnumeratorHelper
52 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
54 // control what exactly are we enumerating
55 bool SetEncoding(wxFontEncoding encoding
);
56 void SetFixedOnly(bool fixedOnly
)
57 { m_fixedOnly
= fixedOnly
; }
59 // call to start enumeration
63 // the object we forward calls to OnFont() to
64 wxFontEnumerator
*m_fontEnum
;
66 // if != -1, enum only fonts which have this encoding
69 // if not empty, enum only the fonts with this facename
72 // if TRUE, enum only fixed fonts
75 // ============================================================================
77 // ============================================================================
79 // ----------------------------------------------------------------------------
80 // wxFontEnumeratorHelper
81 // ----------------------------------------------------------------------------
83 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
85 m_fontEnum
= fontEnum
;
90 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
92 wxNativeEncodingInfo info
;
93 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
95 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
97 // no such encodings at all
101 m_charset
= info
.charset
;
102 m_facename
= info
.facename
;
107 void wxFontEnumeratorHelper::DoEnumerate()
114 menu
= NewMenu( 32000 , "\pFont" ) ;
115 AppendResMenu( menu
, 'FONT' ) ;
116 lines
= CountMenuItems( menu
) ;
118 for ( int i
= 1 ; i
< lines
+1 ; i
++ )
120 GetMenuItemText( menu
, i
, p_name
) ;
121 wxString c_name
= wxMacMakeStringFromPascal(p_name
) ;
127 // check that it's a fixed pitch font (there is *no* error here, the
128 // flag name is misleading!)
129 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
131 // not a fixed pitch font
136 if ( m_charset != -1 )
138 // check that we have the right encoding
139 if ( lf->lfCharSet != m_charset )
146 m_fontEnum
->OnFacename( c_name
) ;
148 DisposeMenu( menu
) ;
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 bool wxFontEnumerator::EnumerateFacenames(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("wxFontEnumerator::EnumerateEncodings() not yet implemented"));