Thread fixes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3131 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-10-27 14:59:05 +00:00
parent 2fa149743a
commit 1244cd5310
3 changed files with 194 additions and 221 deletions

View file

@ -1,3 +1,10 @@
Tue Oct 27 15:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSDPSContext.m: Fixed per-thread code to be OpenStep
complient and less inefficient.
* Source/NSEvent.m: Fixed per-thread code to be OpenStep complient
and less inefficient.
Mon Oct 26 13:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Mon Oct 26 13:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Tools/gpbs.m: Changed cStringNoCopy to cString. * Tools/gpbs.m: Changed cStringNoCopy to cString.

View file

@ -60,20 +60,10 @@ NSString *DPSCantConnectException = @"DPSCantConnectException";
// //
// Class variables // Class variables
// //
static NSMutableDictionary *GNU_CONTEXT_THREAD_DICT = nil; static NSString *GNU_CONTEXT_THREAD_KEY = @"GnuContextThreadKey";
static NSRecursiveLock *GNU_CONTEXT_LOCK = nil;
static BOOL GNU_CONTEXT_TRACED = NO; static BOOL GNU_CONTEXT_TRACED = NO;
static BOOL GNU_CONTEXT_SYNCHRONIZED = NO; static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
#if defined(NeXT_PDO)
@implementation NSThread (Containers)
- copyWithZone:(NSZone*)zone
{
return [self retain];
}
@end
#endif
@implementation NSDPSContext @implementation NSDPSContext
+ (void)initialize + (void)initialize
@ -83,12 +73,6 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
// Set initial version // Set initial version
[self setVersion: 1]; [self setVersion: 1];
// Allocate dictionary for maintaining
// mapping of threads to contexts
GNU_CONTEXT_THREAD_DICT = [NSMutableDictionary new];
// Create lock for serializing access to dictionary
GNU_CONTEXT_LOCK = [[NSRecursiveLock alloc] init];
GNU_CONTEXT_TRACED = NO; GNU_CONTEXT_TRACED = NO;
GNU_CONTEXT_SYNCHRONIZED = NO; GNU_CONTEXT_SYNCHRONIZED = NO;
} }
@ -162,9 +146,8 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
current_thread = [NSThread currentThread]; current_thread = [NSThread currentThread];
// Get current context for current thread // Get current context for current thread
[GNU_CONTEXT_LOCK lock];
current_context = [GNU_CONTEXT_THREAD_DICT objectForKey: current_thread]; current_context = [[current_thread threadDictionary] objectForKey: GNU_CONTEXT_THREAD_KEY];
// If not in dictionary then create one // If not in dictionary then create one
if (!current_context) if (!current_context)
@ -172,7 +155,6 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
current_context = [[NSDPSContext alloc] init]; current_context = [[NSDPSContext alloc] init];
[self setCurrentContext: current_context]; [self setCurrentContext: current_context];
} }
[GNU_CONTEXT_LOCK unlock];
return current_context; return current_context;
} }
@ -181,20 +163,15 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
{ {
NSThread *current_thread = [NSThread currentThread]; NSThread *current_thread = [NSThread currentThread];
[GNU_CONTEXT_LOCK lock];
// If no context then remove from dictionary // If no context then remove from dictionary
if (!context) if (!context)
{ {
[GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread]; [[current_thread threadDictionary] removeObjectForKey: GNU_CONTEXT_THREAD_KEY];
} }
else else
{ {
[GNU_CONTEXT_THREAD_DICT setObject: context [[current_thread threadDictionary] setObject: context forKey: GNU_CONTEXT_THREAD_KEY];
forKey: current_thread];
} }
[GNU_CONTEXT_LOCK unlock];
} }
- (NSDPSContext *)DPSContext - (NSDPSContext *)DPSContext

View file

@ -5,10 +5,10 @@
Copyright (C) 1996 Free Software Foundation, Inc. Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com> Author: Scott Christley <scottc@net-community.com>
Author: Ovidiu Predescu <ovidiu@net-community.com> Author: Ovidiu Predescu <ovidiu@net-community.com>
Date: 1996 Date: 1996
Author: Felipe A. Rodriguez <far@ix.netcom.com> Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: Sept 1998 Date: Sept 1998
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
@ -20,7 +20,7 @@
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details. Library General Public License for more details.
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
@ -46,8 +46,7 @@
@implementation NSEvent @implementation NSEvent
// Class variables // Class variables
static NSMutableDictionary* timers = nil; static NSString *timerKey = @"NSEventTimersKey";
static NSRecursiveLock* timersLock = nil;
// //
// Class methods // Class methods
@ -55,32 +54,30 @@ static NSRecursiveLock* timersLock = nil;
+ (void)initialize + (void)initialize
{ {
if (self == [NSEvent class]) if (self == [NSEvent class])
{ {
NSDebugLog(@"Initialize NSEvent class\n"); NSDebugLog(@"Initialize NSEvent class\n");
// Initial version // Initial version
[self setVersion:1]; [self setVersion:1];
timers = [NSMutableDictionary new]; }
timersLock = [NSRecursiveLock new];
}
} }
// //
// Creating NSEvent objects // Creating NSEvent objects
// //
+ (NSEvent *)enterExitEventWithType:(NSEventType)type + (NSEvent *)enterExitEventWithType:(NSEventType)type
location:(NSPoint)location location:(NSPoint)location
modifierFlags:(unsigned int)flags modifierFlags:(unsigned int)flags
timestamp:(NSTimeInterval)time timestamp:(NSTimeInterval)time
windowNumber:(int)windowNum windowNumber:(int)windowNum
context:(NSDPSContext *)context context:(NSDPSContext *)context
eventNumber:(int)eventNum eventNumber:(int)eventNum
trackingNumber:(int)trackingNum trackingNumber:(int)trackingNum
userData:(void *)userData userData:(void *)userData
{ {
NSEvent *e = [[[NSEvent alloc] init] autorelease]; NSEvent *e = [[[NSEvent alloc] init] autorelease];
// do nothing if // do nothing if
if ((type != NSMouseEntered) && (type != NSMouseExited) // event is not of if ((type != NSMouseEntered) && (type != NSMouseExited) // event is not of
&& (type != NSCursorUpdate)) // a desired type && (type != NSCursorUpdate)) // a desired type
return nil; return nil;
@ -98,15 +95,15 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease];
} }
+ (NSEvent *)keyEventWithType:(NSEventType)type + (NSEvent *)keyEventWithType:(NSEventType)type
location:(NSPoint)location location:(NSPoint)location
modifierFlags:(unsigned int)flags modifierFlags:(unsigned int)flags
timestamp:(NSTimeInterval)time timestamp:(NSTimeInterval)time
windowNumber:(int)windowNum windowNumber:(int)windowNum
context:(NSDPSContext *)context context:(NSDPSContext *)context
characters:(NSString *)keys characters:(NSString *)keys
charactersIgnoringModifiers:(NSString *)ukeys charactersIgnoringModifiers:(NSString *)ukeys
isARepeat:(BOOL)repeatKey isARepeat:(BOOL)repeatKey
keyCode:(unsigned short)code keyCode:(unsigned short)code
{ {
NSEvent *e = [[[NSEvent alloc] init] autorelease]; NSEvent *e = [[[NSEvent alloc] init] autorelease];
// do nothing if // do nothing if
@ -131,13 +128,13 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease];
+ (NSEvent *)mouseEventWithType:(NSEventType)type + (NSEvent *)mouseEventWithType:(NSEventType)type
location:(NSPoint)location location:(NSPoint)location
modifierFlags:(unsigned int)flags modifierFlags:(unsigned int)flags
timestamp:(NSTimeInterval)time timestamp:(NSTimeInterval)time
windowNumber:(int)windowNum windowNumber:(int)windowNum
context:(NSDPSContext *)context context:(NSDPSContext *)context
eventNumber:(int)eventNum eventNumber:(int)eventNum
clickCount:(int)clickNum clickCount:(int)clickNum
pressure:(float)pressureValue pressure:(float)pressureValue
{ {
NSEvent *e = [[[NSEvent alloc] init] autorelease]; // do nothing if NSEvent *e = [[[NSEvent alloc] init] autorelease]; // do nothing if
// event is not of // event is not of
@ -145,7 +142,7 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease]; // do nothing if
&& (type != NSLeftMouseDown) && (type != NSRightMouseDown) && (type != NSLeftMouseDown) && (type != NSRightMouseDown)
&& (type != NSRightMouseUp) && (type != NSLeftMouseDragged) && (type != NSRightMouseUp) && (type != NSLeftMouseDragged)
&& (type != NSRightMouseDragged)) && (type != NSRightMouseDragged))
return nil; return nil;
e->event_type = type; // Set the event's e->event_type = type; // Set the event's
e->location_point = location; // fields e->location_point = location; // fields
@ -161,14 +158,14 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease]; // do nothing if
} }
+ (NSEvent *)otherEventWithType:(NSEventType)type + (NSEvent *)otherEventWithType:(NSEventType)type
location:(NSPoint)location location:(NSPoint)location
modifierFlags:(unsigned int)flags modifierFlags:(unsigned int)flags
timestamp:(NSTimeInterval)time timestamp:(NSTimeInterval)time
windowNumber:(int)windowNum windowNumber:(int)windowNum
context:(NSDPSContext *)context context:(NSDPSContext *)context
subtype:(short)subType subtype:(short)subType
data1:(int)data1 data1:(int)data1
data2:(int)data2 data2:(int)data2
{ {
NSEvent *e = [[[NSEvent alloc] init] autorelease]; NSEvent *e = [[[NSEvent alloc] init] autorelease];
// do nothing if // do nothing if
@ -192,22 +189,20 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease];
// Requesting Periodic Events // Requesting Periodic Events
// //
+ (void)startPeriodicEventsAfterDelay:(NSTimeInterval)delaySeconds + (void)startPeriodicEventsAfterDelay:(NSTimeInterval)delaySeconds
withPeriod:(NSTimeInterval)periodSeconds withPeriod:(NSTimeInterval)periodSeconds
{ {
NSTimer* timer; NSTimer* timer;
NSThread* currentThread = [NSThread currentThread]; NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
[timersLock lock]; NSDebugLog (@"startPeriodicEventsAfterDelay:withPeriod:");
NSDebugLog (@"startPeriodicEventsAfterDelay:withPeriod:");
// Check this thread // Check this thread
if ([timers objectForKey:currentThread]) // for a pending timer if ([dict objectForKey: timerKey]) // for a pending timer
[NSException raise:NSInternalInconsistencyException [NSException raise:NSInternalInconsistencyException
format:@"Periodic events are already being generated for " format:@"Periodic events are already being generated for "
@"this thread %x", currentThread]; @"this thread %x", [NSThread currentThread]];
// If the delay time is 0 then register // If the delay time is 0 then register
// a timer immediately. Otherwise // a timer immediately. Otherwise
// register a timer with no repeat that // register a timer with no repeat that
if (!delaySeconds) // when fired registers the real timer if (!delaySeconds) // when fired registers the real timer
timer = [NSTimer timerWithTimeInterval:periodSeconds // register an timer = [NSTimer timerWithTimeInterval:periodSeconds // register an
target:self // immediate target:self // immediate
@ -215,17 +210,15 @@ NSThread* currentThread = [NSThread currentThread];
userInfo:nil userInfo:nil
repeats:YES]; repeats:YES];
else // register a one else // register a one
timer = [NSTimer timerWithTimeInterval:delaySeconds // shot timer to timer = [NSTimer timerWithTimeInterval:delaySeconds // shot timer to
target:self // register a timer target:self // register a timer
selector:@selector(_registerRealTimer:) selector:@selector(_registerRealTimer:)
userInfo:[NSNumber numberWithDouble:periodSeconds] userInfo:[NSNumber numberWithDouble:periodSeconds]
repeats:NO]; repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer [[NSRunLoop currentRunLoop] addTimer: timer
forMode:NSEventTrackingRunLoopMode]; forMode: NSEventTrackingRunLoopMode];
[timers setObject:timer forKey:currentThread]; [dict setObject: timer forKey: timerKey];
[timersLock unlock];
} }
+ (void)_timerFired:(NSTimer*)timer + (void)_timerFired:(NSTimer*)timer
@ -248,39 +241,35 @@ NSEvent* periodicEvent = [self otherEventWithType:NSPeriodic
+ (void)_registerRealTimer:(NSTimer*)timer + (void)_registerRealTimer:(NSTimer*)timer
{ // this method provides a { // this method provides a
NSTimer* realTimer; // means of delaying the NSTimer* realTimer; // means of delaying the
// start of periodic events // start of periodic events
[timersLock lock]; NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
NSDebugLog (@"_registerRealTimer:");
realTimer = [NSTimer timerWithTimeInterval:[[timer userInfo] doubleValue] NSDebugLog (@"_registerRealTimer:");
realTimer = [NSTimer timerWithTimeInterval:[[timer userInfo] doubleValue]
target:self target:self
selector:@selector(_timerFired:) selector:@selector(_timerFired:)
userInfo:nil userInfo:nil
repeats:YES]; // Add the real timer to the timers repeats:YES]; // Add the real timer to the timers
// dictionary and to the run loop // dictionary and to the run loop
[timers setObject:realTimer forKey:[NSThread currentThread]]; /* xxx what if there is already a timer - are we sure there isn't? */
[[NSRunLoop currentRunLoop] addTimer:realTimer [dict setObject: realTimer forKey: timerKey];
forMode:NSEventTrackingRunLoopMode]; [[NSRunLoop currentRunLoop] addTimer: realTimer
forMode: NSEventTrackingRunLoopMode];
[timersLock unlock];
} }
+ (void)stopPeriodicEvents + (void)stopPeriodicEvents
{ {
NSTimer* timer; NSTimer* timer;
NSThread* currentThread; NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
NSDebugLog (@"stopPeriodicEvents"); NSDebugLog (@"stopPeriodicEvents");
[timersLock lock];
currentThread = [NSThread currentThread];
/* Remove any existing timer for this thread */ /* Remove any existing timer for this thread */
timer = [timers objectForKey:currentThread]; timer = [dict objectForKey: timerKey];
[timer invalidate]; [timer invalidate];
[timers removeObjectForKey:currentThread]; [dict removeObjectForKey: timerKey];
[timersLock unlock];
} }
// //
@ -289,10 +278,10 @@ NSTimer* realTimer; // means of delaying the
- (void)dealloc - (void)dealloc
{ {
if ((event_type == NSKeyUp) || (event_type == NSKeyDown)) if ((event_type == NSKeyUp) || (event_type == NSKeyDown))
{ {
[event_data.key.char_keys release]; [event_data.key.char_keys release];
[event_data.key.unmodified_keys release]; [event_data.key.unmodified_keys release];
} }
[super dealloc]; [super dealloc];
} }
@ -341,7 +330,7 @@ NSTimer* realTimer; // means of delaying the
- (NSString *)characters - (NSString *)characters
{ {
if ((event_type != NSKeyUp) && (event_type != NSKeyDown)) if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
return nil; return nil;
return event_data.key.char_keys; return event_data.key.char_keys;
} }
@ -349,7 +338,7 @@ NSTimer* realTimer; // means of delaying the
- (NSString *)charactersIgnoringModifiers - (NSString *)charactersIgnoringModifiers
{ {
if ((event_type != NSKeyUp) && (event_type != NSKeyDown)) if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
return nil; return nil;
return event_data.key.unmodified_keys; return event_data.key.unmodified_keys;
} }
@ -357,7 +346,7 @@ NSTimer* realTimer; // means of delaying the
- (BOOL)isARepeat - (BOOL)isARepeat
{ {
if ((event_type != NSKeyUp) && (event_type != NSKeyDown)) if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
return NO; return NO;
return event_data.key.repeat; return event_data.key.repeat;
} }
@ -365,7 +354,7 @@ NSTimer* realTimer; // means of delaying the
- (unsigned short)keyCode - (unsigned short)keyCode
{ {
if ((event_type != NSKeyUp) && (event_type != NSKeyDown)) if ((event_type != NSKeyUp) && (event_type != NSKeyDown))
return 0; return 0;
return event_data.key.key_code; return event_data.key.key_code;
} }
@ -377,10 +366,10 @@ NSTimer* realTimer; // means of delaying the
{ {
// Make sure it is one of the right event types // Make sure it is one of the right event types
if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp) && if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp) &&
(event_type != NSRightMouseDown) && (event_type != NSRightMouseUp) && (event_type != NSRightMouseDown) && (event_type != NSRightMouseUp) &&
(event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged) && (event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged) &&
(event_type != NSMouseMoved)) (event_type != NSMouseMoved))
return 0; return 0;
return event_data.mouse.click; return event_data.mouse.click;
} }
@ -389,26 +378,26 @@ NSTimer* realTimer; // means of delaying the
{ {
// Make sure it is one of the right event types // Make sure it is one of the right event types
if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp) && if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp) &&
(event_type != NSRightMouseDown) && (event_type != NSRightMouseUp) && (event_type != NSRightMouseDown) && (event_type != NSRightMouseUp) &&
(event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged) && (event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged) &&
(event_type != NSMouseMoved) && (event_type != NSMouseMoved) &&
(event_type != NSMouseEntered) && (event_type != NSMouseExited)) (event_type != NSMouseEntered) && (event_type != NSMouseExited))
return 0; return 0;
if ((event_type == NSMouseEntered) || (event_type == NSMouseExited)) if ((event_type == NSMouseEntered) || (event_type == NSMouseExited))
return event_data.tracking.event_num; return event_data.tracking.event_num;
else else
return event_data.mouse.event_num; return event_data.mouse.event_num;
} }
- (float)pressure - (float)pressure
{ {
// Make sure it is one of the right event types // Make sure it is one of the right event types
if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp) && if ((event_type != NSLeftMouseDown) && (event_type != NSLeftMouseUp) &&
(event_type != NSRightMouseDown) && (event_type != NSRightMouseUp) && (event_type != NSRightMouseDown) && (event_type != NSRightMouseUp) &&
(event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged) && (event_type != NSLeftMouseDragged) && (event_type != NSRightMouseDragged) &&
(event_type != NSMouseMoved)) (event_type != NSMouseMoved))
return 0; return 0;
return event_data.mouse.pressure; return event_data.mouse.pressure;
} }
@ -419,8 +408,8 @@ NSTimer* realTimer; // means of delaying the
- (int)trackingNumber - (int)trackingNumber
{ {
if ((event_type != NSMouseEntered) && (event_type != NSMouseExited) if ((event_type != NSMouseEntered) && (event_type != NSMouseExited)
&& (event_type != NSCursorUpdate)) && (event_type != NSCursorUpdate))
return 0; return 0;
return event_data.tracking.tracking_num; return event_data.tracking.tracking_num;
} }
@ -428,8 +417,8 @@ NSTimer* realTimer; // means of delaying the
- (void *)userData - (void *)userData
{ {
if ((event_type != NSMouseEntered) && (event_type != NSMouseExited) if ((event_type != NSMouseEntered) && (event_type != NSMouseExited)
&& (event_type != NSCursorUpdate)) && (event_type != NSCursorUpdate))
return NULL; return NULL;
return event_data.tracking.user_data; return event_data.tracking.user_data;
} }
@ -441,7 +430,7 @@ NSTimer* realTimer; // means of delaying the
{ {
// Make sure it is one of the right event types // Make sure it is one of the right event types
if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic)) if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic))
return 0; return 0;
return event_data.misc.data1; return event_data.misc.data1;
} }
@ -450,7 +439,7 @@ NSTimer* realTimer; // means of delaying the
{ {
// Make sure it is one of the right event types // Make sure it is one of the right event types
if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic)) if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic))
return 0; return 0;
return event_data.misc.data2; return event_data.misc.data2;
} }
@ -459,7 +448,7 @@ NSTimer* realTimer; // means of delaying the
{ {
// Make sure it is one of the right event types // Make sure it is one of the right event types
if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic)) if ((event_type != NSFlagsChanged) && (event_type != NSPeriodic))
return 0; return 0;
return event_data.misc.sub_type;; return event_data.misc.sub_type;;
} }
@ -480,40 +469,40 @@ NSTimer* realTimer; // means of delaying the
// Encode the event date based upon the event type // Encode the event date based upon the event type
switch (event_type) switch (event_type)
{ {
case NSLeftMouseDown: case NSLeftMouseDown:
case NSLeftMouseUp: case NSLeftMouseUp:
case NSRightMouseDown: case NSRightMouseDown:
case NSRightMouseUp: case NSRightMouseUp:
case NSMouseMoved: case NSMouseMoved:
case NSLeftMouseDragged: case NSLeftMouseDragged:
case NSRightMouseDragged: case NSRightMouseDragged:
[aCoder encodeValuesOfObjCTypes: "iif", &event_data.mouse.event_num, [aCoder encodeValuesOfObjCTypes: "iif", &event_data.mouse.event_num,
&event_data.mouse.click, &event_data.mouse.pressure]; &event_data.mouse.click, &event_data.mouse.pressure];
break; break;
case NSMouseEntered: case NSMouseEntered:
case NSMouseExited: case NSMouseExited:
case NSCursorUpdate: case NSCursorUpdate:
// Can't do anything with the user_data!? // Can't do anything with the user_data!?
[aCoder encodeValuesOfObjCTypes: "ii", &event_data.tracking.event_num, [aCoder encodeValuesOfObjCTypes: "ii", &event_data.tracking.event_num,
&event_data.tracking.tracking_num]; &event_data.tracking.tracking_num];
break; break;
case NSKeyDown: case NSKeyDown:
case NSKeyUp: case NSKeyUp:
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &event_data.key.repeat]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &event_data.key.repeat];
[aCoder encodeObject: event_data.key.char_keys]; [aCoder encodeObject: event_data.key.char_keys];
[aCoder encodeObject: event_data.key.unmodified_keys]; [aCoder encodeObject: event_data.key.unmodified_keys];
[aCoder encodeValueOfObjCType: "S" at: &event_data.key.key_code]; [aCoder encodeValueOfObjCType: "S" at: &event_data.key.key_code];
break; break;
case NSFlagsChanged: case NSFlagsChanged:
case NSPeriodic: case NSPeriodic:
[aCoder encodeValuesOfObjCTypes: "sii", &event_data.misc.sub_type, [aCoder encodeValuesOfObjCTypes: "sii", &event_data.misc.sub_type,
&event_data.misc.data1, &event_data.misc.data2]; &event_data.misc.data1, &event_data.misc.data2];
break; break;
} }
} }
- initWithCoder:aDecoder - initWithCoder:aDecoder
@ -526,41 +515,41 @@ NSTimer* realTimer; // means of delaying the
// Decode the event date based upon the event type // Decode the event date based upon the event type
switch (event_type) switch (event_type)
{ {
case NSLeftMouseDown: case NSLeftMouseDown:
case NSLeftMouseUp: case NSLeftMouseUp:
case NSRightMouseDown: case NSRightMouseDown:
case NSRightMouseUp: case NSRightMouseUp:
case NSMouseMoved: case NSMouseMoved:
case NSLeftMouseDragged: case NSLeftMouseDragged:
case NSRightMouseDragged: case NSRightMouseDragged:
[aDecoder decodeValuesOfObjCTypes: "iif", &event_data.mouse.event_num, [aDecoder decodeValuesOfObjCTypes: "iif", &event_data.mouse.event_num,
&event_data.mouse.click, &event_data.mouse.pressure]; &event_data.mouse.click, &event_data.mouse.pressure];
break; break;
case NSMouseEntered: case NSMouseEntered:
case NSMouseExited: case NSMouseExited:
case NSCursorUpdate: case NSCursorUpdate:
// Can't do anything with the user_data!? // Can't do anything with the user_data!?
[aDecoder decodeValuesOfObjCTypes: "ii", &event_data.tracking.event_num, [aDecoder decodeValuesOfObjCTypes: "ii", &event_data.tracking.event_num,
&event_data.tracking.tracking_num]; &event_data.tracking.tracking_num];
break; break;
case NSKeyDown: case NSKeyDown:
case NSKeyUp: case NSKeyUp:
[aDecoder decodeValueOfObjCType: @encode(BOOL) [aDecoder decodeValueOfObjCType: @encode(BOOL)
at: &event_data.key.repeat]; at: &event_data.key.repeat];
event_data.key.char_keys = [aDecoder decodeObject]; event_data.key.char_keys = [aDecoder decodeObject];
event_data.key.unmodified_keys = [aDecoder decodeObject]; event_data.key.unmodified_keys = [aDecoder decodeObject];
[aDecoder decodeValueOfObjCType: "S" at: &event_data.key.key_code]; [aDecoder decodeValueOfObjCType: "S" at: &event_data.key.key_code];
break; break;
case NSFlagsChanged: case NSFlagsChanged:
case NSPeriodic: case NSPeriodic:
[aDecoder decodeValuesOfObjCTypes: "sii", &event_data.misc.sub_type, [aDecoder decodeValuesOfObjCTypes: "sii", &event_data.misc.sub_type,
&event_data.misc.data1, &event_data.misc.data2]; &event_data.misc.data1, &event_data.misc.data2];
break; break;
} }
return self; return self;
} }
@ -568,20 +557,20 @@ NSTimer* realTimer; // means of delaying the
- (NSString*)description - (NSString*)description
{ {
const char* eventTypes[] = { "leftMouseDown", "leftMouseUp", const char* eventTypes[] = { "leftMouseDown", "leftMouseUp",
"rightMouseDown", "rightMouseUp", "mouseMoved", "leftMouseDragged", "rightMouseDown", "rightMouseUp", "mouseMoved", "leftMouseDragged",
"rightMouseDragged", "mouseEntered", "mouseExited", "keyDown", "keyUp", "rightMouseDragged", "mouseEntered", "mouseExited", "keyDown", "keyUp",
"flagsChanged", "periodic", "cursorUpdate" "flagsChanged", "periodic", "cursorUpdate"
}; };
switch (event_type) { switch (event_type) {
case NSLeftMouseDown: case NSLeftMouseDown:
case NSLeftMouseUp: case NSLeftMouseUp:
case NSRightMouseDown: case NSRightMouseDown:
case NSRightMouseUp: case NSRightMouseUp:
case NSMouseMoved: case NSMouseMoved:
case NSLeftMouseDragged: case NSLeftMouseDragged:
case NSRightMouseDragged: case NSRightMouseDragged:
return [NSString stringWithFormat: return [NSString stringWithFormat:
@"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u," @"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u,"
@" time = %f, window = %d, dpsContext = %p," @" time = %f, window = %d, dpsContext = %p,"
@" event number = %d, click = %d, pressure = %f", @" event number = %d, click = %d, pressure = %f",
@ -589,11 +578,11 @@ NSTimer* realTimer; // means of delaying the
modifier_flags, event_time, window_num, event_context, modifier_flags, event_time, window_num, event_context,
event_data.mouse.event_num, event_data.mouse.click, event_data.mouse.event_num, event_data.mouse.click,
event_data.mouse.pressure]; event_data.mouse.pressure];
break; break;
case NSMouseEntered: case NSMouseEntered:
case NSMouseExited: case NSMouseExited:
return [NSString stringWithFormat: return [NSString stringWithFormat:
@"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u," @"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u,"
@" time = %f, window = %d, dpsContext = %p, " @" time = %f, window = %d, dpsContext = %p, "
@" event number = %d, tracking number = %d, user data = %p", @" event number = %d, tracking number = %d, user data = %p",
@ -602,11 +591,11 @@ NSTimer* realTimer; // means of delaying the
event_data.tracking.event_num, event_data.tracking.event_num,
event_data.tracking.tracking_num, event_data.tracking.tracking_num,
event_data.tracking.user_data]; event_data.tracking.user_data];
break; break;
case NSKeyDown: case NSKeyDown:
case NSKeyUp: case NSKeyUp:
return [NSString stringWithFormat: return [NSString stringWithFormat:
@"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u," @"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u,"
@" time = %f, window = %d, dpsContext = %p, " @" time = %f, window = %d, dpsContext = %p, "
@" repeat = %s, keys = %@, ukeys = %@, keyCode = 0x%x", @" repeat = %s, keys = %@, ukeys = %@, keyCode = 0x%x",
@ -615,12 +604,12 @@ NSTimer* realTimer; // means of delaying the
(event_data.key.repeat ? "YES" : "NO"), (event_data.key.repeat ? "YES" : "NO"),
event_data.key.char_keys, event_data.key.unmodified_keys, event_data.key.char_keys, event_data.key.unmodified_keys,
event_data.key.key_code]; event_data.key.key_code];
break; break;
case NSFlagsChanged: case NSFlagsChanged:
case NSPeriodic: case NSPeriodic:
case NSCursorUpdate: case NSCursorUpdate:
return [NSString stringWithFormat: return [NSString stringWithFormat:
@"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u," @"NSEvent: eventType = %s, point = { %f, %f }, modifiers = %u,"
@" time = %f, window = %d, dpsContext = %p, " @" time = %f, window = %d, dpsContext = %p, "
@" subtype = %d, data1 = %p, data2 = %p", @" subtype = %d, data1 = %p, data2 = %p",
@ -628,7 +617,7 @@ NSTimer* realTimer; // means of delaying the
modifier_flags, event_time, window_num, event_context, modifier_flags, event_time, window_num, event_context,
event_data.misc.sub_type, event_data.misc.data1, event_data.misc.sub_type, event_data.misc.data1,
event_data.misc.data2]; event_data.misc.data2];
break; break;
} }
return [super description]; return [super description];