1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/fontenum.h"
22 #include "wx/fontutil.h"
23 #include "wx/fontmap.h"
24 #include "wx/fontutil.h"
25 #include "wx/encinfo.h"
27 #include "wx/mac/private.h"
30 class wxFontEnumeratorHelper
33 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
35 // control what exactly are we enumerating
36 bool SetEncoding(wxFontEncoding encoding
);
37 void SetFixedOnly(bool fixedOnly
)
38 { m_fixedOnly
= fixedOnly
; }
40 // call to start enumeration
44 // the object we forward calls to OnFont() to
45 wxFontEnumerator
*m_fontEnum
;
47 // if != -1, enum only fonts which have this encoding
50 // if not empty, enum only the fonts with this facename
53 // if true, enum only fixed fonts
57 // ============================================================================
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // wxFontEnumeratorHelper
63 // ----------------------------------------------------------------------------
65 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
67 m_fontEnum
= fontEnum
;
72 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
74 wxNativeEncodingInfo info
;
75 if ( !wxGetNativeFontEncoding( encoding
, &info
) )
77 if ( !wxFontMapper::Get()->GetAltForEncoding( encoding
, &info
) )
78 // no such encodings at all
82 m_charset
= info
.charset
;
83 m_facename
= info
.facename
;
88 void wxFontEnumeratorHelper::DoEnumerate()
94 menu
= NewMenu( 32000, "\pFont" );
95 AppendResMenu( menu
, 'FONT' );
96 lines
= CountMenuItems( menu
);
98 for ( int i
= 1; i
< lines
+ 1; i
++ )
100 GetMenuItemText( menu
, i
, p_name
);
101 wxString c_name
= wxMacMakeStringFromPascal( p_name
);
106 // check that it's a fixed pitch font:
107 // there is *no* error here: the flag name is misleading!
108 if ( tm
->tmPitchAndFamily
& TMPF_FIXED_PITCH
)
109 // not a fixed pitch font
113 if ( m_charset
!= -1 )
115 // check that we have the right encoding
116 if ( lf
->lfCharSet
!= m_charset
)
121 m_fontEnum
->OnFacename( c_name
);
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
134 wxFontEnumeratorHelper
fe(this);
135 if ( fe
.SetEncoding(encoding
) )
137 fe
.SetFixedOnly(fixedWidthOnly
);
141 // else: no such fonts, unknown encoding
146 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
148 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));