]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/radiobut.mm
No real changes, just make wxWindow::CanScroll() virtual.
[wxWidgets.git] / src / osx / cocoa / radiobut.mm
CommitLineData
f033830e
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/cocoa/radiobut.mm
3// Purpose: wxRadioButton
4// Author: Stefan Csomor
03647350 5// Modified by:
f033830e 6// Created: ??/??/98
f033830e
SC
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
2ec5dba3
SC
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
25const int maxAlternateActions = 100;
26NSString* alternateActionsSelector = @"controlAction%d:";
27
28extern 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
03647350
VZ
99wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
100 wxWindowMac* WXUNUSED(parent),
101 wxWindowID WXUNUSED(id),
d8207702 102 const wxString& WXUNUSED(label),
03647350 103 const wxPoint& pos,
f033830e 104 const wxSize& size,
03647350
VZ
105 long WXUNUSED(style),
106 long WXUNUSED(extraStyle))
f033830e 107{
dbeddfb9 108 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
2ec5dba3 109 wxNSRadioButton* v = [[wxNSRadioButton alloc] initWithFrame:r];
f033830e 110
03647350
VZ
111 [v setButtonType:NSRadioButton];
112
2ec5dba3
SC
113 static int alternateAction = 1;
114
115 [v setAction: NSSelectorFromString([NSString stringWithFormat: alternateActionsSelector, alternateAction])];
116 if ( ++alternateAction > maxAlternateActions )
117 alternateAction = 1;
118
f033830e 119 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
f033830e
SC
120 return c;
121}
122
123#endif