*** /home/qmathe/myCVS/gnustep/core/gui/Source/NSMenu.m	Thu Feb  5 13:07:38 2004
--- NSMenu.m	Thu Feb  5 15:26:33 2004
***************
*** 293,298 ****
--- 293,301 ----
  - (void) dealloc
  {
    [nc removeObserver: self];
+   
+   // Now clean the pointer to us stored each _items element
+   [_items makeObjectsPerformSelector: @selector(setMenu:) withObject: nil];
  
    RELEASE(_notifications);
    RELEASE(_title);
***************
*** 393,399 ****
     * isn't added.
     */
    if ([newItem menu] != nil)
!     return;
    
    [_items insertObject: newItem atIndex: index];
    _needsSizing = YES;
--- 396,405 ----
     * isn't added.
     */
    if ([newItem menu] != nil)
!     {
!       NSLog(@"The object %@ is already attached to a menu, then it isn't possible to add it.\n", newItem);
!       return;
!     }
    
    [_items insertObject: newItem atIndex: index];
    _needsSizing = YES;
***************
*** 402,416 ****
    d = [NSDictionary
  	  dictionaryWithObject: [NSNumber numberWithInt: index]
  	  forKey: @"NSMenuItemIndex"];
!   inserted = [NSNotification
! 		 notificationWithName: NSMenuDidAddItemNotification
! 		 object: self
! 		 userInfo: d];
!   
    if (_changedMessagesEnabled)
!     [nc postNotification: inserted];
!   else
!     [_notifications addObject: inserted];
  
    // Set this after the insert notification has been send.
    [newItem setMenu: self];
--- 408,428 ----
    d = [NSDictionary
  	  dictionaryWithObject: [NSNumber numberWithInt: index]
  	  forKey: @"NSMenuItemIndex"];
! 
    if (_changedMessagesEnabled)
!     {
!       [nc postNotificationName: NSMenuDidAddItemNotification object: self userInfo: d];
!     }
!   else 
!     {
!       // We doesn't set self as the notification object now because it would retain the menu, then the menu release would be impossible
!       inserted = [NSNotification
! 		    notificationWithName: NSMenuDidAddItemNotification
! 		    object: nil
! 	  	    userInfo: d];
! 		   
!       [_notifications addObject: inserted];
!     }
  
    // Set this after the insert notification has been send.
    [newItem setMenu: self];
***************
*** 472,486 ****
    
    d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index]
  		    forKey: @"NSMenuItemIndex"];
!   removed = [NSNotification
! 		notificationWithName: NSMenuDidRemoveItemNotification
! 		object: self
! 		userInfo: d];
!   
    if (_changedMessagesEnabled)
!     [nc postNotification: removed];
!   else
!     [_notifications addObject: removed];
  }
  
  - (void) itemChanged: (id <NSMenuItem>)anObject
--- 484,504 ----
    
    d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index]
  		    forKey: @"NSMenuItemIndex"];
! 
    if (_changedMessagesEnabled)
!     {
!       [nc postNotificationName: NSMenuDidRemoveItemNotification object: self userInfo: d];
!     }
!   else 
!     {
!       // We doesn't set self as the notification object now because it would retain the menu, then the menu release would be impossible
!       removed = [NSNotification
! 		   notificationWithName: NSMenuDidRemoveItemNotification
!   		   object: nil
! 		   userInfo: d];
!       [_notifications addObject: removed];
!     }
! 
  }
  
  - (void) itemChanged: (id <NSMenuItem>)anObject
***************
*** 496,510 ****
  
    d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index]
  		    forKey: @"NSMenuItemIndex"];
-   changed = [NSNotification
- 	      notificationWithName: NSMenuDidChangeItemNotification
- 	                    object: self
- 	                  userInfo: d];
  
    if (_changedMessagesEnabled)
!     [nc postNotification: changed];
!   else
!     [_notifications addObject: changed];
  
    // Update the menu.
    [self update];
--- 514,533 ----
  
    d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index]
  		    forKey: @"NSMenuItemIndex"];
  
    if (_changedMessagesEnabled)
!     {
!       [nc postNotificationName: NSMenuDidChangeItemNotification object: self userInfo: d];
!     }
!   else 
!     {
!       // We doesn't set self as the notification object now because it would retain the menu, then the menu release would be impossible
!       changed = [NSNotification
! 		   notificationWithName: NSMenuDidChangeItemNotification
! 		   object: nil
! 		   userInfo: d];
!       [_notifications addObject: changed];
!     }
  
    // Update the menu.
    [self update];
***************
*** 957,967 ****
  	{
  	  if ([_notifications count])
  	    {
! 	      NSEnumerator *enumerator = [_notifications objectEnumerator];
! 	      id            aNotification;
  
  	      while ((aNotification = [enumerator nextObject]))
! 		[nc postNotification: aNotification];
  	    }
  
  	  // Clean the notification array.
--- 980,996 ----
  	{
  	  if ([_notifications count])
  	    {
!               NSEnumerator *enumerator = [_notifications objectEnumerator];
! 	      NSNotification *aNotification;
  
  	      while ((aNotification = [enumerator nextObject]))
! 	        /* 
! 		 * We set self as the notification object now because we did not want
! 		 * to retain the menu (which is self) when we create the notification
! 		 */ 
! 		[nc postNotificationName: [aNotification name] 
! 		                  object: self 
! 				userInfo: [aNotification userInfo]];
  	    }
  
  	  // Clean the notification array.
