]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/fontdlg.cpp
corrected version in the libraries names: it's only 2 digits even in development...
[wxWidgets.git] / src / mac / carbon / fontdlg.cpp
index e1aa19d2c66322b80d37d6c29975c134ec604953..67b93fb6cb27182e46411518ddcf275cf329a12b 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        fontdlg.cpp
+// Name:        src/mac/carbon/fontdlg.cpp
 // Purpose:     wxFontDialog class for carbon 10.2+.
 // Author:      Ryan Norton
 // Modified by:
 // Purpose:     wxFontDialog class for carbon 10.2+.
 // Author:      Ryan Norton
 // Modified by:
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#if wxUSE_FONTDLG
+
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
 
 #ifndef WX_PRECOMP
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
 
 #ifndef WX_PRECOMP
-#include "wx/intl.h"
-#include "wx/wxchar.h"
-#include "wx/dcclient.h"
-#include "wx/frame.h"
-#include "wx/textctrl.h"
-#include "wx/listbox.h"
-#include "wx/checkbox.h"
-#include "wx/choice.h"
-#include "wx/sizer.h"
-#include "wx/stattext.h"
-#include "wx/button.h"
+    #include "wx/intl.h"
+    #include "wx/wxchar.h"
+    #include "wx/dcclient.h"
+    #include "wx/frame.h"
+    #include "wx/textctrl.h"
+    #include "wx/listbox.h"
+    #include "wx/checkbox.h"
+    #include "wx/choice.h"
+    #include "wx/sizer.h"
+    #include "wx/stattext.h"
+    #include "wx/button.h"
 #endif
 
 #include "wx/fontdlg.h"
 #endif
 
 #include "wx/fontdlg.h"
-#include "wx/dcclient.h"
-    
+
 #if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
 
 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
 #if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
 
 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
@@ -48,7 +49,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
 #include "wx/mac/private.h"
 
 // ---------------------------------------------------------------------------
 #include "wx/mac/private.h"
 
 // ---------------------------------------------------------------------------
-// wxFontDialog  
+// wxFontDialog
 // ---------------------------------------------------------------------------
 
 static const EventTypeSpec eventList[] =
 // ---------------------------------------------------------------------------
 
 static const EventTypeSpec eventList[] =
@@ -62,40 +63,47 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
     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 :
         {
-            FMFont fontId = 0 ;
+            ATSUFontID fontId = 0 ;
             if ( cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr )
             if ( 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);
 
-                ByteCount actualLength = 0;
                 CFStringRef cfName = NULL;
                 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;
                 char *c = NULL;
-                OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode, 
+                OSStatus err = ATSUFindFontName(fontId , kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
                     kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
                 if ( err == noErr)
                 {
                     actualLength += 1 ;
                     char *c = (char*)malloc( actualLength );
                     kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
                 if ( err == noErr)
                 {
                     actualLength += 1 ;
                     char *c = (char*)malloc( actualLength );
-                    err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode, 
+                    err = ATSUFindFontName(fontId, kFontFamilyName, kFontUnicodePlatform, kFontNoScriptCode,
                         kFontNoLanguageCode, actualLength, c , NULL, NULL);
                     cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
                 }
                 else
                 {
                         kFontNoLanguageCode, actualLength, c , NULL, NULL);
                     cfName = CFStringCreateWithCharacters(NULL, (UniChar*) c, (actualLength-1) >> 1);
                 }
                 else
                 {
-                    err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode, 
+                    err = ATSUFindFontName(fontId , kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
                     kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
                     if ( err == noErr )
                     {
                         actualLength += 1 ;
                         c = (char*)malloc(actualLength);
                     kFontNoLanguageCode , 0 , NULL , &actualLength , NULL );
                     if ( err == noErr )
                     {
                         actualLength += 1 ;
                         c = (char*)malloc(actualLength);
-                        err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode, 
+                        err = ATSUFindFontName(fontId, kFontFamilyName, kFontNoPlatformCode, kFontNoScriptCode,
                             kFontNoLanguageCode, actualLength, c , NULL, NULL);
                         c[actualLength-1] = 0;
                         cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman );
                             kFontNoLanguageCode, actualLength, c , NULL, NULL);
                         c[actualLength-1] = 0;
                         cfName = CFStringCreateWithCString(NULL, c, kCFStringEncodingMacRoman );
@@ -103,20 +111,21 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
                 }
                 if ( c!=NULL )
                     free(c);
                 }
                 if ( c!=NULL )
                     free(c);
-                
+#endif
+                 
                 if ( cfName!=NULL )
                 {
                     fontdata.m_chosenFont.SetFaceName(wxMacCFStringHolder(cfName).AsString(wxLocale::GetSystemEncoding()));
                     fontdata.m_chosenFont.SetPointSize(fontSize);
                 if ( cfName!=NULL )
                 {
                     fontdata.m_chosenFont.SetFaceName(wxMacCFStringHolder(cfName).AsString(wxLocale::GetSystemEncoding()));
                     fontdata.m_chosenFont.SetPointSize(fontSize);
-                    fontdata.m_chosenFont.SetStyle(fontStyle & italic ? wxFONTSTYLE_ITALIC : 0);
-                    fontdata.m_chosenFont.SetUnderlined(fontStyle & underline ? wxFONTSTYLE_ITALIC : 0);
-                    fontdata.m_chosenFont.SetWeight(fontStyle & bold ? wxBOLD : wxNORMAL);
+                    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);
                 }
             }
 
             RGBColor fontColor ;
             if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
                 }
             }
 
             RGBColor fontColor ;
             if ( cEvent.GetParameter<RGBColor>(kEventParamFontColor, &fontColor) == noErr )
-                fontdata.m_fontColour.Set((WXCOLORREF*) &fontColor);
+                fontdata.m_fontColour.FromRGBColor((WXCOLORREF*) &fontColor);
             else
             {
                 CFDictionaryRef dict ;
             else
             {
                 CFDictionaryRef dict ;
@@ -141,7 +150,7 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
                             {
                                 if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor))
                                 {
                             {
                                 if ( tagPtr[i] == kATSUColorTag && sizePtr[i] == sizeof(RGBColor))
                                 {
-                                    fontdata.m_fontColour.Set((WXCOLORREF*) valuesPtr);
+                                    fontdata.m_fontColour.FromRGBColor((WXCOLORREF*) valuesPtr);
                                     break ;
                                 }
                                 bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]);
                                     break ;
                                 }
                                 bytePtr = (UInt32*)( (UInt8*)bytePtr + sizePtr[i]);
@@ -153,7 +162,7 @@ pascal OSStatus wxMacCarbonFontPanelHandler(EventHandlerCallRef nextHandler, Eve
         }
             break ;
     } ;
         }
             break ;
     } ;
-    
+
     return result ;
 }
 
     return result ;
 }
 
@@ -186,7 +195,7 @@ int wxFontDialog::ShowModal()
     {
         font = m_fontData.m_initialFont ;
     }
     {
         font = m_fontData.m_initialFont ;
     }
-    
+
     ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
     err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
     // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
     ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
     err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
     // just clicking on ENTER will not send us any font setting event, therefore we have to make sure
@@ -197,13 +206,13 @@ int wxFontDialog::ShowModal()
 
     err = InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList), eventList, this , &handler );
 
 
     err = InstallApplicationEventHandler( GetwxMacCarbonFontPanelHandlerUPP(), GetEventTypeCount(eventList), eventList, this , &handler );
 
-    if ( !FPIsFontPanelVisible() ) 
+    if ( !FPIsFontPanelVisible() )
         FPShowHideFontPanel();
         FPShowHideFontPanel();
-    
+
     int retval = RunMixedFontDialog(this);
     int retval = RunMixedFontDialog(this);
-    
+
     ::RemoveEventHandler(handler);
     ::RemoveEventHandler(handler);
-    
+
     return retval ;
 }
 
     return retval ;
 }
 
@@ -279,7 +288,7 @@ class wxFontColourSwatchCtrl: public wxControl
     DECLARE_CLASS(wxFontColourSwatchCtrl)
 public:
     wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
     DECLARE_CLASS(wxFontColourSwatchCtrl)
 public:
     wxFontColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
-    ~wxFontColourSwatchCtrl();
+    virtual ~wxFontColourSwatchCtrl();
 
     void OnPaint(wxPaintEvent& event);
     void OnMouseEvent(wxMouseEvent& event);
 
     void OnPaint(wxPaintEvent& event);
     void OnMouseEvent(wxMouseEvent& event);
@@ -326,11 +335,11 @@ void wxFontColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event)
             parent = parent->GetParent();
 
         wxColourData data;
             parent = parent->GetParent();
 
         wxColourData data;
-        data.SetChooseFull(TRUE);
+        data.SetChooseFull(true);
         data.SetColour(m_colour);
         wxColourDialog *dialog = new wxColourDialog(parent, &data);
         // Crashes on wxMac (no m_peer)
         data.SetColour(m_colour);
         wxColourDialog *dialog = new wxColourDialog(parent, &data);
         // Crashes on wxMac (no m_peer)
-#ifndef __WXMAC__                
+#ifndef __WXMAC__
         dialog->SetTitle(_("Background colour"));
 #endif
         if (dialog->ShowModal() == wxID_OK)
         dialog->SetTitle(_("Background colour"));
 #endif
         if (dialog->ShowModal() == wxID_OK)
@@ -426,7 +435,7 @@ bool wxFontDialog::Create(wxWindow* parent, const wxFontData& fontData)
  */
 
 void wxFontDialog::CreateControls()
  */
 
 void wxFontDialog::CreateControls()
-{    
+{
     wxFontDialog* itemDialog1 = this;
 
     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
     wxFontDialog* itemDialog1 = this;
 
     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
@@ -488,12 +497,12 @@ void wxFontDialog::CreateControls()
             m_underlinedCtrl->SetToolTip(_("Check to make the font underlined."));
         itemBoxSizer11->Add(m_underlinedCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
     }
             m_underlinedCtrl->SetToolTip(_("Check to make the font underlined."));
         itemBoxSizer11->Add(m_underlinedCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
     }
-    
+
     if (m_fontData.GetEnableEffects())
     {
         wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
         itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL|wxADJUST_MINSIZE, 5);
     if (m_fontData.GetEnableEffects())
     {
         wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("Colour:"), wxDefaultPosition, wxDefaultSize, 0 );
         itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL|wxADJUST_MINSIZE, 5);
-        
+
         m_colourCtrl = new wxFontColourSwatchCtrl( itemDialog1, wxID_FONTDIALOG_COLOUR, wxDefaultPosition, wxSize(-1, 30), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
         m_colourCtrl->SetHelpText(_("Click to change the font colour."));
         if (ShowToolTips())
         m_colourCtrl = new wxFontColourSwatchCtrl( itemDialog1, wxID_FONTDIALOG_COLOUR, wxDefaultPosition, wxSize(-1, 30), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
         m_colourCtrl->SetHelpText(_("Click to change the font colour."));
         if (ShowToolTips())
@@ -528,18 +537,18 @@ void wxFontDialog::CreateControls()
 
     wxFontEnumerator enumerator;
     enumerator.EnumerateFacenames();
 
     wxFontEnumerator enumerator;
     enumerator.EnumerateFacenames();
-    wxArrayString* facenames = enumerator.GetFacenames();
+    wxArrayString facenames = enumerator.GetFacenames();
     if (facenames)
     {
     if (facenames)
     {
-        facenames->Add(_("<Any>"));
-        facenames->Add(_("<Any Roman>"));
-        facenames->Add(_("<Any Decorative>"));
-        facenames->Add(_("<Any Modern>"));
-        facenames->Add(_("<Any Script>"));
-        facenames->Add(_("<Any Swiss>"));
-        facenames->Add(_("<Any Teletype>"));
-        facenames->Sort();
-        m_facenameCtrl->Append(*facenames);
+        facenames.Add(_("<Any>"));
+        facenames.Add(_("<Any Roman>"));
+        facenames.Add(_("<Any Decorative>"));
+        facenames.Add(_("<Any Modern>"));
+        facenames.Add(_("<Any Script>"));
+        facenames.Add(_("<Any Swiss>"));
+        facenames.Add(_("<Any Teletype>"));
+        facenames.Sort();
+        m_facenameCtrl->Append(facenames);
     }
 
     InitializeControls();
     }
 
     InitializeControls();
@@ -670,7 +679,7 @@ void wxFontDialog::InitializeControls()
     m_boldCtrl->SetValue(m_dialogFont.GetWeight() == wxBOLD);
     m_italicCtrl->SetValue(m_dialogFont.GetStyle() == wxITALIC);
     m_sizeCtrl->SetValue(m_dialogFont.GetPointSize());
     m_boldCtrl->SetValue(m_dialogFont.GetWeight() == wxBOLD);
     m_italicCtrl->SetValue(m_dialogFont.GetStyle() == wxITALIC);
     m_sizeCtrl->SetValue(m_dialogFont.GetPointSize());
-    
+
     wxString facename = m_dialogFont.GetFaceName();
     if (facename.empty() || m_facenameCtrl->FindString(facename) == wxNOT_FOUND)
     {
     wxString facename = m_dialogFont.GetFaceName();
     if (facename.empty() || m_facenameCtrl->FindString(facename) == wxNOT_FOUND)
     {
@@ -775,4 +784,6 @@ int FontFamilyStringToInt(const wxChar *family)
 
 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
 
 
 #endif // !USE_NATIVE_FONT_DIALOG_FOR_MACOSX
 
-#endif
+#endif // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
+
+#endif // wxUSE_FONTDLG