+
+#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
+
+IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
+
+#include "wx/mac/uma.h"
+
+// ---------------------------------------------------------------------------
+// wxFontDialog
+// ---------------------------------------------------------------------------
+
+static const EventTypeSpec eventList[] =
+{
+ { kEventClassFont, kEventFontSelection } ,
+} ;
+
+
+pascal OSStatus
+wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
+ EventRef event,
+ void *userData)
+{
+ OSStatus result = eventNotHandledErr ;
+ wxFontDialog *fontdialog = (wxFontDialog*) userData ;
+ wxFontData& fontdata= fontdialog->GetFontData() ;
+
+ wxMacCarbonEvent cEvent( event );
+ switch(cEvent.GetKind())
+ {
+ case kEventFontSelection :
+ {
+ bool setup = false ;
+#if wxMAC_USE_CORE_TEXT
+ if ( UMAGetSystemVersion() >= 0x1050 )
+ {
+ CTFontDescriptorRef descr;
+ if ( cEvent.GetParameter<CTFontDescriptorRef>( kEventParamCTFontDescriptor, typeCTFontDescriptorRef, &descr ) == noErr )
+ {
+ wxFont font;
+ font.MacCreateFromCTFontDescriptor(descr);
+ fontdata.SetChosenFont( font ) ;
+ setup = true;
+ }
+ }
+#endif
+#if wxMAC_USE_ATSU_TEXT
+ ATSUFontID fontId = 0 ;
+ if ( !setup && (cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr) )
+ {
+ FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle);
+ FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize);
+
+ CFStringRef cfName = NULL;
+#if 1
+ FMFontFamily fontFamily = cEvent.GetParameter<FMFontFamily>(kEventParamFMFontFamily);
+ ATSFontFamilyRef atsfontfamilyref = FMGetATSFontFamilyRefFromFontFamily( fontFamily ) ;
+ OSStatus err = ATSFontFamilyGetName( atsfontfamilyref , kATSOptionFlagsDefault , &cfName ) ;
+ wxASSERT_MSG( err == noErr , wxT("ATSFontFamilyGetName failed") );
+#else
+ // we don't use the ATSU naming anymore
+ ByteCount actualLength = 0;
+ char *c = NULL;
+ OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
+ kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
+ if ( err == noErr)
+ {
+ actualLength += 1 ;
+ char *c = (char*)malloc( actualLength );
+ err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
+ kFontNoLanguageCode, actualLength, c , NULL, NULL);
+ cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
+ }
+ else
+ {
+ err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
+ kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
+ if ( err == noErr )
+ {
+ actualLength += 1 ;
+ c = (char*)malloc(actualLength);
+ err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
+ kFontNoLanguageCode, actualLength, c , NULL, NULL);
+ c[actualLength-1] = 0;
+ cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman );
+ }
+ }
+ if ( c!=NULL )
+ free(c);
+#endif
+ if ( cfName!=NULL )
+ {
+ fontdata.m_chosenFont.SetFaceName(wxCFStringRef(cfName).AsString(wxLocale::GetSystemEncoding()));
+ fontdata.m_chosenFont.SetPointSize(fontSize);
+ fontdata.m_chosenFont.SetStyle(fontStyle & italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
+ fontdata.m_chosenFont.SetUnderlined((fontStyle & underline)!=0);
+ fontdata.m_chosenFont.SetWeight(fontStyle & bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
+ }
+ }
+#endif // wxMAC_USE_ATSU_TEXT
+
+ // retrieving the color
+ RGBColor fontColor ;
+ if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
+ {
+ fontdata.m_fontColour = fontColor;
+ }
+ else
+ {
+ CFDictionaryRef dict ;
+ if ( cEvent.GetParameter<CFDictionaryRef>(kEventParamDictionary, &dict) == noErr )
+ {
+ CFDictionaryRef attributesDict ;
+ if ( CFDictionaryGetValueIfPresent(dict, kFontPanelAttributesKey, (const void **)&attributesDict) )
+ {
+ CFDataRef tagsData;
+ CFDataRef sizesData;
+ CFDataRef valuesData;
+ if ( CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeTagsKey, (const void **)&tagsData) &&
+ CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeSizesKey, (const void **)&sizesData) &&
+ CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeValuesKey, (const void **)&valuesData) )
+ {
+ ItemCount count = CFDataGetLength(tagsData)/sizeof(ATSUAttributeTag);
+ ATSUAttributeTag *tagPtr = (ATSUAttributeTag *)CFDataGetBytePtr(tagsData);
+ ByteCount *sizePtr = (ByteCount *)CFDataGetBytePtr(sizesData);
+ UInt32 *bytePtr = (UInt32*)CFDataGetBytePtr(valuesData);
+ ATSUAttributeValuePtr valuesPtr = bytePtr ;
+ for ( ItemCount i = 0 ; i < count ; ++i)
+ {
+ if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor))
+ {
+ fontdata.m_fontColour = *(RGBColor *)valuesPtr;
+ break ;
+ }
+ bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]);
+ }
+ }
+ }
+ }
+ }
+ }
+ break ;
+ } ;