X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8207702d1cf580a7200114abd52f186b4b9a4f3..7c60222510bc5e197b12f153c4bf05db66cb0f4a:/src/osx/cocoa/radiobut.mm diff --git a/src/osx/cocoa/radiobut.mm b/src/osx/cocoa/radiobut.mm index 195860144b..e1bc623607 100644 --- a/src/osx/cocoa/radiobut.mm +++ b/src/osx/cocoa/radiobut.mm @@ -2,9 +2,9 @@ // Name: src/osx/cocoa/radiobut.mm // Purpose: wxRadioButton // Author: Stefan Csomor -// Modified by: +// Modified by: // Created: ??/??/98 -// RCS-ID: $Id: radiobut.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) AUTHOR // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -16,20 +16,107 @@ #include "wx/radiobut.h" #include "wx/osx/private.h" -wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer, - wxWindowMac* WXUNUSED(parent), - wxWindowID WXUNUSED(id), +// ugly workaround for the fact that since 10.8 is treating all subviews of a view +// which share the same action selector as a group and sets their value automatically +// so we are creating different selectors and iterate through them +// as we are assigning their selectors as actions + +#include + +const int maxAlternateActions = 100; +NSString* alternateActionsSelector = @"controlAction%d:"; + +extern void wxOSX_controlAction(NSView* self, SEL _cmd, id sender); + +@interface wxNSRadioButton : NSButton +{ + NSTrackingRectTag rectTag; +} + +@end + +@implementation wxNSRadioButton ++ (void)initialize +{ + static BOOL initialized = NO; + if (!initialized) + { + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); + for ( int i = 1 ; i <= maxAlternateActions ; i++ ) + { + class_addMethod(self, NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, i]), (IMP) wxOSX_controlAction, "v@:@" ); + } + } +} + +- (void) setState: (NSInteger) v +{ + [super setState:v]; + // [[self cell] setState:v]; +} + +- (int) intValue +{ + switch ( [self state] ) + { + case NSOnState: + return 1; + case NSMixedState: + return 2; + default: + return 0; + } +} + +- (void) setIntValue: (int) v +{ + switch( v ) + { + case 2: + [self setState:NSMixedState]; + break; + case 1: + [self setState:NSOnState]; + break; + default : + [self setState:NSOffState]; + break; + } +} + +- (void) setTrackingTag: (NSTrackingRectTag)tag +{ + rectTag = tag; +} + +- (NSTrackingRectTag) trackingTag +{ + return rectTag; +} + +@end + +wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), const wxString& WXUNUSED(label), - const wxPoint& pos, + const wxPoint& pos, const wxSize& size, - long WXUNUSED(style), - long WXUNUSED(extraStyle)) + long WXUNUSED(style), + long WXUNUSED(extraStyle)) { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; - wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; + wxNSRadioButton* v = [[wxNSRadioButton alloc] initWithFrame:r]; + + [v setButtonType:NSRadioButton]; + + static int alternateAction = 1; + + [v setAction: NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, alternateAction])]; + if ( ++alternateAction > maxAlternateActions ) + alternateAction = 1; - [v setButtonType:NSRadioButton]; - wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); return c; }