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