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()
93 menu
= NewMenu( 32000, "\pFont" );
94 AppendResMenu( menu
, 'FONT' );
95 lines
= CountMenuItems( menu
);
97 for ( int i
= 1; i
< lines
+ 1; i
++ )
100 #if TARGET_API_MAC_CARBON
101 CFStringRef menutext
;
102 c_name
= wxEmptyString
;
103 if ( CopyMenuItemTextAsCFString (menu
, i
, &menutext
) == noErr
)
105 c_name
= wxMacCFStringHolder(menutext
).AsString(wxLocale::GetSystemEncoding());
109 GetMenuItemText( menu
, i
, p_name
);
110 c_name
= wxMacMakeStringFromPascal( p_name
);
116 // check that it's a fixed pitch font:
117 // there is *no* error here: the flag name is misleading!
118 if ( tm
->tmPitchAndFamily
& TMPF_FIXED_PITCH
)
119 // not a fixed pitch font
123 if ( m_charset
!= -1 )
125 // check that we have the right encoding
126 if ( lf
->lfCharSet
!= m_charset
)
131 m_fontEnum
->OnFacename( c_name
);
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
144 wxFontEnumeratorHelper
fe(this);
145 if ( fe
.SetEncoding(encoding
) )
147 fe
.SetFixedOnly(fixedWidthOnly
);
151 // else: no such fonts, unknown encoding
156 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
158 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));