mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Event updates
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4372 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7a0c72a800
commit
39037c2c7f
5 changed files with 574 additions and 258 deletions
|
@ -1,3 +1,12 @@
|
|||
Sun Jun 6 20:40:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Headers/AppKit/NSEvent.h: Added new event types and masks and tidied.
|
||||
* Headers/AppKit/NSGraphicsContext.h: Added event queue ivar
|
||||
* Source/NSEvent.m: Rewrite to add new event types, optimise, and
|
||||
generate all the exceptions it should.
|
||||
* Source/NSGraphicsContext.m: Incorporate event handling code from
|
||||
backend libraries.
|
||||
|
||||
Sun Jun 6 9:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSScrollView.m: tidyup
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
The event class
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
Copyright (C) 1996,1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
@ -37,6 +37,10 @@
|
|||
@class NSWindow;
|
||||
@class NSGraphicsContext;
|
||||
|
||||
/*
|
||||
* Enumerated type for events - order IS significant as ranges of values
|
||||
* are used for testing for valid event types.
|
||||
*/
|
||||
typedef enum _NSEventType {
|
||||
NSLeftMouseDown,
|
||||
NSLeftMouseUp,
|
||||
|
@ -50,27 +54,32 @@ typedef enum _NSEventType {
|
|||
NSKeyDown,
|
||||
NSKeyUp,
|
||||
NSFlagsChanged,
|
||||
NSAppKitDefined,
|
||||
NSSystemDefined,
|
||||
NSApplicationDefined,
|
||||
NSPeriodic,
|
||||
NSCursorUpdate
|
||||
} NSEventType;
|
||||
|
||||
enum {
|
||||
NSLeftMouseDownMask = 1,
|
||||
NSLeftMouseUpMask = 2,
|
||||
NSRightMouseDownMask = 4,
|
||||
NSRightMouseUpMask = 8,
|
||||
NSMouseMovedMask = 16,
|
||||
NSLeftMouseDraggedMask = 32,
|
||||
NSRightMouseDraggedMask = 64,
|
||||
NSMouseEnteredMask = 128,
|
||||
NSMouseExitedMask = 256,
|
||||
NSKeyDownMask = 512,
|
||||
NSKeyUpMask = 1024,
|
||||
NSFlagsChangedMask = 2048,
|
||||
NSPeriodicMask = 4096,
|
||||
NSCursorUpdateMask = 8192,
|
||||
// Note that NSAnyEventMask is an OR-combination of all other event masks
|
||||
NSAnyEventMask = 16383
|
||||
NSLeftMouseDownMask = (1 << NSLeftMouseDown),
|
||||
NSLeftMouseUpMask = (1 << NSLeftMouseUp),
|
||||
NSRightMouseDownMask = (1 << NSRightMouseDown),
|
||||
NSRightMouseUpMask = (1 << NSRightMouseUp),
|
||||
NSMouseMovedMask = (1 << NSMouseMoved),
|
||||
NSLeftMouseDraggedMask = (1 << NSLeftMouseDragged),
|
||||
NSRightMouseDraggedMask = (1 << NSRightMouseDragged),
|
||||
NSMouseEnteredMask = (1 << NSMouseEntered),
|
||||
NSMouseExitedMask = (1 << NSMouseExited),
|
||||
NSKeyDownMask = (1 << NSKeyDown),
|
||||
NSKeyUpMask = (1 << NSKeyUp),
|
||||
NSFlagsChangedMask = (1 << NSFlagsChanged),
|
||||
NSAppKitDefinedMask = (1 << NSAppKitDefined),
|
||||
NSSystemDefinedMask = (1 << NSSystemDefined),
|
||||
NSApplicationDefinedMask = (1 << NSApplicationDefined),
|
||||
NSPeriodicMask = (1 << NSPeriodic),
|
||||
NSCursorUpdateMask = (1 << NSCursorUpdate),
|
||||
NSAnyEventMask = 0xffffffff
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -86,139 +95,138 @@ enum {
|
|||
|
||||
@interface NSEvent : NSObject <NSCoding>
|
||||
{
|
||||
// Attributes
|
||||
NSEventType event_type;
|
||||
NSPoint location_point;
|
||||
unsigned int modifier_flags;
|
||||
NSTimeInterval event_time;
|
||||
int window_num;
|
||||
NSGraphicsContext*event_context;
|
||||
NSEventType event_type;
|
||||
NSPoint location_point;
|
||||
unsigned int modifier_flags;
|
||||
NSTimeInterval event_time;
|
||||
int window_num;
|
||||
NSGraphicsContext *event_context;
|
||||
union _MB_event_data
|
||||
{
|
||||
struct
|
||||
{
|
||||
int event_num;
|
||||
int click;
|
||||
float pressure;
|
||||
} mouse;
|
||||
{
|
||||
struct
|
||||
{
|
||||
BOOL repeat;
|
||||
NSString *char_keys;
|
||||
NSString *unmodified_keys;
|
||||
int event_num;
|
||||
int click;
|
||||
float pressure;
|
||||
} mouse;
|
||||
struct
|
||||
{
|
||||
BOOL repeat;
|
||||
NSString *char_keys;
|
||||
NSString *unmodified_keys;
|
||||
unsigned short key_code;
|
||||
} key;
|
||||
struct
|
||||
{
|
||||
int event_num;
|
||||
int tracking_num;
|
||||
void *user_data;
|
||||
} tracking;
|
||||
struct
|
||||
{
|
||||
short sub_type;
|
||||
int data1;
|
||||
int data2;
|
||||
} misc;
|
||||
} event_data;
|
||||
struct
|
||||
{
|
||||
int event_num;
|
||||
int tracking_num;
|
||||
void *user_data;
|
||||
} tracking;
|
||||
struct
|
||||
{
|
||||
short sub_type;
|
||||
int data1;
|
||||
int data2;
|
||||
} misc;
|
||||
} event_data;
|
||||
}
|
||||
|
||||
//
|
||||
// Creating NSEvent objects
|
||||
//
|
||||
/*
|
||||
* Creating NSEvent objects
|
||||
*/
|
||||
|
||||
+ (NSEvent *)enterExitEventWithType:(NSEventType)type
|
||||
location:(NSPoint)location
|
||||
modifierFlags:(unsigned int)flags
|
||||
timestamp:(NSTimeInterval)time
|
||||
windowNumber:(int)windowNum
|
||||
context:(NSGraphicsContext*)context
|
||||
eventNumber:(int)eventNum
|
||||
trackingNumber:(int)trackingNum
|
||||
userData:(void *)userData;
|
||||
+ (NSEvent*) enterExitEventWithType: (NSEventType)type
|
||||
location: (NSPoint)location
|
||||
modifierFlags: (unsigned int)flags
|
||||
timestamp: (NSTimeInterval)time
|
||||
windowNumber: (int)windowNum
|
||||
context: (NSGraphicsContext*)context
|
||||
eventNumber: (int)eventNum
|
||||
trackingNumber: (int)trackingNum
|
||||
userData: (void *)userData;
|
||||
|
||||
+ (NSEvent *)keyEventWithType:(NSEventType)type
|
||||
location:(NSPoint)location
|
||||
modifierFlags:(unsigned int)flags
|
||||
timestamp:(NSTimeInterval)time
|
||||
windowNumber:(int)windowNum
|
||||
context:(NSGraphicsContext*)context
|
||||
characters:(NSString *)keys
|
||||
charactersIgnoringModifiers:(NSString *)ukeys
|
||||
isARepeat:(BOOL)repeatKey
|
||||
keyCode:(unsigned short)code;
|
||||
+ (NSEvent*) keyEventWithType: (NSEventType)type
|
||||
location: (NSPoint)location
|
||||
modifierFlags: (unsigned int)flags
|
||||
timestamp: (NSTimeInterval)time
|
||||
windowNumber: (int)windowNum
|
||||
context: (NSGraphicsContext*)context
|
||||
characters: (NSString *)keys
|
||||
charactersIgnoringModifiers: (NSString *)ukeys
|
||||
isARepeat: (BOOL)repeatKey
|
||||
keyCode: (unsigned short)code;
|
||||
|
||||
+ (NSEvent *)mouseEventWithType:(NSEventType)type
|
||||
location:(NSPoint)location
|
||||
modifierFlags:(unsigned int)flags
|
||||
timestamp:(NSTimeInterval)time
|
||||
windowNumber:(int)windowNum
|
||||
context:(NSGraphicsContext*)context
|
||||
eventNumber:(int)eventNum
|
||||
clickCount:(int)clickNum
|
||||
pressure:(float)pressureValue;
|
||||
+ (NSEvent*) mouseEventWithType: (NSEventType)type
|
||||
location: (NSPoint)location
|
||||
modifierFlags: (unsigned int)flags
|
||||
timestamp: (NSTimeInterval)time
|
||||
windowNumber: (int)windowNum
|
||||
context: (NSGraphicsContext*)context
|
||||
eventNumber: (int)eventNum
|
||||
clickCount: (int)clickNum
|
||||
pressure: (float)pressureValue;
|
||||
|
||||
+ (NSEvent *)otherEventWithType:(NSEventType)type
|
||||
location:(NSPoint)location
|
||||
modifierFlags:(unsigned int)flags
|
||||
timestamp:(NSTimeInterval)time
|
||||
windowNumber:(int)windowNum
|
||||
context:(NSGraphicsContext*)context
|
||||
subtype:(short)subType
|
||||
data1:(int)data1
|
||||
data2:(int)data2;
|
||||
+ (NSEvent*) otherEventWithType: (NSEventType)type
|
||||
location: (NSPoint)location
|
||||
modifierFlags: (unsigned int)flags
|
||||
timestamp: (NSTimeInterval)time
|
||||
windowNumber: (int)windowNum
|
||||
context: (NSGraphicsContext*)context
|
||||
subtype: (short)subType
|
||||
data1: (int)data1
|
||||
data2: (int)data2;
|
||||
|
||||
//
|
||||
// Getting General Event Information
|
||||
//
|
||||
- (NSGraphicsContext*)context;
|
||||
- (NSPoint)locationInWindow;
|
||||
- (unsigned int)modifierFlags;
|
||||
- (NSTimeInterval)timestamp;
|
||||
- (NSEventType)type;
|
||||
- (NSWindow *)window;
|
||||
- (int)windowNumber;
|
||||
/*
|
||||
* Getting General Event Information
|
||||
*/
|
||||
- (NSGraphicsContext*) context;
|
||||
- (NSPoint) locationInWindow;
|
||||
- (unsigned int) modifierFlags;
|
||||
- (NSTimeInterval) timestamp;
|
||||
- (NSEventType) type;
|
||||
- (NSWindow *) window;
|
||||
- (int) windowNumber;
|
||||
|
||||
//
|
||||
// Getting Key Event Information
|
||||
//
|
||||
- (NSString *)characters;
|
||||
- (NSString *)charactersIgnoringModifiers;
|
||||
- (BOOL)isARepeat;
|
||||
- (unsigned short)keyCode;
|
||||
/*
|
||||
* Getting Key Event Information
|
||||
*/
|
||||
- (NSString *) characters;
|
||||
- (NSString *) charactersIgnoringModifiers;
|
||||
- (BOOL) isARepeat;
|
||||
- (unsigned short) keyCode;
|
||||
|
||||
//
|
||||
// Getting Mouse Event Information
|
||||
//
|
||||
- (int)clickCount;
|
||||
- (int)eventNumber;
|
||||
- (float)pressure;
|
||||
/*
|
||||
* Getting Mouse Event Information
|
||||
*/
|
||||
- (int) clickCount;
|
||||
- (int) eventNumber;
|
||||
- (float) pressure;
|
||||
|
||||
//
|
||||
// Getting Tracking Event Information
|
||||
//
|
||||
- (int)trackingNumber;
|
||||
- (void *)userData;
|
||||
/*
|
||||
* Getting Tracking Event Information
|
||||
*/
|
||||
- (int) trackingNumber;
|
||||
- (void *) userData;
|
||||
|
||||
//
|
||||
// Requesting Periodic Events
|
||||
//
|
||||
+ (void)startPeriodicEventsAfterDelay:(NSTimeInterval)delaySeconds
|
||||
withPeriod:(NSTimeInterval)periodSeconds;
|
||||
+ (void)stopPeriodicEvents;
|
||||
/*
|
||||
* Requesting Periodic Events
|
||||
*/
|
||||
+ (void) startPeriodicEventsAfterDelay: (NSTimeInterval)delaySeconds
|
||||
withPeriod: (NSTimeInterval)periodSeconds;
|
||||
+ (void) stopPeriodicEvents;
|
||||
|
||||
//
|
||||
// Getting Information about Specially Defined Events
|
||||
//
|
||||
- (int)data1;
|
||||
- (int)data2;
|
||||
- (short)subtype;
|
||||
/*
|
||||
* Getting Information about Specially Defined Events
|
||||
*/
|
||||
- (int) data1;
|
||||
- (int) data2;
|
||||
- (short) subtype;
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder;
|
||||
- initWithCoder:aDecoder;
|
||||
/*
|
||||
* NSCoding protocol
|
||||
*/
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder;
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -297,10 +305,10 @@ enum {
|
|||
NSModeSwitchFunctionKey = 0xF747
|
||||
};
|
||||
|
||||
//
|
||||
// Convert an Event Mask Type to a Mask
|
||||
//
|
||||
/*
|
||||
* Convert an Event Mask Type to a Mask
|
||||
*/
|
||||
unsigned int NSEventMaskFromType(NSEventType type);
|
||||
|
||||
|
||||
#endif // _GNUstep_H_NSEvent
|
||||
#endif /* _GNUstep_H_NSEvent */
|
||||
|
|
|
@ -99,6 +99,7 @@ typedef enum _NSWindowOrderingMode
|
|||
NSDictionary *context_info;
|
||||
NSMutableData *context_data;
|
||||
NSMutableArray *focus_stack;
|
||||
NSMutableArray *event_queue;
|
||||
}
|
||||
|
||||
+ (NSGraphicsContext*) currentContext;
|
||||
|
|
276
Source/NSEvent.m
276
Source/NSEvent.m
|
@ -10,6 +10,8 @@
|
|||
Date: 1996
|
||||
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
Date: Sept 1998
|
||||
Updated: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: June 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -47,30 +49,34 @@
|
|||
* gstep-base has a faster mechanism to get the current thread.
|
||||
*/
|
||||
#ifndef GNUSTEP_BASE_LIBRARY
|
||||
#define GSCurrentThread() [NSThread currentThread]
|
||||
#define GSCurrentThread() [NSThread currentThread]
|
||||
#define GSCurrentThreadDictionary() [[NSThread currentThread] threadDictionary]
|
||||
#endif
|
||||
|
||||
@implementation NSEvent
|
||||
|
||||
// Class variables
|
||||
/*
|
||||
* Class variables
|
||||
*/
|
||||
static NSString *timerKey = @"NSEventTimersKey";
|
||||
static Class eventClass;
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
/*
|
||||
* Class methods
|
||||
*/
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSEvent class])
|
||||
{
|
||||
NSDebugLog(@"Initialize NSEvent class\n");
|
||||
[self setVersion: 1];
|
||||
eventClass = [NSEvent class];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Creating NSEvent objects
|
||||
//
|
||||
/*
|
||||
* Creating NSEvent objects
|
||||
*/
|
||||
+ (NSEvent*) enterExitEventWithType: (NSEventType)type
|
||||
location: (NSPoint)location
|
||||
modifierFlags: (unsigned int)flags
|
||||
|
@ -81,12 +87,18 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
trackingNumber: (int)trackingNum
|
||||
userData: (void *)userData
|
||||
{
|
||||
NSEvent *e = [[[NSEvent alloc] init] autorelease];
|
||||
NSEvent *e;
|
||||
|
||||
if (type == NSCursorUpdate)
|
||||
[(id)userData retain];
|
||||
RETAIN((id)userData);
|
||||
else if ((type != NSMouseEntered) && (type != NSMouseExited))
|
||||
return nil;
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"enterExitEvent with wrong type"];
|
||||
|
||||
e = (NSEvent*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
if (self != eventClass)
|
||||
e = [e init];
|
||||
AUTORELEASE(e);
|
||||
|
||||
e->event_type = type;
|
||||
|
||||
|
@ -113,10 +125,16 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
isARepeat: (BOOL)repeatKey
|
||||
keyCode: (unsigned short)code
|
||||
{
|
||||
NSEvent *e = [[[NSEvent alloc] init] autorelease];
|
||||
NSEvent *e;
|
||||
|
||||
if ((type != NSKeyDown) && (type != NSKeyUp))
|
||||
return nil;
|
||||
if (type < NSKeyDown || type > NSFlagsChanged)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"keyEvent with wrong type"];
|
||||
|
||||
e = (NSEvent*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
if (self != eventClass)
|
||||
e = [e init];
|
||||
AUTORELEASE(e);
|
||||
|
||||
e->event_type = type;
|
||||
e->location_point = location;
|
||||
|
@ -124,9 +142,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
e->event_time = time;
|
||||
e->window_num = windowNum;
|
||||
e->event_context = context;
|
||||
[keys retain];
|
||||
RETAIN(keys);
|
||||
e->event_data.key.char_keys = keys;
|
||||
[ukeys retain];
|
||||
RETAIN(ukeys);
|
||||
e->event_data.key.unmodified_keys = ukeys;
|
||||
e->event_data.key.repeat = repeatKey;
|
||||
e->event_data.key.key_code = code;
|
||||
|
@ -144,13 +162,16 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
clickCount: (int)clickNum
|
||||
pressure: (float)pressureValue
|
||||
{
|
||||
NSEvent *e = [[[NSEvent alloc] init] autorelease];
|
||||
NSEvent *e;
|
||||
|
||||
if ((type != NSMouseMoved) && (type != NSLeftMouseUp)
|
||||
&& (type != NSLeftMouseDown) && (type != NSRightMouseDown)
|
||||
&& (type != NSRightMouseUp) && (type != NSLeftMouseDragged)
|
||||
&& (type != NSRightMouseDragged))
|
||||
return nil;
|
||||
if (type < NSLeftMouseDown || type > NSRightMouseDragged)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"mouseEvent with wrong type"];
|
||||
|
||||
e = (NSEvent*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
if (self != eventClass)
|
||||
e = [e init];
|
||||
AUTORELEASE(e);
|
||||
|
||||
e->event_type = type;
|
||||
e->location_point = location;
|
||||
|
@ -175,10 +196,16 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
data1: (int)data1
|
||||
data2: (int)data2
|
||||
{
|
||||
NSEvent *e = [[[NSEvent alloc] init] autorelease];
|
||||
NSEvent *e;
|
||||
|
||||
if ((type != NSFlagsChanged) && (type != NSPeriodic))
|
||||
return nil;
|
||||
if (type < NSAppKitDefined || type > NSPeriodic)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"otherEvent with wrong type"];
|
||||
|
||||
e = (NSEvent*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
if (self != eventClass)
|
||||
e = [e init];
|
||||
AUTORELEASE(e);
|
||||
|
||||
e->event_type = type;
|
||||
e->location_point = location;
|
||||
|
@ -193,9 +220,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
return e;
|
||||
}
|
||||
|
||||
//
|
||||
// Requesting Periodic Events
|
||||
//
|
||||
/*
|
||||
* Requesting Periodic Events
|
||||
*/
|
||||
+ (void) startPeriodicEventsAfterDelay: (NSTimeInterval)delaySeconds
|
||||
withPeriod: (NSTimeInterval)periodSeconds
|
||||
{
|
||||
|
@ -209,8 +236,10 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
format: @"Periodic events are already being generated for "
|
||||
@"this thread %x", GSCurrentThread()];
|
||||
|
||||
// If the delay time is 0 then register a timer immediately. Otherwise
|
||||
// register a timer with no repeat that when fired registers the real timer
|
||||
/*
|
||||
* If the delay time is 0 then register a timer immediately. Otherwise
|
||||
* register a timer with no repeat that when fired registers the real timer
|
||||
*/
|
||||
if (!delaySeconds)
|
||||
timer = [NSTimer timerWithTimeInterval: periodSeconds
|
||||
target: self
|
||||
|
@ -225,33 +254,37 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
repeats: NO];
|
||||
|
||||
[[NSRunLoop currentRunLoop] addTimer: timer
|
||||
forMode: NSEventTrackingRunLoopMode];
|
||||
forMode: NSEventTrackingRunLoopMode];
|
||||
[dict setObject: timer forKey: timerKey];
|
||||
}
|
||||
|
||||
+ (void) _timerFired: (NSTimer*)timer
|
||||
{
|
||||
NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceReferenceDate];
|
||||
NSApplication *theApp = [NSApplication sharedApplication];
|
||||
NSEvent* periodicEvent = [self otherEventWithType: NSPeriodic
|
||||
location: NSZeroPoint
|
||||
modifierFlags: 0
|
||||
timestamp: timeInterval
|
||||
windowNumber: 0
|
||||
context: [theApp context]
|
||||
subtype: 0
|
||||
data1: 0
|
||||
data2: 0];
|
||||
NSTimeInterval timeInterval;
|
||||
NSEvent *periodicEvent;
|
||||
|
||||
timeInterval = [[NSDate date] timeIntervalSinceReferenceDate];
|
||||
periodicEvent = [self otherEventWithType: NSPeriodic
|
||||
location: NSZeroPoint
|
||||
modifierFlags: 0
|
||||
timestamp: timeInterval
|
||||
windowNumber: 0
|
||||
context: [NSApp context]
|
||||
subtype: 0
|
||||
data1: 0
|
||||
data2: 0];
|
||||
|
||||
NSDebugLog (@"_timerFired: ");
|
||||
[theApp postEvent: periodicEvent atStart: NO];
|
||||
[NSApp postEvent: periodicEvent atStart: NO];
|
||||
}
|
||||
|
||||
// this method provides a means of delaying the start of periodic events
|
||||
/*
|
||||
* This method provides a means of delaying the start of periodic events
|
||||
*/
|
||||
+ (void) _registerRealTimer: (NSTimer*)timer
|
||||
{
|
||||
NSTimer* realTimer;
|
||||
NSMutableDictionary *dict = GSCurrentThreadDictionary();
|
||||
NSTimer *realTimer;
|
||||
NSMutableDictionary *dict = GSCurrentThreadDictionary();
|
||||
|
||||
NSDebugLog (@"_registerRealTimer: ");
|
||||
|
||||
|
@ -267,8 +300,8 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
|
||||
+ (void) stopPeriodicEvents
|
||||
{
|
||||
NSTimer* timer;
|
||||
NSMutableDictionary *dict = GSCurrentThreadDictionary();
|
||||
NSTimer *timer;
|
||||
NSMutableDictionary *dict = GSCurrentThreadDictionary();
|
||||
|
||||
NSDebugLog (@"stopPeriodicEvents");
|
||||
timer = [dict objectForKey: timerKey];
|
||||
|
@ -276,25 +309,25 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
[dict removeObjectForKey: timerKey];
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
/*
|
||||
* Instance methods
|
||||
*/
|
||||
- (void) dealloc
|
||||
{
|
||||
if ((event_type == NSKeyUp) || (event_type == NSKeyDown))
|
||||
{
|
||||
[event_data.key.char_keys release];
|
||||
[event_data.key.unmodified_keys release];
|
||||
RELEASE(event_data.key.char_keys);
|
||||
RELEASE(event_data.key.unmodified_keys);
|
||||
}
|
||||
else if (event_type == NSCursorUpdate)
|
||||
[(id)event_data.tracking.user_data release];
|
||||
RELEASE((id)event_data.tracking.user_data);
|
||||
|
||||
[super dealloc];
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
|
||||
//
|
||||
// Getting General Event Information
|
||||
//
|
||||
/*
|
||||
* Getting General Event Information
|
||||
*/
|
||||
- (NSGraphicsContext*) context
|
||||
{
|
||||
return event_context;
|
||||
|
@ -330,13 +363,14 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
return window_num;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Key Event Information
|
||||
//
|
||||
/*
|
||||
* Getting Key Event Information
|
||||
*/
|
||||
- (NSString *) characters
|
||||
{
|
||||
if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
|
||||
return nil;
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"characters requested for non-keyboard event"];
|
||||
|
||||
return event_data.key.char_keys;
|
||||
}
|
||||
|
@ -344,7 +378,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
- (NSString *) charactersIgnoringModifiers
|
||||
{
|
||||
if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
|
||||
return nil;
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"charactersIgnoringModifiers requested for "
|
||||
@"non-keyboard event"];
|
||||
|
||||
return event_data.key.unmodified_keys;
|
||||
}
|
||||
|
@ -352,43 +388,41 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
- (BOOL) isARepeat
|
||||
{
|
||||
if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
|
||||
return NO;
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"isARepeat requested for non-keyboard event"];
|
||||
|
||||
return event_data.key.repeat;
|
||||
}
|
||||
|
||||
- (unsigned short) keyCode
|
||||
{
|
||||
if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
|
||||
return 0;
|
||||
if ((event_type != NSKeyUp) && (event_type != NSKeyDown)
|
||||
&& (event_type != NSFlagsChanged))
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"keyCode requested for non-keyboard event"];
|
||||
|
||||
return event_data.key.key_code;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Mouse Event Information
|
||||
//
|
||||
/*
|
||||
* Getting Mouse Event Information
|
||||
*/
|
||||
- (int) clickCount
|
||||
{
|
||||
// Make sure it is one of the right event types
|
||||
if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp)
|
||||
&& (event_type != NSRightMouseDown) && (event_type != NSRightMouseUp)
|
||||
&& (event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged)
|
||||
&& (event_type != NSMouseMoved))
|
||||
return 0;
|
||||
/* Make sure it is one of the right event types */
|
||||
if (event_type < NSLeftMouseDown || event_type > NSRightMouseDragged)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"clickCount requested for non-mouse event"];
|
||||
|
||||
return event_data.mouse.click;
|
||||
}
|
||||
|
||||
- (int) eventNumber
|
||||
{
|
||||
// Make sure it is one of the right event types
|
||||
if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp)
|
||||
&& (event_type != NSRightMouseDown) && (event_type != NSRightMouseUp)
|
||||
&& (event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged)
|
||||
&& (event_type != NSMouseMoved) && (event_type != NSMouseEntered)
|
||||
&& (event_type != NSMouseExited))
|
||||
return 0;
|
||||
/* Make sure it is one of the right event types */
|
||||
if (event_type < NSLeftMouseDown || event_type > NSMouseExited)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"eventNumber requested for non-mouse event"];
|
||||
|
||||
if ((event_type == NSMouseEntered) || (event_type == NSMouseExited))
|
||||
return event_data.tracking.event_num;
|
||||
|
@ -398,70 +432,70 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
|
||||
- (float) pressure
|
||||
{
|
||||
// Make sure it is one of the right event types
|
||||
if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp)
|
||||
&& (event_type != NSRightMouseDown) && (event_type != NSRightMouseUp)
|
||||
&& (event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged)
|
||||
&& (event_type != NSMouseMoved))
|
||||
return 0;
|
||||
/* Make sure it is one of the right event types */
|
||||
if (event_type < NSLeftMouseDown || event_type > NSRightMouseDragged)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"pressure requested for non-mouse event"];
|
||||
|
||||
return event_data.mouse.pressure;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Tracking Event Information
|
||||
//
|
||||
/*
|
||||
* Getting Tracking Event Information
|
||||
*/
|
||||
- (int) trackingNumber
|
||||
{
|
||||
if ((event_type != NSMouseEntered) && (event_type != NSMouseExited)
|
||||
&& (event_type != NSCursorUpdate))
|
||||
return 0;
|
||||
if (event_type != NSMouseEntered && event_type != NSMouseExited
|
||||
&& event_type != NSCursorUpdate)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"trackingNumber requested for non-tracking event"];
|
||||
|
||||
return event_data.tracking.tracking_num;
|
||||
}
|
||||
|
||||
- (void *) userData
|
||||
{
|
||||
if ((event_type != NSMouseEntered) && (event_type != NSMouseExited)
|
||||
&& (event_type != NSCursorUpdate))
|
||||
return NULL;
|
||||
if (event_type != NSMouseEntered && event_type != NSMouseExited
|
||||
&& event_type != NSCursorUpdate)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"userData requested for non-tracking event"];
|
||||
|
||||
return event_data.tracking.user_data;
|
||||
}
|
||||
|
||||
//
|
||||
// Getting Information about Specially Defined Events
|
||||
//
|
||||
/*
|
||||
* Getting Information about Specially Defined Events
|
||||
*/
|
||||
- (int) data1
|
||||
{
|
||||
// Make sure it is one of the right event types
|
||||
if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic))
|
||||
return 0;
|
||||
if (event_type < NSAppKitDefined || event_type > NSPeriodic)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"data1 requested for invalid event type"];
|
||||
|
||||
return event_data.misc.data1;
|
||||
}
|
||||
|
||||
- (int) data2
|
||||
{
|
||||
// Make sure it is one of the right event types
|
||||
if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic))
|
||||
return 0;
|
||||
if (event_type < NSAppKitDefined || event_type > NSPeriodic)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"data2 requested for invalid event type"];
|
||||
|
||||
return event_data.misc.data2;
|
||||
}
|
||||
|
||||
- (short) subtype
|
||||
{
|
||||
// Make sure it is one of the right event types
|
||||
if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic))
|
||||
return 0;
|
||||
if (event_type < NSAppKitDefined || event_type > NSPeriodic)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"subtype requested for invalid event type"];
|
||||
|
||||
return event_data.misc.sub_type;;
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
/*
|
||||
* NSCoding protocol
|
||||
*/
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(NSEventType) at: &event_type];
|
||||
|
@ -469,11 +503,7 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &modifier_flags];
|
||||
[aCoder encodeValueOfObjCType: @encode(NSTimeInterval) at: &event_time];
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &window_num];
|
||||
// We don't want to encode the context, right?
|
||||
// DPSContext doesn't conform to NSCoding
|
||||
//[aCoder encodeObjectReference: event_context withName: @"Context"];
|
||||
|
||||
// Encode the event date based upon the event type
|
||||
switch (event_type)
|
||||
{
|
||||
case NSLeftMouseDown:
|
||||
|
@ -506,6 +536,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
|
||||
case NSFlagsChanged:
|
||||
case NSPeriodic:
|
||||
case NSAppKitDefined:
|
||||
case NSSystemDefined:
|
||||
case NSApplicationDefined:
|
||||
[aCoder encodeValuesOfObjCTypes: "sii", &event_data.misc.sub_type,
|
||||
&event_data.misc.data1, &event_data.misc.data2];
|
||||
break;
|
||||
|
@ -553,6 +586,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
|
||||
case NSFlagsChanged:
|
||||
case NSPeriodic:
|
||||
case NSAppKitDefined:
|
||||
case NSSystemDefined:
|
||||
case NSApplicationDefined:
|
||||
[aDecoder decodeValuesOfObjCTypes: "sii", &event_data.misc.sub_type,
|
||||
&event_data.misc.data1, &event_data.misc.data2];
|
||||
break;
|
||||
|
@ -565,8 +601,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
{
|
||||
const char* eventTypes[] = { "leftMouseDown", "leftMouseUp",
|
||||
"rightMouseDown", "rightMouseUp", "mouseMoved", "leftMouseDragged",
|
||||
"rightMouseDragged", "mouseEntered", "mouseExited", "keyDown", "keyUp",
|
||||
"flagsChanged", "periodic", "cursorUpdate"
|
||||
"rightMouseDragged", "mouseEntered", "mouseExited",
|
||||
"keyDown", "keyUp", "flagsChanged", "appKitDefined",
|
||||
"systemDefined", "applicationDefined", "periodic", "cursorUpdate"
|
||||
};
|
||||
|
||||
switch (event_type)
|
||||
|
@ -617,6 +654,9 @@ static NSString *timerKey = @"NSEventTimersKey";
|
|||
case NSFlagsChanged:
|
||||
case NSPeriodic:
|
||||
case NSCursorUpdate:
|
||||
case NSAppKitDefined:
|
||||
case NSSystemDefined:
|
||||
case NSApplicationDefined:
|
||||
return [NSString stringWithFormat:
|
||||
@"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u,"
|
||||
@" time = %f, window = %d, dpsContext = %p, "
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
#include "AppKit/NSGraphicsContext.h"
|
||||
|
@ -153,6 +154,7 @@ struct NSWindow_struct
|
|||
DESTROY(focus_stack);
|
||||
DESTROY(context_data);
|
||||
DESTROY(context_info);
|
||||
DESTROY(event_queue);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -178,6 +180,8 @@ struct NSWindow_struct
|
|||
context_info = [info retain];
|
||||
focus_stack = [[NSMutableArray allocWithZone: [self zone]]
|
||||
initWithCapacity: 1];
|
||||
event_queue = [[NSMutableArray allocWithZone: [self zone]]
|
||||
initWithCapacity: 32];
|
||||
|
||||
/*
|
||||
* The classMethodTable dictionary and the list of all contexts must both
|
||||
|
@ -1542,19 +1546,273 @@ struct NSWindow_struct
|
|||
inMode: (NSString*)mode
|
||||
dequeue: (BOOL)flag
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
unsigned pos = 0; /* Position in queue scanned so far */
|
||||
NSRunLoop *loop = nil;
|
||||
|
||||
do
|
||||
{
|
||||
unsigned count = [event_queue count];
|
||||
NSEvent *event;
|
||||
unsigned i = 0;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
event = nil;
|
||||
}
|
||||
else if (mask == NSAnyEventMask)
|
||||
{
|
||||
/*
|
||||
* Special case - if the mask matches any event, we just get the
|
||||
* first event on the queue.
|
||||
*/
|
||||
event = [event_queue objectAtIndex: 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
event = nil;
|
||||
/*
|
||||
* Scan the queue from the last position we have seen, up to the end.
|
||||
*/
|
||||
if (count > pos)
|
||||
{
|
||||
unsigned end = count - pos;
|
||||
NSRange r = NSMakeRange(pos, end);
|
||||
NSEvent *events[end];
|
||||
|
||||
[event_queue getObjects: events range: r];
|
||||
for (i = 0; i < end; i++)
|
||||
{
|
||||
BOOL matched = NO;
|
||||
|
||||
switch ([events[i] type])
|
||||
{
|
||||
case NSLeftMouseDown:
|
||||
if (mask & NSLeftMouseDownMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSLeftMouseUp:
|
||||
if (mask & NSLeftMouseUpMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSRightMouseDown:
|
||||
if (mask & NSRightMouseDownMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSRightMouseUp:
|
||||
if (mask & NSRightMouseUpMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSMouseMoved:
|
||||
if (mask & NSMouseMovedMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSMouseEntered:
|
||||
if (mask & NSMouseEnteredMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSMouseExited:
|
||||
if (mask & NSMouseExitedMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSLeftMouseDragged:
|
||||
if (mask & NSLeftMouseDraggedMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSRightMouseDragged:
|
||||
if (mask & NSRightMouseDraggedMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSKeyDown:
|
||||
if (mask & NSKeyDownMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSKeyUp:
|
||||
if (mask & NSKeyUpMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSFlagsChanged:
|
||||
if (mask & NSFlagsChangedMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSPeriodic:
|
||||
if (mask & NSPeriodicMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
case NSCursorUpdate:
|
||||
if (mask & NSCursorUpdateMask)
|
||||
matched = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (matched)
|
||||
{
|
||||
event = events[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Note the positon we have read up to.
|
||||
*/
|
||||
pos += i;
|
||||
|
||||
/*
|
||||
* If we found a matching event, we (depending on the flag) de-queue it.
|
||||
* We return the event RETAINED - the caller must release it.
|
||||
*/
|
||||
if (event)
|
||||
{
|
||||
RETAIN(event);
|
||||
if (flag)
|
||||
{
|
||||
[event_queue removeObjectAtIndex: pos];
|
||||
}
|
||||
return AUTORELEASE(event);
|
||||
}
|
||||
if (loop == nil)
|
||||
loop = [NSRunLoop currentRunLoop];
|
||||
}
|
||||
while ([loop runMode: mode beforeDate: limit] == YES);
|
||||
|
||||
return nil; /* No events in specified time */
|
||||
}
|
||||
|
||||
- (void) DPSDiscardEventsMatchingMask: (unsigned)mask
|
||||
beforeEvent: (NSEvent*)limit
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
unsigned index = [event_queue count];
|
||||
|
||||
/*
|
||||
* If there is a range to use - remove all the matching events in it
|
||||
* which were created before the specified event.
|
||||
*/
|
||||
if (index > 0)
|
||||
{
|
||||
NSTimeInterval when = [limit timestamp];
|
||||
NSEvent *events[index];
|
||||
|
||||
[event_queue getObjects: events];
|
||||
|
||||
while (index-- > 0)
|
||||
{
|
||||
NSEvent *event = events[index];
|
||||
|
||||
if ([event timestamp] < when)
|
||||
{
|
||||
BOOL shouldRemove = NO;
|
||||
|
||||
if (mask == NSAnyEventMask)
|
||||
{
|
||||
shouldRemove = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ([event type])
|
||||
{
|
||||
case NSLeftMouseDown:
|
||||
if (mask & NSLeftMouseDownMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSLeftMouseUp:
|
||||
if (mask & NSLeftMouseUpMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSRightMouseDown:
|
||||
if (mask & NSRightMouseDownMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSRightMouseUp:
|
||||
if (mask & NSRightMouseUpMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSMouseMoved:
|
||||
if (mask & NSMouseMovedMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSMouseEntered:
|
||||
if (mask & NSMouseEnteredMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSMouseExited:
|
||||
if (mask & NSMouseExitedMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSLeftMouseDragged:
|
||||
if (mask & NSLeftMouseDraggedMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSRightMouseDragged:
|
||||
if (mask & NSRightMouseDraggedMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSKeyDown:
|
||||
if (mask & NSKeyDownMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSKeyUp:
|
||||
if (mask & NSKeyUpMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSFlagsChanged:
|
||||
if (mask & NSFlagsChangedMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSPeriodic:
|
||||
if (mask & NSPeriodicMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
case NSCursorUpdate:
|
||||
if (mask & NSCursorUpdateMask)
|
||||
shouldRemove = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shouldRemove)
|
||||
[event_queue removeObjectAtIndex: index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) DPSPostEvent: (NSEvent*)anEvent atStart: (BOOL)flag
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
if (flag)
|
||||
[event_queue insertObject: anEvent atIndex: 0];
|
||||
else
|
||||
[event_queue addObject: anEvent];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue