X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f033830e257227dc73225809de2326db0093e5fe..55410bb4f67febe1ca20654f078ea4fb9a6223ae:/src/osx/cocoa/button.mm diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index 789b07d086..fb57055cd5 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -34,7 +34,7 @@ wxSize wxButton::DoGetBestSize() const { case wxWINDOW_VARIANT_NORMAL: case wxWINDOW_VARIANT_LARGE: - sz.y = 20 ; + sz.y = 23 ; break; case wxWINDOW_VARIANT_SMALL: @@ -49,6 +49,21 @@ wxSize wxButton::DoGetBestSize() const break; } + wxRect r ; + + m_peer->GetBestRect(&r); + + if ( r.GetWidth() == 0 && r.GetHeight() == 0 ) + { + } + sz.x = r.GetWidth(); + sz.y = r.GetHeight(); + + int wBtn = 96; + + if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT)) + sz.x = wBtn; + #if wxOSX_USE_CARBON Rect bestsize = { 0 , 0 , 0 , 0 } ; m_peer->GetBestRect( &bestsize ) ; @@ -108,40 +123,16 @@ wxSize wxButton::GetDefaultSize() @implementation wxNSButton -- (id)initWithFrame:(NSRect)frame ++ (void)initialize { - [super initWithFrame:frame]; - m_impl = NULL; - [self setTarget: self]; - [self setAction: @selector(clickedAction:)]; - return self; -} - -- (void) clickedAction: (id) sender -{ - if ( m_impl ) + static BOOL initialized = NO; + if (!initialized) { - wxButton* wxpeer = (wxButton*) m_impl->GetWXPeer(); - if ( wxpeer ) - wxpeer->HandleClicked(0); + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); } } -- (void)setImplementation: (wxWidgetImpl *) theImplementation -{ - m_impl = theImplementation; -} - -- (wxWidgetImpl*) implementation -{ - return m_impl; -} - -- (BOOL) isFlipped -{ - return YES; -} - - (int) intValue { switch ( [self state] ) @@ -183,10 +174,7 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, long style, long extraStyle) { - NSView* sv = (wxpeer->GetParent()->GetHandle() ); - - NSRect r = wxToNSRect( sv, wxRect( pos, size) ); - // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ; + NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; if ( id == wxID_HELP ) @@ -199,9 +187,7 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, } [v setButtonType:NSMomentaryPushInButton]; - [sv addSubview:v]; wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); - [v setImplementation:c]; return c; /* OSStatus err; @@ -256,12 +242,31 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault ) { - [m_osxView setKeyEquivalent: isDefault ? @"\r" : nil ]; -// SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ; + if ( isDefault && [m_osxView isKindOfClass:[NSButton class]] ) + // NOTE: setKeyEquivalent: nil will trigger an assert + // instead do not call in that case. + [(NSButton*)m_osxView setKeyEquivalent: @"\r" ]; } void wxWidgetCocoaImpl::PerformClick() { } -// TODO for the disclosure button : NSDisclosureBezelStyle and the button type to NSOnOffButton. +wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ + NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; + wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; + [v setBezelStyle:NSDisclosureBezelStyle]; + [v setButtonType:NSOnOffButton]; + [v setTitle:wxCFStringRef( label).AsNSString()]; + [v setImagePosition:NSImageRight]; + wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); + return c; +}