📄 fontdlgosx.mm
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/carbon/fontdlgosx.cpp
// Purpose: wxFontDialog class.
// Author: Ryan Norton
// Modified by:
// Created: 2004-10-03
// RCS-ID: $Id: fontdlgosx.mm,v 1.13 2006/05/25 21:08:01 ABX Exp $
// Copyright: (c) Ryan Norton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
// ===========================================================================
// declarations
// ===========================================================================
// ---------------------------------------------------------------------------
// headers
// ---------------------------------------------------------------------------
#include "wx/fontdlg.h"
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/cmndata.h"
#endif
#include "wx/fontutil.h"
// ============================================================================
// implementation
// ============================================================================
#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"
@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
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
// Cocoa headers
#import <AppKit/NSFont.h>
#import <AppKit/NSFontManager.h>
#import <AppKit/NSFontPanel.h>
#import <AppKit/NSColor.h>
#import <AppKit/NSColorPanel.h>
// ---------------------------------------------------------------------------
// wxWCDelegate - Window Closed delegate
// ---------------------------------------------------------------------------
@interface wxWCDelegate : NSObject
{
bool m_bIsClosed;
}
// Delegate methods
- (id)init;
- (BOOL)windowShouldClose:(id)sender;
- (BOOL)isClosed;
@end // interface wxNSFontPanelDelegate : NSObject
@implementation wxWCDelegate : NSObject
- (id)init
{
[super init];
m_bIsClosed = false;
return self;
}
- (BOOL)windowShouldClose:(id)sender
{
m_bIsClosed = true;
[NSApp abortModal];
[NSApp stopModal];
return YES;
}
- (BOOL)isClosed
{
return m_bIsClosed;
}
@end // wxNSFontPanelDelegate
// ---------------------------------------------------------------------------
// wxWCODelegate - Window Closed or Open delegate
// ---------------------------------------------------------------------------
@interface wxWCODelegate : NSObject
{
bool m_bIsClosed;
bool m_bIsOpen;
}
// Delegate methods
- (id)init;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowDidUpdate:(NSNotification *)aNotification;
- (BOOL)isClosed;
- (BOOL)isOpen;
@end // interface wxNSFontPanelDelegate : NSObject
@implementation wxWCODelegate : NSObject
- (id)init
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -