Merge pull request #152 from gnustep/issue151_nsradiobutton_behavior

This commit is contained in:
Gregory Casamento 2022-09-05 20:23:43 -04:00 committed by GitHub
commit 7a42b1d04c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 0 deletions

View file

@ -1,3 +1,15 @@
2022-09-01 Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSButtonCell.m: Move method to detect if button is a
radio button to this class (- _isRadio)
* Source/NSButton.m: Add method to check current state of button
clicked and flip other buttons to off (-_handleRadioStates)
2022-08-27 Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSButton.m: Fix to address issue #151, NSRadio button
behavior on 10.7 should now be implemented.
2022-08-09 Gregory John Casamento <greg.casamento@gmail.com> 2022-08-09 Gregory John Casamento <greg.casamento@gmail.com>
* Headers/AppKit/NSPredicateEditorRowTemplate.h: * Headers/AppKit/NSPredicateEditorRowTemplate.h:

View file

@ -37,11 +37,17 @@
#import "AppKit/NSEvent.h" #import "AppKit/NSEvent.h"
#import "AppKit/NSWindow.h" #import "AppKit/NSWindow.h"
#import "GSFastEnumeration.h"
// //
// class variables // class variables
// //
static id buttonCellClass = nil; static id buttonCellClass = nil;
@interface NSButtonCell (_NSButton_Private_)
- (BOOL) _isRadio;
@end
/** /**
TODO Description TODO Description
*/ */
@ -543,4 +549,49 @@ static id buttonCellClass = nil;
return [_cell sound]; return [_cell sound];
} }
// Implement 10.7+ radio button behavior
- (void) _flipState: (NSButton *)b
{
if ([[b cell] _isRadio])
{
if ([self action] == [b action] && b != self)
{
[b setState: NSOffState];
}
}
}
- (void) _handleRadioStates
{
if ([[self cell] _isRadio] == NO)
return;
else
{
NSView *sv = [self superview];
NSArray *subviews = [sv subviews];
FOR_IN(NSView*, v, subviews)
{
if ([v isKindOfClass: [NSButton class]])
{
NSButton *b = (NSButton *)v;
[self _flipState: b];
}
}
END_FOR_IN(subviews);
}
}
- (BOOL) sendAction: (SEL)theAction to: (id)theTarget
{
BOOL flag = [super sendAction: theAction
to: theTarget];
if (flag == YES)
{
[self _handleRadioStates];
}
return flag;
}
@end @end

View file

@ -1922,4 +1922,19 @@
return self; return self;
} }
// Implement 10.7 NSRadio button behavior...
- (BOOL) _isRadio
{
return ([self image] == [NSImage imageNamed: @"NSRadioButton"]);
}
- (NSInteger) nextState
{
if ([self _isRadio] && [self state] == NSOnState)
return [self state];
return [super nextState];
}
@end @end