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