]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/fontdlgosx.mm
Implemented Mac-style button toggling within wxButtonToolBar, and line
[wxWidgets.git] / src / mac / carbon / fontdlgosx.mm
index 7bc885bd3c8045267042a9aec7ebd6ec7fc77d51..79a4c20fe85d6aa9693be2ec83c0566190461b2e 100644 (file)
 // headers
 // ---------------------------------------------------------------------------
 
-#ifdef __GNUG__
-#pragma implementation "fontdlg.h"
-#endif
-
-// For compilers that support precompilation, includes "wx.h".
-#include "wx/wxprec.h"
-
-#ifdef __BORLANDC__
-    #pragma hdrstop
-#endif
-
-#ifndef WX_PRECOMP
-    #include "wx/cmndata.h"
-    #include "wx/fontdlg.h"
-    #include "wx/fontutil.h"
-    #include "wx/log.h"
-#endif
+#include "wx/cmndata.h"
+#include "wx/fontdlg.h"
+#include "wx/fontutil.h"
+#include "wx/log.h"
     
 // ============================================================================
 // implementation
 // ============================================================================
 
-//Mac OSX 10.2+ only
+
+#include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/string.h"
+
+#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
+
+#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
+
+#include "wx/mac/uma.h"
+#include "wx/intl.h"
+
+@interface wxMacFontPanelAccView : NSView
+{   
+    BOOL m_okPressed ;
+    BOOL m_shouldClose ;
+    NSButton* m_cancelButton ;
+    NSButton* m_okButton ;
+}
+
+- (IBAction)cancelPressed:(id)sender;
+- (IBAction)okPressed:(id)sender;
+- (void)resetFlags;
+- (BOOL)closedWithOk;
+- (BOOL)shouldCloseCarbon;
+- (NSButton*)okButton;
+@end
+
+@implementation wxMacFontPanelAccView : NSView
+- (id)initWithFrame:(NSRect)rectBox
+{
+    [super initWithFrame:rectBox];
+    
+    wxMacCFStringHolder cfOkString( wxT("OK"), wxLocale::GetSystemEncoding() );
+    wxMacCFStringHolder cfCancelString( wxT("Cancel"), wxLocale::GetSystemEncoding() );
+
+    NSRect rectCancel = NSMakeRect( 10.0 , 10.0 , 82  , 24 );
+    NSRect rectOK = NSMakeRect( 100.0 , 10.0 , 82  , 24 );
+    
+    NSButton* cancelButton = [[NSButton alloc] initWithFrame:rectCancel];
+    [cancelButton setTitle:(NSString*)cfCancelString.Detach()];
+    [cancelButton setBezelStyle:NSRoundedBezelStyle];
+    [cancelButton setButtonType:NSMomentaryPushInButton];
+    [cancelButton setAction:@selector(cancelPressed:)];
+    [cancelButton setTarget:self];
+    m_cancelButton = cancelButton ;
+    
+    NSButton* okButton = [[NSButton alloc] initWithFrame:rectOK];
+    [okButton setTitle:(NSString*)cfOkString.Detach()];
+    [okButton setBezelStyle:NSRoundedBezelStyle];
+    [okButton setButtonType:NSMomentaryPushInButton];
+    [okButton setAction:@selector(okPressed:)];
+    [okButton setTarget:self];
+    // doesn't help either, the button is not highlighted after a color dialog has been used
+    // [okButton setKeyEquivalent:@"\r"];
+    m_okButton = okButton ;
+
+
+    [self addSubview:cancelButton];
+    [self addSubview:okButton];
+    
+    [self resetFlags];
+    return self;
+}
+
+- (void)resetFlags
+{
+    m_okPressed = NO ;
+    m_shouldClose = NO ;    
+}
+
+- (IBAction)cancelPressed:(id)sender
+{
+    m_shouldClose = YES ;
+    [NSApp stopModal];
+}
+
+- (IBAction)okPressed:(id)sender
+{
+    m_okPressed = YES ;
+    m_shouldClose = YES ;
+    [NSApp stopModal];
+}
+
+-(BOOL)closedWithOk
+{
+    return m_okPressed ;
+}
+
+-(BOOL)shouldCloseCarbon
+{
+    return m_shouldClose ;
+}
+
+-(NSButton*)okButton
+{
+    return m_okButton ;
+}
+@end
+
+
+extern "C" int RunMixedFontDialog(wxFontDialog* dialog) ;
+
+int RunMixedFontDialog(wxFontDialog* dialog)
+{
+    int retval = wxID_CANCEL ;
+
+    bool cocoaLoaded = NSApplicationLoad();
+    wxASSERT_MSG(cocoaLoaded,wxT("Couldn't load Cocoa in Carbon Environment")) ;
+
+    wxAutoNSAutoreleasePool pool;
+
+    // setting up the ok/cancel buttons
+    NSFontPanel* fontPanel = [NSFontPanel sharedFontPanel] ;
+
+    // adjust modality for carbon environment
+    WindowRef carbonWindowRef = (WindowRef)[fontPanel windowRef] ;
+    SetWindowModality(carbonWindowRef, kWindowModalityAppModal , 0) ;
+    SetWindowGroup(carbonWindowRef , GetWindowGroupOfClass(kMovableModalWindowClass));
+    
+    [fontPanel setFloatingPanel:NO] ;
+    [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:NO] ;
+    
+    wxMacFontPanelAccView* accessoryView = (wxMacFontPanelAccView*) [fontPanel accessoryView] ;
+    if ( accessoryView == nil)
+    {
+        NSRect rectBox = NSMakeRect( 0 , 0 , 192 , 40 );
+        accessoryView = [[wxMacFontPanelAccView alloc] initWithFrame:rectBox];
+        [fontPanel setAccessoryView:accessoryView];
+        
+        [fontPanel setDefaultButtonCell:[[accessoryView okButton] cell]] ;
+    }
+
+    [accessoryView resetFlags];
+    
+    NSModalSession session = [NSApp beginModalSessionForWindow:fontPanel];
+
+    [NSApp runModalSession:session];
+
+    [NSApp endModalSession:session];
+
+    // if we don't reenable it, FPShowHideFontPanel does not work
+    [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:YES] ;
+    if( FPIsFontPanelVisible())
+        FPShowHideFontPanel() ;
+    
+    if ( [accessoryView closedWithOk])
+    {
+        retval = wxID_OK ;
+    }
+
+
+    return retval ;
+}
+
+#else
+
 #if USE_NATIVE_FONT_DIALOG_FOR_MACOSX
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
-#endif
 
 // Cocoa headers
-#include "wx/cocoa/autorelease.h"
-#include "wx/cocoa/string.h"
 
 #import <AppKit/NSFont.h>
 #import <AppKit/NSFontManager.h>
@@ -222,18 +361,19 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
             ];
             
         wxASSERT_MSG(theDefaultFont, wxT("Invalid default font for wxCocoaFontDialog!"));
-     
-        //set the initial font of the NSFontPanel 
-        //(the font manager calls the appropriate NSFontPanel method)
-        [[NSFontManager sharedFontManager] setSelectedFont:theDefaultFont isMultiple:NO];
+
+        //Apple docs say to call NSFontManager::setSelectedFont
+        //However, 10.3 doesn't seem to create the font panel
+        //is this is done, so create it ourselves
+        [[NSFontPanel sharedFontPanel] setPanelFont:theDefaultFont isMultiple:NO];
 
     }
 
     if(m_fontData.m_fontColour.Ok())
         [[NSColorPanel sharedColorPanel] setColor:
             [NSColor colorWithCalibratedRed:m_fontData.m_fontColour.Red() / 255.0
-                                        green:m_fontData.m_fontColour.Red() / 255.0
-                                        blue:m_fontData.m_fontColour.Red() / 255.0
+                                        green:m_fontData.m_fontColour.Green() / 255.0
+                                        blue:m_fontData.m_fontColour.Blue() / 255.0
                                         alpha:1.0]
         ];
     else
@@ -277,7 +417,7 @@ int wxFontDialog::ShowModal()
     //
     // So we set up delegates for both the color and font panels,
     //  and the if the font panel opens the color panel, we 
-    //  stop the modal loop, and start a seperate modal loop for
+    //  stop the modal loop, and start a separate modal loop for
     //  the color panel until the color panel closes, switching
     //  back to the font panel modal loop once it does close.
     //
@@ -381,3 +521,5 @@ bool wxFontDialog::IsShown() const
 }
 
 #endif // 10.2+
+
+#endif