1 /////////////////////////////////////////////////////////////////////////////
 
   2 // Name:        src/osx/cocoa/radiobut.mm
 
   3 // Purpose:     wxRadioButton
 
   4 // Author:      Stefan Csomor
 
   7 // Copyright:   (c) AUTHOR
 
   8 // Licence:     wxWindows licence
 
   9 /////////////////////////////////////////////////////////////////////////////
 
  11 #include "wx/wxprec.h"
 
  15 #include "wx/radiobut.h"
 
  16 #include "wx/osx/private.h"
 
  18 // ugly workaround for the fact that since 10.8 is treating all subviews of a view
 
  19 // which share the same action selector as a group and sets their value automatically
 
  20 // so we are creating <maxAlternateActions> different selectors and iterate through them
 
  21 // as we are assigning their selectors as actions
 
  23 #include <objc/objc-runtime.h>
 
  25 const int maxAlternateActions = 100;
 
  26 NSString* alternateActionsSelector = @"controlAction%d:";
 
  28 extern void wxOSX_controlAction(NSView* self, SEL _cmd, id sender);
 
  30 @interface wxNSRadioButton : NSButton
 
  32     NSTrackingRectTag rectTag;
 
  37 @implementation wxNSRadioButton
 
  40     static BOOL initialized = NO;
 
  44         wxOSXCocoaClassAddWXMethods( self );
 
  45         for ( int i = 1 ; i <= maxAlternateActions ; i++ )
 
  47             class_addMethod(self, NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, i]), (IMP) wxOSX_controlAction, "v@:@" );
 
  52 - (void) setState: (NSInteger) v
 
  55     //    [[self cell] setState:v];
 
  60     switch ( [self state] )
 
  71 - (void) setIntValue: (int) v
 
  76             [self setState:NSMixedState];
 
  79             [self setState:NSOnState];
 
  82             [self setState:NSOffState];
 
  87 - (void) setTrackingTag: (NSTrackingRectTag)tag
 
  92 - (NSTrackingRectTag) trackingTag
 
  99 wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
 
 100                                     wxWindowMac* WXUNUSED(parent),
 
 101                                     wxWindowID WXUNUSED(id),
 
 102                                     const wxString& WXUNUSED(label),
 
 105                                     long WXUNUSED(style),
 
 106                                     long WXUNUSED(extraStyle))
 
 108     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 
 109     wxNSRadioButton* v = [[wxNSRadioButton alloc] initWithFrame:r];
 
 111     [v setButtonType:NSRadioButton];
 
 113     static int alternateAction = 1;
 
 115     [v setAction: NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, alternateAction])];
 
 116     if ( ++alternateAction > maxAlternateActions )
 
 119     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );