]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/radiobut.mm
No changes, just use wxRecursionGuard instead of manual boolean flag.
[wxWidgets.git] / src / osx / cocoa / radiobut.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/radiobut.mm
3 // Purpose: wxRadioButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: ??/??/98
7 // Copyright: (c) AUTHOR
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_RADIOBTN
14
15 #include "wx/radiobut.h"
16 #include "wx/osx/private.h"
17
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
22
23 #include <objc/objc-runtime.h>
24
25 const int maxAlternateActions = 100;
26 NSString* alternateActionsSelector = @"controlAction%d:";
27
28 extern void wxOSX_controlAction(NSView* self, SEL _cmd, id sender);
29
30 @interface wxNSRadioButton : NSButton
31 {
32 NSTrackingRectTag rectTag;
33 }
34
35 @end
36
37 @implementation wxNSRadioButton
38 + (void)initialize
39 {
40 static BOOL initialized = NO;
41 if (!initialized)
42 {
43 initialized = YES;
44 wxOSXCocoaClassAddWXMethods( self );
45 for ( int i = 1 ; i <= maxAlternateActions ; i++ )
46 {
47 class_addMethod(self, NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, i]), (IMP) wxOSX_controlAction, "v@:@" );
48 }
49 }
50 }
51
52 - (void) setState: (NSInteger) v
53 {
54 [super setState:v];
55 // [[self cell] setState:v];
56 }
57
58 - (int) intValue
59 {
60 switch ( [self state] )
61 {
62 case NSOnState:
63 return 1;
64 case NSMixedState:
65 return 2;
66 default:
67 return 0;
68 }
69 }
70
71 - (void) setIntValue: (int) v
72 {
73 switch( v )
74 {
75 case 2:
76 [self setState:NSMixedState];
77 break;
78 case 1:
79 [self setState:NSOnState];
80 break;
81 default :
82 [self setState:NSOffState];
83 break;
84 }
85 }
86
87 - (void) setTrackingTag: (NSTrackingRectTag)tag
88 {
89 rectTag = tag;
90 }
91
92 - (NSTrackingRectTag) trackingTag
93 {
94 return rectTag;
95 }
96
97 @end
98
99 wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
100 wxWindowMac* WXUNUSED(parent),
101 wxWindowID WXUNUSED(id),
102 const wxString& WXUNUSED(label),
103 const wxPoint& pos,
104 const wxSize& size,
105 long WXUNUSED(style),
106 long WXUNUSED(extraStyle))
107 {
108 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
109 wxNSRadioButton* v = [[wxNSRadioButton alloc] initWithFrame:r];
110
111 [v setButtonType:NSRadioButton];
112
113 static int alternateAction = 1;
114
115 [v setAction: NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, alternateAction])];
116 if ( ++alternateAction > maxAlternateActions )
117 alternateAction = 1;
118
119 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
120 return c;
121 }
122
123 #endif