Horizontal menu related code removed

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16236 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
stoyan 2003-03-23 21:41:44 +00:00
parent a163a5992a
commit f572a3f079
3 changed files with 181 additions and 232 deletions

View file

@ -1,3 +1,29 @@
2003-03-23 Serg Stoyan <stoyan@on.com.ua>
* Source/NSMenuView.m: Removed horizontal menu related code.
(setHorizontal:): Removed.
(isHorizontal:): Removed.
(_addLeftBorderOffsetToRect): Removed isHorizontal parameter.
(setMenu:): Place [self setNeedsSizing: YES] before [self update].
(update): Removed title view removal, because it's not always known
owner of menu at this point. Remove title view creating.
(sizeToFit:): Reformatting.
(innerRect:): Idem.
(setWindowFrameForAttachingToRect:onScreen:preferredEdge:popUpSelectedItem:):
Title view removal code placed here, because this is only place where
non-titled menu can appear.
(initWithFrame:): Removed comment about _leftBorderOffset for popups,
because we use _leftBorderOffset for regular and popups now. Title view
creating added.
(rectOfItemAtIndex:): Removed comment about _leftBorderOffset for popups.
(indexOfItemAtPoint:): Idem. Add left border offset for popups too. Correct
calling of _addLeftBorderOffsetToRect.
(setNeedsDisplayForItemAtIndex:): Idem.
(rightMouseDown:): Ddded comment.
* Headers/NSMenuView.h
(setHorizontal:): Removed.
(isHorizontal:): Removed.
2003-03-22 Willem Rein Oudshoorn <woudshoo@xs4all.nl> 2003-03-22 Willem Rein Oudshoorn <woudshoo@xs4all.nl>
* Source/NSMenu.m ([NSMenu -display]): Added optimization of Michael Hanni * Source/NSMenu.m ([NSMenu -display]): Added optimization of Michael Hanni

View file

@ -99,8 +99,8 @@
- (id)initAsTearOff; - (id)initAsTearOff;
- (void)setMenu:(NSMenu *)menu; - (void)setMenu:(NSMenu *)menu;
- (NSMenu *)menu; - (NSMenu *)menu;
- (void)setHorizontal:(BOOL)flag; /*- (void)setHorizontal:(BOOL)flag;
- (BOOL)isHorizontal; - (BOOL)isHorizontal;*/
- (void)setFont:(NSFont *)font; - (void)setFont:(NSFont *)font;
- (NSFont *)font; - (NSFont *)font;
- (void)setHighlightedItemIndex:(int)index; - (void)setHighlightedItemIndex:(int)index;

View file

@ -72,18 +72,11 @@
@implementation NSMenuView @implementation NSMenuView
static NSRect static NSRect
_addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal) _addLeftBorderOffsetToRect(NSRect aRect)
{ {
if (isHorizontal == NO)
{
aRect.origin.x--; aRect.origin.x--;
aRect.size.width++; aRect.size.width++;
}
else
{
aRect.origin.y--;
aRect.size.height++;
}
return aRect; return aRect;
} }
@ -139,14 +132,18 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
_horizontalEdgePad = 4.; _horizontalEdgePad = 4.;
/* Set the necessary offset for the menuView. That is, how many pixels /* Set the necessary offset for the menuView. That is, how many pixels
* do we need for our left side border line. For regular menus this * do we need for our left side border line.
* equals 1, for popups it is 0.
*/ */
_leftBorderOffset = 1; _leftBorderOffset = 1;
// Create an array to store our menu item cells. // Create an array to store our menu item cells.
_itemCells = [NSMutableArray new]; _itemCells = [NSMutableArray new];
// Add title view. If this menu owned by popup
_titleView = [[NSMenuWindowTitleView alloc] init];
[self addSubview: _titleView];
[_titleView release];
return self; return self;
} }
@ -210,9 +207,10 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
name: NSMenuDidRemoveItemNotification name: NSMenuDidRemoveItemNotification
object: _menu]; object: _menu];
[self update];
// Force menu view's layout to be recalculated. // Force menu view's layout to be recalculated.
[self setNeedsSizing: YES]; [self setNeedsSizing: YES];
[self update];
} }
- (NSMenu*) menu - (NSMenu*) menu
@ -220,16 +218,6 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
return _menu; return _menu;
} }
- (void) setHorizontal: (BOOL)flag
{
_horizontal = flag;
}
- (BOOL) isHorizontal
{
return _horizontal;
}
- (void) setFont: (NSFont*)font - (void) setFont: (NSFont*)font
{ {
ASSIGN(_font, font); ASSIGN(_font, font);
@ -469,18 +457,6 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
{ {
NSDebugLLog (@"NSMenu", @"update called on menu view"); NSDebugLLog (@"NSMenu", @"update called on menu view");
if ([_menu _ownedByPopUp] && _titleView)
{
[_titleView removeFromSuperview];
_titleView = nil;
}
if (![_menu _ownedByPopUp] && !_titleView)
{
_titleView = [[NSMenuWindowTitleView alloc] init];
[_titleView setMenu: _menu];
[self addSubview: _titleView];
[_titleView release];
}
[_titleView setMenu: _menu]; [_titleView setMenu: _menu];
if (_needsSizing) if (_needsSizing)
@ -641,18 +617,11 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
_keyEqOffset = _cellSize.width - _keyEqWidth - popupImageWidth; _keyEqOffset = _cellSize.width - _keyEqWidth - popupImageWidth;
} }
if (_horizontal == NO) [self setFrameSize: NSMakeSize (_cellSize.width + _leftBorderOffset,
{ (howMany * _cellSize.height)
[self setFrameSize: NSMakeSize(_cellSize.width + _leftBorderOffset, + menuBarHeight)];
(howMany * _cellSize.height) + menuBarHeight)];
[_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height, [_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height,
NSWidth (_bounds), menuBarHeight)]; NSWidth (_bounds), menuBarHeight)];
}
else
{
[self setFrameSize: NSMakeSize((howMany * _cellSize.width),
_cellSize.height + _leftBorderOffset)];
}
_needsSizing = NO; _needsSizing = NO;
} }
@ -707,16 +676,10 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
- (NSRect) innerRect - (NSRect) innerRect
{ {
if (_horizontal == NO) return NSMakeRect(_bounds.origin.x + _leftBorderOffset,
{ _bounds.origin.y,
return NSMakeRect(_bounds.origin.x + _leftBorderOffset, _bounds.origin.y, _bounds.size.width - _leftBorderOffset,
_bounds.size.width - _leftBorderOffset, _bounds.size.height); _bounds.size.height);
}
else
{
return NSMakeRect(_bounds.origin.x, _bounds.origin.y + _leftBorderOffset,
_bounds.size.width, _bounds.size.height - _leftBorderOffset);
}
} }
- (NSRect) rectOfItemAtIndex: (int)index - (NSRect) rectOfItemAtIndex: (int)index
@ -730,20 +693,10 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
/* When we are a normal menu we fiddle with the origin so that the item /* When we are a normal menu we fiddle with the origin so that the item
* rect is shifted 1 pixel over so we do not draw on the heavy line at * rect is shifted 1 pixel over so we do not draw on the heavy line at
* origin.x = 0. However, for popups we don't want this modification of * origin.x = 0.
* our rect so our _leftBorderOffset = 0 (set in sizeToFit).
*/ */
if (_horizontal == NO)
{
theRect.origin.y = _cellSize.height * ([_itemCells count] - index - 1); theRect.origin.y = _cellSize.height * ([_itemCells count] - index - 1);
theRect.origin.x = _leftBorderOffset; theRect.origin.x = _leftBorderOffset;
}
else
{
theRect.origin.x = _cellSize.width * index;
theRect.origin.y = _leftBorderOffset;
}
theRect.size = _cellSize; theRect.size = _cellSize;
/* NOTE: This returns the correct NSRect for drawing cells, but nothing /* NOTE: This returns the correct NSRect for drawing cells, but nothing
@ -767,13 +720,7 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
{ {
NSRect aRect = [self rectOfItemAtIndex: i]; NSRect aRect = [self rectOfItemAtIndex: i];
/* We need to modify the rect to take into account the modifications aRect = _addLeftBorderOffsetToRect(aRect);
* to origin made by [-rectOfItemAtIndex:] in order to return an
* item clicked at the left hand margin. However, for a popup this
* calculation is unnecessary since we have no extra margin.
*/
if (![_menu _ownedByPopUp])
aRect = _addLeftBorderOffsetToRect(aRect, _horizontal);
if (NSMouseInRect(point, aRect, NO)) if (NSMouseInRect(point, aRect, NO))
return (int)i; return (int)i;
@ -788,13 +735,7 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
aRect = [self rectOfItemAtIndex: index]; aRect = [self rectOfItemAtIndex: index];
/* We need to modify the rect to take into account the modifications aRect = _addLeftBorderOffsetToRect(aRect);
* to origin made by [-rectOfItemAtIndex:] in order to return an
* item clicked at the left hand margin. However, for a popup this
* calculation is unnecessary since we have no extra margin.
*/
if (![_menu _ownedByPopUp])
aRect = _addLeftBorderOffsetToRect(aRect, _horizontal);
[self setNeedsDisplayInRect: aRect]; [self setNeedsDisplayInRect: aRect];
} }
@ -816,16 +757,13 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
else else
submenuFrame = NSZeroRect; submenuFrame = NSZeroRect;
if (_horizontal == NO)
{
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil) if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil)
== GSWindowMakerInterfaceStyle) == GSWindowMakerInterfaceStyle)
{ {
NSRect aRect = [self rectOfItemAtIndex: NSRect aRect = [self rectOfItemAtIndex:
[_menu indexOfItemWithSubmenu: aSubmenu]]; [_menu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen: NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, NSMakePoint(aRect.origin.x, aRect.origin.y)];
aRect.origin.y)];
return NSMakePoint (NSMaxX(frame), return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) - 3 + subOrigin.y - NSHeight(submenuFrame) - 3 +
@ -836,17 +774,6 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
return NSMakePoint(NSMaxX(frame), return NSMakePoint(NSMaxX(frame),
NSMaxY(frame) - NSHeight(submenuFrame)); NSMaxY(frame) - NSHeight(submenuFrame));
} }
}
else
{
NSRect aRect = [self rectOfItemAtIndex:
[_menu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(NSMinX(aRect),
NSMaxY(aRect))];
return NSMakePoint(subOrigin.x,
subOrigin.y - NSHeight(submenuFrame));
}
} }
- (void) resizeWindowWithMaxHeight: (float)maxHeight - (void) resizeWindowWithMaxHeight: (float)maxHeight
@ -869,6 +796,13 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
cellFrame.origin = [_window convertScreenToBase: screenRect.origin]; cellFrame.origin = [_window convertScreenToBase: screenRect.origin];
cellFrame = [self convertRect: cellFrame fromView: nil]; cellFrame = [self convertRect: cellFrame fromView: nil];
// Remove title view if we owned by popup button
if ([_menu _ownedByPopUp] && _titleView)
{
[_titleView removeFromSuperview];
_titleView = nil;
}
_cellSize = cellFrame.size; _cellSize = cellFrame.size;
[self sizeToFit]; [self sizeToFit];
@ -880,36 +814,21 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
{ {
float f; float f;
if (_horizontal == NO)
{
f = screenRect.size.height * (items - 1); f = screenRect.size.height * (items - 1);
screenFrame.size.height += f + _leftBorderOffset; screenFrame.size.height += f + _leftBorderOffset;
screenFrame.origin.y -= f; screenFrame.origin.y -= f;
screenFrame.size.width += _leftBorderOffset; screenFrame.size.width += _leftBorderOffset;
screenFrame.origin.x -= _leftBorderOffset; screenFrame.origin.x -= _leftBorderOffset;
} }
else
{
f = screenRect.size.width * (items - 1);
screenFrame.size.width += f;
}
}
// Move the menu window to screen? // Move the menu window to screen?
// TODO // TODO
// Compute position for popups, if needed // Compute position for popups, if needed
if (selectedItemIndex != -1) if (selectedItemIndex != -1)
{
if (_horizontal == NO)
{ {
screenFrame.origin.y += screenRect.size.height * selectedItemIndex; screenFrame.origin.y += screenRect.size.height * selectedItemIndex;
} }
else
{
screenFrame.origin.x -= screenRect.size.width * selectedItemIndex;
}
}
// Get the frameRect // Get the frameRect
r = [NSWindow frameRectForContentRect: screenFrame r = [NSWindow frameRectForContentRect: screenFrame
@ -1168,8 +1087,11 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
*/ */
candidateMenu = [_menu supermenu]; candidateMenu = [_menu supermenu];
while (candidateMenu while (candidateMenu
&& !NSMouseInRect (locationInScreenCoordinates, [[candidateMenu window] frame], NO) // not found yet && !NSMouseInRect (locationInScreenCoordinates,
&& (! ([candidateMenu isTornOff] && ![candidateMenu isTransient])) // no root of display tree [[candidateMenu window] frame],
NO) // not found yet
&& (! ([candidateMenu isTornOff]
&& ![candidateMenu isTransient])) // no root of display tree
&& [candidateMenu isAttached]) // has displayed parent && [candidateMenu isAttached]) // has displayed parent
{ {
candidateMenu = [candidateMenu supermenu]; candidateMenu = [candidateMenu supermenu];
@ -1401,7 +1323,6 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
[encoder encodeObject: _itemCells]; [encoder encodeObject: _itemCells];
[encoder encodeObject: _font]; [encoder encodeObject: _font];
[encoder encodeValueOfObjCType: @encode(BOOL) at: &_horizontal];
[encoder encodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad]; [encoder encodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad];
[encoder encodeValueOfObjCType: @encode(NSSize) at: &_cellSize]; [encoder encodeValueOfObjCType: @encode(NSSize) at: &_cellSize];
} }
@ -1416,7 +1337,6 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
withObject: self]; withObject: self];
[decoder decodeValueOfObjCType: @encode(id) at: &_font]; [decoder decodeValueOfObjCType: @encode(id) at: &_font];
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_horizontal];
[decoder decodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad]; [decoder decodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad];
[decoder decodeValueOfObjCType: @encode(NSSize) at: &_cellSize]; [decoder decodeValueOfObjCType: @encode(NSSize) at: &_cellSize];
@ -1475,8 +1395,10 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
if (attr == nil) if (attr == nil)
{ {
attr = [[NSDictionary alloc] initWithObjectsAndKeys: attr = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSFont boldSystemFontOfSize: 0], NSFontAttributeName, [NSFont boldSystemFontOfSize: 0],
[NSColor windowFrameTextColor], NSForegroundColorAttributeName, NSFontAttributeName,
[NSColor windowFrameTextColor],
NSForegroundColorAttributeName,
nil]; nil];
} }
@ -1600,6 +1522,7 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
// We do not need app menu over menu
- (void) rightMouseDown: (NSEvent*)theEvent - (void) rightMouseDown: (NSEvent*)theEvent
{ {
} }