From 063b64fd789d575c93f691955fe7dc801cc5908d Mon Sep 17 00:00:00 2001 From: nico Date: Sat, 22 Jun 2002 18:38:51 +0000 Subject: [PATCH] Fixed highlighting of cells when new cells are added git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13955 72102866-910b-0410-8b05-ffd578937521 --- Source/NSMenuView.m | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index fd48a5783..14779b880 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -313,17 +313,29 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal) objectForKey: @"NSMenuItemIndex"] intValue]; NSMenuItem *anItem = [_items_link objectAtIndex: index]; id aCell = [NSMenuItemCell new]; + int wasHighlighted = _highlightedItemIndex; [aCell setMenuItem: anItem]; [aCell setMenuView: self]; [aCell setFont: _font]; - if ([self highlightedItemIndex] == index) - [aCell setHighlighted: YES]; - else - [aCell setHighlighted: NO]; - + /* Unlight the previous highlighted cell if the index of the highlighted + * cell will be ruined up by the insertion of the new cell. */ + if (wasHighlighted >= index) + { + [self setHighlightedItemIndex: -1]; + } + [_itemCells insertObject: aCell atIndex: index]; + + /* Restore the highlighted cell, with the new index for it. */ + if (wasHighlighted >= index) + { + /* Please note that if wasHighlighted == -1, it shouldn't be possible + * to be here. */ + [self setHighlightedItemIndex: ++wasHighlighted]; + } + [aCell setNeedsSizing: YES]; RELEASE(aCell);