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