]>
Commit | Line | Data |
---|---|---|
ee6b1d97 | 1 | /////////////////////////////////////////////////////////////////////////////// |
1089fc00 | 2 | // Name: src/mac/carbon/fontenum.cpp |
ee6b1d97 SC |
3 | // Purpose: wxFontEnumerator class for MacOS |
4 | // Author: Stefan Csomor | |
1089fc00 | 5 | // Modified by: |
ee6b1d97 SC |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
ee6b1d97 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
ee6b1d97 SC |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
179e085f RN |
15 | #if wxUSE_FONTMAP |
16 | ||
ee6b1d97 SC |
17 | #ifndef WX_PRECOMP |
18 | #include "wx/font.h" | |
19 | #endif | |
20 | ||
21 | #include "wx/fontenum.h" | |
5b781a67 | 22 | #include "wx/fontutil.h" |
ee6b1d97 | 23 | #include "wx/fontmap.h" |
3b7e6277 | 24 | #include "wx/fontutil.h" |
b12ce1d3 | 25 | #include "wx/encinfo.h" |
ee6b1d97 | 26 | |
76a5e5d2 SC |
27 | #include "wx/mac/private.h" |
28 | ||
ee6b1d97 SC |
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 | ||
1089fc00 | 53 | // if true, enum only fixed fonts |
ee6b1d97 SC |
54 | bool m_fixedOnly; |
55 | }; | |
1089fc00 | 56 | |
ee6b1d97 SC |
57 | // ============================================================================ |
58 | // implementation | |
59 | // ============================================================================ | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // wxFontEnumeratorHelper | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
65 | wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum) | |
66 | { | |
67 | m_fontEnum = fontEnum; | |
68 | m_charset = -1; | |
1089fc00 | 69 | m_fixedOnly = false; |
ee6b1d97 SC |
70 | } |
71 | ||
72 | bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding) | |
73 | { | |
74 | wxNativeEncodingInfo info; | |
1089fc00 | 75 | if ( !wxGetNativeFontEncoding( encoding, &info ) ) |
ee6b1d97 | 76 | { |
1089fc00 | 77 | if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) ) |
ee6b1d97 | 78 | // no such encodings at all |
1089fc00 | 79 | return false; |
ee6b1d97 | 80 | } |
1089fc00 | 81 | |
ee6b1d97 SC |
82 | m_charset = info.charset; |
83 | m_facename = info.facename; | |
84 | ||
1089fc00 | 85 | return true; |
ee6b1d97 SC |
86 | } |
87 | ||
88 | void wxFontEnumeratorHelper::DoEnumerate() | |
89 | { | |
1089fc00 DS |
90 | MenuHandle menu; |
91 | Str255 p_name; | |
92 | short lines; | |
e40298d5 | 93 | |
1089fc00 DS |
94 | menu = NewMenu( 32000, "\pFont" ); |
95 | AppendResMenu( menu, 'FONT' ); | |
96 | lines = CountMenuItems( menu ); | |
e40298d5 | 97 | |
1089fc00 | 98 | for ( int i = 1; i < lines + 1; i ++ ) |
e40298d5 | 99 | { |
1089fc00 DS |
100 | GetMenuItemText( menu, i, p_name ); |
101 | wxString c_name = wxMacMakeStringFromPascal( p_name ); | |
e40298d5 | 102 | |
1089fc00 DS |
103 | #if 0 |
104 | if ( m_fixedOnly ) | |
e40298d5 | 105 | { |
1089fc00 DS |
106 | // check that it's a fixed pitch font: |
107 | // there is *no* error here: the flag name is misleading! | |
e40298d5 | 108 | if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) |
e40298d5 | 109 | // not a fixed pitch font |
1089fc00 | 110 | return true; |
e40298d5 | 111 | } |
1089fc00 | 112 | |
e40298d5 JS |
113 | if ( m_charset != -1 ) |
114 | { | |
115 | // check that we have the right encoding | |
116 | if ( lf->lfCharSet != m_charset ) | |
1089fc00 | 117 | return true; |
e40298d5 | 118 | } |
1089fc00 DS |
119 | #endif |
120 | ||
121 | m_fontEnum->OnFacename( c_name ); | |
e40298d5 | 122 | } |
1089fc00 DS |
123 | |
124 | DisposeMenu( menu ); | |
ee6b1d97 SC |
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 | ||
1089fc00 | 143 | return true; |
ee6b1d97 SC |
144 | } |
145 | ||
146 | bool wxFontEnumerator::EnumerateEncodings(const wxString& family) | |
147 | { | |
8d480857 | 148 | wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented")); |
ee6b1d97 | 149 | |
1089fc00 | 150 | return true; |
ee6b1d97 | 151 | } |
179e085f RN |
152 | |
153 | #endif |