]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/fontdlgosx.mm
Fix file paths in the header comments.
[wxWidgets.git] / src / osx / carbon / fontdlgosx.mm
index 0fa7163333def6413a3f0fafbe2422be403f0f58..a83b7d5e028970d428676dd9631ad7e75ae71e05 100644 (file)
 
 extern "C" int RunMixedFontDialog(wxFontDialog* dialog) ;
 
 
 extern "C" int RunMixedFontDialog(wxFontDialog* dialog) ;
 
-int RunMixedFontDialog(wxFontDialog* WXUNUSED(dialog))
+int RunMixedFontDialog(wxFontDialog* dialog)
 {
 {
+#if wxOSX_USE_COCOA
+    wxFontData& fontdata= ((wxFontDialog*)dialog)->GetFontData() ;
+#else
+    wxUnusedVar(dialog);
+#endif
     int retval = wxID_CANCEL ;
 
     int retval = wxID_CANCEL ;
 
-    if ( !NSApplicationLoad() )
-    {
-        wxFAIL_MSG("Couldn't load Cocoa in Carbon Environment");
-    }
-
     wxAutoNSAutoreleasePool pool;
 
     // setting up the ok/cancel buttons
     wxAutoNSAutoreleasePool pool;
 
     // setting up the ok/cancel buttons
@@ -172,25 +172,55 @@ int RunMixedFontDialog(wxFontDialog* WXUNUSED(dialog))
     }
 
     [accessoryView resetFlags];
     }
 
     [accessoryView resetFlags];
+#if wxOSX_USE_COCOA
+    wxFont font = *wxNORMAL_FONT ;
+    if ( fontdata.m_initialFont.Ok() )
+    {
+        font = fontdata.m_initialFont ;
+    }
 
 
-    NSModalSession session = [NSApp beginModalSessionForWindow:fontPanel];
-
-    [NSApp runModalSession:session];
-
-    [NSApp endModalSession:session];
+    [[NSFontPanel sharedFontPanel] setPanelFont: font.OSXGetNSFont() isMultiple:NO];
 
 
+    if(fontdata.m_fontColour.Ok())
+        [[NSColorPanel sharedColorPanel] setColor:
+            [NSColor colorWithCalibratedRed:fontdata.m_fontColour.Red() / 255.0
+                                        green:fontdata.m_fontColour.Green() / 255.0
+                                        blue:fontdata.m_fontColour.Blue() / 255.0
+                                        alpha:1.0]
+        ];
+    else
+        [[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]];
+#endif
+    
+    [NSApp runModalForWindow:fontPanel];
+    
     // if we don't reenable it, FPShowHideFontPanel does not work
     [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:YES] ;
 #if wxOSX_USE_CARBON
     if( FPIsFontPanelVisible())
         FPShowHideFontPanel() ;
     // if we don't reenable it, FPShowHideFontPanel does not work
     [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:YES] ;
 #if wxOSX_USE_CARBON
     if( FPIsFontPanelVisible())
         FPShowHideFontPanel() ;
+#else
+    [fontPanel close];
 #endif
 
     if ( [accessoryView closedWithOk])
     {
 #endif
 
     if ( [accessoryView closedWithOk])
     {
+#if wxOSX_USE_COCOA
+        NSFont* theFont = [fontPanel panelConvertFont:[NSFont userFontOfSize:0]];
+
+        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];
+
+        fontdata.m_fontColour.Set((unsigned char) ([theColor redComponent] * 255.0),
+                                    (unsigned char) ([theColor greenComponent] * 255.0),
+                                    (unsigned char) ([theColor blueComponent] * 255.0));
+#endif
         retval = wxID_OK ;
     }
         retval = wxID_OK ;
     }
-
+    [fontPanel setAccessoryView:nil];
+    [accessoryView release];
 
     return retval ;
 }
 
     return retval ;
 }
@@ -334,18 +364,6 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
 {
     m_fontData = data;
 
 {
     m_fontData = data;
 
-    //
-    //  This is the key call - this initializes
-    //  events and window stuff for cocoa for carbon
-    //  applications.
-    //
-    //  This is also the only call here that is
-    //  10.2+ specific (the rest is OSX only),
-    //  which, ironically, the carbon font
-    //  panel requires.
-    //
-    bool bOK = NSApplicationLoad();
-
     //autorelease pool - req'd for carbon
     NSAutoreleasePool *thePool;
     thePool = [[NSAutoreleasePool alloc] init];
     //autorelease pool - req'd for carbon
     NSAutoreleasePool *thePool;
     thePool = [[NSAutoreleasePool alloc] init];
@@ -396,7 +414,7 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
     //We're done - free up the pool
     [thePool release];
 
     //We're done - free up the pool
     [thePool release];
 
-    return bOK;
+    return true;
 }
 
 int wxFontDialog::ShowModal()
 }
 
 int wxFontDialog::ShowModal()
@@ -435,6 +453,7 @@ int wxFontDialog::ShowModal()
     //  the color panel until the color panel closes, switching
     //  back to the font panel modal loop once it does close.
     //
     //  the color panel until the color panel closes, switching
     //  back to the font panel modal loop once it does close.
     //
+    wxDialog::OSXBeginModalDialog();
     do
     {
         //
     do
     {
         //
@@ -473,7 +492,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);
         //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];
     //free up the memory for the delegates - we don't need them anymore
     [theFPDelegate release];
     [theCPDelegate release];