mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 12:00:45 +00:00
Move logic to detect if it's a radio button to NSButtonCell, also simplify logic to flip the button state and prevent switch to off if button is currently on and is a radio button. This is consistent with 10.7+ behavior
This commit is contained in:
parent
3558247662
commit
a2b57fd1f3
3 changed files with 43 additions and 27 deletions
|
@ -1,3 +1,10 @@
|
|||
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
|
||||
|
|
|
@ -46,6 +46,10 @@
|
|||
//
|
||||
static id buttonCellClass = nil;
|
||||
|
||||
@interface NSButtonCell (_NSButton_Private_)
|
||||
- (BOOL) _isRadio;
|
||||
@end
|
||||
|
||||
/**
|
||||
TODO Description
|
||||
*/
|
||||
|
@ -548,46 +552,36 @@ static id buttonCellClass = nil;
|
|||
}
|
||||
|
||||
// Implement 10.7+ radio button behavior
|
||||
- (BOOL) _isRadioButton
|
||||
{
|
||||
return ([[self cell] image] ==
|
||||
[NSImage imageNamed: @"NSRadioButton"]);
|
||||
}
|
||||
|
||||
- (void) _flipState: (NSButton *)b
|
||||
{
|
||||
if ([b _isRadioButton])
|
||||
if ([[b cell] _isRadio])
|
||||
{
|
||||
if ([self action] == [b action] && b != self)
|
||||
{
|
||||
if ([self state] == NSOnState)
|
||||
{
|
||||
[b setState: NSOffState];
|
||||
}
|
||||
[b setState: NSOffState];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _handleRadioStates
|
||||
{
|
||||
if ([self _isRadioButton] == NO)
|
||||
if ([[self cell] _isRadio] == NO)
|
||||
return;
|
||||
else
|
||||
{
|
||||
NSView *sv = [self superview];
|
||||
NSArray *subviews = [sv subviews];
|
||||
|
||||
if ([[self superview] isKindOfClass: [NSMatrix class]] == NO)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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
|
||||
|
|
|
@ -1922,4 +1922,19 @@
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue