1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/radiobut.mm
3 // Purpose: wxRadioButton
4 // Author: Stefan Csomor
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/radiobut.h"
17 #include "wx/osx/private.h"
19 // ugly workaround for the fact that since 10.8 is treating all subviews of a view
20 // which share the same action selector as a group and sets their value automatically
21 // so we are creating <maxAlternateActions> different selectors and iterate through them
22 // as we are assigning their selectors as actions
24 #include <objc/objc-runtime.h>
26 const int maxAlternateActions = 100;
27 NSString* alternateActionsSelector = @"controlAction%d:";
29 extern void wxOSX_controlAction(NSView* self, SEL _cmd, id sender);
31 @interface wxNSRadioButton : NSButton
33 NSTrackingRectTag rectTag;
38 @implementation wxNSRadioButton
41 static BOOL initialized = NO;
45 wxOSXCocoaClassAddWXMethods( self );
46 for ( int i = 1 ; i <= maxAlternateActions ; i++ )
48 class_addMethod(self, NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, i]), (IMP) wxOSX_controlAction, "v@:@" );
53 - (void) setState: (NSInteger) v
56 // [[self cell] setState:v];
61 switch ( [self state] )
72 - (void) setIntValue: (int) v
77 [self setState:NSMixedState];
80 [self setState:NSOnState];
83 [self setState:NSOffState];
88 - (void) setTrackingTag: (NSTrackingRectTag)tag
93 - (NSTrackingRectTag) trackingTag
100 wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
101 wxWindowMac* WXUNUSED(parent),
102 wxWindowID WXUNUSED(id),
103 const wxString& WXUNUSED(label),
106 long WXUNUSED(style),
107 long WXUNUSED(extraStyle))
109 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
110 wxNSRadioButton* v = [[wxNSRadioButton alloc] initWithFrame:r];
112 [v setButtonType:NSRadioButton];
114 static int alternateAction = 1;
116 [v setAction: NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, alternateAction])];
117 if ( ++alternateAction > maxAlternateActions )
120 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );