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