]>
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 | Str255 p_name; | |
92 | short lines; | |
93 | ||
94 | menu = NewMenu( 32000, "\pFont" ); | |
95 | AppendResMenu( menu, 'FONT' ); | |
96 | lines = CountMenuItems( menu ); | |
97 | ||
98 | for ( int i = 1; i < lines + 1; i ++ ) | |
99 | { | |
100 | GetMenuItemText( menu, i, p_name ); | |
101 | wxString c_name = wxMacMakeStringFromPascal( p_name ); | |
102 | ||
103 | #if 0 | |
104 | if ( m_fixedOnly ) | |
105 | { | |
106 | // check that it's a fixed pitch font: | |
107 | // there is *no* error here: the flag name is misleading! | |
108 | if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) | |
109 | // not a fixed pitch font | |
110 | return true; | |
111 | } | |
112 | ||
113 | if ( m_charset != -1 ) | |
114 | { | |
115 | // check that we have the right encoding | |
116 | if ( lf->lfCharSet != m_charset ) | |
117 | return true; | |
118 | } | |
119 | #endif | |
120 | ||
121 | m_fontEnum->OnFacename( c_name ); | |
122 | } | |
123 | ||
124 | DisposeMenu( menu ); | |
125 | } | |
126 | ||
127 | // ---------------------------------------------------------------------------- | |
128 | // wxFontEnumerator | |
129 | // ---------------------------------------------------------------------------- | |
130 | ||
131 | bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, | |
132 | bool fixedWidthOnly) | |
133 | { | |
134 | wxFontEnumeratorHelper fe(this); | |
135 | if ( fe.SetEncoding(encoding) ) | |
136 | { | |
137 | fe.SetFixedOnly(fixedWidthOnly); | |
138 | ||
139 | fe.DoEnumerate(); | |
140 | } | |
141 | // else: no such fonts, unknown encoding | |
142 | ||
143 | return true; | |
144 | } | |
145 | ||
146 | bool wxFontEnumerator::EnumerateEncodings(const wxString& family) | |
147 | { | |
148 | wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented")); | |
149 | ||
150 | return true; | |
151 | } | |
152 | ||
153 | #endif |