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