Menu handling fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5700 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-01-07 20:46:45 +00:00
parent 66353787d4
commit fb77d815b2
4 changed files with 110 additions and 42 deletions

View file

@ -1,3 +1,12 @@
Fri Jan 7 20:30:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSResponder.m: Changed _rightMouseDisplay to take the event
as a parameter.
* Source/NSMenu.m: Implemented ([-_rightMouseDisplay:]) with various
minor supporting changes.
* Source/NSMenuView.m: Lots of messing with mouse tracking in support
of right-mouse menu popup and somewhat smoother operation.
Fri Jan 7 18:09:15 2000 Nicola Pero <n.pero@mi.flashnet.it> Fri Jan 7 18:09:15 2000 Nicola Pero <n.pero@mi.flashnet.it>
* Headers/AppKit/NSBrowser.h: Fixed typo. * Headers/AppKit/NSBrowser.h: Fixed typo.

View file

@ -1016,9 +1016,11 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
[titleView _releaseCloseButton]; [titleView _releaseCloseButton];
} }
- (void) _rightMouseDisplay - (void) _rightMouseDisplay: (NSEvent*)theEvent
{ {
// TODO: implement this method. [self displayTransient];
[menu_view mouseDown: theEvent];
[self closeTransient];
} }
- (void) display - (void) display
@ -1085,12 +1087,27 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
menu_follow_transient = YES; menu_follow_transient = YES;
// Cache the old submenu if any. /*
* Cache the old submenu if any and query the supermenu our position.
* Otherwise, raise menu under the mouse.
*/
if (menu_supermenu != nil)
{
_oldAttachedMenu = menu_supermenu->menu_attachedMenu; _oldAttachedMenu = menu_supermenu->menu_attachedMenu;
menu_supermenu->menu_attachedMenu = self; menu_supermenu->menu_attachedMenu = self;
// Query the supermenu our position.
location = [menu_supermenu locationForSubmenu: self]; location = [menu_supermenu locationForSubmenu: self];
}
else
{
NSRect frame = [aWindow frame];
location = [aWindow mouseLocationOutsideOfEventStream];
location = [aWindow convertBaseToScreen: location];
location.x -= frame.size.width/2;
if (location.x < 0)
location.x = 0;
location.y -= frame.size.height - 10;
}
[bWindow setFrameOrigin: location]; [bWindow setFrameOrigin: location];
@ -1144,7 +1161,8 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
[[aWindow contentView] setNeedsDisplay: YES]; [[aWindow contentView] setNeedsDisplay: YES];
// Restore the old submenu. // Restore the old submenu (if any).
if (menu_supermenu != nil)
menu_supermenu->menu_attachedMenu = _oldAttachedMenu; menu_supermenu->menu_attachedMenu = _oldAttachedMenu;
menu_follow_transient = NO; menu_follow_transient = NO;
@ -1152,7 +1170,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
menu_isPartlyOffScreen = IS_OFFSCREEN(aWindow); menu_isPartlyOffScreen = IS_OFFSCREEN(aWindow);
} }
- (NSWindow *) window - (NSWindow*) window
{ {
if (menu_follow_transient) if (menu_follow_transient)
return (NSWindow *)bWindow; return (NSWindow *)bWindow;

View file

@ -709,15 +709,12 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
[targetMenuView setHighlightedItemIndex: -1]; [targetMenuView setHighlightedItemIndex: -1];
} }
#define MOVE_THRESHOLD_DELTA 1.0 #define MOVE_THRESHOLD_DELTA 2.0
#define DELAY_MULTIPLIER 6 #define DELAY_MULTIPLIER 6
- (BOOL) trackWithEvent: (NSEvent *)event - (BOOL) trackWithEvent: (NSEvent*)event
{ {
NSApplication *theApp = [NSApplication sharedApplication]; unsigned eventMask = NSPeriodicMask;
unsigned eventMask = NSLeftMouseUpMask
| NSLeftMouseDraggedMask
| NSPeriodicMask;
NSDate *theDistantFuture = [NSDate distantFuture]; NSDate *theDistantFuture = [NSDate distantFuture];
int index; int index;
NSPoint location; NSPoint location;
@ -728,6 +725,27 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
int delayCount = 0; int delayCount = 0;
float xDelta = MOVE_THRESHOLD_DELTA; float xDelta = MOVE_THRESHOLD_DELTA;
float yDelta = 0.0; float yDelta = 0.0;
NSEvent *original;
NSEventType type = [event type];
NSEventType end;
/*
* The original event is unused except to determine whether the method
* was invoked in response to a right or left mouse down.
* We pass the same event on when we want tracking to move into a
* submenu.
*/
original = AUTORELEASE(RETAIN(event));
if (type == NSRightMouseDown)
{
end = NSRightMouseUp;
eventMask |= NSRightMouseUpMask | NSRightMouseDraggedMask;
}
else
{
end = NSLeftMouseUp;
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
}
do do
{ {
@ -738,7 +756,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
{ {
mouseMoved = YES; /* Ok - had an initial movement. */ mouseMoved = YES; /* Ok - had an initial movement. */
} }
if ([event type] == NSPeriodic) if (type == NSPeriodic)
{ {
if ([menuv_menu isPartlyOffScreen]) if ([menuv_menu isPartlyOffScreen])
{ {
@ -781,7 +799,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
*/ */
delayCount++; delayCount++;
if (delayCount >= DELAY_MULTIPLIER if (delayCount >= DELAY_MULTIPLIER
|| (xDiff < -xDelta) || (xDiff < 0)
|| (yDelta < 0.0 && yDiff > -yDelta) || (yDelta < 0.0 && yDiff > -yDelta)
|| (yDelta > 0.0 && yDiff < -yDelta)) || (yDelta > 0.0 && yDiff < -yDelta))
{ {
@ -798,9 +816,26 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
if (index == -1) if (index == -1)
{ {
if ([menuv_menu attachedMenu]) NSWindow *w;
location = [window convertBaseToScreen: location];
/*
* If the mouse is back in the supermenu, we return NO so that
* our caller knows the button was not released.
*/
w = [[menuv_menu supermenu] window];
if (w != nil && NSMouseInRect(location, [w frame], NO) == YES)
{ {
if ([[self attachedMenuView] trackWithEvent: event]) return NO;
}
/*
* if the mouse is in our attached menu - get that menu to track it.
*/
w = [[menuv_menu attachedMenu] window];
if (w != nil && NSMouseInRect(location, [w frame], NO) == YES)
{
if ([[self attachedMenuView] trackWithEvent: original])
return YES; return YES;
} }
else else
@ -808,10 +843,11 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
if (index != menuv_highlightedItemIndex) if (index != menuv_highlightedItemIndex)
[self setHighlightedItemIndex: index]; [self setHighlightedItemIndex: index];
} }
#if 0
if (([menuv_menu supermenu] && ![menuv_menu isTornOff]) if (([menuv_menu supermenu] && ![menuv_menu isTornOff])
|| [menuv_menu isFollowTransient]) || [menuv_menu isFollowTransient])
return NO; return NO;
#endif
} }
else else
{ {
@ -841,12 +877,13 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
} }
} }
event = [theApp nextEventMatchingMask: eventMask event = [NSApp nextEventMatchingMask: eventMask
untilDate: theDistantFuture untilDate: theDistantFuture
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
dequeue: YES]; dequeue: YES];
type = [event type];
} }
while ([event type] != NSLeftMouseUp); while (type != end);
// Perform actions as needed. // Perform actions as needed.
if (index != -1 && !alreadyAttachedMenu) if (index != -1 && !alreadyAttachedMenu)
@ -883,7 +920,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;
@ -892,10 +929,12 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
menuv_keepAttachedMenus = YES; menuv_keepAttachedMenus = YES;
for (candidateMenu = masterMenu = menuv_menu; masterMenu = menuv_menu;
(candidateMenu = [masterMenu supermenu]) while ((candidateMenu = [masterMenu supermenu]) != nil
&& (![masterMenu isTornOff] || [masterMenu isFollowTransient]); && ([masterMenu isTornOff] == NO || [masterMenu isFollowTransient] == YES))
masterMenu = candidateMenu); {
masterMenu = candidateMenu;
}
originalLocation = [[masterMenu window] frame].origin; originalLocation = [[masterMenu window] frame].origin;

View file

@ -204,14 +204,16 @@
- (void) rightMouseDown: (NSEvent *)theEvent - (void) rightMouseDown: (NSEvent *)theEvent
{ {
if (next_responder) if (next_responder != nil)
{
return [next_responder rightMouseDown: theEvent]; return [next_responder rightMouseDown: theEvent];
}
else else
{ {
NSMenu *menu = [NSApp mainMenu]; NSMenu *menu = [NSApp mainMenu];
if (menu) if (menu != nil)
[menu _rightMouseDisplay]; [menu _rightMouseDisplay: theEvent];
else else
return [self noResponderFor: @selector(rightMouseDown:)]; return [self noResponderFor: @selector(rightMouseDown:)];
} }