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