diff --git a/ChangeLog b/ChangeLog index c60570163..89201ebe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-09-24 Fred Kiefer + + * Source/NSMenuView.m (-setMenu:): Only call update when the new + menu is not nil. + * Source/NSMenu.m (-setMenuRepresentation:): Unset the menu of the + old view. + (-dealloc): Unset the menu of the view. + (-initWithTitle:): Use setMenuRepresentation: to set the view. + 2004-09-24 Adam Fedor * Version 0.9.4 diff --git a/Source/NSMenu.m b/Source/NSMenu.m index 6004eeab7..419b76348 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -300,6 +300,7 @@ static NSNotificationCenter *nc; RELEASE(_notifications); RELEASE(_title); RELEASE(_items); + [_view setMenu: nil]; RELEASE(_view); RELEASE(_aWindow); RELEASE(_bWindow); @@ -312,14 +313,14 @@ static NSNotificationCenter *nc; */ - (id) initWithTitle: (NSString*)aTitle { - NSView *contentView; + NSMenuView *menuRep; [super init]; // Keep the title. ASSIGN(_title, aTitle); - // Create an array to store out menu items. + // Create an array to store our menu items. _items = [[NSMutableArray alloc] init]; _changedMessagesEnabled = YES; @@ -340,11 +341,9 @@ static NSNotificationCenter *nc; [_bWindow setLevel: NSPopUpMenuWindowLevel]; // Create a NSMenuView to draw our menu items. - _view = [[NSMenuView alloc] initWithFrame: NSZeroRect]; - [_view setMenu: self]; - - contentView = [_aWindow contentView]; - [contentView addSubview: _view]; + menuRep = [[NSMenuView alloc] initWithFrame: NSZeroRect]; + [self setMenuRepresentation: menuRep]; + RELEASE(menuRep); /* Set up the notification to start the process of redisplaying the menus where the user left them the last time. @@ -940,9 +939,18 @@ static NSNotificationCenter *nc; return; } - // remove the old representation + if (_view == menuRep) + { + return; + } + contentView = [_aWindow contentView]; - [contentView removeSubview: _view]; + if (_view != nil) + { + // remove the old representation + [contentView removeSubview: _view]; + [_view setMenu: nil]; + } ASSIGN(_view, menuRep); [_view setMenu: self]; diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index 95fb64a2b..c6058f8d8 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -185,12 +185,12 @@ _addLeftBorderOffsetToRect(NSRect aRect) selector: @selector(itemRemoved:) name: NSMenuDidRemoveItemNotification object: _attachedMenu]; + + // Force menu view's layout to be recalculated. + [self setNeedsSizing: YES]; + + [self update]; } - - // Force menu view's layout to be recalculated. - [self setNeedsSizing: YES]; - - [self update]; } - (NSMenu*) menu