From 5b6779a3a9264484271d07bc56775268b91171c0 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Mon, 23 Apr 2012 16:51:10 -0400 Subject: [PATCH 1/6] Fix for menu selection that was broken with the change to CPEvent timestamp --- AppKit/CPMenu/_CPMenuManager.j | 10 +++++----- Tests/Manual/CPMenuTest/AppController.j | 22 ++++++++-------------- Tests/Manual/CPMenuTest/MyView.j | 18 ------------------ 3 files changed, 13 insertions(+), 37 deletions(-) delete mode 100644 Tests/Manual/CPMenuTest/MyView.j diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index 9b680674a4..210c8b8b9a 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -126,8 +126,8 @@ var STICKY_TIME_INTERVAL = 0.5, } if (_keyBuffer) - { - if (([anEvent timestamp] - _startTime) > (STICKY_TIME_INTERVAL + [activeMenu numberOfItems] / 2)) + { // periodic events have a timestamp of 0 so use the currentTimestamp + if (([CPEvent currentTimestamp] - _startTime) > (STICKY_TIME_INTERVAL + [activeMenu numberOfItems] / 2)) [self selectNextItemBeginningWith:_keyBuffer inMenu:menu clearBuffer:YES]; if (type === CPPeriodic) @@ -245,7 +245,7 @@ var STICKY_TIME_INTERVAL = 0.5, 3. The user clicks, drags and then releases. Tracking ends. */ - if (_mouseWasDragged || ([anEvent timestamp] - _startTime > STICKY_TIME_INTERVAL)) + if (_mouseWasDragged || ([CPEvent currentTimestamp] - _startTime > STICKY_TIME_INTERVAL)) { /* Close the menu if: @@ -485,7 +485,7 @@ var STICKY_TIME_INTERVAL = 0.5, { if (!_keyBuffer) { - _startTime = [CPDate date]; + _startTime = [CPEvent currentTimestamp]; _keyBuffer = character; [CPEvent stopPeriodicEvents]; @@ -522,7 +522,7 @@ var STICKY_TIME_INTERVAL = 0.5, _keyBuffer = Nil; } else - _startTime = [CPDate date]; + _startTime = [CPEvent currentTimestamp]; } - (void)scrollToBeginningOfDocument:(CPMenu)menu diff --git a/Tests/Manual/CPMenuTest/AppController.j b/Tests/Manual/CPMenuTest/AppController.j index 3c2e43393d..09e1c15e94 100644 --- a/Tests/Manual/CPMenuTest/AppController.j +++ b/Tests/Manual/CPMenuTest/AppController.j @@ -1,14 +1,13 @@ /* * AppController.j - * CPMenuTest + * CPMenu * - * Created by Alexander Ljungberg on August 31, 2010. - * Copyright 2010, WireLoad, LLC All rights reserved. + * Created by Blair Duncan on April 23, 2012. + * Copyright 2012, SGL Studio, BBDO Toronto All rights reserved. */ @import -@import "MyView.j" @implementation AppController : CPObject { @@ -17,16 +16,10 @@ - (void)applicationDidFinishLaunching:(CPNotification)aNotification { var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], - contentView = [[MyView alloc] initWithFrame:CGRectMakeZero()]; + contentView = [theWindow contentView], + popupButton = [[CPPopUpButton alloc] initWithFrame:CGRectMakeZero()]; - [contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; - [theWindow setContentView:contentView]; - - var popupButton = [[CPPopUpButton alloc] initWithFrame:CGRectMakeZero()]; - - [popupButton addItemWithTitle:@"Item 1"]; - [popupButton addItemWithTitle:@"Item 2"]; - [popupButton addItemWithTitle:@"Item 3"]; + [popupButton addItemsWithTitles:[[CPFontManager sharedFontManager] availableFonts]]; [popupButton sizeToFit]; [popupButton setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; @@ -37,7 +30,8 @@ [theWindow orderFront:self]; // Uncomment the following line to turn on the standard menu bar. - [CPMenu setMenuBarVisible:YES]; + //[CPMenu setMenuBarVisible:YES]; } + @end diff --git a/Tests/Manual/CPMenuTest/MyView.j b/Tests/Manual/CPMenuTest/MyView.j deleted file mode 100644 index 0f2b01870d..0000000000 --- a/Tests/Manual/CPMenuTest/MyView.j +++ /dev/null @@ -1,18 +0,0 @@ -@import - -@implementation MyView : CPView -{ -} - -- (CPMenu)menu -{ - var menu = [[CPMenu alloc] initWithTitle:@""]; - - [menu addItemWithTitle:@"Item 1" action:nil keyEquivalent:nil]; - [menu addItemWithTitle:@"Item 2" action:nil keyEquivalent:nil]; - [menu addItemWithTitle:@"Item 3" action:nil keyEquivalent:nil]; - - return menu; -} - -@end \ No newline at end of file From 5b5034da6390069c1a4f9b4611e4646e4b7d4d63 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Mon, 23 Apr 2012 18:19:37 -0400 Subject: [PATCH 2/6] CPEvent - send a valid timestamp for periodic events --- AppKit/CPEvent.j | 2 +- AppKit/CPMenu/_CPMenuManager.j | 8 ++++---- Tests/Manual/CPMenuTest/AppController.j | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AppKit/CPEvent.j b/AppKit/CPEvent.j index 4f309e3503..a5fe949bd1 100644 --- a/AppKit/CPEvent.j +++ b/AppKit/CPEvent.j @@ -634,7 +634,7 @@ var _CPEventPeriodicEventPeriod = 0, function _CPEventFirePeriodEvent() { - [CPApp sendEvent:[CPEvent otherEventWithType:CPPeriodic location:_CGPointMakeZero() modifierFlags:0 timestamp:0 windowNumber:0 context:nil subtype:0 data1:0 data2:0]]; + [CPApp sendEvent:[CPEvent otherEventWithType:CPPeriodic location:_CGPointMakeZero() modifierFlags:0 timestamp:[CPEvent currentTimestamp] windowNumber:0 context:nil subtype:0 data1:0 data2:0]]; } var CPEventClass = [CPEvent class]; diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index 210c8b8b9a..00f5082748 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -126,8 +126,8 @@ var STICKY_TIME_INTERVAL = 0.5, } if (_keyBuffer) - { // periodic events have a timestamp of 0 so use the currentTimestamp - if (([CPEvent currentTimestamp] - _startTime) > (STICKY_TIME_INTERVAL + [activeMenu numberOfItems] / 2)) + { + if (([anEvent timestamp] - _startTime) > (STICKY_TIME_INTERVAL + [activeMenu numberOfItems] / 2)) [self selectNextItemBeginningWith:_keyBuffer inMenu:menu clearBuffer:YES]; if (type === CPPeriodic) @@ -245,7 +245,7 @@ var STICKY_TIME_INTERVAL = 0.5, 3. The user clicks, drags and then releases. Tracking ends. */ - if (_mouseWasDragged || ([CPEvent currentTimestamp] - _startTime > STICKY_TIME_INTERVAL)) + if (_mouseWasDragged || ([anEvent timestamp] - _startTime > STICKY_TIME_INTERVAL)) { /* Close the menu if: @@ -485,7 +485,7 @@ var STICKY_TIME_INTERVAL = 0.5, { if (!_keyBuffer) { - _startTime = [CPEvent currentTimestamp]; + _startTime = [anEvent timestamp]; _keyBuffer = character; [CPEvent stopPeriodicEvents]; diff --git a/Tests/Manual/CPMenuTest/AppController.j b/Tests/Manual/CPMenuTest/AppController.j index 09e1c15e94..0de3663f20 100644 --- a/Tests/Manual/CPMenuTest/AppController.j +++ b/Tests/Manual/CPMenuTest/AppController.j @@ -1,6 +1,6 @@ /* * AppController.j - * CPMenu + * CPMenuTest * * Created by Blair Duncan on April 23, 2012. * Copyright 2012, SGL Studio, BBDO Toronto All rights reserved. From 02ebb6e4f7067ea94ddf776347c9f8cd760b0506 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Mon, 23 Apr 2012 23:06:31 -0400 Subject: [PATCH 3/6] highlite menu item only if the active item was found --- AppKit/CPMenu/_CPMenuManager.j | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index 00f5082748..16554a4a5f 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -211,7 +211,8 @@ var STICKY_TIME_INTERVAL = 0.5, _lastMouseOverMenuView = nil; } - [activeMenu _highlightItemAtIndex:activeItemIndex]; + if (activeItemIndex != CPNotFound) + [activeMenu _highlightItemAtIndex:activeItemIndex]; if (type === CPMouseMoved || type === CPLeftMouseDragged || type === CPLeftMouseDown || type === CPPeriodic) { From 864db16e3395139e64f00c6f648682ca3ac7b060 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Mon, 23 Apr 2012 23:54:13 -0400 Subject: [PATCH 4/6] Fix for issue 1491, don't scroll if active menu container is menubar --- AppKit/CPMenu/_CPMenuManager.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index 16554a4a5f..dbf2249b34 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -161,7 +161,7 @@ var STICKY_TIME_INTERVAL = 0.5, var mouseOverMenuView = [activeItem view]; - if (type === CPScrollWheel) + if (type === CPScrollWheel ![activeMenuContainer isMenuBar]) [activeMenuContainer scrollByDelta:[anEvent deltaY]]; if (type === CPPeriodic) From d6429e532bce98bfca133ab4c70777529865c236 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Tue, 24 Apr 2012 00:02:12 -0400 Subject: [PATCH 5/6] typo fix --- AppKit/CPMenu/_CPMenuManager.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index dbf2249b34..e78b084750 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -161,7 +161,7 @@ var STICKY_TIME_INTERVAL = 0.5, var mouseOverMenuView = [activeItem view]; - if (type === CPScrollWheel ![activeMenuContainer isMenuBar]) + if (type === CPScrollWheel && ![activeMenuContainer isMenuBar]) [activeMenuContainer scrollByDelta:[anEvent deltaY]]; if (type === CPPeriodic) From eeceaa0c9b5a475b4a2cc1d6eed6637c6f6158d3 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Fri, 1 Jun 2012 20:17:09 -0400 Subject: [PATCH 6/6] unlite if mouse is moved off and cursor up hilites last item if none --- AppKit/CPMenu/_CPMenuManager.j | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index e78b084750..d8a92c39c5 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -137,10 +137,7 @@ var STICKY_TIME_INTERVAL = 0.5, // Periodic events don't have a valid location. var globalLocation = type === CPPeriodic ? _lastGlobalLocation : [anEvent globalLocation]; - // Remember this for the next periodic event. - _lastGlobalLocation = globalLocation; - - if (!_lastGlobalLocation) + if (!globalLocation) return; // Find which menu window the mouse is currently on top of @@ -152,6 +149,14 @@ var STICKY_TIME_INTERVAL = 0.5, activeItemIndex = activeMenuContainer ? [activeMenuContainer itemIndexAtPoint:menuLocation] : CPNotFound, activeItem = activeItemIndex !== CPNotFound ? [activeMenu itemAtIndex:activeItemIndex] : nil; + // unhighlight when mouse is moved off the menu + if (_lastGlobalLocation && CGRectContainsPoint([activeMenuContainer globalFrame], _lastGlobalLocation) + && !CGRectContainsPoint([activeMenuContainer globalFrame], globalLocation)) + [activeMenu _highlightItemAtIndex:CPNotFound]; + + // Remember this for the next periodic event. + _lastGlobalLocation = globalLocation; + // If the item isn't enabled its as if we clicked on nothing. if (![activeItem isEnabled] || [activeItem _isMenuBarButton]) { @@ -667,8 +672,11 @@ var STICKY_TIME_INTERVAL = 0.5, var index = menu._highlightedIndex - 1; if (index < 0) + { + if (index != CPNotFound) + [menu _highlightItemAtIndex:[menu numberOfItems] - 1]; return; - + } [menu _highlightItemAtIndex:index]; var item = [menu highlightedItem];