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