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