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 9b680674a4..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]) { @@ -161,7 +166,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) @@ -211,7 +216,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) { @@ -485,7 +491,7 @@ var STICKY_TIME_INTERVAL = 0.5, { if (!_keyBuffer) { - _startTime = [CPDate date]; + _startTime = [anEvent timestamp]; _keyBuffer = character; [CPEvent stopPeriodicEvents]; @@ -522,7 +528,7 @@ var STICKY_TIME_INTERVAL = 0.5, _keyBuffer = Nil; } else - _startTime = [CPDate date]; + _startTime = [CPEvent currentTimestamp]; } - (void)scrollToBeginningOfDocument:(CPMenu)menu @@ -666,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]; diff --git a/Tests/Manual/CPMenuTest/AppController.j b/Tests/Manual/CPMenuTest/AppController.j index 3c2e43393d..0de3663f20 100644 --- a/Tests/Manual/CPMenuTest/AppController.j +++ b/Tests/Manual/CPMenuTest/AppController.j @@ -2,13 +2,12 @@ * AppController.j * CPMenuTest * - * 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