From ad22faa6a26fd7fe55e4cb94249bfcb61d05bb75 Mon Sep 17 00:00:00 2001 From: Lyndon Tremblay Date: Wed, 20 Oct 1999 17:29:56 +0000 Subject: [PATCH] Added stuff so that NSMenu won't get sized to smaller than it's title width. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5043 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ Headers/gnustep/gui/NSMenuView.h | 2 ++ Source/NSMenu.m | 11 ++++++++--- Source/NSMenuView.m | 18 +++++++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61f0a0300..fc9ff67c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Oct 19 11:33:46 1999 Lyndon Tremblay + + * Source/NSMenuView.m: ([-sizeToFit]) added handling for title width. + ([-setTitleWidth:]) new private function called by NSMenu to + make the menu not get smaller than menu title. + * Source/NSMenu.m: (-[sizeToFit]) added handling for title width. + * Headers/AppKit/NSMenuView.h: added declaration for -setTitleWidth. + Tue Oct 19 1999 Richard Frith-Macdonald * Source/NSApplication.m: ([-terminate:]) modification based on diff --git a/Headers/gnustep/gui/NSMenuView.h b/Headers/gnustep/gui/NSMenuView.h index b227b1c2f..8db2a8518 100644 --- a/Headers/gnustep/gui/NSMenuView.h +++ b/Headers/gnustep/gui/NSMenuView.h @@ -60,6 +60,7 @@ float menuv_keyEqWidth; BOOL menuv_needsSizing; NSSize cellSize; + float i_titleWidth; @private id menuv_popb; id menuv_items_link; @@ -117,6 +118,7 @@ cellSize: (NSSize)aSize; - (void) setPopUpButton: (NSPopUpButton *)popb; - (NSPopUpButton *) popupButton; +- (void)setTitleWidth:(float)titleWidth; @end #endif diff --git a/Source/NSMenu.m b/Source/NSMenu.m index df373e88e..cab773e8b 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -77,6 +77,7 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations"; - (id) init { return [self initWithTitle: @"Menu"]; + //return self; } - (id) initWithPopUpButton: (NSPopUpButton *)popb @@ -134,6 +135,7 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations"; NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; NSApplication* theApp = [NSApplication sharedApplication]; NSRect winRect = {{0, 0}, {20, 17}}; + //float titleWidth = 0; [super init]; @@ -366,7 +368,9 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations"; - (id ) itemAtIndex: (int)index { - // FIXME should raise an exception if out of range. + if (index >= [menu_items count] || index < 0) + [NSException raise:NSRangeException format:@"menu index %i out of range", + index]; return [menu_items objectAtIndex: index]; } @@ -717,8 +721,9 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations"; NSRect mFrame; NSSize size; - [menu_view sizeToFit]; - + + //-setTitleWidth: ends up calling -sizeToFit. + [menu_view setTitleWidth:[[NSFont systemFontOfSize:12] widthOfString:menu_title]]; mFrame = [menu_view frame]; size.width = mFrame.size.width; diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index e8aa55874..5eb2ed4ac 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -59,13 +59,14 @@ static float GSMenuBarHeight = 25.0; // a guess. - (id)initWithFrame: (NSRect)aFrame { cellSize = NSMakeSize(110,20); + i_titleWidth = 110; menuv_highlightedItemIndex = -1; return [super initWithFrame: aFrame]; } - (id)initWithFrame: (NSRect)aFrame - cellSize: (NSSize)aSize + cellSize: (NSSize)aSize { [self initWithFrame:aFrame]; @@ -315,12 +316,23 @@ static float GSMenuBarHeight = 25.0; // a guess. return menuv_needsSizing; } +/* +================ +-setTitleWidth: +================ +*/ +- (void)setTitleWidth:(float)titleWidth +{ + i_titleWidth = titleWidth; + [self sizeToFit]; +} + - (void)sizeToFit { int i; int howMany = [menuv_items_link count]; int howHigh = (howMany * cellSize.height); - float neededWidth = 0; + float neededWidth = i_titleWidth; for (i=0;i