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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/fontenum.h"
34 #include "wx/fontutil.h"
35 #include "wx/fontmap.h"
36 #include "wx/fontutil.h"
37 #include "wx/encinfo.h"
39 #include "wx/mac/private.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 class wxFontEnumeratorHelper
48 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
50 // control what exactly are we enumerating
51 bool SetEncoding(wxFontEncoding encoding
);
52 void SetFixedOnly(bool fixedOnly
)
53 { m_fixedOnly
= fixedOnly
; }
55 // call to start enumeration
59 // the object we forward calls to OnFont() to
60 wxFontEnumerator
*m_fontEnum
;
62 // if != -1, enum only fonts which have this encoding
65 // if not empty, enum only the fonts with this facename
68 // if TRUE, enum only fixed fonts
71 // ============================================================================
73 // ============================================================================
75 // ----------------------------------------------------------------------------
76 // wxFontEnumeratorHelper
77 // ----------------------------------------------------------------------------
79 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
81 m_fontEnum
= fontEnum
;
86 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
88 wxNativeEncodingInfo info
;
89 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
91 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
93 // no such encodings at all
97 m_charset
= info
.charset
;
98 m_facename
= info
.facename
;
103 void wxFontEnumeratorHelper::DoEnumerate()
110 menu
= NewMenu( 32000 , "\pFont" ) ;
111 AppendResMenu( menu
, 'FONT' ) ;
112 lines
= CountMenuItems( menu
) ;
114 for ( int i
= 1 ; i
< lines
+1 ; i
++ )
116 GetMenuItemText( menu
, i
, p_name
) ;
117 wxString c_name
= wxMacMakeStringFromPascal(p_name
) ;
123 // check that it's a fixed pitch font (there is *no* error here, the
124 // flag name is misleading!)
125 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
127 // not a fixed pitch font
132 if ( m_charset != -1 )
134 // check that we have the right encoding
135 if ( lf->lfCharSet != m_charset )
142 m_fontEnum
->OnFacename( c_name
) ;
144 DisposeMenu( menu
) ;
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
154 wxFontEnumeratorHelper
fe(this);
155 if ( fe
.SetEncoding(encoding
) )
157 fe
.SetFixedOnly(fixedWidthOnly
);
161 // else: no such fonts, unknown encoding
166 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
168 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));