X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/509b4eccfeb7e13a30d3192c4cb1a42b2aed3f70..947f3b358cae28b63c6f69af21c493cab355fb7e:/src/mac/carbon/fontdlgosx.mm diff --git a/src/mac/carbon/fontdlgosx.mm b/src/mac/carbon/fontdlgosx.mm index b3fdb9d80e..55071430b2 100644 --- a/src/mac/carbon/fontdlgosx.mm +++ b/src/mac/carbon/fontdlgosx.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: fontdlg.cpp +// Name: src/mac/carbon/fontdlgosx.cpp // Purpose: wxFontDialog class. // Author: Ryan Norton // Modified by: @@ -9,6 +9,8 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +#include "wx/wxprec.h" + // =========================================================================== // declarations // =========================================================================== @@ -17,11 +19,16 @@ // headers // --------------------------------------------------------------------------- -#include "wx/cmndata.h" #include "wx/fontdlg.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/cmndata.h" +#endif + #include "wx/fontutil.h" -#include "wx/log.h" - + // ============================================================================ // implementation // ============================================================================ @@ -38,7 +45,7 @@ #include "wx/mac/uma.h" @interface wxMacFontPanelAccView : NSView -{ +{ BOOL m_okPressed ; BOOL m_shouldClose ; NSButton* m_cancelButton ; @@ -57,24 +64,23 @@ - (id)initWithFrame:(NSRect)rectBox { [super initWithFrame:rectBox]; - - wxMacCFStringHolder cfOkString( wxT("OK"), wxLocale::GetSystemEncoding() ); - wxMacCFStringHolder cfCancelString( wxT("Cancel"), wxLocale::GetSystemEncoding() ); + + wxCFStringRef cfOkString( wxT("OK"), wxLocale::GetSystemEncoding() ); + wxCFStringRef cfCancelString( wxT("Cancel"), wxLocale::GetSystemEncoding() ); NSRect rectCancel = NSMakeRect( 10.0 , 10.0 , 82 , 24 ); NSRect rectOK = NSMakeRect( 100.0 , 10.0 , 82 , 24 ); - NSView* panel = [[NSView alloc] initWithFrame:rectBox]; - + NSButton* cancelButton = [[NSButton alloc] initWithFrame:rectCancel]; - [cancelButton setTitle:(NSString*)cfCancelString.Detach()]; + [cancelButton setTitle:(NSString*)wxCFRetain((CFStringRef)cfCancelString)]; [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 setTitle:(NSString*)wxCFRetain((CFStringRef)cfOkString)]; [okButton setBezelStyle:NSRoundedBezelStyle]; [okButton setButtonType:NSMomentaryPushInButton]; [okButton setAction:@selector(okPressed:)]; @@ -86,7 +92,7 @@ [self addSubview:cancelButton]; [self addSubview:okButton]; - + [self resetFlags]; return self; } @@ -94,17 +100,19 @@ - (void)resetFlags { m_okPressed = NO ; - m_shouldClose = NO ; + m_shouldClose = NO ; } - (IBAction)cancelPressed:(id)sender { + wxUnusedVar(sender); m_shouldClose = YES ; [NSApp stopModal]; } - (IBAction)okPressed:(id)sender { + wxUnusedVar(sender); m_okPressed = YES ; m_shouldClose = YES ; [NSApp stopModal]; @@ -129,12 +137,14 @@ extern "C" int RunMixedFontDialog(wxFontDialog* dialog) ; -int RunMixedFontDialog(wxFontDialog* dialog) +int RunMixedFontDialog(wxFontDialog* WXUNUSED(dialog)) { int retval = wxID_CANCEL ; - bool cocoaLoaded = NSApplicationLoad(); - wxASSERT_MSG(cocoaLoaded,wxT("Couldn't load Cocoa in Carbon Environment")) ; + if ( !NSApplicationLoad() ) + { + wxFAIL_MSG("Couldn't load Cocoa in Carbon Environment"); + } wxAutoNSAutoreleasePool pool; @@ -145,30 +155,33 @@ int RunMixedFontDialog(wxFontDialog* dialog) 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 ; @@ -220,7 +233,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) - (BOOL)windowShouldClose:(id)sender { m_bIsClosed = true; - + [NSApp abortModal]; [NSApp stopModal]; return YES; @@ -266,7 +279,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) { m_bIsClosed = true; m_bIsOpen = false; - + [NSApp abortModal]; [NSApp stopModal]; return YES; @@ -318,14 +331,14 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) m_fontData = data; // - // This is the key call - this initializes - // events and window stuff for cocoa for carbon - // applications. + // 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. + // 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(); @@ -335,20 +348,20 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) //Get the initial wx font wxFont& thewxfont = m_fontData.m_initialFont; - - //if the font is valid set the default (selected) font of the + + //if the font is valid set the default (selected) font of the //NSFontDialog to that font if (thewxfont.Ok()) { NSFontTraitMask theMask = 0; - + if(thewxfont.GetStyle() == wxFONTSTYLE_ITALIC) theMask |= NSItalicFontMask; - + if(thewxfont.IsFixedWidth()) theMask |= NSFixedPitchFontMask; - NSFont* theDefaultFont = + NSFont* theDefaultFont = [[NSFontManager sharedFontManager] fontWithFamily: wxNSStringWithWxString(thewxfont.GetFaceName()) traits:theMask @@ -356,7 +369,7 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) thewxfont.GetWeight() == wxLIGHT ? 0 : 5 size: (float)(thewxfont.GetPointSize()) ]; - + wxASSERT_MSG(theDefaultFont, wxT("Invalid default font for wxCocoaFontDialog!")); //Apple docs say to call NSFontManager::setSelectedFont @@ -374,17 +387,17 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data) alpha:1.0] ]; else - [[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]]; - + [[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]]; + //We're done - free up the pool [thePool release]; - + return bOK; } int wxFontDialog::ShowModal() -{ - //Start the pool. Required for carbon interaction +{ + //Start the pool. Required for carbon interaction //(For those curious, the only thing that happens //if you don't do this is a bunch of error //messages about leaks on the console, @@ -393,7 +406,7 @@ int wxFontDialog::ShowModal() thePool = [[NSAutoreleasePool alloc] init]; //Get the shared color and font panel - NSFontPanel* theFontPanel = [NSFontPanel sharedFontPanel]; + NSFontPanel* theFontPanel = [NSFontPanel sharedFontPanel]; NSColorPanel* theColorPanel = [NSColorPanel sharedColorPanel]; //Create and assign the delegates (cocoa event handlers) so @@ -403,17 +416,17 @@ int wxFontDialog::ShowModal() wxWCODelegate* theCPDelegate = [[wxWCODelegate alloc] init]; [theColorPanel setDelegate:theCPDelegate]; - + // - // Begin the modal loop for the font and color panels + // Begin the modal loop for the font and color panels // - // The idea is that we first make the font panel modal, + // The idea is that we first make the font panel modal, // but if the color panel is opened, unless we stop the // modal loop the color panel opens behind the font panel // with no input acceptable to it - which makes it useless. // - // So we set up delegates for both the color and font panels, - // and the if the font panel opens the color panel, we + // 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 separate modal loop for // the color panel until the color panel closes, switching // back to the font panel modal loop once it does close. @@ -421,31 +434,31 @@ int wxFontDialog::ShowModal() do { // - // Start the font panel modal loop + // Start the font panel modal loop // NSModalSession session = [NSApp beginModalSessionForWindow:theFontPanel]; - for (;;) + for (;;) { [NSApp runModalSession:session]; - + //If the font panel is closed or the font panel //opened the color panel, break if ([theFPDelegate isClosed] || [theCPDelegate isOpen]) break; } [NSApp endModalSession:session]; - + //is the color panel open? if ([theCPDelegate isOpen]) { // - // Start the color panel modal loop + // Start the color panel modal loop // NSModalSession session = [NSApp beginModalSessionForWindow:theColorPanel]; - for (;;) + for (;;) { [NSApp runModalSession:session]; - + //If the color panel is closed, return the font panel modal loop if ([theCPDelegate isClosed]) break; @@ -456,50 +469,50 @@ int wxFontDialog::ShowModal() //out of its modal loop because the color panel was //opened) return the font panel modal loop }while([theFPDelegate isClosed] == NO); - + //free up the memory for the delegates - we don't need them anymore [theFPDelegate release]; [theCPDelegate release]; - + //Get the font the user selected - NSFont* theFont = [theFontPanel panelConvertFont:[NSFont userFontOfSize:0]]; - + NSFont* theFont = [theFontPanel 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]; - + //Set the wx font to the appropriate data if(theTraits & NSFixedPitchFontMask) m_fontData.m_chosenFont.SetFamily(wxTELETYPE); - + m_fontData.m_chosenFont.SetFaceName(wxStringWithNSString([theFont familyName])); m_fontData.m_chosenFont.SetPointSize(theFontSize); m_fontData.m_chosenFont.SetStyle(theTraits & NSItalicFontMask ? wxFONTSTYLE_ITALIC : 0); m_fontData.m_chosenFont.SetWeight(theFontWeight < 5 ? wxLIGHT : - theFontWeight >= 9 ? wxBOLD : wxNORMAL); - + theFontWeight >= 9 ? wxBOLD : wxNORMAL); + //Get the shared color panel along with the chosen color and set the chosen color NSColor* theColor = [[theColorPanel color] colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - + m_fontData.m_fontColour.Set((unsigned char) ([theColor redComponent] * 255.0), (unsigned char) ([theColor greenComponent] * 255.0), (unsigned char) ([theColor blueComponent] * 255.0)); //Friendly debug stuff #ifdef FONTDLGDEBUG - wxPrintf(wxT("---Font Panel---\n--NS--\nSize:%f\nWeight:%i\nTraits:%i\n--WX--\nFaceName:%s\nPointSize:%i\nStyle:%i\nWeight:%i\nColor:%i,%i,%i\n---END Font Panel---\n"), - + wxPrintf(wxT("---Font Panel---\n--NS--\nSize:%f\nWeight:%i\nTraits:%i\n--WX--\nFaceName:%s\nPointSize:%i\nStyle:%i\nWeight:%i\nColor:%i,%i,%i\n---END Font Panel---\n"), + (float) theFontSize, theFontWeight, theTraits, - + m_fontData.m_chosenFont.GetFaceName().c_str(), m_fontData.m_chosenFont.GetPointSize(), m_fontData.m_chosenFont.GetStyle(), m_fontData.m_chosenFont.GetWeight(), - m_fontData.m_fontColour.Red(), - m_fontData.m_fontColour.Green(), + m_fontData.m_fontColour.Red(), + m_fontData.m_fontColour.Green(), m_fontData.m_fontColour.Blue() ); #endif