From bb2eab66cd3566434419a17d1a846cdbe16eebf9 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 27 Nov 2024 16:01:32 -0500 Subject: [PATCH 1/3] Move setMenuItem call to bottom so that it can consider the state when seeting up --- Source/NSPopUpButtonCell.m | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index 8db5a4e474..3b98e6719d 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -609,6 +609,7 @@ - (NSImage *) _currentArrowImage if (_pbcFlags.preferredEdge == NSMaxYEdge) { + NSLog(@"\tDOWN ARROW!!!!!!"); return _pbc_image[1]; } else if (_pbcFlags.preferredEdge == NSMaxXEdge) @@ -1336,16 +1337,17 @@ - (id) initWithCoder: (NSCoder*)aDecoder [self setMenu: menu]; selectedItem = [aDecoder decodeObject]; decode_NSInteger(aDecoder, &flag); - _pbcFlags.pullsDown = flag; + [self setPullsDown: flag]; decode_NSInteger(aDecoder, &flag); - _pbcFlags.preferredEdge = flag; + [self setPreferredEdge: flag]; decode_NSInteger(aDecoder, &flag); - _pbcFlags.usesItemFromMenu = flag; + [self setUsesItemFromMenu: flag]; decode_NSInteger(aDecoder, &flag); - _pbcFlags.altersStateOfSelectedItem = flag; + [self setAltersStateOfSelectedItem: flag]; decode_NSInteger(aDecoder, &flag); - _pbcFlags.arrowPosition = flag; - + [self setArrowPosition: flag]; + [self setMenuItem: (NSMenuItem *)selectedItem]; + if (version < 2) { int i; @@ -1371,6 +1373,22 @@ - (id) initWithCoder: (NSCoder*)aDecoder [self setArrowPosition: NSPopUpArrowAtCenter]; } [self selectItem: selectedItem]; + + NSEnumerator *menuItemEnumerator; + NSMenuItem *menuItem; + + // FIXME: This special handling is needed bacause the NSClassSwapper + // might have replaced the cell, but the items still refere to it. + menuItemEnumerator = [[menu itemArray] objectEnumerator]; + + while ((menuItem = [menuItemEnumerator nextObject]) != nil) + { + if (sel_isEqual([menuItem action], @selector(_popUpItemAction:)) + && ([menuItem target] != self)) + { + [menuItem setTarget: self]; + } + } } return self; From 1ad7d1834ee205631e202bb4651b077846e6dc81 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 27 Nov 2024 17:12:15 -0500 Subject: [PATCH 2/3] Set pullsDown last to avoid accidentally setting state --- Source/NSPopUpButtonCell.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index 3b98e6719d..b02fd6f245 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -654,7 +654,6 @@ - (void) setMenuItem: (NSMenuItem *)item [_menuItem setImage: nil]; } - //[super setMenuItem: item]; ASSIGN(_menuItem, item); if ([_menuItem image] == nil) @@ -1321,7 +1320,7 @@ - (id) initWithCoder: (NSCoder*)aDecoder } else { - NSInteger flag; + NSInteger flag, pullsDown; id selectedItem; int version = [aDecoder versionForClassName: @"NSPopUpButtonCell"]; @@ -1336,8 +1335,7 @@ - (id) initWithCoder: (NSCoder*)aDecoder [self setMenu: nil]; [self setMenu: menu]; selectedItem = [aDecoder decodeObject]; - decode_NSInteger(aDecoder, &flag); - [self setPullsDown: flag]; + decode_NSInteger(aDecoder, &pullsDown); decode_NSInteger(aDecoder, &flag); [self setPreferredEdge: flag]; decode_NSInteger(aDecoder, &flag); @@ -1347,6 +1345,7 @@ - (id) initWithCoder: (NSCoder*)aDecoder decode_NSInteger(aDecoder, &flag); [self setArrowPosition: flag]; [self setMenuItem: (NSMenuItem *)selectedItem]; + [self setPullsDown: pullsDown]; if (version < 2) { From 49e8da568c5ae55a83741e82ba8a7ddaa0788488 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 4 Dec 2024 20:44:41 -0500 Subject: [PATCH 3/3] Testing code --- Source/NSPopUpButtonCell.m | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index b02fd6f245..94ba4e4082 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -607,9 +607,10 @@ - (NSImage *) _currentArrowImage return nil; } + NSLog(@"Arrow position = %d", [self arrowPosition]); if (_pbcFlags.preferredEdge == NSMaxYEdge) { - NSLog(@"\tDOWN ARROW!!!!!!"); + NSLog(@"\tDOWN ARROW!!!!!! %d", [self arrowPosition]); return _pbc_image[1]; } else if (_pbcFlags.preferredEdge == NSMaxXEdge) @@ -1320,7 +1321,7 @@ - (id) initWithCoder: (NSCoder*)aDecoder } else { - NSInteger flag, pullsDown; + NSInteger flag; id selectedItem; int version = [aDecoder versionForClassName: @"NSPopUpButtonCell"]; @@ -1335,6 +1336,18 @@ - (id) initWithCoder: (NSCoder*)aDecoder [self setMenu: nil]; [self setMenu: menu]; selectedItem = [aDecoder decodeObject]; + decode_NSInteger(aDecoder, &flag); + _pbcFlags.pullsDown = flag; + decode_NSInteger(aDecoder, &flag); + _pbcFlags.preferredEdge = flag; + decode_NSInteger(aDecoder, &flag); + _pbcFlags.usesItemFromMenu = flag; + decode_NSInteger(aDecoder, &flag); + _pbcFlags.altersStateOfSelectedItem = flag; + decode_NSInteger(aDecoder, &flag); + _pbcFlags.arrowPosition = flag; + /* + selectedItem = [aDecoder decodeObject]; decode_NSInteger(aDecoder, &pullsDown); decode_NSInteger(aDecoder, &flag); [self setPreferredEdge: flag]; @@ -1344,8 +1357,16 @@ - (id) initWithCoder: (NSCoder*)aDecoder [self setAltersStateOfSelectedItem: flag]; decode_NSInteger(aDecoder, &flag); [self setArrowPosition: flag]; + */ + /* + if (_pbcFlags.pullsDown) + { + [self setPreferredEdge: NSMinYEdge]; + } + */ + // [self setMenuItem: nil]; [self setMenuItem: (NSMenuItem *)selectedItem]; - [self setPullsDown: pullsDown]; + // [self setPullsDown: pullsDown]; if (version < 2) {