backport r61297 and r61298

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_9_0_BRANCH@61299 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-07-03 07:16:53 +00:00
parent ad6f478768
commit f5629d8737
3 changed files with 81 additions and 31 deletions

View File

@@ -112,10 +112,10 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
if(m_colourData.GetColour().IsOk()) if(m_colourData.GetColour().IsOk())
[[NSColorPanel sharedColorPanel] setColor: [[NSColorPanel sharedColorPanel] setColor:
[NSColor colorWithCalibratedRed:m_colourData.GetColour().Red() / 255.0 [NSColor colorWithCalibratedRed:(CGFloat) (m_colourData.GetColour().Red() / 255.0)
green:m_colourData.GetColour().Green() / 255.0 green:(CGFloat) (m_colourData.GetColour().Green() / 255.0)
blue:m_colourData.GetColour().Blue() / 255.0 blue:(CGFloat) (m_colourData.GetColour().Blue() / 255.0)
alpha:1.0] alpha:(CGFloat) 1.0]
]; ];
else else
[[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]]; [[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]];

View File

@@ -137,15 +137,15 @@
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; wxAutoNSAutoreleasePool pool;
// setting up the ok/cancel buttons // setting up the ok/cancel buttons
@@ -172,10 +172,33 @@ 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 ;
}
[[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
NSModalSession session = [NSApp beginModalSessionForWindow:fontPanel]; NSModalSession session = [NSApp beginModalSessionForWindow:fontPanel];
[NSApp runModalSession:session]; for (;;)
{
if ([NSApp runModalSession:session] != NSRunContinuesResponse)
break;
}
[NSApp endModalSession:session]; [NSApp endModalSession:session];
@@ -184,13 +207,41 @@ int RunMixedFontDialog(wxFontDialog* WXUNUSED(dialog))
#if wxOSX_USE_CARBON #if wxOSX_USE_CARBON
if( FPIsFontPanelVisible()) if( FPIsFontPanelVisible())
FPShowHideFontPanel() ; FPShowHideFontPanel() ;
#else
[fontPanel close];
#endif #endif
if ( [accessoryView closedWithOk]) if ( [accessoryView closedWithOk])
{ {
#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]) );
//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 +385,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 //autorelease pool - req'd for carbon
NSAutoreleasePool *thePool; NSAutoreleasePool *thePool;
thePool = [[NSAutoreleasePool alloc] init]; thePool = [[NSAutoreleasePool alloc] init];
@@ -396,7 +435,7 @@ bool wxFontDialog::Create(wxWindow *parent, const wxFontData& data)
//We're done - free up the pool //We're done - free up the pool
[thePool release]; [thePool release];
return bOK; return true;
} }
int wxFontDialog::ShowModal() int wxFontDialog::ShowModal()

View File

@@ -166,18 +166,29 @@ WX_NSFont wxFont::OSXCreateNSFont(wxOSXSystemFont font, wxNativeFontInfo* info)
void wxNativeFontInfo::OSXValidateNSFontDescriptor() void wxNativeFontInfo::OSXValidateNSFontDescriptor()
{ {
NSFontDescriptor* desc = [NSFontDescriptor fontDescriptorWithName:wxCFStringRef(m_faceName).AsNSString() size:m_pointSize]; NSFontDescriptor* desc = nil;
NSFontSymbolicTraits traits = 0; NSFontSymbolicTraits traits = 0;
float weight = 0;
if (m_weight == wxFONTWEIGHT_BOLD) if (m_weight == wxFONTWEIGHT_BOLD)
{
traits |= NSFontBoldTrait; traits |= NSFontBoldTrait;
weight = 1.0;
}
else if (m_weight == wxFONTWEIGHT_LIGHT)
weight = -1;
if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT) if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT)
traits |= NSFontItalicTrait; traits |= NSFontItalicTrait;
if ( traits != 0 ) desc = [NSFontDescriptor fontDescriptorWithFontAttributes:
{ [[NSDictionary alloc] initWithObjectsAndKeys:
desc = [desc fontDescriptorWithSymbolicTraits:traits]; wxCFStringRef(m_faceName).AsNSString(), NSFontFamilyAttribute,
} [NSNumber numberWithFloat:m_pointSize], NSFontSizeAttribute,
[NSNumber numberWithUnsignedInt:traits], NSFontSymbolicTrait,
[NSNumber numberWithFloat:weight],NSFontWeightTrait,
nil]];
wxMacCocoaRetain(desc); wxMacCocoaRetain(desc);
m_nsFontDescriptor = desc; m_nsFontDescriptor = desc;
} }