mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 00:30:49 +00:00
Started rewrite that simplifies menu tracking code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33926 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0de761d88e
commit
db54238627
2 changed files with 50 additions and 34 deletions
|
@ -1,6 +1,11 @@
|
||||||
2011-10-01 Fred Kiefer <FredKiefer@gmx.de>
|
2011-10-01 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/GSThemeMenu.m,
|
* Source/NSMenuView.m (-_trackWithEvent:startingMenuView:,
|
||||||
|
-trackWithEvent:): Started rewrite that simplifies menu tracking code.
|
||||||
|
|
||||||
|
2011-10-01 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSMenuView.m,
|
||||||
* Source/GSThemeMenu.m,
|
* Source/GSThemeMenu.m,
|
||||||
* Source/GSWindowDecorationView.m: Rewrite of the in-window menu handling.
|
* Source/GSWindowDecorationView.m: Rewrite of the in-window menu handling.
|
||||||
|
|
||||||
|
|
|
@ -1413,13 +1413,6 @@ static NSMapTable *viewInfo = 0;
|
||||||
NSInterfaceStyle style =
|
NSInterfaceStyle style =
|
||||||
NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self);
|
NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self);
|
||||||
|
|
||||||
/*If we have menu in window, close the menu after select
|
|
||||||
an option*/
|
|
||||||
if (style == NSWindows95InterfaceStyle)
|
|
||||||
{
|
|
||||||
[[[[NSApp mainWindow] menu] attachedMenu] close];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexOfActionToExecute >= 0
|
if (indexOfActionToExecute >= 0
|
||||||
&& [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
|
&& [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
|
||||||
[[_items_link objectAtIndex: indexOfActionToExecute] submenu])
|
[[_items_link objectAtIndex: indexOfActionToExecute] submenu])
|
||||||
|
@ -1450,6 +1443,7 @@ static NSMapTable *viewInfo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) _trackWithEvent: (NSEvent*)event
|
- (BOOL) _trackWithEvent: (NSEvent*)event
|
||||||
|
startingMenuView: (NSMenuView*)mainWindowMenuView
|
||||||
{
|
{
|
||||||
unsigned eventMask = NSPeriodicMask;
|
unsigned eventMask = NSPeriodicMask;
|
||||||
NSDate *theDistantFuture = [NSDate distantFuture];
|
NSDate *theDistantFuture = [NSDate distantFuture];
|
||||||
|
@ -1525,13 +1519,12 @@ static NSMapTable *viewInfo = 0;
|
||||||
}
|
}
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/*Close the menu if the user press a modifier key and menu
|
/* Close the menu if the user press a modifier key and menu
|
||||||
is in a window*/
|
is in a window */
|
||||||
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) ==
|
if (mainWindowMenuView != nil && type == NSFlagsChanged)
|
||||||
NSWindows95InterfaceStyle && type == NSFlagsChanged)
|
|
||||||
{
|
{
|
||||||
[self setHighlightedItemIndex: -1];
|
[self setHighlightedItemIndex: -1];
|
||||||
[[[[NSApp mainWindow] menu] attachedMenu] close];
|
[[[mainWindowMenuView menu] attachedMenu] close];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1541,6 +1534,7 @@ static NSMapTable *viewInfo = 0;
|
||||||
{
|
{
|
||||||
shouldFinish = YES;
|
shouldFinish = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == NSPeriodic || event == original)
|
if (type == NSPeriodic || event == original)
|
||||||
{
|
{
|
||||||
NSPoint location;
|
NSPoint location;
|
||||||
|
@ -1578,7 +1572,6 @@ static NSMapTable *viewInfo = 0;
|
||||||
[_attachedMenu shiftOnScreen];
|
[_attachedMenu shiftOnScreen];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 2 - Check if we have to reset the justAttachedNewSubmenu
|
* 2 - Check if we have to reset the justAttachedNewSubmenu
|
||||||
* flag to NO.
|
* flag to NO.
|
||||||
|
@ -1636,22 +1629,22 @@ static NSMapTable *viewInfo = 0;
|
||||||
&& NSMouseInRect (locationInScreenCoordinates,
|
&& NSMouseInRect (locationInScreenCoordinates,
|
||||||
[[candidateMenu window] frame], NO))
|
[[candidateMenu window] frame], NO))
|
||||||
{
|
{
|
||||||
BOOL candidateMenuResult;
|
BOOL candidateMenuResult;
|
||||||
|
NSMenuView *subMenuView = [[candidateMenu attachedMenu] menuRepresentation];
|
||||||
|
|
||||||
// The call to fetch attachedMenu is not needed. But putting
|
// The call to fetch attachedMenu is not needed. But putting
|
||||||
// it here avoids flicker when we go back to an ancestor
|
// it here avoids flicker when we go back to an ancestor
|
||||||
// menu and the attached menu is already correct.
|
// menu and the attached menu is already correct.
|
||||||
[[[candidateMenu attachedMenu] menuRepresentation]
|
[subMenuView detachSubmenu];
|
||||||
detachSubmenu];
|
|
||||||
|
|
||||||
// Reset highlighted index for this menu.
|
// Reset highlighted index for this menu.
|
||||||
// This way if we return to this submenu later there
|
// This way if we return to this submenu later there
|
||||||
// won't be a highlighted item.
|
// won't be a highlighted item.
|
||||||
[[[candidateMenu attachedMenu] menuRepresentation]
|
[subMenuView setHighlightedItemIndex: -1];
|
||||||
setHighlightedItemIndex: -1];
|
|
||||||
|
|
||||||
candidateMenuResult = [[candidateMenu menuRepresentation]
|
candidateMenuResult = [[candidateMenu menuRepresentation]
|
||||||
_trackWithEvent: original];
|
_trackWithEvent: original
|
||||||
|
startingMenuView: mainWindowMenuView];
|
||||||
return candidateMenuResult;
|
return candidateMenuResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1665,7 +1658,8 @@ static NSMapTable *viewInfo = 0;
|
||||||
BOOL subMenuResult;
|
BOOL subMenuResult;
|
||||||
|
|
||||||
subMenuResult
|
subMenuResult
|
||||||
= [[self attachedMenuView] _trackWithEvent: original];
|
= [[self attachedMenuView] _trackWithEvent: original
|
||||||
|
startingMenuView: mainWindowMenuView];
|
||||||
if (subMenuResult
|
if (subMenuResult
|
||||||
&& wasTransient == [_attachedMenu isTransient])
|
&& wasTransient == [_attachedMenu isTransient])
|
||||||
{
|
{
|
||||||
|
@ -1674,18 +1668,13 @@ static NSMapTable *viewInfo = 0;
|
||||||
return subMenuResult;
|
return subMenuResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*We track the menu correctly when this is located
|
/* We track the menu correctly when this is located
|
||||||
in a window*/
|
in a window */
|
||||||
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) ==
|
if (mainWindowMenuView != nil)
|
||||||
NSWindows95InterfaceStyle &&
|
|
||||||
![[self menu] isTransient] &&
|
|
||||||
![[self menu] _ownedByPopUp])
|
|
||||||
{
|
{
|
||||||
// If the user moves the mouse into the main window
|
// If the user moves the mouse into the main window
|
||||||
// horizontal menu, start tracking again.
|
// horizontal menu, start tracking again.
|
||||||
NSWindow *mainWindow = [NSApp mainWindow];
|
NSWindow *mainWindow = [mainWindowMenuView window];
|
||||||
NSMenuView *mainWindowMenuView = [[mainWindow menu]
|
|
||||||
menuRepresentation];
|
|
||||||
NSPoint locationInMainWindow = [mainWindow
|
NSPoint locationInMainWindow = [mainWindow
|
||||||
convertScreenToBase: locationInScreenCoordinates];
|
convertScreenToBase: locationInScreenCoordinates];
|
||||||
if ([mainWindowMenuView
|
if ([mainWindowMenuView
|
||||||
|
@ -1700,7 +1689,8 @@ static NSMapTable *viewInfo = 0;
|
||||||
{
|
{
|
||||||
[self setHighlightedItemIndex: -1];
|
[self setHighlightedItemIndex: -1];
|
||||||
return [mainWindowMenuView
|
return [mainWindowMenuView
|
||||||
_trackWithEvent: original];
|
_trackWithEvent: original
|
||||||
|
startingMenuView: mainWindowMenuView];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1809,8 +1799,19 @@ static NSMapTable *viewInfo = 0;
|
||||||
// Before executing the action, uncapture the mouse
|
// Before executing the action, uncapture the mouse
|
||||||
[_window _releaseMouse: self];
|
[_window _releaseMouse: self];
|
||||||
|
|
||||||
if([self _executeItemAtIndex: indexOfActionToExecute
|
/* If we have menu in window, close the menu after select
|
||||||
removeSubmenu: subMenusNeedRemoving] == NO)
|
an option */
|
||||||
|
if (mainWindowMenuView != nil)
|
||||||
|
{
|
||||||
|
if (self != mainWindowMenuView)
|
||||||
|
{
|
||||||
|
[mainWindowMenuView setHighlightedItemIndex: -1];
|
||||||
|
}
|
||||||
|
[[[mainWindowMenuView menu] attachedMenu] close];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([self _executeItemAtIndex: indexOfActionToExecute
|
||||||
|
removeSubmenu: subMenusNeedRemoving] == NO)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -1833,12 +1834,22 @@ static NSMapTable *viewInfo = 0;
|
||||||
- (BOOL) trackWithEvent: (NSEvent*)event
|
- (BOOL) trackWithEvent: (NSEvent*)event
|
||||||
{
|
{
|
||||||
BOOL result = NO;
|
BOOL result = NO;
|
||||||
|
NSMenuView *mainWindowMenuView = nil;
|
||||||
|
|
||||||
|
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) ==
|
||||||
|
NSWindows95InterfaceStyle &&
|
||||||
|
![[self menu] isTransient] &&
|
||||||
|
![[self menu] _ownedByPopUp])
|
||||||
|
{
|
||||||
|
mainWindowMenuView = self;
|
||||||
|
}
|
||||||
|
|
||||||
// Capture the mouse so we get clicks outside the menus and
|
// Capture the mouse so we get clicks outside the menus and
|
||||||
// GNUstep windows.
|
// GNUstep windows.
|
||||||
[_window _captureMouse: self];
|
[_window _captureMouse: self];
|
||||||
NS_DURING
|
NS_DURING
|
||||||
result = [self _trackWithEvent: event];
|
result = [self _trackWithEvent: event
|
||||||
|
startingMenuView: mainWindowMenuView];
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
[_window _releaseMouse: self];
|
[_window _releaseMouse: self];
|
||||||
[localException raise];
|
[localException raise];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue