]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/fontdlgosx.mm
fixes #13557
[wxWidgets.git] / src / osx / carbon / fontdlgosx.mm
index c9f6b041bb927c9ca8266179f200c91d65a9acf0..6c2ab56c81a3e5a25b92f3c9e1c117ece1a26267 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/osx/carbon/fontdlgosx.cpp
+// Name:        src/osx/carbon/fontdlgosx.mm
 // Purpose:     wxFontDialog class.
 // Author:      Ryan Norton
 // Modified by:
@@ -167,6 +167,7 @@ int RunMixedFontDialog(wxFontDialog* dialog)
         NSRect rectBox = NSMakeRect( 0 , 0 , 192 , 40 );
         accessoryView = [[wxMacFontPanelAccView alloc] initWithFrame:rectBox];
         [fontPanel setAccessoryView:accessoryView];
+        [accessoryView release];
 
         [fontPanel setDefaultButtonCell:[[accessoryView okButton] cell]] ;
     }
@@ -174,14 +175,14 @@ int RunMixedFontDialog(wxFontDialog* dialog)
     [accessoryView resetFlags];
 #if wxOSX_USE_COCOA
     wxFont font = *wxNORMAL_FONT ;
-    if ( fontdata.m_initialFont.Ok() )
+    if ( fontdata.m_initialFont.IsOk() )
     {
         font = fontdata.m_initialFont ;
     }
 
     [[NSFontPanel sharedFontPanel] setPanelFont: font.OSXGetNSFont() isMultiple:NO];
 
-    if(fontdata.m_fontColour.Ok())
+    if(fontdata.m_fontColour.IsOk())
         [[NSColorPanel sharedColorPanel] setColor:
             [NSColor colorWithCalibratedRed:fontdata.m_fontColour.Red() / 255.0
                                         green:fontdata.m_fontColour.Green() / 255.0
@@ -191,17 +192,9 @@ int RunMixedFontDialog(wxFontDialog* dialog)
     else
         [[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]];
 #endif
-
-    NSModalSession session = [NSApp beginModalSessionForWindow:fontPanel];
-
-    for (;;)
-    {
-        if ([NSApp runModalSession:session] != NSRunContinuesResponse)
-            break;
-    }
-
-    [NSApp endModalSession:session];
-
+    
+    [NSApp runModalForWindow:fontPanel];
+    
     // if we don't reenable it, FPShowHideFontPanel does not work
     [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:YES] ;
 #if wxOSX_USE_CARBON
@@ -216,20 +209,7 @@ int RunMixedFontDialog(wxFontDialog* dialog)
 #if wxOSX_USE_COCOA
         NSFont* theFont = [fontPanel panelConvertFont:[NSFont userFontOfSize:0]];
 
-        //Get more information about the user's chosen font
-        NSFontTraitMask theTraits = [[NSFontManager sharedFontManager] traitsOfFont:theFont];
-        int theFontWeight = [[NSFontManager sharedFontManager] weightOfFont:theFont];
-        int theFontSize = (int) [theFont pointSize];
-
-        wxFontFamily fontFamily = wxFONTFAMILY_DEFAULT;
-        //Set the wx font to the appropriate data
-        if(theTraits & NSFixedPitchFontMask)
-            fontFamily = wxFONTFAMILY_TELETYPE;
-
-        fontdata.m_chosenFont = wxFont( theFontSize, fontFamily,
-            theTraits & NSItalicFontMask ? wxFONTSTYLE_ITALIC : 0,
-            theFontWeight < 5 ? wxLIGHT : theFontWeight >= 9 ? wxBOLD : wxNORMAL,
-            false, wxStringWithNSString([theFont familyName]) );
+        fontdata.m_chosenFont = wxFont( theFont );
 
         //Get the shared color panel along with the chosen color and set the chosen color
         NSColor* theColor = [[[NSColorPanel sharedColorPanel] color] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
@@ -241,7 +221,6 @@ int RunMixedFontDialog(wxFontDialog* dialog)
         retval = wxID_OK ;
     }
     [fontPanel setAccessoryView:nil];
-    [accessoryView release];
 
     return retval ;
 }
@@ -372,6 +351,11 @@ wxFontDialog::wxFontDialog()
 {
 }
 
+wxFontDialog::wxFontDialog(wxWindow *parent)
+{
+    Create(parent);
+}
+
 wxFontDialog::wxFontDialog(wxWindow *parent, const wxFontData&  data)
 {
     Create(parent, data);
@@ -381,10 +365,20 @@ wxFontDialog::~wxFontDialog()
 {
 }
 
+bool wxFontDialog::Create(wxWindow *parent)
+{
+    return Create(parent);
+}
+
 bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
 {
     m_fontData = data;
 
+    return Create(parent);
+}
+
+bool wxFontDialog::Create(wxWindow *parent)
+{
     //autorelease pool - req'd for carbon
     NSAutoreleasePool *thePool;
     thePool = [[NSAutoreleasePool alloc] init];
@@ -394,7 +388,7 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
 
     //if the font is valid set the default (selected) font of the
     //NSFontDialog to that font
-    if (thewxfont.Ok())
+    if (thewxfont.IsOk())
     {
         NSFontTraitMask theMask = 0;
 
@@ -422,7 +416,7 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
 
     }
 
-    if(m_fontData.m_fontColour.Ok())
+    if(m_fontData.m_fontColour.IsOk())
         [[NSColorPanel sharedColorPanel] setColor:
             [NSColor colorWithCalibratedRed:m_fontData.m_fontColour.Red() / 255.0
                                         green:m_fontData.m_fontColour.Green() / 255.0
@@ -474,6 +468,7 @@ int wxFontDialog::ShowModal()
     //  the color panel until the color panel closes, switching
     //  back to the font panel modal loop once it does close.
     //
+    wxDialog::OSXBeginModalDialog();
     do
     {
         //
@@ -512,7 +507,8 @@ int wxFontDialog::ShowModal()
         //out of its modal loop because the color panel was
         //opened) return the font panel modal loop
     }while([theFPDelegate isClosed] == NO);
-
+    wxDialog::OSXEndModalDialog();
+    
     //free up the memory for the delegates - we don't need them anymore
     [theFPDelegate release];
     [theCPDelegate release];