From: Kevin Ollivier Date: Sat, 7 Mar 2009 04:19:26 +0000 (+0000) Subject: Add alignment support, and more tweaks for label size issues, though I hope to find... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c2a4d42831932bb935ace55663c6caebf7f69457?ds=inline Add alignment support, and more tweaks for label size issues, though I hope to find the core cause and solution soon. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59399 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/osx/cocoa/stattext.mm b/src/osx/cocoa/stattext.mm index 9134d2ef79..74e3aad2f6 100644 --- a/src/osx/cocoa/stattext.mm +++ b/src/osx/cocoa/stattext.mm @@ -27,6 +27,38 @@ #include +@interface wxNSStaticTextView : NSTextView +{ + wxWidgetCocoaImpl* impl; +} + +- (void) setImplementation:(wxWidgetCocoaImpl*) item; +- (wxWidgetCocoaImpl*) implementation; +@end +@implementation wxNSStaticTextView + ++ (void)initialize +{ + static BOOL initialized = NO; + if (!initialized) + { + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); + } +} + +- (wxWidgetCocoaImpl*) implementation +{ + return impl; +} + +- (void) setImplementation:(wxWidgetCocoaImpl*) item +{ + impl = item; +} +@end + + wxSize wxStaticText::DoGetBestSize() const { Point bounds; @@ -49,9 +81,10 @@ Point bounds; wxClientDC dc(const_cast(this)); wxCoord width, height ; dc.GetMultiLineTextExtent( m_label , &width, &height); - // Some labels seem to have their last characters - // stripped out. Adding 4 pixels seems to be enough to fix this. - bounds.h = width+4; + // FIXME: Some labels seem to have their last characters + // stripped out. Adding 12 pixels seems to be enough to fix this. + // Perhaps m_label is not being synced properly... + bounds.h = width+12; bounds.v = height; } @@ -81,11 +114,17 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, long extraStyle) { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; - wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r]; + wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r]; - [v setBezeled:NO]; [v setEditable:NO]; [v setDrawsBackground:NO]; + [v setString: wxCFStringRef( label , wxpeer->GetFont().GetEncoding() ).AsNSString()]; + + NSRange allText = NSMakeRange(0, label.length()); + if (style & wxALIGN_CENTER) + [v setAlignment: NSCenterTextAlignment range: allText]; + else if (style & wxALIGN_RIGHT) + [v setAlignment: NSRightTextAlignment range: allText]; wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); return c;