]> git.saurik.com Git - wxWidgets.git/blob - src/mac/fontenum.cpp
minor fix for OS/2
[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 #include "wx/fontutil.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 ( !wxTheFontMapper->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 name ;
105 short lines ;
106
107 menu = NewMenu( 32000 , "\pFont" ) ;
108 AppendResMenu( menu , 'FONT' ) ;
109 lines = CountMenuItems( menu ) ;
110
111 for ( int i = 1 ; i < lines+1 ; i ++ )
112 {
113 GetMenuItemText( menu , i , name ) ;
114 p2cstr( name ) ;
115 /*
116
117 if ( m_fixedOnly )
118 {
119 // check that it's a fixed pitch font (there is *no* error here, the
120 // flag name is misleading!)
121 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
122 {
123 // not a fixed pitch font
124 return TRUE;
125 }
126 }
127
128 if ( m_charset != -1 )
129 {
130 // check that we have the right encoding
131 if ( lf->lfCharSet != m_charset )
132 {
133 return TRUE;
134 }
135 }
136
137 */
138 m_fontEnum->OnFacename( name ) ;
139 }
140 DisposeMenu( menu ) ;
141 }
142
143 // ----------------------------------------------------------------------------
144 // wxFontEnumerator
145 // ----------------------------------------------------------------------------
146
147 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
148 bool fixedWidthOnly)
149 {
150 wxFontEnumeratorHelper fe(this);
151 if ( fe.SetEncoding(encoding) )
152 {
153 fe.SetFixedOnly(fixedWidthOnly);
154
155 fe.DoEnumerate();
156 }
157 // else: no such fonts, unknown encoding
158
159 return TRUE;
160 }
161
162 bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
163 {
164 wxFAIL_MSG(wxT("TODO"));
165
166 return TRUE;
167 }