Minor fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5672 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-01-05 17:42:47 +00:00
parent c23e5e2e11
commit 623f5da51a
2 changed files with 122 additions and 121 deletions

View file

@ -3,6 +3,7 @@ Wed Jan 5 16:27:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSMenuItem.m: minor fixes and tidying. * Source/NSMenuItem.m: minor fixes and tidying.
* Source/NSMenuView.m: reverted to previous version - last change * Source/NSMenuView.m: reverted to previous version - last change
broke much more than it fixed. broke much more than it fixed.
Also tidied coding style a bit and fixed a couple of encode/decode bugs.
Mon Jan 3 18:35:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk> Mon Jan 3 18:35:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -36,7 +36,7 @@
static float GSMenuBarHeight = 25.0; // A wild guess. static float GSMenuBarHeight = 25.0; // A wild guess.
// FIXME Check this strange comment: // FIXME Check this strange comment:
// These private methods are used in NSPopUpButton. For NSPB we need to be // These private methods are used in NSPopUpButton. For NSPB we need to be
// able to init with a frame, but have a very custom cell size. // able to init with a frame, but have a very custom cell size.
@ -46,31 +46,31 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
@implementation NSMenuView @implementation NSMenuView
// /*
// Class methods. * Class methods.
// */
+ (float)menuBarHeight + (float) menuBarHeight
{ {
return GSMenuBarHeight; return GSMenuBarHeight;
} }
// /*
// NSView overrides * NSView overrides
// */
- (BOOL)acceptsFirstMouse: (NSEvent *)theEvent - (BOOL) acceptsFirstMouse: (NSEvent*)theEvent
{ {
return YES; return YES;
} }
// /*
// Init methods. * Init methods.
// */
- (id)init - (id) init
{ {
return [self initWithFrame: NSZeroRect]; return [self initWithFrame: NSZeroRect];
} }
- (id)initWithFrame: (NSRect)aFrame - (id) initWithFrame: (NSRect)aFrame
{ {
cellSize = NSMakeSize(110,20); cellSize = NSMakeSize(110,20);
@ -83,29 +83,29 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return [super initWithFrame: aFrame]; return [super initWithFrame: aFrame];
} }
- (void)_setCellSize:(NSSize)aSize - (void) _setCellSize: (NSSize)aSize
{ {
cellSize = aSize; cellSize = aSize;
} }
- (id)initWithFrame: (NSRect)aFrame - (id) initWithFrame: (NSRect)aFrame
cellSize: (NSSize)aSize cellSize: (NSSize)aSize
{ {
[self initWithFrame:aFrame]; [self initWithFrame: aFrame];
cellSize = aSize; cellSize = aSize;
return self; return self;
} }
// /*
// Getting and Setting Menu View Attributes * Getting and Setting Menu View Attributes
// */
- (void)setMenu: (NSMenu *)menu - (void) setMenu: (NSMenu*)menu
{ {
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
if (menuv_menu) if (menuv_menu != nil)
{ {
// Remove this menu view from the old menu list of observers. // Remove this menu view from the old menu list of observers.
[theCenter removeObserver: self name: nil object: menuv_menu]; [theCenter removeObserver: self name: nil object: menuv_menu];
@ -135,32 +135,32 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self setNeedsSizing: YES]; [self setNeedsSizing: YES];
} }
- (NSMenu *)menu - (NSMenu*) menu
{ {
return menuv_menu; return menuv_menu;
} }
- (void)setHorizontal: (BOOL)flag - (void) setHorizontal: (BOOL)flag
{ {
menuv_horizontal = flag; menuv_horizontal = flag;
} }
- (BOOL)isHorizontal - (BOOL) isHorizontal
{ {
return menuv_horizontal; return menuv_horizontal;
} }
- (void)setFont: (NSFont *)font - (void) setFont: (NSFont*)font
{ {
ASSIGN(menuv_font, font); ASSIGN(menuv_font, font);
} }
- (NSFont *)font - (NSFont*) font
{ {
return menuv_font; return menuv_font;
} }
- (void)setHighlightedItemIndex: (int)index - (void) setHighlightedItemIndex: (int)index
{ {
id aCell; id aCell;
@ -174,7 +174,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
aCell = [menuv_itemCells objectAtIndex: menuv_highlightedItemIndex]; aCell = [menuv_itemCells objectAtIndex: menuv_highlightedItemIndex];
[aCell highlight: NO withFrame:aRect inView: self]; [aCell highlight: NO withFrame: aRect inView: self];
[window flushWindow]; [window flushWindow];
@ -183,7 +183,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
} }
else if (index >= 0) else if (index >= 0)
{ {
if ( menuv_highlightedItemIndex != -1) if (menuv_highlightedItemIndex != -1)
{ {
NSRect aRect = [self rectOfItemAtIndex: menuv_highlightedItemIndex]; NSRect aRect = [self rectOfItemAtIndex: menuv_highlightedItemIndex];
@ -221,13 +221,13 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self unlockFocus]; [self unlockFocus];
} }
- (int)highlightedItemIndex - (int) highlightedItemIndex
{ {
return menuv_highlightedItemIndex; return menuv_highlightedItemIndex;
} }
- (void)setMenuItemCell: (NSMenuItemCell *)cell - (void) setMenuItemCell: (NSMenuItemCell *)cell
forItemAtIndex: (int)index forItemAtIndex: (int)index
{ {
[menuv_itemCells replaceObjectAtIndex: index withObject: cell]; [menuv_itemCells replaceObjectAtIndex: index withObject: cell];
@ -236,14 +236,14 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self setNeedsSizing: YES]; [self setNeedsSizing: YES];
} }
- (NSMenuItemCell *)menuItemCellForItemAtIndex: (int)index - (NSMenuItemCell*) menuItemCellForItemAtIndex: (int)index
{ {
return [menuv_itemCells objectAtIndex: index]; return [menuv_itemCells objectAtIndex: index];
} }
- (NSMenuView *)attachedMenuView - (NSMenuView*) attachedMenuView
{ {
NSMenu *attachedMenu; NSMenu *attachedMenu;
if ((attachedMenu = [menuv_menu attachedMenu])) if ((attachedMenu = [menuv_menu attachedMenu]))
return [attachedMenu menuRepresentation]; return [attachedMenu menuRepresentation];
@ -251,35 +251,35 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return nil; return nil;
} }
- (NSMenu *)attachedMenu - (NSMenu*) attachedMenu
{ {
return [menuv_menu attachedMenu]; return [menuv_menu attachedMenu];
} }
- (BOOL)isAttached - (BOOL) isAttached
{ {
return [menuv_menu isAttached]; return [menuv_menu isAttached];
} }
- (BOOL)isTornOff - (BOOL) isTornOff
{ {
return [menuv_menu isTornOff]; return [menuv_menu isTornOff];
} }
- (void)setHorizontalEdgePadding: (float)pad - (void) setHorizontalEdgePadding: (float)pad
{ {
menuv_horizontalEdgePad = pad; menuv_horizontalEdgePad = pad;
} }
- (float)horizontalEdgePadding - (float) horizontalEdgePadding
{ {
return menuv_horizontalEdgePad; return menuv_horizontalEdgePad;
} }
// /*
// Notification Methods * Notification Methods
// */
- (void) itemChanged: (NSNotification *)notification - (void) itemChanged: (NSNotification*)notification
{ {
int index = [[[notification userInfo] objectForKey: @"NSMenuItemIndex"] int index = [[[notification userInfo] objectForKey: @"NSMenuItemIndex"]
intValue]; intValue];
@ -291,7 +291,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self setNeedsSizing: YES]; [self setNeedsSizing: YES];
} }
- (void) itemAdded: (NSNotification *)notification - (void) itemAdded: (NSNotification*)notification
{ {
int index = [[[notification userInfo] int index = [[[notification userInfo]
objectForKey: @"NSMenuItemIndex"] intValue]; objectForKey: @"NSMenuItemIndex"] intValue];
@ -314,7 +314,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self setNeedsSizing: YES]; [self setNeedsSizing: YES];
} }
- (void) itemRemoved: (NSNotification *)notification - (void) itemRemoved: (NSNotification*)notification
{ {
int wasHighlighted = [self highlightedItemIndex]; int wasHighlighted = [self highlightedItemIndex];
int index = [[[notification userInfo] objectForKey: @"NSMenuItemIndex"] int index = [[[notification userInfo] objectForKey: @"NSMenuItemIndex"]
@ -334,10 +334,10 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self setNeedsSizing: YES]; [self setNeedsSizing: YES];
} }
// /*
// Working with Submenus. * Working with Submenus.
// */
- (void)detachSubmenu - (void) detachSubmenu
{ {
NSMenu *attachedMenu = [menuv_menu attachedMenu]; NSMenu *attachedMenu = [menuv_menu attachedMenu];
NSMenuView *attachedMenuView; NSMenuView *attachedMenuView;
@ -360,13 +360,14 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[attachedMenu close]; [attachedMenu close];
} }
- (void)attachSubmenuForItemAtIndex: (int)index - (void) attachSubmenuForItemAtIndex: (int)index
{ {
// Transient menus are used for torn-off menus, which are already on the /*
// screen and for sons of transient menus. As transients disappear as * Transient menus are used for torn-off menus, which are already on the
// soon as we release the mouse the user will be able to leave submenus * screen and for sons of transient menus. As transients disappear as
// open on the screen and interact with other menus at the same time. * soon as we release the mouse the user will be able to leave submenus
* open on the screen and interact with other menus at the same time.
*/
NSMenu *attachableMenu = [[menuv_items_link objectAtIndex: index] submenu]; NSMenu *attachableMenu = [[menuv_items_link objectAtIndex: index] submenu];
if ([attachableMenu isTornOff] || [menuv_menu isFollowTransient]) if ([attachableMenu isTornOff] || [menuv_menu isFollowTransient])
@ -380,10 +381,10 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[attachableMenu display]; [attachableMenu display];
} }
// /*
// Calculating Menu Geometry * Calculating Menu Geometry
// */
- (void)update - (void) update
{ {
[menuv_menu update]; [menuv_menu update];
@ -391,12 +392,12 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self sizeToFit]; [self sizeToFit];
} }
- (void)setNeedsSizing: (BOOL)flag - (void) setNeedsSizing: (BOOL)flag
{ {
menuv_needsSizing = flag; menuv_needsSizing = flag;
} }
- (BOOL)needsSizing - (BOOL) needsSizing
{ {
return menuv_needsSizing; return menuv_needsSizing;
} }
@ -433,23 +434,23 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
anImageWidth = [aCell imageWidth]; anImageWidth = [aCell imageWidth];
switch ([aCell imagePosition]) switch ([aCell imagePosition])
{ {
case NSNoImage: case NSNoImage:
anImageAndTitleWidth = aTitleWidth; anImageAndTitleWidth = aTitleWidth;
break; break;
case NSImageOnly: case NSImageOnly:
anImageAndTitleWidth = anImageWidth; anImageAndTitleWidth = anImageWidth;
break; break;
case NSImageLeft: case NSImageLeft:
case NSImageRight: case NSImageRight:
anImageAndTitleWidth = anImageWidth + aTitleWidth + xDist; anImageAndTitleWidth = anImageWidth + aTitleWidth + xDist;
break; break;
case NSImageBelow: case NSImageBelow:
case NSImageAbove: case NSImageAbove:
case NSImageOverlaps: case NSImageOverlaps:
default: default:
if (aTitleWidth > anImageWidth) if (aTitleWidth > anImageWidth)
anImageAndTitleWidth = aTitleWidth; anImageAndTitleWidth = aTitleWidth;
else else
@ -489,7 +490,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
menuv_needsSizing = NO; menuv_needsSizing = NO;
} }
- (float)stateImageOffset - (float) stateImageOffset
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -497,7 +498,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return menuv_stateImageOffset; return menuv_stateImageOffset;
} }
- (float)stateImageWidth - (float) stateImageWidth
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -505,7 +506,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return menuv_stateImageWidth; return menuv_stateImageWidth;
} }
- (float)imageAndTitleOffset - (float) imageAndTitleOffset
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -513,7 +514,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return menuv_imageAndTitleOffset; return menuv_imageAndTitleOffset;
} }
- (float)imageAndTitleWidth - (float) imageAndTitleWidth
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -521,7 +522,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return menuv_imageAndTitleWidth; return menuv_imageAndTitleWidth;
} }
- (float)keyEquivalentOffset - (float) keyEquivalentOffset
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -529,7 +530,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return menuv_keyEqOffset; return menuv_keyEqOffset;
} }
- (float)keyEquivalentWidth - (float) keyEquivalentWidth
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -537,7 +538,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return menuv_keyEqWidth; return menuv_keyEqWidth;
} }
- (NSRect)innerRect - (NSRect) innerRect
{ {
NSRect aRect = {{bounds.origin.x + 1, bounds.origin.y}, NSRect aRect = {{bounds.origin.x + 1, bounds.origin.y},
{bounds.size.width - 1, bounds.size.height}}; {bounds.size.width - 1, bounds.size.height}};
@ -545,7 +546,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return aRect; return aRect;
} }
- (NSRect)rectOfItemAtIndex: (int)index - (NSRect) rectOfItemAtIndex: (int)index
{ {
NSRect theRect; NSRect theRect;
@ -562,7 +563,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return theRect; return theRect;
} }
- (int)indexOfItemAtPoint: (NSPoint)point - (int) indexOfItemAtPoint: (NSPoint)point
{ {
// The MacOSX API says that this method calls - rectOfItemAtIndex for // The MacOSX API says that this method calls - rectOfItemAtIndex for
// *every* cell to figure this out. Well, instead we will just do some // *every* cell to figure this out. Well, instead we will just do some
@ -573,7 +574,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
|| point.x > frame.size.width + frame.origin.x || point.x > frame.size.width + frame.origin.x
|| point.y <= frame.origin.y || point.y <= frame.origin.y
|| point.y > frame.size.height + frame.origin.y) ? || point.y > frame.size.height + frame.origin.y) ?
-1 : -1 :
(frame.size.height - point.y) / cellSize.height; (frame.size.height - point.y) / cellSize.height;
} }
@ -584,7 +585,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[self setNeedsDisplayInRect: aRect]; [self setNeedsDisplayInRect: aRect];
} }
- (NSPoint)locationForSubmenu: (NSMenu *)aSubmenu - (NSPoint) locationForSubmenu: (NSMenu *)aSubmenu
{ {
if (menuv_needsSizing) if (menuv_needsSizing)
[self sizeToFit]; [self sizeToFit];
@ -597,15 +598,15 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return NSZeroPoint; return NSZeroPoint;
} }
- (void)resizeWindowWithMaxHeight: (float)maxHeight - (void) resizeWindowWithMaxHeight: (float)maxHeight
{ {
// set the menuview's window to max height in order to keep on screen? // set the menuview's window to max height in order to keep on screen?
} }
- (void)setWindowFrameForAttachingToRect: (NSRect)screenRect - (void) setWindowFrameForAttachingToRect: (NSRect)screenRect
onScreen: (NSScreen *)screen onScreen: (NSScreen*)screen
preferredEdge: (NSRectEdge)edge preferredEdge: (NSRectEdge)edge
popUpSelectedItem: (int)selectedItemIndex popUpSelectedItem: (int)selectedItemIndex
{ {
NSRect r; NSRect r;
@ -625,7 +626,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
styleMask: [window styleMask]]; styleMask: [window styleMask]];
// Update position,if needed, using the preferredEdge; // Update position,if needed, using the preferredEdge;
// It seems we should be calling [self resizeWindowWithMaxHeight: ]; // It seems we should be calling [self resizeWindowWithMaxHeight:];
// see the (quite obscure) doc. // see the (quite obscure) doc.
// TODO // TODO
@ -634,10 +635,10 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
display: YES]; display: YES];
} }
// /*
// Drawing. * Drawing.
// */
- (void)drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
int i; int i;
NSRect aRect = [self innerRect]; NSRect aRect = [self innerRect];
@ -659,20 +660,20 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
aRect.size = cellSize; aRect.size = cellSize;
for (i = 0; i < howMany; i++) for (i = 0; i < howMany; i++)
{ {
id aCell; id aCell;
aCell = [menuv_itemCells objectAtIndex: i]; aCell = [menuv_itemCells objectAtIndex: i];
[aCell drawWithFrame: aRect inView: self]; [aCell drawWithFrame: aRect inView: self];
aRect.origin.y -= cellSize.height; aRect.origin.y -= cellSize.height;
} }
} }
// /*
// Event Handling * Event Handling
// */
- (void)performActionWithHighlightingForItemAtIndex: (int)index - (void) performActionWithHighlightingForItemAtIndex: (int)index
{ {
NSMenu *candidateMenu = menuv_menu; NSMenu *candidateMenu = menuv_menu;
NSMenuView *targetMenuView; NSMenuView *targetMenuView;
@ -680,9 +681,9 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
for (;;) for (;;)
{ {
if (![candidateMenu supermenu] || if (![candidateMenu supermenu]
[candidateMenu isAttached] || || [candidateMenu isAttached]
[candidateMenu isTornOff]) || [candidateMenu isTornOff])
{ {
targetMenuView = [candidateMenu menuRepresentation]; targetMenuView = [candidateMenu menuRepresentation];
@ -711,7 +712,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
#define MOVE_THRESHOLD_DELTA 1.0 #define MOVE_THRESHOLD_DELTA 1.0
#define DELAY_MULTIPLIER 12 #define DELAY_MULTIPLIER 12
- (BOOL)trackWithEvent: (NSEvent *)event - (BOOL) trackWithEvent: (NSEvent *)event
{ {
NSApplication *theApp = [NSApplication sharedApplication]; NSApplication *theApp = [NSApplication sharedApplication];
unsigned eventMask = NSLeftMouseUpMask unsigned eventMask = NSLeftMouseUpMask
@ -735,7 +736,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
{ {
if ([menuv_menu isPartlyOffScreen]) if ([menuv_menu isPartlyOffScreen])
{ {
NSPoint pointerLoc = [window convertBaseToScreen: NSPoint pointerLoc = [window convertBaseToScreen:
location]; location];
// TODO: Why 1 in the Y axis? // TODO: Why 1 in the Y axis?
@ -819,9 +820,8 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
} }
// Close menus if needed. // Close menus if needed.
if (!menuv_keepAttachedMenus || if (!menuv_keepAttachedMenus || index == -1
index == -1 || || (alreadyAttachedMenu && [alreadyAttachedMenu isFollowTransient]))
(alreadyAttachedMenu && [alreadyAttachedMenu isFollowTransient]))
{ {
NSMenu *parentMenu; NSMenu *parentMenu;
NSMenu *masterMenu; NSMenu *masterMenu;
@ -843,7 +843,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
return YES; return YES;
} }
- (void)mouseDown: (NSEvent *)theEvent - (void) mouseDown: (NSEvent *)theEvent
{ {
NSMenu *candidateMenu; NSMenu *candidateMenu;
NSMenu *masterMenu; NSMenu *masterMenu;
@ -879,15 +879,15 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
menuv_keepAttachedMenus = NO; menuv_keepAttachedMenus = NO;
} }
-(BOOL) performKeyEquivalent: (NSEvent *)theEvent - (BOOL) performKeyEquivalent: (NSEvent *)theEvent
{ {
return [menuv_menu performKeyEquivalent: theEvent]; return [menuv_menu performKeyEquivalent: theEvent];
} }
// /*
// NSCoding Protocol * NSCoding Protocol
// */
- (void)encodeWithCoder:(NSCoder *)encoder - (void) encodeWithCoder: (NSCoder*)encoder
{ {
[super encodeWithCoder: encoder]; [super encodeWithCoder: encoder];
@ -900,12 +900,12 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[encoder encodeValueOfObjCType: @encode(NSSize) at: &cellSize]; [encoder encodeValueOfObjCType: @encode(NSSize) at: &cellSize];
} }
- (id)initWithCoder:(NSCoder *)decoder - (id) initWithCoder: (NSCoder*)decoder
{ {
self = [super initWithCoder: decoder]; self = [super initWithCoder: decoder];
menuv_itemCells = [decoder decodeObject]; [decoder decodeValueOfObjCType: @encode(id) at: &menuv_itemCells];
menuv_font = [decoder decodeObject]; [decoder decodeValueOfObjCType: @encode(id) at: &menuv_font];
menuv_menu = [decoder decodeObject]; menuv_menu = [decoder decodeObject];
menuv_items_link = [decoder decodeObject]; menuv_items_link = [decoder decodeObject];
[decoder decodeValueOfObjCType: @encode(BOOL) at: &menuv_horizontal]; [decoder decodeValueOfObjCType: @encode(BOOL) at: &menuv_horizontal];