]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/fontdlg.cpp
check that the version of __sync_sub_and_fetch that returns a value is supported...
[wxWidgets.git] / src / mac / carbon / fontdlg.cpp
index 5e0b9757812762cddc194e854f266cba2aa8d5dd..13909cd946a5b6f840236e0fda0b4ba6e065638c 100644 (file)
@@ -28,7 +28,7 @@
 
 #ifndef WX_PRECOMP
     #include "wx/intl.h"
 
 #ifndef WX_PRECOMP
     #include "wx/intl.h"
-    #include "wx/wxchar.h"
+    #include "wx/crt.h"
     #include "wx/dcclient.h"
     #include "wx/frame.h"
     #include "wx/textctrl.h"
     #include "wx/dcclient.h"
     #include "wx/frame.h"
     #include "wx/textctrl.h"
@@ -46,7 +46,7 @@
 
 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
 
 
 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
 
-#include "wx/mac/private.h"
+#include "wx/mac/uma.h"
 
 // ---------------------------------------------------------------------------
 // wxFontDialog
 
 // ---------------------------------------------------------------------------
 // wxFontDialog
@@ -58,23 +58,41 @@ static const EventTypeSpec eventList[] =
 } ;
 
 
 } ;
 
 
-pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
+pascal OSStatus
+wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
+                            EventRef event,
+                            void *userData)
 {
     OSStatus result = eventNotHandledErr ;
     wxFontDialog *fontdialog = (wxFontDialog*) userData ;
     wxFontData& fontdata= fontdialog->GetFontData() ;
 {
     OSStatus result = eventNotHandledErr ;
     wxFontDialog *fontdialog = (wxFontDialog*) userData ;
     wxFontData& fontdata= fontdialog->GetFontData() ;
-
+    
     wxMacCarbonEvent cEvent( event );
     switch(cEvent.GetKind())
     {
         case kEventFontSelection :
         {
     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 ;
             ATSUFontID fontId = 0 ;
-            if ( cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr )
+            if ( !setup && (cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr) )
             {
                 FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle);
                 FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize);
             {
                 FMFontStyle fontStyle = cEvent.GetParameter<FMFontStyle>(kEventParamFMFontStyle);
                 FMFontSize fontSize = cEvent.GetParameter<FMFontSize>(kEventParamFMFontSize);
-
+                
                 CFStringRef cfName = NULL;
 #if 1
                 FMFontFamily fontFamily = cEvent.GetParameter<FMFontFamily>(kEventParamFMFontFamily);
                 CFStringRef cfName = NULL;
 #if 1
                 FMFontFamily fontFamily = cEvent.GetParameter<FMFontFamily>(kEventParamFMFontFamily);
@@ -86,25 +104,25 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
                 ByteCount actualLength = 0;
                 char *c = NULL;
                 OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
                 ByteCount actualLength = 0;
                 char *c = NULL;
                 OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
-                    kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
+                                                kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
                 if ( err == noErr)
                 {
                     actualLength += 1 ;
                     char *c = (char*)malloc( actualLength );
                     err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
                 if ( err == noErr)
                 {
                     actualLength += 1 ;
                     char *c = (char*)malloc( actualLength );
                     err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
-                        kFontNoLanguageCode, actualLength, c , NULL, NULL);
+                                           kFontNoLanguageCode, actualLength, c , NULL, NULL);
                     cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
                 }
                 else
                 {
                     err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
                     cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
                 }
                 else
                 {
                     err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
-                    kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
+                                           kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
                     if ( err == noErr )
                     {
                         actualLength += 1 ;
                         c = (char*)malloc(actualLength);
                         err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
                     if ( err == noErr )
                     {
                         actualLength += 1 ;
                         c = (char*)malloc(actualLength);
                         err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
-                            kFontNoLanguageCode, actualLength, c , NULL, NULL);
+                                               kFontNoLanguageCode, actualLength, c , NULL, NULL);
                         c[actualLength-1] = 0;
                         cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman );
                     }
                         c[actualLength-1] = 0;
                         cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman );
                     }
@@ -112,7 +130,6 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
                 if ( c!=NULL )
                     free(c);
 #endif
                 if ( c!=NULL )
                     free(c);
 #endif
-                 
                 if ( cfName!=NULL )
                 {
                     fontdata.m_chosenFont.SetFaceName(wxMacCFStringHolder(cfName).AsString(wxLocale::GetSystemEncoding()));
                 if ( cfName!=NULL )
                 {
                     fontdata.m_chosenFont.SetFaceName(wxMacCFStringHolder(cfName).AsString(wxLocale::GetSystemEncoding()));
@@ -122,7 +139,9 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
                     fontdata.m_chosenFont.SetWeight(fontStyle & bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
                 }
             }
                     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 )
             {
             RGBColor fontColor ;
             if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
             {
@@ -140,8 +159,8 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
                         CFDataRef sizesData;
                         CFDataRef valuesData;
                         if ( CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeTagsKey, (const void **)&tagsData) &&
                         CFDataRef sizesData;
                         CFDataRef valuesData;
                         if ( CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeTagsKey, (const void **)&tagsData) &&
-                             CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeSizesKey, (const void **)&sizesData) &&
-                             CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeValuesKey, (const void **)&valuesData) )
+                            CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeSizesKey, (const void **)&sizesData) &&
+                            CFDictionaryGetValueIfPresent(attributesDict, kFontPanelAttributeValuesKey, (const void **)&valuesData) )
                         {
                             ItemCount count = CFDataGetLength(tagsData)/sizeof(ATSUAttributeTag);
                             ATSUAttributeTag *tagPtr = (ATSUAttributeTag *)CFDataGetBytePtr(tagsData);
                         {
                             ItemCount count = CFDataGetLength(tagsData)/sizeof(ATSUAttributeTag);
                             ATSUAttributeTag *tagPtr = (ATSUAttributeTag *)CFDataGetBytePtr(tagsData);
@@ -164,7 +183,7 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
         }
             break ;
     } ;
         }
             break ;
     } ;
-
+    
     return result ;
 }
 
     return result ;
 }
 
@@ -183,7 +202,7 @@ wxFontDialog::~wxFontDialog()
 {
 }
 
 {
 }
 
-bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
+bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data)
 {
     m_fontData = data;
     return true ;
 {
     m_fontData = data;
     return true ;
@@ -198,8 +217,23 @@ int wxFontDialog::ShowModal()
         font = m_fontData.m_initialFont ;
     }
 
         font = m_fontData.m_initialFont ;
     }
 
-    ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
-    err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
+    bool setup = false;
+#if wxMAC_USE_CORE_TEXT
+    if ( UMAGetSystemVersion() >= 0x1050 )
+    {
+        CTFontDescriptorRef descr = (CTFontDescriptorRef)font.MacGetCTFontDescriptor();
+        err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL);
+        setup = true;
+    }
+#endif
+#if wxMAC_USE_ATSU_TEXT
+    if ( !setup )
+    {
+        ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
+        err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
+        setup = true;
+    }
+#endif
     // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
     // that field is already correct
     m_fontData.m_chosenFont = font ;
     // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
     // that field is already correct
     m_fontData.m_chosenFont = font ;
@@ -354,7 +388,7 @@ void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event)
         Refresh();
 
         wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
         Refresh();
 
         wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
-        GetEventHandler()->ProcessEvent(event);
+        HandleWindowEvent(event);
     }
 }
 
     }
 }