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 // ----------------------------------------------------------------------------
21 #pragma implementation "fontenum.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/fontenum.h"
36 #include "wx/fontutil.h"
37 #include "wx/fontmap.h"
38 #include "wx/fontutil.h"
40 #include "wx/mac/private.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 class wxFontEnumeratorHelper
49 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
51 // control what exactly are we enumerating
52 bool SetEncoding(wxFontEncoding encoding
);
53 void SetFixedOnly(bool fixedOnly
)
54 { m_fixedOnly
= fixedOnly
; }
56 // call to start enumeration
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 not empty, enum only the fonts with this facename
69 // if TRUE, enum only fixed fonts
72 // ============================================================================
74 // ============================================================================
76 // ----------------------------------------------------------------------------
77 // wxFontEnumeratorHelper
78 // ----------------------------------------------------------------------------
80 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
82 m_fontEnum
= fontEnum
;
87 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
89 wxNativeEncodingInfo info
;
90 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
92 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
94 // no such encodings at all
98 m_charset
= info
.charset
;
99 m_facename
= info
.facename
;
104 void wxFontEnumeratorHelper::DoEnumerate()
111 menu
= NewMenu( 32000 , "\pFont" ) ;
112 AppendResMenu( menu
, 'FONT' ) ;
113 lines
= CountMenuItems( menu
) ;
115 for ( int i
= 1 ; i
< lines
+1 ; i
++ )
117 GetMenuItemText( menu
, i
, p_name
) ;
118 wxString c_name
= wxMacMakeStringFromPascal(p_name
) ;
124 // check that it's a fixed pitch font (there is *no* error here, the
125 // flag name is misleading!)
126 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
128 // not a fixed pitch font
133 if ( m_charset != -1 )
135 // check that we have the right encoding
136 if ( lf->lfCharSet != m_charset )
143 m_fontEnum
->OnFacename( c_name
) ;
145 DisposeMenu( menu
) ;
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
155 wxFontEnumeratorHelper
fe(this);
156 if ( fe
.SetEncoding(encoding
) )
158 fe
.SetFixedOnly(fixedWidthOnly
);
162 // else: no such fonts, unknown encoding
167 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
169 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));