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"
17 #include "wx/fontenum.h"
24 #include "wx/fontutil.h"
25 #include "wx/fontmap.h"
26 #include "wx/fontutil.h"
27 #include "wx/encinfo.h"
29 #include "wx/mac/private.h"
32 class wxFontEnumeratorHelper
35 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
37 // control what exactly are we enumerating
38 bool SetEncoding(wxFontEncoding encoding
);
39 void SetFixedOnly(bool fixedOnly
)
40 { m_fixedOnly
= fixedOnly
; }
42 // call to start enumeration
46 // the object we forward calls to OnFont() to
47 wxFontEnumerator
*m_fontEnum
;
49 // if != -1, enum only fonts which have this encoding
52 // if not empty, enum only the fonts with this facename
55 // if true, enum only fixed fonts
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
64 // wxFontEnumeratorHelper
65 // ----------------------------------------------------------------------------
67 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
69 m_fontEnum
= fontEnum
;
74 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
76 wxNativeEncodingInfo info
;
77 if ( !wxGetNativeFontEncoding( encoding
, &info
) )
79 if ( !wxFontMapper::Get()->GetAltForEncoding( encoding
, &info
) )
80 // no such encodings at all
84 m_charset
= info
.charset
;
85 m_facename
= info
.facename
;
90 void wxFontEnumeratorHelper::DoEnumerate()
95 menu
= NewMenu( 32000, "\pFont" );
96 AppendResMenu( menu
, 'FONT' );
97 lines
= CountMenuItems( menu
);
99 for ( int i
= 1; i
< lines
+ 1; i
++ )
102 #if TARGET_API_MAC_CARBON
103 CFStringRef menutext
;
104 c_name
= wxEmptyString
;
105 if ( CopyMenuItemTextAsCFString (menu
, i
, &menutext
) == noErr
)
107 c_name
= wxMacCFStringHolder(menutext
).AsString(wxLocale::GetSystemEncoding());
111 GetMenuItemText( menu
, i
, p_name
);
112 c_name
= wxMacMakeStringFromPascal( p_name
);
118 // check that it's a fixed pitch font:
119 // there is *no* error here: the flag name is misleading!
120 if ( tm
->tmPitchAndFamily
& TMPF_FIXED_PITCH
)
121 // not a fixed pitch font
125 if ( m_charset
!= -1 )
127 // check that we have the right encoding
128 if ( lf
->lfCharSet
!= m_charset
)
133 m_fontEnum
->OnFacename( c_name
);
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
146 wxFontEnumeratorHelper
fe(this);
147 if ( fe
.SetEncoding(encoding
) )
149 fe
.SetFixedOnly(fixedWidthOnly
);
153 // else: no such fonts, unknown encoding
158 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
160 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
165 #endif // wxUSE_FONTMAP