1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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"
31 #include "wx/fontenum.h"
32 #include "wx/fontutil.h"
33 #include "wx/fontmap.h"
34 #include "wx/fontutil.h"
35 #include "wx/encinfo.h"
37 #include "wx/mac/private.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class wxFontEnumeratorHelper
46 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
48 // control what exactly are we enumerating
49 bool SetEncoding(wxFontEncoding encoding
);
50 void SetFixedOnly(bool fixedOnly
)
51 { m_fixedOnly
= fixedOnly
; }
53 // call to start enumeration
57 // the object we forward calls to OnFont() to
58 wxFontEnumerator
*m_fontEnum
;
60 // if != -1, enum only fonts which have this encoding
63 // if not empty, enum only the fonts with this facename
66 // if TRUE, enum only fixed fonts
69 // ============================================================================
71 // ============================================================================
73 // ----------------------------------------------------------------------------
74 // wxFontEnumeratorHelper
75 // ----------------------------------------------------------------------------
77 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
79 m_fontEnum
= fontEnum
;
84 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
86 wxNativeEncodingInfo info
;
87 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
89 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
91 // no such encodings at all
95 m_charset
= info
.charset
;
96 m_facename
= info
.facename
;
101 void wxFontEnumeratorHelper::DoEnumerate()
108 menu
= NewMenu( 32000 , "\pFont" ) ;
109 AppendResMenu( menu
, 'FONT' ) ;
110 lines
= CountMenuItems( menu
) ;
112 for ( int i
= 1 ; i
< lines
+1 ; i
++ )
114 GetMenuItemText( menu
, i
, p_name
) ;
115 wxString c_name
= wxMacMakeStringFromPascal(p_name
) ;
121 // check that it's a fixed pitch font (there is *no* error here, the
122 // flag name is misleading!)
123 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
125 // not a fixed pitch font
130 if ( m_charset != -1 )
132 // check that we have the right encoding
133 if ( lf->lfCharSet != m_charset )
140 m_fontEnum
->OnFacename( c_name
) ;
142 DisposeMenu( menu
) ;
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
152 wxFontEnumeratorHelper
fe(this);
153 if ( fe
.SetEncoding(encoding
) )
155 fe
.SetFixedOnly(fixedWidthOnly
);
159 // else: no such fonts, unknown encoding
164 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
166 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));