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