]>
Commit | Line | Data |
---|---|---|
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 | #ifndef WX_PRECOMP | |
18 | #include "wx/font.h" | |
19 | #endif | |
20 | ||
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" | |
26 | ||
27 | #include "wx/mac/private.h" | |
28 | ||
29 | ||
30 | class wxFontEnumeratorHelper | |
31 | { | |
32 | public: | |
33 | wxFontEnumeratorHelper(wxFontEnumerator *fontEnum); | |
34 | ||
35 | // control what exactly are we enumerating | |
36 | bool SetEncoding(wxFontEncoding encoding); | |
37 | void SetFixedOnly(bool fixedOnly) | |
38 | { m_fixedOnly = fixedOnly; } | |
39 | ||
40 | // call to start enumeration | |
41 | void DoEnumerate(); | |
42 | ||
43 | private: | |
44 | // the object we forward calls to OnFont() to | |
45 | wxFontEnumerator *m_fontEnum; | |
46 | ||
47 | // if != -1, enum only fonts which have this encoding | |
48 | int m_charset; | |
49 | ||
50 | // if not empty, enum only the fonts with this facename | |
51 | wxString m_facename; | |
52 | ||
53 | // if true, enum only fixed fonts | |
54 | bool m_fixedOnly; | |
55 | }; | |
56 | ||
57 | // ============================================================================ | |
58 | // implementation | |
59 | // ============================================================================ | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // wxFontEnumeratorHelper | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
65 | wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum) | |
66 | { | |
67 | m_fontEnum = fontEnum; | |
68 | m_charset = -1; | |
69 | m_fixedOnly = false; | |
70 | } | |
71 | ||
72 | bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding) | |
73 | { | |
74 | wxNativeEncodingInfo info; | |
75 | if ( !wxGetNativeFontEncoding( encoding, &info ) ) | |
76 | { | |
77 | if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) ) | |
78 | // no such encodings at all | |
79 | return false; | |
80 | } | |
81 | ||
82 | m_charset = info.charset; | |
83 | m_facename = info.facename; | |
84 | ||
85 | return true; | |
86 | } | |
87 | ||
88 | void wxFontEnumeratorHelper::DoEnumerate() | |
89 | { | |
90 | MenuHandle menu; | |
91 | short lines; | |
92 | ||
93 | menu = NewMenu( 32000, "\pFont" ); | |
94 | AppendResMenu( menu, 'FONT' ); | |
95 | lines = CountMenuItems( menu ); | |
96 | ||
97 | for ( int i = 1; i < lines + 1; i ++ ) | |
98 | { | |
99 | wxString c_name ; | |
100 | #if TARGET_API_MAC_CARBON | |
101 | CFStringRef menutext ; | |
102 | c_name = wxEmptyString ; | |
103 | if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr ) | |
104 | { | |
105 | c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding()); | |
106 | } | |
107 | #else | |
108 | Str255 p_name; | |
109 | GetMenuItemText( menu, i, p_name ); | |
110 | c_name = wxMacMakeStringFromPascal( p_name ); | |
111 | #endif | |
112 | ||
113 | #if 0 | |
114 | if ( m_fixedOnly ) | |
115 | { | |
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 | |
120 | return true; | |
121 | } | |
122 | ||
123 | if ( m_charset != -1 ) | |
124 | { | |
125 | // check that we have the right encoding | |
126 | if ( lf->lfCharSet != m_charset ) | |
127 | return true; | |
128 | } | |
129 | #endif | |
130 | ||
131 | m_fontEnum->OnFacename( c_name ); | |
132 | } | |
133 | ||
134 | DisposeMenu( menu ); | |
135 | } | |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // wxFontEnumerator | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
141 | bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, | |
142 | bool fixedWidthOnly) | |
143 | { | |
144 | wxFontEnumeratorHelper fe(this); | |
145 | if ( fe.SetEncoding(encoding) ) | |
146 | { | |
147 | fe.SetFixedOnly(fixedWidthOnly); | |
148 | ||
149 | fe.DoEnumerate(); | |
150 | } | |
151 | // else: no such fonts, unknown encoding | |
152 | ||
153 | return true; | |
154 | } | |
155 | ||
156 | bool wxFontEnumerator::EnumerateEncodings(const wxString& family) | |
157 | { | |
158 | wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented")); | |
159 | ||
160 | return true; | |
161 | } | |
162 | ||
163 | #endif |