([NSMenu -display]): Added optimization of Michael Hanni

to only resize menu view when actually displayed.
([NSMenu -setTitle:]): Idem
([NSMenu -sizeToFit:]): Fixed problem with jumping menus when items
are added.
([NSMenu -display:]): added optimization of Michael Hanni to resize
only once.  Also fixed race condition bug in getting menu location.
([NSMenu -displayTransient]): Added optimization of M. Hanni, removed
resetting position to (0, 0).


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16221 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
wim 2003-03-22 16:29:40 +00:00
parent 6c48e30909
commit 2f222d7aa5

View file

@ -820,9 +820,12 @@ static NSNotificationCenter *nc;
[self setMenuChangedMessagesEnabled: YES]; [self setMenuChangedMessagesEnabled: YES];
} }
if (_changed) if (_changed && ([_aWindow isVisible] || [_bWindow isVisible]))
[self sizeToFit]; {
NSDebugLLog (@"NSMenu", @" Calling Size To Fit (A)");
[self sizeToFit];
}
return; return;
} }
@ -919,7 +922,12 @@ static NSNotificationCenter *nc;
- (void) setTitle: (NSString*)aTitle - (void) setTitle: (NSString*)aTitle
{ {
ASSIGN(_title, aTitle); ASSIGN(_title, aTitle);
[self sizeToFit];
_changed = YES;
if ([_aWindow isVisible] || [_bWindow isVisible])
{
[self sizeToFit];
}
} }
- (NSString*) title - (NSString*) title
@ -992,7 +1000,8 @@ static NSNotificationCenter *nc;
- (void) sizeToFit - (void) sizeToFit
{ {
NSRect windowFrame; NSRect oldWindowFrame;
NSRect newWindowFrame;
NSRect menuFrame; NSRect menuFrame;
NSSize size; NSSize size;
@ -1001,15 +1010,21 @@ static NSNotificationCenter *nc;
menuFrame = [_view frame]; menuFrame = [_view frame];
size = menuFrame.size; size = menuFrame.size;
windowFrame = [_aWindow frame]; newWindowFrame = [NSWindow frameRectForContentRect: menuFrame
[_aWindow setContentSize: size]; styleMask: [_aWindow styleMask]];
[_aWindow setFrameTopLeftPoint: oldWindowFrame = [_aWindow frame];
NSMakePoint(NSMinX(windowFrame),NSMaxY(windowFrame))]; newWindowFrame.origin = NSMakePoint (oldWindowFrame.origin.x,
oldWindowFrame.origin.y + oldWindowFrame.size.height
- newWindowFrame.size.height);
[_aWindow setFrame: newWindowFrame display: NO];
windowFrame = [_bWindow frame]; newWindowFrame = [NSWindow frameRectForContentRect: menuFrame
[_bWindow setContentSize: size]; styleMask: [_bWindow styleMask]];
[_bWindow setFrameTopLeftPoint: oldWindowFrame = [_bWindow frame];
NSMakePoint(NSMinX(windowFrame),NSMaxY(windowFrame))]; newWindowFrame.origin = NSMakePoint (oldWindowFrame.origin.x,
oldWindowFrame.origin.y + oldWindowFrame.size.height
- newWindowFrame.size.height);
[_bWindow setFrame: newWindowFrame display: NO];
if (_popUpButtonCell == nil) if (_popUpButtonCell == nil)
{ {
@ -1207,24 +1222,22 @@ static NSNotificationCenter *nc;
{ {
NSDebugLLog (@"NSMenu", @"trying to display while alreay displayed transient"); NSDebugLLog (@"NSMenu", @"trying to display while alreay displayed transient");
} }
[_view update];
if (_changed) if (_changed)
[self sizeToFit]; [self sizeToFit];
// get geometry only if not set if (_superMenu && ![self isTornOff])
if ([_aWindow frame].origin.y <= 0) {
{ // query super menu for position
if (_superMenu && ![self isTornOff]) [_aWindow setFrameOrigin: [_superMenu locationForSubmenu: self]];
{ _superMenu->_attachedMenu = self;
// query super menu for position
[_aWindow setFrameOrigin: [_superMenu locationForSubmenu: self]];
_superMenu->_attachedMenu = self;
}
else
{
[self setGeometry];
}
} }
else if ([_aWindow frame].origin.y <= 0) // get geometry only if not set
{
[self setGeometry];
}
NSDebugLLog (@"NSMenu", @"Display, origin: %@", NSStringFromPoint ([_aWindow frame].origin));
[_aWindow orderFrontRegardless]; [_aWindow orderFrontRegardless];
} }
@ -1271,6 +1284,11 @@ static NSNotificationCenter *nc;
contentView = [_bWindow contentView]; contentView = [_bWindow contentView];
[contentView addSubview: _view]; [contentView addSubview: _view];
[_view update]; [_view update];
if (_changed)
{
[self sizeToFit];
}
[_bWindow orderFront: self]; [_bWindow orderFront: self];
} }
@ -1330,13 +1348,13 @@ static NSNotificationCenter *nc;
_attachedMenu = sub; _attachedMenu = sub;
} }
[_aWindow orderOut: self]; [_aWindow orderOut: self];
[_aWindow setFrameOrigin: NSMakePoint (0, 0)];
if (_superMenu && ![self isTornOff]) if (_superMenu && ![self isTornOff])
{ {
_superMenu->_attachedMenu = nil; _superMenu->_attachedMenu = nil;
[[_superMenu menuRepresentation] setHighlightedItemIndex: -1]; [[_superMenu menuRepresentation] setHighlightedItemIndex: -1];
} }
[_view update];
} }
- (void) closeTransient - (void) closeTransient