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"
39 #include "wx/encinfo.h"
41 #include "wx/mac/private.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 class wxFontEnumeratorHelper
50 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
52 // control what exactly are we enumerating
53 bool SetEncoding(wxFontEncoding encoding
);
54 void SetFixedOnly(bool fixedOnly
)
55 { m_fixedOnly
= fixedOnly
; }
57 // call to start enumeration
61 // the object we forward calls to OnFont() to
62 wxFontEnumerator
*m_fontEnum
;
64 // if != -1, enum only fonts which have this encoding
67 // if not empty, enum only the fonts with this facename
70 // if TRUE, enum only fixed fonts
73 // ============================================================================
75 // ============================================================================
77 // ----------------------------------------------------------------------------
78 // wxFontEnumeratorHelper
79 // ----------------------------------------------------------------------------
81 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
83 m_fontEnum
= fontEnum
;
88 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
90 wxNativeEncodingInfo info
;
91 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
93 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
95 // no such encodings at all
99 m_charset
= info
.charset
;
100 m_facename
= info
.facename
;
105 void wxFontEnumeratorHelper::DoEnumerate()
112 menu
= NewMenu( 32000 , "\pFont" ) ;
113 AppendResMenu( menu
, 'FONT' ) ;
114 lines
= CountMenuItems( menu
) ;
116 for ( int i
= 1 ; i
< lines
+1 ; i
++ )
118 GetMenuItemText( menu
, i
, p_name
) ;
119 wxString c_name
= wxMacMakeStringFromPascal(p_name
) ;
125 // check that it's a fixed pitch font (there is *no* error here, the
126 // flag name is misleading!)
127 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
129 // not a fixed pitch font
134 if ( m_charset != -1 )
136 // check that we have the right encoding
137 if ( lf->lfCharSet != m_charset )
144 m_fontEnum
->OnFacename( c_name
) ;
146 DisposeMenu( menu
) ;
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
156 wxFontEnumeratorHelper
fe(this);
157 if ( fe
.SetEncoding(encoding
) )
159 fe
.SetFixedOnly(fixedWidthOnly
);
163 // else: no such fonts, unknown encoding
168 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
170 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));