Merge pull request #1513 from BlairDuncan/MenuTimestampFix

Fix for menu selection that was broken with the change to CPEvent timestamp
This commit is contained in:
Antoine Mercadal
2012-06-14 17:02:06 -07:00
4 changed files with 26 additions and 41 deletions
+1 -1
View File
@@ -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];
+18 -9
View File
@@ -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];
+7 -13
View File
@@ -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
{
@@ -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
-18
View File
@@ -1,18 +0,0 @@
@import <AppKit/CPView.j>
@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