White space clean up.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@26080 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2008-02-17 17:18:34 +00:00
parent 86fdb04504
commit d8b13a0a6d
2 changed files with 297 additions and 286 deletions

View file

@ -47,7 +47,7 @@
#include <Foundation/Foundation.h>
typedef struct _GSCellRect {
NSRect rect;
NSRect rect;
} GSCellRect;
#define GSI_ARRAY_TYPES 0
@ -61,9 +61,9 @@ typedef struct _GSCellRect {
#endif
#include <GNUstepBase/GSIArray.h>
static NSMapTable *viewInfo = 0;
static NSMapTable *viewInfo = 0;
#define cellRects ((GSIArray)NSMapGet(viewInfo, self))
#define cellRects ((GSIArray)NSMapGet(viewInfo, self))
/*
NSMenuView contains:
@ -82,7 +82,7 @@ static NSMapTable *viewInfo = 0;
@implementation NSMenuView (Private)
- (BOOL) _rootIsHorizontal: (BOOL*)isAppMenu
{
NSMenu *m = _attachedMenu;
NSMenu *m = _attachedMenu;
/* Determine root menu of this menu hierarchy */
while ([m supermenu] != nil)
@ -93,7 +93,7 @@ static NSMapTable *viewInfo = 0;
{
if (m == [NSApp mainMenu])
{
*isAppMenu = YES;
*isAppMenu = YES;
}
else
{
@ -165,6 +165,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (id) initWithFrame: (NSRect)aFrame
{
self = [super initWithFrame: aFrame];
if (!self)
return nil;
[self setFont: [NSFont menuFontOfSize: 0.0]];
@ -174,7 +176,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
/* Set the necessary offset for the menuView. That is, how many pixels
* do we need for our left side border line.
*/
_leftBorderOffset = 1;
_leftBorderOffset = 1;
// Create an array to store our menu item cells.
_itemCells = [NSMutableArray new];
@ -185,7 +187,9 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (id) initAsTearOff
{
[self initWithFrame: NSZeroRect];
if (!self)
return nil;
if (_attachedMenu)
[_attachedMenu setTornOff: YES];
@ -198,13 +202,13 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if (_attachedMenu != nil)
{
[[NSNotificationCenter defaultCenter] removeObserver: self
name: nil
object: _attachedMenu];
name: nil
object: _attachedMenu];
}
/* Clean the pointer to us stored into the _itemCells. */
[_itemCells makeObjectsPerformSelector: @selector(setMenuView:)
withObject: nil];
withObject: nil];
RELEASE(_itemCells);
RELEASE(_font);
@ -213,7 +217,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
* Get rid of any cached cell rects.
*/
{
GSIArray a = NSMapGet(viewInfo, self);
GSIArray a = NSMapGet(viewInfo, self);
if (a != 0)
{
@ -231,9 +235,9 @@ _addLeftBorderOffsetToRect(NSRect aRect)
*/
- (void) setMenu: (NSMenu*)menu
{
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
unsigned count;
unsigned i;
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
unsigned count;
unsigned i;
if (_attachedMenu != nil)
{
@ -249,13 +253,13 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
// Add this menu view to the menu's list of observers.
[theCenter addObserver: self
selector: @selector(itemChanged:)
name: NSMenuDidChangeItemNotification
selector: @selector(itemChanged:)
name: NSMenuDidChangeItemNotification
object: _attachedMenu];
[theCenter addObserver: self
selector: @selector(itemAdded:)
name: NSMenuDidAddItemNotification
selector: @selector(itemAdded:)
name: NSMenuDidAddItemNotification
object: _attachedMenu];
[theCenter addObserver: self
@ -267,15 +271,15 @@ _addLeftBorderOffsetToRect(NSRect aRect)
count = [[[self menu] itemArray] count];
for (i = 0; i < count; i++)
{
NSNumber *n = [NSNumber numberWithInt: i];
NSDictionary *d;
NSNumber *n = [NSNumber numberWithInt: i];
NSDictionary *d;
d = [NSDictionary dictionaryWithObject: n forKey: @"NSMenuItemIndex"];
[self itemAdded: [NSNotification
notificationWithName: NSMenuDidAddItemNotification
object: self
userInfo: d]];
notificationWithName: NSMenuDidAddItemNotification
object: self
userInfo: d]];
}
// Force menu view's layout to be recalculated.
@ -292,21 +296,21 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
if (flag == YES && _horizontal == NO)
{
GSIArray a = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIArray_t));
GSIArray a = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity(a, NSDefaultMallocZone(), 8);
NSMapInsert(viewInfo, self, a);
}
else if (flag == NO && _horizontal == YES)
{
GSIArray a = NSMapGet(viewInfo, self);
GSIArray a = NSMapGet(viewInfo, self);
if (a != 0)
{
GSIArrayEmpty(a);
NSZoneFree(NSDefaultMallocZone(), a);
NSMapRemove(viewInfo, self);
}
{
GSIArrayEmpty(a);
NSZoneFree(NSDefaultMallocZone(), a);
NSMapRemove(viewInfo, self);
}
}
_horizontal = flag;
@ -373,7 +377,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
}
- (void) setMenuItemCell: (NSMenuItemCell *)cell
forItemAtIndex: (int)index
forItemAtIndex: (int)index
{
NSMenuItem *anItem = [_items_link objectAtIndex: index];
@ -434,7 +438,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (void) itemChanged: (NSNotification*)notification
{
int index = [[[notification userInfo] objectForKey: @"NSMenuItemIndex"]
intValue];
intValue];
NSMenuItemCell *aCell = [_itemCells objectAtIndex: index];
// Enabling of the item may have changed
@ -449,10 +453,10 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (void) itemAdded: (NSNotification*)notification
{
int index = [[[notification userInfo]
objectForKey: @"NSMenuItemIndex"] intValue];
int index = [[[notification userInfo]
objectForKey: @"NSMenuItemIndex"] intValue];
NSMenuItem *anItem = [_items_link objectAtIndex: index];
id aCell = [NSMenuItemCell new];
id aCell = [NSMenuItemCell new];
int wasHighlighted = _highlightedItemIndex;
// FIXME do we need to differentiate between popups and non popups
@ -488,7 +492,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
int wasHighlighted = [self highlightedItemIndex];
int index = [[[notification userInfo] objectForKey: @"NSMenuItemIndex"]
intValue];
intValue];
if (index <= wasHighlighted)
{
@ -568,8 +572,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
*/
- (void) update
{
BOOL needTitleView;
BOOL rootIsAppMenu;
BOOL needTitleView;
BOOL rootIsAppMenu;
NSDebugLLog (@"NSMenu", @"update called on menu view");
@ -647,24 +651,24 @@ _addLeftBorderOffsetToRect(NSRect aRect)
_cellSize.height = scRect.size.height;
for (i = 0; i < howMany; i++)
{
GSCellRect elem;
NSMenuItemCell *aCell = [_itemCells objectAtIndex: i];
float titleWidth = [aCell titleWidth];
{
GSCellRect elem;
NSMenuItemCell *aCell = [_itemCells objectAtIndex: i];
float titleWidth = [aCell titleWidth];
if ([aCell imageWidth])
{
titleWidth += [aCell imageWidth] + GSCellTextImageXDist;
}
if ([aCell imageWidth])
{
titleWidth += [aCell imageWidth] + GSCellTextImageXDist;
}
elem.rect = NSMakeRect (currentX,
0,
(titleWidth + (2 * _horizontalEdgePad)),
_cellSize.height);
GSIArrayAddItem(cellRects, (GSIArrayItem)elem);
elem.rect = NSMakeRect (currentX,
0,
(titleWidth + (2 * _horizontalEdgePad)),
_cellSize.height);
GSIArrayAddItem(cellRects, (GSIArrayItem)elem);
currentX += titleWidth + (2 * _horizontalEdgePad);
}
currentX += titleWidth + (2 * _horizontalEdgePad);
}
}
else
{
@ -680,95 +684,95 @@ _addLeftBorderOffsetToRect(NSRect aRect)
// Popup menu doesn't need title bar
if (![_attachedMenu _ownedByPopUp] && _titleView)
{
NSMenu *m = [_attachedMenu supermenu];
NSMenuView *r = [m menuRepresentation];
{
NSMenu *m = [_attachedMenu supermenu];
NSMenuView *r = [m menuRepresentation];
neededImageAndTitleWidth = [_titleView titleSize].width;
if (r != nil && [r isHorizontal] == YES)
{
NSMenuItemCell *msr;
neededImageAndTitleWidth = [_titleView titleSize].width;
if (r != nil && [r isHorizontal] == YES)
{
NSMenuItemCell *msr;
msr = [r menuItemCellForItemAtIndex:
[m indexOfItemWithTitle: [_attachedMenu title]]];
neededImageAndTitleWidth
= [msr titleWidth] + GSCellTextImageXDist;
}
msr = [r menuItemCellForItemAtIndex:
[m indexOfItemWithTitle: [_attachedMenu title]]];
neededImageAndTitleWidth
= [msr titleWidth] + GSCellTextImageXDist;
}
if (_titleView)
menuBarHeight = [[self class] menuBarHeight];
else
menuBarHeight += _leftBorderOffset;
}
if (_titleView)
menuBarHeight = [[self class] menuBarHeight];
else
menuBarHeight += _leftBorderOffset;
}
else
{
menuBarHeight += _leftBorderOffset;
}
{
menuBarHeight += _leftBorderOffset;
}
for (i = 0; i < howMany; i++)
{
float aStateImageWidth;
float aTitleWidth;
float anImageWidth;
float anImageAndTitleWidth;
float aKeyEquivalentWidth;
NSMenuItemCell *aCell = [_itemCells objectAtIndex: i];
// State image area.
aStateImageWidth = [aCell stateImageWidth];
// Title and Image area.
aTitleWidth = [aCell titleWidth];
anImageWidth = [aCell imageWidth];
// Key equivalent area.
aKeyEquivalentWidth = [aCell keyEquivalentWidth];
switch ([aCell imagePosition])
{
case NSNoImage:
anImageAndTitleWidth = aTitleWidth;
break;
case NSImageOnly:
anImageAndTitleWidth = anImageWidth;
break;
case NSImageLeft:
case NSImageRight:
anImageAndTitleWidth
= anImageWidth + aTitleWidth + GSCellTextImageXDist;
break;
case NSImageBelow:
case NSImageAbove:
case NSImageOverlaps:
default:
if (aTitleWidth > anImageWidth)
anImageAndTitleWidth = aTitleWidth;
else
anImageAndTitleWidth = anImageWidth;
break;
}
if (aStateImageWidth > neededStateImageWidth)
neededStateImageWidth = aStateImageWidth;
if (anImageAndTitleWidth > neededImageAndTitleWidth)
neededImageAndTitleWidth = anImageAndTitleWidth;
if (aKeyEquivalentWidth > neededKeyEquivalentWidth)
neededKeyEquivalentWidth = aKeyEquivalentWidth;
// Title view width less than item's left part width
if ((anImageAndTitleWidth + aStateImageWidth)
> neededImageAndTitleWidth)
wideTitleView = 0;
// Popup menu has only one item with nibble or arrow image
if (anImageWidth)
popupImageWidth = anImageWidth;
}
{
float aStateImageWidth;
float aTitleWidth;
float anImageWidth;
float anImageAndTitleWidth;
float aKeyEquivalentWidth;
NSMenuItemCell *aCell = [_itemCells objectAtIndex: i];
// State image area.
aStateImageWidth = [aCell stateImageWidth];
// Title and Image area.
aTitleWidth = [aCell titleWidth];
anImageWidth = [aCell imageWidth];
// Key equivalent area.
aKeyEquivalentWidth = [aCell keyEquivalentWidth];
switch ([aCell imagePosition])
{
case NSNoImage:
anImageAndTitleWidth = aTitleWidth;
break;
case NSImageOnly:
anImageAndTitleWidth = anImageWidth;
break;
case NSImageLeft:
case NSImageRight:
anImageAndTitleWidth
= anImageWidth + aTitleWidth + GSCellTextImageXDist;
break;
case NSImageBelow:
case NSImageAbove:
case NSImageOverlaps:
default:
if (aTitleWidth > anImageWidth)
anImageAndTitleWidth = aTitleWidth;
else
anImageAndTitleWidth = anImageWidth;
break;
}
if (aStateImageWidth > neededStateImageWidth)
neededStateImageWidth = aStateImageWidth;
if (anImageAndTitleWidth > neededImageAndTitleWidth)
neededImageAndTitleWidth = anImageAndTitleWidth;
if (aKeyEquivalentWidth > neededKeyEquivalentWidth)
neededKeyEquivalentWidth = aKeyEquivalentWidth;
// Title view width less than item's left part width
if ((anImageAndTitleWidth + aStateImageWidth)
> neededImageAndTitleWidth)
wideTitleView = 0;
// Popup menu has only one item with nibble or arrow image
if (anImageWidth)
popupImageWidth = anImageWidth;
}
// Cache the needed widths.
_stateImageWidth = neededStateImageWidth;
@ -777,59 +781,59 @@ _addLeftBorderOffsetToRect(NSRect aRect)
accumulatedOffset = _horizontalEdgePad;
if (howMany)
{
// Calculate the offsets and cache them.
if (neededStateImageWidth)
{
_stateImageOffset = accumulatedOffset;
accumulatedOffset += neededStateImageWidth += _horizontalEdgePad;
}
if (neededImageAndTitleWidth)
{
_imageAndTitleOffset = accumulatedOffset;
accumulatedOffset += neededImageAndTitleWidth;
}
if (wideTitleView)
{
_keyEqOffset = accumulatedOffset = neededImageAndTitleWidth
+ (3 * _horizontalEdgePad);
}
else
{
_keyEqOffset = accumulatedOffset += (2 * _horizontalEdgePad);
}
accumulatedOffset += neededKeyEquivalentWidth + _horizontalEdgePad;
if ([_attachedMenu supermenu] != nil && neededKeyEquivalentWidth < 8)
{
accumulatedOffset += 8 - neededKeyEquivalentWidth;
}
}
{
// Calculate the offsets and cache them.
if (neededStateImageWidth)
{
_stateImageOffset = accumulatedOffset;
accumulatedOffset += neededStateImageWidth += _horizontalEdgePad;
}
if (neededImageAndTitleWidth)
{
_imageAndTitleOffset = accumulatedOffset;
accumulatedOffset += neededImageAndTitleWidth;
}
if (wideTitleView)
{
_keyEqOffset = accumulatedOffset = neededImageAndTitleWidth
+ (3 * _horizontalEdgePad);
}
else
{
_keyEqOffset = accumulatedOffset += (2 * _horizontalEdgePad);
}
accumulatedOffset += neededKeyEquivalentWidth + _horizontalEdgePad;
if ([_attachedMenu supermenu] != nil && neededKeyEquivalentWidth < 8)
{
accumulatedOffset += 8 - neededKeyEquivalentWidth;
}
}
else
{
accumulatedOffset += neededImageAndTitleWidth + 3 + 2;
if ([_attachedMenu supermenu] != nil)
accumulatedOffset += 15;
}
{
accumulatedOffset += neededImageAndTitleWidth + 3 + 2;
if ([_attachedMenu supermenu] != nil)
accumulatedOffset += 15;
}
// Calculate frame size.
if (![_attachedMenu _ownedByPopUp])
{
// Add the border width: 1 for left, 2 for right sides
_cellSize.width = accumulatedOffset + 3;
}
{
// Add the border width: 1 for left, 2 for right sides
_cellSize.width = accumulatedOffset + 3;
}
else
{
_keyEqOffset = _cellSize.width - _keyEqWidth - popupImageWidth;
}
{
_keyEqOffset = _cellSize.width - _keyEqWidth - popupImageWidth;
}
[self setFrameSize: NSMakeSize(_cellSize.width + _leftBorderOffset,
(howMany * _cellSize.height)
+ menuBarHeight)];
(howMany * _cellSize.height)
+ menuBarHeight)];
[_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height,
NSWidth (_bounds), menuBarHeight)];
NSWidth (_bounds), menuBarHeight)];
}
_needsSizing = NO;
}
@ -887,16 +891,16 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if (_horizontal == NO)
{
return NSMakeRect (_bounds.origin.x + _leftBorderOffset,
_bounds.origin.y,
_bounds.size.width - _leftBorderOffset,
_bounds.size.height);
_bounds.origin.y,
_bounds.size.width - _leftBorderOffset,
_bounds.size.height);
}
else
{
return NSMakeRect (_bounds.origin.x,
_bounds.origin.y + _leftBorderOffset,
_bounds.size.width,
_bounds.size.height - _leftBorderOffset);
_bounds.origin.y + _leftBorderOffset,
_bounds.size.width,
_bounds.size.height - _leftBorderOffset);
}
}
@ -975,41 +979,41 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if (_horizontal == NO)
{
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle",
[aSubmenu menuRepresentation])
== GSWindowMakerInterfaceStyle)
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, aRect.origin.y)];
return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) - 3 +
2*[NSMenuView menuBarHeight]);
}
else if ([self _rootIsHorizontal: 0] == YES)
{
NSRect aRect = [self rectOfItemAtIndex:
[aSubmenu menuRepresentation])
== GSWindowMakerInterfaceStyle)
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, aRect.origin.y)];
return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) - 3 +
2*[NSMenuView menuBarHeight]);
}
else if ([self _rootIsHorizontal: 0] == YES)
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, aRect.origin.y)];
// FIXME ... why is the offset +1 needed below?
return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) + aRect.size.height + 1);
}
return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) + aRect.size.height + 1);
}
else
{
return NSMakePoint(NSMaxX(frame),
NSMaxY(frame) - NSHeight(submenuFrame));
}
{
return NSMakePoint(NSMaxX(frame),
NSMaxY(frame) - NSHeight(submenuFrame));
}
}
else
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(NSMinX(aRect),
NSMinY(aRect))];
NSMakePoint(NSMinX(aRect),
NSMinY(aRect))];
return NSMakePoint(subOrigin.x, subOrigin.y - NSHeight(submenuFrame));
}
@ -1087,11 +1091,11 @@ _addLeftBorderOffsetToRect(NSRect aRect)
}
else if (edge == NSMaxYEdge)
{
screenFrame.origin.y += screenRect.size.height;
screenFrame.origin.y += screenRect.size.height;
}
else if (edge == NSMaxXEdge)
{
screenFrame.origin.x += screenRect.size.width;
screenFrame.origin.x += screenRect.size.width;
}
else if (edge == NSMinXEdge)
{
@ -1138,8 +1142,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
// Draw the menu cells.
for (i = 0; i < howMany; i++)
{
NSRect aRect;
NSMenuItemCell *aCell;
NSRect aRect;
NSMenuItemCell *aCell;
aRect = [self rectOfItemAtIndex: i];
if (NSIntersectsRect(rect, aRect) == YES)
@ -1178,7 +1182,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
candidateMenu = superMenu;
}
}
oldHighlightedIndex = [targetMenuView highlightedItemIndex];
[targetMenuView setHighlightedItemIndex: indexToHighlight];
@ -1201,18 +1205,18 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (BOOL) trackWithEvent: (NSEvent*)event
{
unsigned eventMask = NSPeriodicMask;
NSDate *theDistantFuture = [NSDate distantFuture];
NSPoint lastLocation = {0,0};
BOOL justAttachedNewSubmenu = NO;
BOOL subMenusNeedRemoving = YES;
BOOL shouldFinish = YES;
int delayCount = 0;
int indexOfActionToExecute = -1;
int firstIndex = -1;
NSEvent *original;
NSEventType type;
NSEventType end;
unsigned eventMask = NSPeriodicMask;
NSDate *theDistantFuture = [NSDate distantFuture];
NSPoint lastLocation = {0,0};
BOOL justAttachedNewSubmenu = NO;
BOOL subMenusNeedRemoving = YES;
BOOL shouldFinish = YES;
int delayCount = 0;
int indexOfActionToExecute = -1;
int firstIndex = -1;
NSEvent *original;
NSEventType type;
NSEventType end;
/*
* The original event is unused except to determine whether the method
@ -1261,24 +1265,24 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
if (type == end)
{
shouldFinish = YES;
shouldFinish = YES;
}
if (type == NSPeriodic || event == original)
{
NSPoint location;
int index;
NSPoint location;
int index;
location = [_window mouseLocationOutsideOfEventStream];
index = [self indexOfItemAtPoint: location];
location = [_window mouseLocationOutsideOfEventStream];
index = [self indexOfItemAtPoint: location];
if (event == original)
{
firstIndex = index;
}
if (index != firstIndex)
{
shouldFinish = YES;
}
if (event == original)
{
firstIndex = index;
}
if (index != firstIndex)
{
shouldFinish = YES;
}
/*
* 1 - if menus is only partly visible and the mouse is at the
@ -1293,8 +1297,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
* GNUstep screen coordinates start with 1.
*/
if (pointerLoc.x == 0 || pointerLoc.y == 1
|| pointerLoc.x == [[_window screen] frame].size.width - 1
|| pointerLoc.y == [[_window screen] frame].size.height)
|| pointerLoc.x == [[_window screen] frame].size.width - 1
|| pointerLoc.y == [[_window screen] frame].size.height)
[_attachedMenu shiftOnScreen];
}
@ -1304,7 +1308,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
* flag to NO.
*/
if (justAttachedNewSubmenu && index != -1
&& index != _highlightedItemIndex)
&& index != _highlightedItemIndex)
{
if (location.x - lastLocation.x > MOVE_THRESHOLD_DELTA)
{
@ -1324,9 +1328,9 @@ _addLeftBorderOffsetToRect(NSRect aRect)
// 3 - If we have moved outside this menu, take appropriate action
if (index == -1)
{
NSPoint locationInScreenCoordinates;
NSPoint locationInScreenCoordinates;
NSWindow *windowUnderMouse;
NSMenu *candidateMenu;
NSMenu *candidateMenu;
subMenusNeedRemoving = NO;
@ -1343,24 +1347,24 @@ _addLeftBorderOffsetToRect(NSRect aRect)
*/
candidateMenu = [_attachedMenu supermenu];
while (candidateMenu
&& !NSMouseInRect (locationInScreenCoordinates,
[[candidateMenu window] frame], NO) // not found yet
&& (! ([candidateMenu isTornOff]
&& ![candidateMenu isTransient])) // no root of display tree
&& [candidateMenu isAttached]) // has displayed parent
&& !NSMouseInRect (locationInScreenCoordinates,
[[candidateMenu window] frame], NO) // not found yet
&& (! ([candidateMenu isTornOff]
&& ![candidateMenu isTransient])) // no root of display tree
&& [candidateMenu isAttached]) // has displayed parent
{
candidateMenu = [candidateMenu supermenu];
}
if (candidateMenu != nil
&& NSMouseInRect (locationInScreenCoordinates,
[[candidateMenu window] frame], NO))
&& NSMouseInRect (locationInScreenCoordinates,
[[candidateMenu window] frame], NO))
{
BOOL candidateMenuResult;
BOOL candidateMenuResult;
// The call to fetch attachedMenu is not needed. But putting
// it here avoids flicker when we go back to an ancestor
// menu and the attached menu is already correct.
// menu and the attached menu is already correct.
[[[candidateMenu attachedMenu] menuRepresentation]
detachSubmenu];
@ -1372,14 +1376,14 @@ _addLeftBorderOffsetToRect(NSRect aRect)
candidateMenuResult = [[candidateMenu menuRepresentation]
trackWithEvent: original];
return candidateMenuResult;
return candidateMenuResult;
}
// 3b - Check if we enter the attached submenu
windowUnderMouse = [[_attachedMenu attachedMenu] window];
if (windowUnderMouse != nil
&& NSMouseInRect (locationInScreenCoordinates,
[windowUnderMouse frame], NO))
&& NSMouseInRect (locationInScreenCoordinates,
[windowUnderMouse frame], NO))
{
BOOL wasTransient = [_attachedMenu isTransient];
BOOL subMenuResult;
@ -1387,7 +1391,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
subMenuResult
= [[self attachedMenuView] trackWithEvent: original];
if (subMenuResult
&& wasTransient == [_attachedMenu isTransient])
&& wasTransient == [_attachedMenu isTransient])
{
[self detachSubmenu];
}
@ -1491,15 +1495,15 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
#if 1
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self)
== NSMacintoshInterfaceStyle)
{
/*
* FIXME ... always remove submenus in mac mode ... this is not
* quite the way the mac behaves, but it's closer than the normal
* behavior.
*/
== NSMacintoshInterfaceStyle)
{
/*
* FIXME ... always remove submenus in mac mode ... this is not
* quite the way the mac behaves, but it's closer than the normal
* behavior.
*/
subMenusNeedRemoving = YES;
}
}
#endif
if (subMenusNeedRemoving)
{
@ -1512,16 +1516,16 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self)
== NSMacintoshInterfaceStyle)
{
NSMenu *tmp = _attachedMenu;
NSMenu *tmp = _attachedMenu;
do
{
if ([tmp isEqual: [NSApp mainMenu]] == NO)
{
[tmp close];
}
tmp = [tmp supermenu];
}
{
if ([tmp isEqual: [NSApp mainMenu]] == NO)
{
[tmp close];
}
tmp = [tmp supermenu];
}
while (tmp != nil);
}
@ -1542,20 +1546,20 @@ _addLeftBorderOffsetToRect(NSRect aRect)
/**
This method is called when the user clicks on a button in the menu.
Or, if a right click happens and the app menu is brought up.
Or, if a right click happens and the app menu is brought up.
The original position is stored, so we can restore the position of menu.
The position of the menu can change during the event tracking because
The position of the menu can change during the event tracking because
the menu will automatillay move when parts are outside the screen and
the user move the mouse pointer to the edge of the screen.
the user move the mouse pointer to the edge of the screen.
*/
- (void) mouseDown: (NSEvent*)theEvent
{
NSRect currentFrame;
NSRect originalFrame;
NSPoint currentTopLeft;
NSPoint originalTopLeft = NSZeroPoint; /* Silence compiler. */
BOOL restorePosition;
NSRect currentFrame;
NSRect originalFrame;
NSPoint currentTopLeft;
NSPoint originalTopLeft = NSZeroPoint; /* Silence compiler. */
BOOL restorePosition;
/*
* Only for non transient menus do we want
* to remember the position.
@ -1581,7 +1585,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if (NSEqualPoints(currentTopLeft, originalTopLeft) == NO)
{
NSPoint origin = currentFrame.origin;
NSPoint origin = currentFrame.origin;
origin.x += (originalTopLeft.x - currentTopLeft.x);
origin.y += (originalTopLeft.y - currentTopLeft.y);
@ -1623,12 +1627,15 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (id) initWithCoder: (NSCoder*)decoder
{
self = [super initWithCoder: decoder];
if (!self)
return nil;
if ([decoder allowsKeyedCoding] == NO)
{
[decoder decodeValueOfObjCType: @encode(id) at: &_itemCells];
[_itemCells makeObjectsPerformSelector: @selector(setMenuView:)
withObject: self];
withObject: self];
[decoder decodeValueOfObjCType: @encode(id) at: &_font];
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_horizontal];