]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/fontenum.cpp
[ 1473731 ] 'wxColourBase and wxString <-> wxColour implementation' with minor modifi...
[wxWidgets.git] / src / mac / carbon / fontenum.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/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// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#if wxUSE_FONTMAP
16
17#ifndef WX_PRECOMP
18 #include "wx/font.h"
19#endif
20
21#include "wx/fontenum.h"
22#include "wx/fontutil.h"
23#include "wx/fontmap.h"
24#include "wx/fontutil.h"
25#include "wx/encinfo.h"
26#include "wx/intl.h"
27
28#include "wx/mac/private.h"
29
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
54 // if true, enum only fixed fonts
55 bool m_fixedOnly;
56};
57
58// ============================================================================
59// implementation
60// ============================================================================
61
62// ----------------------------------------------------------------------------
63// wxFontEnumeratorHelper
64// ----------------------------------------------------------------------------
65
66wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
67{
68 m_fontEnum = fontEnum;
69 m_charset = -1;
70 m_fixedOnly = false;
71}
72
73bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
74{
75 wxNativeEncodingInfo info;
76 if ( !wxGetNativeFontEncoding( encoding, &info ) )
77 {
78 if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) )
79 // no such encodings at all
80 return false;
81 }
82
83 m_charset = info.charset;
84 m_facename = info.facename;
85
86 return true;
87}
88
89void wxFontEnumeratorHelper::DoEnumerate()
90{
91 MenuHandle menu;
92 short lines;
93
94 menu = NewMenu( 32000, "\pFont" );
95 AppendResMenu( menu, 'FONT' );
96 lines = CountMenuItems( menu );
97
98 for ( int i = 1; i < lines + 1; i ++ )
99 {
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;
110 GetMenuItemText( menu, i, p_name );
111 c_name = wxMacMakeStringFromPascal( p_name );
112#endif
113
114#if 0
115 if ( m_fixedOnly )
116 {
117 // check that it's a fixed pitch font:
118 // there is *no* error here: the flag name is misleading!
119 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
120 // not a fixed pitch font
121 return true;
122 }
123
124 if ( m_charset != -1 )
125 {
126 // check that we have the right encoding
127 if ( lf->lfCharSet != m_charset )
128 return true;
129 }
130#endif
131
132 m_fontEnum->OnFacename( c_name );
133 }
134
135 DisposeMenu( menu );
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
154 return true;
155}
156
157bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
158{
159 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
160
161 return true;
162}
163
164#endif