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"
28 #include "wx/mac/private.h"
31 class wxFontEnumeratorHelper
34 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
36 // control what exactly are we enumerating
37 bool SetEncoding(wxFontEncoding encoding
);
38 void SetFixedOnly(bool fixedOnly
)
39 { m_fixedOnly
= fixedOnly
; }
41 // call to start enumeration
45 // the object we forward calls to OnFont() to
46 wxFontEnumerator
*m_fontEnum
;
48 // if != -1, enum only fonts which have this encoding
51 // if not empty, enum only the fonts with this facename
54 // if true, enum only fixed fonts
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
63 // wxFontEnumeratorHelper
64 // ----------------------------------------------------------------------------
66 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
68 m_fontEnum
= fontEnum
;
73 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
75 wxNativeEncodingInfo info
;
76 if ( !wxGetNativeFontEncoding( encoding
, &info
) )
78 if ( !wxFontMapper::Get()->GetAltForEncoding( encoding
, &info
) )
79 // no such encodings at all
83 m_charset
= info
.charset
;
84 m_facename
= info
.facename
;
89 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
++ )
101 #if TARGET_API_MAC_CARBON
102 CFStringRef menutext
;
103 c_name
= wxEmptyString
;
104 if ( CopyMenuItemTextAsCFString (menu
, i
, &menutext
) == noErr
)
106 c_name
= wxMacCFStringHolder(menutext
).AsString(wxLocale::GetSystemEncoding());
110 GetMenuItemText( menu
, i
, p_name
);
111 c_name
= wxMacMakeStringFromPascal( p_name
);
117 // check that it's a fixed pitch font:
118 // there is *no* error here: the flag name is misleading!
119 if ( tm
->tmPitchAndFamily
& TMPF_FIXED_PITCH
)
120 // not a fixed pitch font
124 if ( m_charset
!= -1 )
126 // check that we have the right encoding
127 if ( lf
->lfCharSet
!= m_charset
)
132 m_fontEnum
->OnFacename( c_name
);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
145 wxFontEnumeratorHelper
fe(this);
146 if ( fe
.SetEncoding(encoding
) )
148 fe
.SetFixedOnly(fixedWidthOnly
);
152 // else: no such fonts, unknown encoding
157 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
159 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));