Fix _menu ivar confusion.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17316 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
alexm 2003-07-23 20:25:09 +00:00
parent 05c4f8fe02
commit bf9ca089c0
4 changed files with 68 additions and 47 deletions

View file

@ -1,3 +1,10 @@
2003-07-23 22:23 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSResponder.h: Make _menu private.
* Headers/gnustep/gui/NSMenuView.h: Add _attachedMenu ivar.
* Source/NSMenuView.m: Use it.
2003-07-22 Adam Fedor <fedor@gnu.org> 2003-07-22 Adam Fedor <fedor@gnu.org>
* Source/NSOpenGLView.m ([NSOpenGLView -initWithFrame:]): Implemented * Source/NSOpenGLView.m ([NSOpenGLView -initWithFrame:]): Implemented

View file

@ -96,6 +96,12 @@
id _items_link; id _items_link;
int _leftBorderOffset; int _leftBorderOffset;
id _titleView; id _titleView;
/*
Private and not named '_menu' to avoid confusion and further problems
with NSResponder's menu.
*/
NSMenu *_attachedMenu;
} }
/*********************************************************************** /***********************************************************************

View file

@ -47,6 +47,14 @@
NSInterfaceStyle _interface_style; NSInterfaceStyle _interface_style;
#endif #endif
NSResponder *_next_responder; NSResponder *_next_responder;
/*
Due to interface brain-damage, but NSResponder and NSMenuView have -menu
and -setMenu: methods, but for different menus. Thus, to prevent (future,
there have already been some) problems and confusion, this ivar is
private (iow, it can't be accidentally used in NSMenuView).
*/
@private
NSMenu *_menu; NSMenu *_menu;
/* /*
* Flags for internal use by NSResponder and it's subclasses. * Flags for internal use by NSResponder and it's subclasses.

View file

@ -142,8 +142,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{ {
[self initWithFrame: NSZeroRect]; [self initWithFrame: NSZeroRect];
if (_menu) if (_attachedMenu)
[_menu setTornOff: YES]; [_attachedMenu setTornOff: YES];
return self; return self;
} }
@ -151,11 +151,11 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (void) dealloc - (void) dealloc
{ {
// We must remove the menu view from the menu list of observers. // We must remove the menu view from the menu list of observers.
if (_menu != nil) if (_attachedMenu != nil)
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self [[NSNotificationCenter defaultCenter] removeObserver: self
name: nil name: nil
object: _menu]; object: _attachedMenu];
} }
/* Clean the pointer to us stored into the _itemCells. */ /* Clean the pointer to us stored into the _itemCells. */
@ -175,33 +175,33 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{ {
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
if (_menu != nil) if (_attachedMenu != 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: _menu]; [theCenter removeObserver: self name: nil object: _attachedMenu];
} }
/* menu is retaining us, so we should not be retaining menu. */ /* menu is retaining us, so we should not be retaining menu. */
_menu = menu; _attachedMenu = menu;
_items_link = [_menu itemArray]; _items_link = [_attachedMenu itemArray];
if (_menu != nil) if (_attachedMenu != nil)
{ {
// Add this menu view to the menu's list of observers. // Add this menu view to the menu's list of observers.
[theCenter addObserver: self [theCenter addObserver: self
selector: @selector(itemChanged:) selector: @selector(itemChanged:)
name: NSMenuDidChangeItemNotification name: NSMenuDidChangeItemNotification
object: _menu]; object: _attachedMenu];
[theCenter addObserver: self [theCenter addObserver: self
selector: @selector(itemAdded:) selector: @selector(itemAdded:)
name: NSMenuDidAddItemNotification name: NSMenuDidAddItemNotification
object: _menu]; object: _attachedMenu];
[theCenter addObserver: self [theCenter addObserver: self
selector: @selector(itemRemoved:) selector: @selector(itemRemoved:)
name: NSMenuDidRemoveItemNotification name: NSMenuDidRemoveItemNotification
object: _menu]; object: _attachedMenu];
} }
// Force menu view's layout to be recalculated. // Force menu view's layout to be recalculated.
@ -212,7 +212,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (NSMenu*) menu - (NSMenu*) menu
{ {
return _menu; return _attachedMenu;
} }
- (void) setHorizontal: (BOOL)flag - (void) setHorizontal: (BOOL)flag
@ -307,22 +307,22 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (NSMenuView*) attachedMenuView - (NSMenuView*) attachedMenuView
{ {
return [[_menu attachedMenu] menuRepresentation]; return [[_attachedMenu attachedMenu] menuRepresentation];
} }
- (NSMenu*) attachedMenu - (NSMenu*) attachedMenu
{ {
return [_menu attachedMenu]; return [_attachedMenu attachedMenu];
} }
- (BOOL) isAttached - (BOOL) isAttached
{ {
return [_menu isAttached]; return [_attachedMenu isAttached];
} }
- (BOOL) isTornOff - (BOOL) isTornOff
{ {
return [_menu isTornOff]; return [_attachedMenu isTornOff];
} }
- (void) setHorizontalEdgePadding: (float)pad - (void) setHorizontalEdgePadding: (float)pad
@ -413,7 +413,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (void) detachSubmenu - (void) detachSubmenu
{ {
NSMenu *attachedMenu = [_menu attachedMenu]; NSMenu *attachedMenu = [_attachedMenu attachedMenu];
NSMenuView *attachedMenuView; NSMenuView *attachedMenuView;
if (!attachedMenu) if (!attachedMenu)
@ -424,7 +424,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
[attachedMenuView detachSubmenu]; [attachedMenuView detachSubmenu];
NSDebugLLog (@"NSMenu", @"detach submenu: %@ from: %@", NSDebugLLog (@"NSMenu", @"detach submenu: %@ from: %@",
attachedMenu, _menu); attachedMenu, _attachedMenu);
if ([attachedMenu isTransient]) if ([attachedMenu isTransient])
{ {
@ -453,7 +453,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
attachableMenu = [[_items_link objectAtIndex: index] submenu]; attachableMenu = [[_items_link objectAtIndex: index] submenu];
if ([attachableMenu isTornOff] || [_menu isTransient]) if ([attachableMenu isTornOff] || [_attachedMenu isTransient])
{ {
NSDebugLLog (@"NSMenu", @"Will open transient: %@", attachableMenu); NSDebugLLog (@"NSMenu", @"Will open transient: %@", attachableMenu);
[attachableMenu displayTransient]; [attachableMenu displayTransient];
@ -473,14 +473,14 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{ {
NSDebugLLog (@"NSMenu", @"update called on menu view"); NSDebugLLog (@"NSMenu", @"update called on menu view");
if (![_menu _ownedByPopUp] && !_titleView) if (![_attachedMenu _ownedByPopUp] && !_titleView)
{ {
// Add title view. If this menu not owned by popup // Add title view. If this menu not owned by popup
_titleView = [[NSMenuWindowTitleView alloc] init]; _titleView = [[NSMenuWindowTitleView alloc] init];
[self addSubview: _titleView]; [self addSubview: _titleView];
RELEASE(_titleView); RELEASE(_titleView);
} }
else if ([_menu _ownedByPopUp] && _titleView) else if ([_attachedMenu _ownedByPopUp] && _titleView)
{ {
// Remove title view if this menu owned by popup // Remove title view if this menu owned by popup
[_titleView removeFromSuperview]; [_titleView removeFromSuperview];
@ -489,17 +489,17 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if ((_titleView != nil) && ([_titleView menu] == nil)) if ((_titleView != nil) && ([_titleView menu] == nil))
{ {
[_titleView setMenu: _menu]; [_titleView setMenu: _attachedMenu];
} }
// Resize it anyway. // Resize it anyway.
[self sizeToFit]; [self sizeToFit];
// Just quit here if we are a popup. // Just quit here if we are a popup.
if ([_menu _ownedByPopUp]) if ([_attachedMenu _ownedByPopUp])
return; return;
if ([_menu isTornOff] && ![_menu isTransient]) if ([_attachedMenu isTornOff] && ![_attachedMenu isTransient])
{ {
[_titleView addCloseButton]; [_titleView addCloseButton];
} }
@ -532,7 +532,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
float menuBarHeight = 0.0; float menuBarHeight = 0.0;
// Popup menu doesn't need title bar // Popup menu doesn't need title bar
if (![_menu _ownedByPopUp] && _titleView) if (![_attachedMenu _ownedByPopUp] && _titleView)
{ {
menuBarHeight = [[self class] menuBarHeight]; menuBarHeight = [[self class] menuBarHeight];
neededImageAndTitleWidth = [_titleView titleSize].width; neededImageAndTitleWidth = [_titleView titleSize].width;
@ -638,7 +638,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
} }
accumulatedOffset += neededKeyEquivalentWidth + _horizontalEdgePad; accumulatedOffset += neededKeyEquivalentWidth + _horizontalEdgePad;
if ([_menu supermenu] != nil && neededKeyEquivalentWidth < 8) if ([_attachedMenu supermenu] != nil && neededKeyEquivalentWidth < 8)
{ {
accumulatedOffset += 8 - neededKeyEquivalentWidth; accumulatedOffset += 8 - neededKeyEquivalentWidth;
} }
@ -646,12 +646,12 @@ _addLeftBorderOffsetToRect(NSRect aRect)
else else
{ {
accumulatedOffset += neededImageAndTitleWidth + 3 + 2; accumulatedOffset += neededImageAndTitleWidth + 3 + 2;
if ([_menu supermenu] != nil) if ([_attachedMenu supermenu] != nil)
accumulatedOffset += 15; accumulatedOffset += 15;
} }
// Calculate frame size. // Calculate frame size.
if (![_menu _ownedByPopUp]) if (![_attachedMenu _ownedByPopUp])
{ {
// Add the border width: 1 for left, 2 for right sides // Add the border width: 1 for left, 2 for right sides
_cellSize.width = accumulatedOffset + 3; _cellSize.width = accumulatedOffset + 3;
@ -824,7 +824,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
== GSWindowMakerInterfaceStyle) == GSWindowMakerInterfaceStyle)
{ {
NSRect aRect = [self rectOfItemAtIndex: NSRect aRect = [self rectOfItemAtIndex:
[_menu indexOfItemWithSubmenu: aSubmenu]]; [_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen: NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, aRect.origin.y)]; NSMakePoint(aRect.origin.x, aRect.origin.y)];
@ -841,7 +841,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
else else
{ {
NSRect aRect = [self rectOfItemAtIndex: NSRect aRect = [self rectOfItemAtIndex:
[_menu indexOfItemWithSubmenu: aSubmenu]]; [_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen: NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(NSMinX(aRect), NSMakePoint(NSMinX(aRect),
NSMinY(aRect))]; NSMinY(aRect))];
@ -959,7 +959,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
*/ */
- (void) performActionWithHighlightingForItemAtIndex: (int)index - (void) performActionWithHighlightingForItemAtIndex: (int)index
{ {
NSMenu *candidateMenu = _menu; NSMenu *candidateMenu = _attachedMenu;
NSMenuView *targetMenuView; NSMenuView *targetMenuView;
int indexToHighlight = index; int indexToHighlight = index;
int oldHighlightedIndex; int oldHighlightedIndex;
@ -992,9 +992,9 @@ _addLeftBorderOffsetToRect(NSRect aRect)
[[NSRunLoop currentRunLoop] [[NSRunLoop currentRunLoop]
runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]]; runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
[_menu performActionForItemAtIndex: index]; [_attachedMenu performActionForItemAtIndex: index];
if (![_menu _ownedByPopUp]) if (![_attachedMenu _ownedByPopUp])
{ {
[targetMenuView setHighlightedItemIndex: oldHighlightedIndex]; [targetMenuView setHighlightedItemIndex: oldHighlightedIndex];
} }
@ -1062,7 +1062,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
* 1 - if menus is only partly visible and the mouse is at the * 1 - if menus is only partly visible and the mouse is at the
* edge of the screen we move the menu so it will be visible. * edge of the screen we move the menu so it will be visible.
*/ */
if ([_menu isPartlyOffScreen]) if ([_attachedMenu isPartlyOffScreen])
{ {
NSPoint pointerLoc = [_window convertBaseToScreen: location]; NSPoint pointerLoc = [_window convertBaseToScreen: location];
/* /*
@ -1073,7 +1073,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
if (pointerLoc.x == 0 || pointerLoc.y == 1 if (pointerLoc.x == 0 || pointerLoc.y == 1
|| pointerLoc.x == [[_window screen] frame].size.width - 1 || pointerLoc.x == [[_window screen] frame].size.width - 1
|| pointerLoc.y == [[_window screen] frame].size.height) || pointerLoc.y == [[_window screen] frame].size.height)
[_menu shiftOnScreen]; [_attachedMenu shiftOnScreen];
} }
@ -1119,7 +1119,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
* We are a non-transient attached menu * We are a non-transient attached menu
* We are a root: isTornOff of AppMenu * We are a root: isTornOff of AppMenu
*/ */
candidateMenu = [_menu supermenu]; candidateMenu = [_attachedMenu supermenu];
while (candidateMenu while (candidateMenu
&& !NSMouseInRect (locationInScreenCoordinates, && !NSMouseInRect (locationInScreenCoordinates,
[[candidateMenu window] frame], [[candidateMenu window] frame],
@ -1152,17 +1152,17 @@ _addLeftBorderOffsetToRect(NSRect aRect)
} }
// 3b - Check if we enter the attached submenu // 3b - Check if we enter the attached submenu
windowUnderMouse = [[_menu attachedMenu] window]; windowUnderMouse = [[_attachedMenu attachedMenu] window];
if (windowUnderMouse != nil if (windowUnderMouse != nil
&& NSMouseInRect (locationInScreenCoordinates, && NSMouseInRect (locationInScreenCoordinates,
[windowUnderMouse frame], NO)) [windowUnderMouse frame], NO))
{ {
BOOL wasTransient = [_menu isTransient]; BOOL wasTransient = [_attachedMenu isTransient];
BOOL subMenuResult; BOOL subMenuResult;
subMenuResult subMenuResult
= [[self attachedMenuView] trackWithEvent: original]; = [[self attachedMenuView] trackWithEvent: original];
if (subMenuResult && wasTransient == [_menu isTransient]) if (subMenuResult && wasTransient == [_attachedMenu isTransient])
{ {
[self detachSubmenu]; [self detachSubmenu];
} }
@ -1234,7 +1234,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
// remove transient menus. -------------------------------------------- // remove transient menus. --------------------------------------------
{ {
NSMenu *currentMenu = _menu; NSMenu *currentMenu = _attachedMenu;
while (currentMenu && ![currentMenu isTransient]) while (currentMenu && ![currentMenu isTransient])
{ {
@ -1262,7 +1262,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
} }
if (indexOfActionToExecute >= 0 if (indexOfActionToExecute >= 0
&& [_menu attachedMenu] != nil && [_menu attachedMenu] == && [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
[[_items_link objectAtIndex: indexOfActionToExecute] submenu]) [[_items_link objectAtIndex: indexOfActionToExecute] submenu])
{ {
if (subMenusNeedRemoving) if (subMenusNeedRemoving)
@ -1273,7 +1273,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
return NO; return NO;
} }
[_menu performActionForItemAtIndex: indexOfActionToExecute]; [_attachedMenu performActionForItemAtIndex: indexOfActionToExecute];
/* /*
* Remove highlighting. * Remove highlighting.
@ -1308,7 +1308,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
* Only for non transient menus do we want * Only for non transient menus do we want
* to remember the position. * to remember the position.
*/ */
restorePosition = ![_menu isTransient]; restorePosition = ![_attachedMenu isTransient];
if (restorePosition) if (restorePosition)
{ // store old position; { // store old position;
@ -1333,7 +1333,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
origin.x += (originalTopLeft.x - currentTopLeft.x); origin.x += (originalTopLeft.x - currentTopLeft.x);
origin.y += (originalTopLeft.y - currentTopLeft.y); origin.y += (originalTopLeft.y - currentTopLeft.y);
[_menu nestedSetFrameOrigin: origin]; [_attachedMenu nestedSetFrameOrigin: origin];
} }
} }
} }
@ -1345,7 +1345,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
- (BOOL) performKeyEquivalent: (NSEvent *)theEvent - (BOOL) performKeyEquivalent: (NSEvent *)theEvent
{ {
return [_menu performKeyEquivalent: theEvent]; return [_attachedMenu performKeyEquivalent: theEvent];
} }