mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 08:41:00 +00:00
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:
parent
8f4d3d0c16
commit
99c7295ae9
2 changed files with 44 additions and 14 deletions
|
@ -5,6 +5,9 @@
|
||||||
* Source/NSMenuItemCell.m:
|
* Source/NSMenuItemCell.m:
|
||||||
* Headers/AppKit/NSMenuItemCell.h:
|
* Headers/AppKit/NSMenuItemCell.h:
|
||||||
Tidyups suggested by Fred. More ideas welcome.
|
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>
|
2006-02-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -1181,8 +1181,10 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
NSPoint lastLocation = {0,0};
|
NSPoint lastLocation = {0,0};
|
||||||
BOOL justAttachedNewSubmenu = NO;
|
BOOL justAttachedNewSubmenu = NO;
|
||||||
BOOL subMenusNeedRemoving = YES;
|
BOOL subMenusNeedRemoving = YES;
|
||||||
|
BOOL shouldFinish = YES;
|
||||||
int delayCount = 0;
|
int delayCount = 0;
|
||||||
int indexOfActionToExecute = -1;
|
int indexOfActionToExecute = -1;
|
||||||
|
int firstIndex = -1;
|
||||||
NSEvent *original;
|
NSEvent *original;
|
||||||
NSEventType type;
|
NSEventType type;
|
||||||
NSEventType end;
|
NSEventType end;
|
||||||
|
@ -1201,26 +1203,41 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
{
|
{
|
||||||
end = NSRightMouseUp;
|
end = NSRightMouseUp;
|
||||||
eventMask |= NSRightMouseUpMask | NSRightMouseDraggedMask;
|
eventMask |= NSRightMouseUpMask | NSRightMouseDraggedMask;
|
||||||
|
eventMask |= NSRightMouseDownMask;
|
||||||
}
|
}
|
||||||
else if (type == NSOtherMouseDown || type == NSOtherMouseDragged)
|
else if (type == NSOtherMouseDown || type == NSOtherMouseDragged)
|
||||||
{
|
{
|
||||||
end = NSOtherMouseUp;
|
end = NSOtherMouseUp;
|
||||||
eventMask |= NSOtherMouseUpMask | NSOtherMouseDraggedMask;
|
eventMask |= NSOtherMouseUpMask | NSOtherMouseDraggedMask;
|
||||||
|
eventMask |= NSOtherMouseDownMask;
|
||||||
}
|
}
|
||||||
else if (type == NSLeftMouseDown || type == NSLeftMouseDragged)
|
else if (type == NSLeftMouseDown || type == NSLeftMouseDragged)
|
||||||
{
|
{
|
||||||
end = NSLeftMouseUp;
|
end = NSLeftMouseUp;
|
||||||
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
||||||
|
eventMask |= NSLeftMouseDownMask;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSLog (@"Unexpected event: %d during event tracking in NSMenuView", type);
|
NSLog (@"Unexpected event: %d during event tracking in NSMenuView", type);
|
||||||
end = NSLeftMouseUp;
|
end = NSLeftMouseUp;
|
||||||
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
||||||
|
eventMask |= NSLeftMouseDownMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([self isHorizontal] == YES)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Ignore the first mouse up if nothing interesting has happened.
|
||||||
|
*/
|
||||||
|
shouldFinish = NO;
|
||||||
|
}
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
if (type == end)
|
||||||
|
{
|
||||||
|
shouldFinish = YES;
|
||||||
|
}
|
||||||
if (type == NSPeriodic || event == original)
|
if (type == NSPeriodic || event == original)
|
||||||
{
|
{
|
||||||
NSPoint location;
|
NSPoint location;
|
||||||
|
@ -1229,6 +1246,15 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
location = [_window mouseLocationOutsideOfEventStream];
|
location = [_window mouseLocationOutsideOfEventStream];
|
||||||
index = [self indexOfItemAtPoint: location];
|
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
|
* 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.
|
||||||
|
@ -1242,8 +1268,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
* GNUstep screen coordinates start with 1.
|
* GNUstep screen coordinates start with 1.
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
[_attachedMenu shiftOnScreen];
|
[_attachedMenu shiftOnScreen];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1253,7 +1279,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
* flag to NO.
|
* flag to NO.
|
||||||
*/
|
*/
|
||||||
if (justAttachedNewSubmenu && index != -1
|
if (justAttachedNewSubmenu && index != -1
|
||||||
&& index != _highlightedItemIndex)
|
&& index != _highlightedItemIndex)
|
||||||
{
|
{
|
||||||
if (location.x - lastLocation.x > MOVE_THRESHOLD_DELTA)
|
if (location.x - lastLocation.x > MOVE_THRESHOLD_DELTA)
|
||||||
{
|
{
|
||||||
|
@ -1292,19 +1318,18 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
*/
|
*/
|
||||||
candidateMenu = [_attachedMenu supermenu];
|
candidateMenu = [_attachedMenu supermenu];
|
||||||
while (candidateMenu
|
while (candidateMenu
|
||||||
&& !NSMouseInRect (locationInScreenCoordinates,
|
&& !NSMouseInRect (locationInScreenCoordinates,
|
||||||
[[candidateMenu window] frame],
|
[[candidateMenu window] frame], NO) // not found yet
|
||||||
NO) // not found yet
|
&& (! ([candidateMenu isTornOff]
|
||||||
&& (! ([candidateMenu isTornOff]
|
&& ![candidateMenu isTransient])) // no root of display tree
|
||||||
&& ![candidateMenu isTransient])) // no root of display tree
|
&& [candidateMenu isAttached]) // has displayed parent
|
||||||
&& [candidateMenu isAttached]) // has displayed parent
|
|
||||||
{
|
{
|
||||||
candidateMenu = [candidateMenu supermenu];
|
candidateMenu = [candidateMenu supermenu];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidateMenu != nil
|
if (candidateMenu != nil
|
||||||
&& NSMouseInRect (locationInScreenCoordinates,
|
&& NSMouseInRect (locationInScreenCoordinates,
|
||||||
[[candidateMenu window] frame], NO))
|
[[candidateMenu window] frame], NO))
|
||||||
{
|
{
|
||||||
BOOL candidateMenuResult;
|
BOOL candidateMenuResult;
|
||||||
|
|
||||||
|
@ -1328,8 +1353,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
// 3b - Check if we enter the attached submenu
|
// 3b - Check if we enter the attached submenu
|
||||||
windowUnderMouse = [[_attachedMenu attachedMenu] window];
|
windowUnderMouse = [[_attachedMenu attachedMenu] window];
|
||||||
if (windowUnderMouse != nil
|
if (windowUnderMouse != nil
|
||||||
&& NSMouseInRect (locationInScreenCoordinates,
|
&& NSMouseInRect (locationInScreenCoordinates,
|
||||||
[windowUnderMouse frame], NO))
|
[windowUnderMouse frame], NO))
|
||||||
{
|
{
|
||||||
BOOL wasTransient = [_attachedMenu isTransient];
|
BOOL wasTransient = [_attachedMenu isTransient];
|
||||||
BOOL subMenuResult;
|
BOOL subMenuResult;
|
||||||
|
@ -1371,7 +1396,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
dequeue: YES];
|
dequeue: YES];
|
||||||
type = [event type];
|
type = [event type];
|
||||||
}
|
}
|
||||||
while (type != end);
|
while (type != end || shouldFinish == NO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ok, we released the mouse
|
* Ok, we released the mouse
|
||||||
|
@ -1439,6 +1464,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
&& [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
|
&& [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
|
||||||
[[_items_link objectAtIndex: indexOfActionToExecute] submenu])
|
[[_items_link objectAtIndex: indexOfActionToExecute] submenu])
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self)
|
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self)
|
||||||
== NSMacintoshInterfaceStyle)
|
== NSMacintoshInterfaceStyle)
|
||||||
{
|
{
|
||||||
|
@ -1449,6 +1475,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
||||||
*/
|
*/
|
||||||
subMenusNeedRemoving = YES;
|
subMenusNeedRemoving = YES;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (subMenusNeedRemoving)
|
if (subMenusNeedRemoving)
|
||||||
{
|
{
|
||||||
[self detachSubmenu];
|
[self detachSubmenu];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue