Attempt to implement MacOS-X mouse tracking behavior for horizontal menu.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22434 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-02-05 19:42:15 +00:00
parent 8f4d3d0c16
commit 99c7295ae9
2 changed files with 44 additions and 14 deletions

View file

@ -5,6 +5,9 @@
* Source/NSMenuItemCell.m:
* Headers/AppKit/NSMenuItemCell.h:
Tidyups suggested by Fred. More ideas welcome.
* Source/NSMenuView.m: When tracking mouse for horizontal MacOS-X
style menu, ignore an immediate mouse up and continue tracking until
something is clicked on. This is the behavior of MacOS-X and windows.
2006-02-04 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -1181,8 +1181,10 @@ _addLeftBorderOffsetToRect(NSRect aRect)
NSPoint lastLocation = {0,0};
BOOL justAttachedNewSubmenu = NO;
BOOL subMenusNeedRemoving = YES;
BOOL shouldFinish = YES;
int delayCount = 0;
int indexOfActionToExecute = -1;
int firstIndex = -1;
NSEvent *original;
NSEventType type;
NSEventType end;
@ -1201,26 +1203,41 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
end = NSRightMouseUp;
eventMask |= NSRightMouseUpMask | NSRightMouseDraggedMask;
eventMask |= NSRightMouseDownMask;
}
else if (type == NSOtherMouseDown || type == NSOtherMouseDragged)
{
end = NSOtherMouseUp;
eventMask |= NSOtherMouseUpMask | NSOtherMouseDraggedMask;
eventMask |= NSOtherMouseDownMask;
}
else if (type == NSLeftMouseDown || type == NSLeftMouseDragged)
{
end = NSLeftMouseUp;
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
eventMask |= NSLeftMouseDownMask;
}
else
{
NSLog (@"Unexpected event: %d during event tracking in NSMenuView", type);
end = NSLeftMouseUp;
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
eventMask |= NSLeftMouseDownMask;
}
if ([self isHorizontal] == YES)
{
/*
* Ignore the first mouse up if nothing interesting has happened.
*/
shouldFinish = NO;
}
do
{
if (type == end)
{
shouldFinish = YES;
}
if (type == NSPeriodic || event == original)
{
NSPoint location;
@ -1229,6 +1246,15 @@ _addLeftBorderOffsetToRect(NSRect aRect)
location = [_window mouseLocationOutsideOfEventStream];
index = [self indexOfItemAtPoint: location];
if (event == original)
{
firstIndex = index;
}
if (index != firstIndex)
{
shouldFinish = YES;
}
/*
* 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.
@ -1293,8 +1319,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
candidateMenu = [_attachedMenu supermenu];
while (candidateMenu
&& !NSMouseInRect (locationInScreenCoordinates,
[[candidateMenu window] frame],
NO) // not found yet
[[candidateMenu window] frame], NO) // not found yet
&& (! ([candidateMenu isTornOff]
&& ![candidateMenu isTransient])) // no root of display tree
&& [candidateMenu isAttached]) // has displayed parent
@ -1371,7 +1396,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
dequeue: YES];
type = [event type];
}
while (type != end);
while (type != end || shouldFinish == NO);
/*
* Ok, we released the mouse
@ -1439,6 +1464,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
&& [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
[[_items_link objectAtIndex: indexOfActionToExecute] submenu])
{
#if 1
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self)
== NSMacintoshInterfaceStyle)
{
@ -1449,6 +1475,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
*/
subMenusNeedRemoving = YES;
}
#endif
if (subMenusNeedRemoving)
{
[self detachSubmenu];