]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/fontenum.cpp
Include wx/intl.h according to precompiled headers of wx/wx.h (with other minor clean...
[wxWidgets.git] / src / mac / carbon / fontenum.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/fontenum.cpp
3 // Purpose: wxFontEnumerator class for MacOS
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_FONTMAP
16
17 #include "wx/fontenum.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/font.h"
21 #include "wx/intl.h"
22 #endif
23
24 #include "wx/fontutil.h"
25 #include "wx/fontmap.h"
26 #include "wx/fontutil.h"
27 #include "wx/encinfo.h"
28
29 #include "wx/mac/private.h"
30
31
32 class wxFontEnumeratorHelper
33 {
34 public:
35 wxFontEnumeratorHelper(wxFontEnumerator *fontEnum);
36
37 // control what exactly are we enumerating
38 bool SetEncoding(wxFontEncoding encoding);
39 void SetFixedOnly(bool fixedOnly)
40 { m_fixedOnly = fixedOnly; }
41
42 // call to start enumeration
43 void DoEnumerate();
44
45 private:
46 // the object we forward calls to OnFont() to
47 wxFontEnumerator *m_fontEnum;
48
49 // if != -1, enum only fonts which have this encoding
50 int m_charset;
51
52 // if not empty, enum only the fonts with this facename
53 wxString m_facename;
54
55 // if true, enum only fixed fonts
56 bool m_fixedOnly;
57 };
58
59 // ============================================================================
60 // implementation
61 // ============================================================================
62
63 // ----------------------------------------------------------------------------
64 // wxFontEnumeratorHelper
65 // ----------------------------------------------------------------------------
66
67 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
68 {
69 m_fontEnum = fontEnum;
70 m_charset = -1;
71 m_fixedOnly = false;
72 }
73
74 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
75 {
76 wxNativeEncodingInfo info;
77 if ( !wxGetNativeFontEncoding( encoding, &info ) )
78 {
79 if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) )
80 // no such encodings at all
81 return false;
82 }
83
84 m_charset = info.charset;
85 m_facename = info.facename;
86
87 return true;
88 }
89
90 void wxFontEnumeratorHelper::DoEnumerate()
91 {
92 MenuHandle menu;
93 short lines;
94
95 menu = NewMenu( 32000, "\pFont" );
96 AppendResMenu( menu, 'FONT' );
97 lines = CountMenuItems( menu );
98
99 for ( int i = 1; i < lines + 1; i ++ )
100 {
101 wxString c_name ;
102 #if TARGET_API_MAC_CARBON
103 CFStringRef menutext ;
104 c_name = wxEmptyString ;
105 if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr )
106 {
107 c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding());
108 }
109 #else
110 Str255 p_name;
111 GetMenuItemText( menu, i, p_name );
112 c_name = wxMacMakeStringFromPascal( p_name );
113 #endif
114
115 #if 0
116 if ( m_fixedOnly )
117 {
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
122 return true;
123 }
124
125 if ( m_charset != -1 )
126 {
127 // check that we have the right encoding
128 if ( lf->lfCharSet != m_charset )
129 return true;
130 }
131 #endif
132
133 m_fontEnum->OnFacename( c_name );
134 }
135
136 DisposeMenu( menu );
137 }
138
139 // ----------------------------------------------------------------------------
140 // wxFontEnumerator
141 // ----------------------------------------------------------------------------
142
143 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
144 bool fixedWidthOnly)
145 {
146 wxFontEnumeratorHelper fe(this);
147 if ( fe.SetEncoding(encoding) )
148 {
149 fe.SetFixedOnly(fixedWidthOnly);
150
151 fe.DoEnumerate();
152 }
153 // else: no such fonts, unknown encoding
154
155 return true;
156 }
157
158 bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
159 {
160 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
161
162 return true;
163 }
164
165 #endif // wxUSE_FONTMAP