Remove function title_height(), replaced calls to it with

[NSMenuView menuBarHeight]. [setSubmenu:forItem:] moved code
to [NSMenuItem setSubmenu]. [update] use _changedMessagesEnabled
to prevent recursion. [sizeToFit] call [setNeedsDisplay:] instead
of [display]. [locationForSubmenu:] moved code to [NSMenuView
locationForSubmenu:].
Added [NSMenuWindowTitleView rightMouseDown:], so the main menu
is not shown in a menu.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10868 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2001-09-11 17:29:51 +00:00
parent 325aa480ad
commit 193ce9d73b

View file

@ -68,22 +68,6 @@
@end @end
static inline
float title_height()
{
static float height = 0.0;
if (height == 0.0)
{
NSFont *font = [NSFont boldSystemFontOfSize: 0.0];
/* Should make up 23 for the default font */
height = ([font boundingRectForFont].size.height) + 8;
}
return height;
}
static NSZone *menuZone = NULL; static NSZone *menuZone = NULL;
static NSString *NSMenuLocationsKey = @"NSMenuLocations"; static NSString *NSMenuLocationsKey = @"NSMenuLocations";
static NSNotificationCenter *nc; static NSNotificationCenter *nc;
@ -187,8 +171,7 @@ static NSNotificationCenter *nc;
- (id) initWithTitle: (NSString*)aTitle - (id) initWithTitle: (NSString*)aTitle
{ {
float height = title_height(); float height;
NSRect winRect = NSMakeRect(0, 0, 50, height);
NSView *contentView; NSView *contentView;
[super init]; [super init];
@ -223,7 +206,8 @@ static NSNotificationCenter *nc;
[_view setMenu: self]; [_view setMenu: self];
// Create the title view // Create the title view
_titleView = [[NSMenuWindowTitleView alloc] initWithFrame: winRect]; height = [[_view class] menuBarHeight];
_titleView = [[NSMenuWindowTitleView alloc] initWithFrame: NSMakeRect(0, 0, 50, height)];
[_titleView setMenu: self]; [_titleView setMenu: self];
contentView = [_aWindow contentView]; contentView = [_aWindow contentView];
@ -531,15 +515,6 @@ static NSNotificationCenter *nc;
forItem: (id <NSMenuItem>)anItem forItem: (id <NSMenuItem>)anItem
{ {
[anItem setSubmenu: aMenu]; [anItem setSubmenu: aMenu];
// FIXME: most of this is already done in setSubmenu:
[anItem setTarget: self];
[anItem setAction: @selector(submenuAction:)];
if (aMenu != nil)
{
[aMenu setSupermenu: self];
[aMenu setTitle: [anItem title]];
}
[self itemChanged: anItem];
} }
- (void) submenuAction: (id)sender - (void) submenuAction: (id)sender
@ -568,34 +543,7 @@ static NSNotificationCenter *nc;
- (NSPoint) locationForSubmenu: (NSMenu*)aSubmenu - (NSPoint) locationForSubmenu: (NSMenu*)aSubmenu
{ {
NSWindow *theWindow = _follow_transient ? _bWindow : _aWindow; return [_view locationForSubmenu: aSubmenu];
NSRect frame = [theWindow frame];
NSRect submenuFrame;
if (aSubmenu)
submenuFrame = [aSubmenu->_aWindow frame];
else
submenuFrame = NSZeroRect;
// FIXME: Fix this to support styles when the menus move.
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil)
== GSWindowMakerInterfaceStyle)
{
NSRect aRect = [_view rectOfItemAtIndex:
[self indexOfItemWithTitle: [aSubmenu title]]];
NSPoint subOrigin = [theWindow convertBaseToScreen:
NSMakePoint(aRect.origin.x,
aRect.origin.y)];
return NSMakePoint (frame.origin.x + frame.size.width,
subOrigin.y - (submenuFrame.size.height - 43));
}
else
{
return NSMakePoint (frame.origin.x + frame.size.width,
frame.origin.y + frame.size.height
- submenuFrame.size.height);
}
} }
- (NSMenu *) supermenu - (NSMenu *) supermenu
@ -623,6 +571,10 @@ static NSNotificationCenter *nc;
- (void) update - (void) update
{ {
// We use this as a recursion check.
if (!_changedMessagesEnabled)
return;
if ([self autoenablesItems]) if ([self autoenablesItems])
{ {
unsigned i, count; unsigned i, count;
@ -679,7 +631,6 @@ static NSNotificationCenter *nc;
if (shouldBeEnabled != wasEnabled) if (shouldBeEnabled != wasEnabled)
{ {
[item setEnabled: shouldBeEnabled]; [item setEnabled: shouldBeEnabled];
[self itemChanged: item];
} }
} }
@ -840,17 +791,17 @@ static NSNotificationCenter *nc;
NSRect menuFrame; NSRect menuFrame;
NSSize size; NSSize size;
windowFrame = [_aWindow frame]; //if ([_view needsSizing])
[_view sizeToFit]; [_view sizeToFit];
menuFrame = [_view frame]; menuFrame = [_view frame];
size = menuFrame.size;
size.width = menuFrame.size.width; windowFrame = [_aWindow frame];
size.height = menuFrame.size.height;
if (!_is_beholdenToPopUpButton) if (!_is_beholdenToPopUpButton)
{ {
float height = title_height(); float height = [[_view class] menuBarHeight];
size.height += height; size.height += height;
[_aWindow setContentSize: size]; [_aWindow setContentSize: size];
@ -865,6 +816,7 @@ static NSNotificationCenter *nc;
[_view setFrameOrigin: NSMakePoint (0, 0)]; [_view setFrameOrigin: NSMakePoint (0, 0)];
[_titleView setFrame: NSMakeRect (0, size.height - height, [_titleView setFrame: NSMakeRect (0, size.height - height,
size.width, height)]; size.width, height)];
[_titleView setNeedsDisplay: YES];
} }
else else
{ {
@ -873,7 +825,7 @@ static NSNotificationCenter *nc;
NSMakePoint(NSMinX(windowFrame),NSMaxY(windowFrame))]; NSMakePoint(NSMinX(windowFrame),NSMaxY(windowFrame))];
} }
[_aWindow display]; [_view setNeedsDisplay: YES];
_changed = NO; _changed = NO;
} }
@ -1496,4 +1448,9 @@ static NSNotificationCenter *nc;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
- (void) rightMouseDown: (NSEvent*)theEvent
{
// Dont show our menu
}
@end /* NSMenuWindowTitleView */ @end /* NSMenuWindowTitleView */