]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/fontenum.cpp
no changes, just corrected the comment for wxConvLocal
[wxWidgets.git] / src / mac / carbon / fontenum.cpp
CommitLineData
ee6b1d97 1///////////////////////////////////////////////////////////////////////////////
1089fc00 2// Name: src/mac/carbon/fontenum.cpp
ee6b1d97
SC
3// Purpose: wxFontEnumerator class for MacOS
4// Author: Stefan Csomor
1089fc00 5// Modified by:
ee6b1d97
SC
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
ee6b1d97
SC
10///////////////////////////////////////////////////////////////////////////////
11
ee6b1d97
SC
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
179e085f
RN
15#if wxUSE_FONTMAP
16
ee6b1d97
SC
17#ifndef WX_PRECOMP
18 #include "wx/font.h"
19#endif
20
21#include "wx/fontenum.h"
5b781a67 22#include "wx/fontutil.h"
ee6b1d97 23#include "wx/fontmap.h"
3b7e6277 24#include "wx/fontutil.h"
b12ce1d3 25#include "wx/encinfo.h"
3a46bcdd 26#include "wx/intl.h"
ee6b1d97 27
76a5e5d2
SC
28#include "wx/mac/private.h"
29
ee6b1d97
SC
30
31class wxFontEnumeratorHelper
32{
33public:
34 wxFontEnumeratorHelper(wxFontEnumerator *fontEnum);
35
36 // control what exactly are we enumerating
37 bool SetEncoding(wxFontEncoding encoding);
38 void SetFixedOnly(bool fixedOnly)
39 { m_fixedOnly = fixedOnly; }
40
41 // call to start enumeration
42 void DoEnumerate();
43
44private:
45 // the object we forward calls to OnFont() to
46 wxFontEnumerator *m_fontEnum;
47
48 // if != -1, enum only fonts which have this encoding
49 int m_charset;
50
51 // if not empty, enum only the fonts with this facename
52 wxString m_facename;
53
1089fc00 54 // if true, enum only fixed fonts
ee6b1d97
SC
55 bool m_fixedOnly;
56};
1089fc00 57
ee6b1d97
SC
58// ============================================================================
59// implementation
60// ============================================================================
61
62// ----------------------------------------------------------------------------
63// wxFontEnumeratorHelper
64// ----------------------------------------------------------------------------
65
66wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
67{
68 m_fontEnum = fontEnum;
69 m_charset = -1;
1089fc00 70 m_fixedOnly = false;
ee6b1d97
SC
71}
72
73bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
74{
75 wxNativeEncodingInfo info;
1089fc00 76 if ( !wxGetNativeFontEncoding( encoding, &info ) )
ee6b1d97 77 {
1089fc00 78 if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) )
ee6b1d97 79 // no such encodings at all
1089fc00 80 return false;
ee6b1d97 81 }
1089fc00 82
ee6b1d97
SC
83 m_charset = info.charset;
84 m_facename = info.facename;
85
1089fc00 86 return true;
ee6b1d97
SC
87}
88
89void wxFontEnumeratorHelper::DoEnumerate()
90{
1089fc00 91 MenuHandle menu;
1089fc00 92 short lines;
e40298d5 93
1089fc00
DS
94 menu = NewMenu( 32000, "\pFont" );
95 AppendResMenu( menu, 'FONT' );
96 lines = CountMenuItems( menu );
e40298d5 97
1089fc00 98 for ( int i = 1; i < lines + 1; i ++ )
e40298d5 99 {
b6b59e43
SC
100 wxString c_name ;
101#if TARGET_API_MAC_CARBON
102 CFStringRef menutext ;
103 c_name = wxEmptyString ;
104 if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr )
105 {
106 c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding());
107 }
108#else
109 Str255 p_name;
1089fc00 110 GetMenuItemText( menu, i, p_name );
b6b59e43
SC
111 c_name = wxMacMakeStringFromPascal( p_name );
112#endif
e40298d5 113
1089fc00
DS
114#if 0
115 if ( m_fixedOnly )
e40298d5 116 {
1089fc00
DS
117 // check that it's a fixed pitch font:
118 // there is *no* error here: the flag name is misleading!
e40298d5 119 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
e40298d5 120 // not a fixed pitch font
1089fc00 121 return true;
e40298d5 122 }
1089fc00 123
e40298d5
JS
124 if ( m_charset != -1 )
125 {
126 // check that we have the right encoding
127 if ( lf->lfCharSet != m_charset )
1089fc00 128 return true;
e40298d5 129 }
1089fc00
DS
130#endif
131
132 m_fontEnum->OnFacename( c_name );
e40298d5 133 }
1089fc00
DS
134
135 DisposeMenu( menu );
ee6b1d97
SC
136}
137
138// ----------------------------------------------------------------------------
139// wxFontEnumerator
140// ----------------------------------------------------------------------------
141
142bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
143 bool fixedWidthOnly)
144{
145 wxFontEnumeratorHelper fe(this);
146 if ( fe.SetEncoding(encoding) )
147 {
148 fe.SetFixedOnly(fixedWidthOnly);
149
150 fe.DoEnumerate();
151 }
152 // else: no such fonts, unknown encoding
153
1089fc00 154 return true;
ee6b1d97
SC
155}
156
157bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
158{
8d480857 159 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
ee6b1d97 160
1089fc00 161 return true;
ee6b1d97 162}
179e085f
RN
163
164#endif