]> git.saurik.com Git - wxWidgets.git/blame - src/osx/core/fontenum.cpp
implementing canBecomeKeyView for user panes, native focus support, fixes #15070
[wxWidgets.git] / src / osx / core / fontenum.cpp
CommitLineData
489468fe 1///////////////////////////////////////////////////////////////////////////////
96dabe43 2// Name: src/osx/core/fontenum.cpp
489468fe
SC
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_FONTENUM
16
17#include "wx/fontenum.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/font.h"
21 #include "wx/intl.h"
22#endif
23
24#include "wx/fontutil.h"
25#include "wx/fontmap.h"
26#include "wx/encinfo.h"
27
1f0c8f31 28#include "wx/osx/private.h"
489468fe
SC
29
30// ----------------------------------------------------------------------------
31// wxFontEnumerator
32// ----------------------------------------------------------------------------
33
8ffac5b0
SC
34#if wxOSX_USE_IPHONE
35extern CFArrayRef CopyAvailableFontFamilyNames();
36#endif
37
489468fe
SC
38bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
39 bool fixedWidthOnly)
40{
63660cba 41 wxArrayString fontFamilies ;
489468fe
SC
42
43 wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
63660cba
SC
44
45#if wxOSX_USE_CORE_TEXT
489468fe 46 {
63660cba 47 CFArrayRef cfFontFamilies = nil;
8ffac5b0
SC
48
49#if wxOSX_USE_COCOA_OR_CARBON
63660cba
SC
50#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
51 if ( UMAGetSystemVersion() >= 0x1060 )
52 cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames();
53 else
54#endif
489468fe 55 {
d1a00499 56#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
63660cba
SC
57 //
58 // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
59 //
60
61 CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);;
62
63 ATSFontFamilyIterator theFontFamilyIterator = NULL;
64 ATSFontFamilyRef theATSFontFamilyRef = 0;
65 OSStatus status = noErr;
66
67 // Create the iterator
68 status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
69 kATSOptionFlagsUnRestrictedScope,
70 &theFontFamilyIterator );
71
72 while (status == noErr)
489468fe 73 {
63660cba
SC
74 // Get the next font in the iteration.
75 status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
76 if(status == noErr)
77 {
78 CFStringRef theName = NULL;
79 ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
80 CFArrayAppendValue(atsfontnames, theName);
81 CFRelease(theName);
82
83 }
84 else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
85 {
86 // reset the iterator
87 status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
88 kATSOptionFlagsUnRestrictedScope,
89 &theFontFamilyIterator);
90 CFArrayRemoveAllValues(atsfontnames);
91 }
489468fe 92 }
63660cba
SC
93 ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
94 cfFontFamilies = atsfontnames;
95#endif
489468fe 96 }
8ffac5b0
SC
97#elif wxOSX_USE_IPHONE
98 cfFontFamilies = CopyAvailableFontFamilyNames();
99#endif
63660cba
SC
100
101 CFIndex count = CFArrayGetCount(cfFontFamilies);
102 for(CFIndex i = 0; i < count; i++)
489468fe 103 {
63660cba
SC
104 CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);
105
106 if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
107 {
108 wxCFRef<CTFontRef> font(CTFontCreateWithName(fontName, 12.0, NULL));
109 if ( encoding != wxFONTENCODING_SYSTEM )
110 {
111 CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font);
112 if ( fontFamiliyEncoding != macEncoding )
113 continue;
114 }
115
116 if ( fixedWidthOnly )
117 {
118 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
119 if ( (traits & kCTFontMonoSpaceTrait) == 0 )
120 continue;
121 }
122
123 }
124
125 wxCFStringRef cfName(wxCFRetain(fontName)) ;
126 fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
489468fe 127 }
63660cba
SC
128
129 CFRelease(cfFontFamilies);
489468fe 130 }
489468fe 131#endif
489468fe
SC
132 for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
133 {
134 if ( OnFacename( fontFamilies[i] ) == false )
135 break ;
136 }
137
138 return true;
139}
140
141bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
142{
143 wxFAIL_MSG(wxT("wxFontEnumerator::EnumerateEncodings() not yet implemented"));
144
145 return true;
146}
147
148#endif // wxUSE_FONTENUM