--- ./CVS/core/gui/Source/NSMenuView.m	Wed Mar 12 22:01:40 2003
+++ ./CVS.build/gui/Source/NSMenuView.m	Sat Mar 15 02:56:56 2003
@@ -53,10 +53,17 @@
 /* A menu's title is an instance of this class */
 @class NSButton;
 
+@interface CloseButton : NSButton
+{
+}
+
+@end
+
+
 @interface NSMenuWindowTitleView : NSView
 {
   NSMenu *menu;
-  NSButton *button;
+  CloseButton *button;
 }
 
 - (void) addCloseButton;
@@ -499,7 +506,7 @@
 {
   unsigned i;
   unsigned howMany = [_itemCells count];
-  float    neededImageAndTitleWidth = [_font widthOfString: [_menu title]];
+  float    neededImageAndTitleWidth = 0.0;
   float    neededKeyEquivalentWidth = 0.0;
   float    neededStateImageWidth = 0.0;
   float    accumulatedOffset = 0.0;
@@ -515,25 +522,31 @@
   if ([_menu _ownedByPopUp])
     _leftBorderOffset = 0;
 
+  if ([_menu supermenu] != nil)
+    neededImageAndTitleWidth = [_font widthOfString: [_menu title]] + 15;
+  else
+    neededImageAndTitleWidth = [_font widthOfString: [_menu title]];
+
   // TODO: Optimize this loop.
   for (i = 0; i < howMany; i++)
     {
-      float		anImageAndTitleWidth;
-      float		anImageWidth;
-      float		aKeyEquivalentWidth;
-      float		aStateImageWidth;
-      float		aTitleWidth;
+    float		anImageAndTitleWidth = 0.0;
+    float		anImageWidth = 0.0;
+    float		aKeyEquivalentWidth = 0.0;
+    float		aStateImageWidth = 0.0;
+    float		aTitleWidth = 0.0;
       NSMenuItemCell	*aCell = [_itemCells objectAtIndex: i];
 
       // State image area.
       aStateImageWidth = [aCell stateImageWidth];
 
-      if (aStateImageWidth > neededStateImageWidth)
-	neededStateImageWidth = aStateImageWidth;
-
-      // Image and title area.
+    // Title and Image area.
       aTitleWidth = [aCell titleWidth];
       anImageWidth = [aCell imageWidth];
+
+    // Key equivalent area.
+    aKeyEquivalentWidth = [aCell keyEquivalentWidth];
+
       switch ([aCell imagePosition])
 	{
 	  case NSNoImage: 
@@ -560,12 +573,13 @@
 	    break;
 	}
       anImageAndTitleWidth += aStateImageWidth;
+
+    if (aStateImageWidth > neededStateImageWidth)
+      neededStateImageWidth = aStateImageWidth;
+
       if (anImageAndTitleWidth > neededImageAndTitleWidth)
 	neededImageAndTitleWidth = anImageAndTitleWidth;
 
-      // Key equivalent area.
-      aKeyEquivalentWidth = [aCell keyEquivalentWidth];
-
       if (aKeyEquivalentWidth > neededKeyEquivalentWidth)
 	neededKeyEquivalentWidth = aKeyEquivalentWidth;
     }
@@ -578,9 +592,9 @@
   // Calculate the offsets and cache them.
   _stateImageOffset = _imageAndTitleOffset = accumulatedOffset 
     = _horizontalEdgePad;
-  accumulatedOffset += 2 * _horizontalEdgePad + neededImageAndTitleWidth;
+  accumulatedOffset += neededImageAndTitleWidth;
 
-  _keyEqOffset = accumulatedOffset += _horizontalEdgePad;
+  _keyEqOffset = accumulatedOffset += 2 * _horizontalEdgePad;
   accumulatedOffset += neededKeyEquivalentWidth + _horizontalEdgePad;
 
   // Calculate frame size.
@@ -1521,15 +1535,11 @@
 		    (_frame.size.height - imageSize.height) / 2},
 		  { imageSize.height, imageSize.width } };
 
-  button = [[NSButton alloc] initWithFrame: rect];
-  [button setButtonType: NSMomentaryLight];
-  [button setImagePosition: NSImageOnly];
+  button = [[CloseButton alloc] initWithFrame: rect];
   [button setImage: closeImage];
   [button setAlternateImage: closeHImage];
-  [button setBordered: NO];
   [button setTarget: menu];
   [button setAction: @selector(_performMenuClose:)];
-  [button setAutoresizingMask: NSViewMinXMargin];
   
   [self setAutoresizingMask:
     NSViewMinXMargin | NSViewMinYMargin | NSViewMaxYMargin];
@@ -1560,3 +1570,23 @@
 }
 
 @end /* NSMenuWindowTitleView */
+
+@implementation CloseButton
+
+- (id) initWithFrame: (NSRect) rect
+{
+  self = [super initWithFrame: rect];
+  [self setButtonType: NSMomentaryChangeButton];
+  [self setImagePosition: NSImageOnly];
+  [self setBordered: NO];
+  [self setAutoresizingMask: NSViewMinXMargin];
+
+  return self;
+}
+
+- (BOOL) acceptsFirstResponder
+{
+  return NO;
+}
+
+@end /* CloseButton */
