Skip to content

Commit

Permalink
Merge pull request #1513 from BlairDuncan/MenuTimestampFix
Browse files Browse the repository at this point in the history
Fix for menu selection that was broken with the change to CPEvent timestamp
  • Loading branch information
primalmotion committed Jun 15, 2012
2 parents 714d36d + eeceaa0 commit 0d29f15
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 41 deletions.
2 changes: 1 addition & 1 deletion AppKit/CPEvent.j
Expand Up @@ -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];
Expand Down
27 changes: 18 additions & 9 deletions AppKit/CPMenu/_CPMenuManager.j
Expand Up @@ -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
Expand All @@ -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])
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -485,7 +491,7 @@ var STICKY_TIME_INTERVAL = 0.5,
{
if (!_keyBuffer)
{
_startTime = [CPDate date];
_startTime = [anEvent timestamp];
_keyBuffer = character;

[CPEvent stopPeriodicEvents];
Expand Down Expand Up @@ -522,7 +528,7 @@ var STICKY_TIME_INTERVAL = 0.5,
_keyBuffer = Nil;
}
else
_startTime = [CPDate date];
_startTime = [CPEvent currentTimestamp];
}

- (void)scrollToBeginningOfDocument:(CPMenu)menu
Expand Down Expand Up @@ -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];
Expand Down
20 changes: 7 additions & 13 deletions Tests/Manual/CPMenuTest/AppController.j
Expand Up @@ -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 <Foundation/CPObject.j>

@import "MyView.j"

@implementation AppController : CPObject
{
Expand All @@ -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];
Expand All @@ -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
18 changes: 0 additions & 18 deletions Tests/Manual/CPMenuTest/MyView.j

This file was deleted.

0 comments on commit 0d29f15

Please sign in to comment.