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 ( !wxTheFontMapper
->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
) ;
119 p2cstrcpy( c_name
, p_name
) ;
122 strcpy( c_name
, (char *)p_name
) ;
128 // check that it's a fixed pitch font (there is *no* error here, the
129 // flag name is misleading!)
130 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
132 // not a fixed pitch font
137 if ( m_charset != -1 )
139 // check that we have the right encoding
140 if ( lf->lfCharSet != m_charset )
147 m_fontEnum
->OnFacename( c_name
) ;
149 DisposeMenu( menu
) ;
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
159 wxFontEnumeratorHelper
fe(this);
160 if ( fe
.SetEncoding(encoding
) )
162 fe
.SetFixedOnly(fixedWidthOnly
);
166 // else: no such fonts, unknown encoding
171 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
173 wxFAIL_MSG(wxT("TODO"));