From c45f681d6d95e3b5172ef73cf0fcd83feaaf0f19 Mon Sep 17 00:00:00 2001 From: CaS Date: Tue, 27 Aug 2002 14:24:54 +0000 Subject: [PATCH] NSObject and NSRunLoop updates for MacOS-X compatibility git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14349 72102866-910b-0410-8b05-ffd578937521 --- Headers/gnustep/base/NSObject.h | 2 + Headers/gnustep/base/NSRunLoop.h | 2 + Source/NSObject.m | 8 ++++ Source/NSRunLoop.m | 72 ++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/Headers/gnustep/base/NSObject.h b/Headers/gnustep/base/NSObject.h index 3c64dae05..c3345ead2 100644 --- a/Headers/gnustep/base/NSObject.h +++ b/Headers/gnustep/base/NSObject.h @@ -138,6 +138,7 @@ + (IMP) instanceMethodForSelector: (SEL)aSelector; + (NSMethodSignature*) instanceMethodSignatureForSelector: (SEL)aSelector; + (BOOL) instancesRespondToSelector: (SEL)aSelector; ++ (BOOL) isSubclassOfClass: (Class)aClass; + (id) new; + (void) poseAsClass: (Class)aClassObject; + (id) setVersion: (int)aVersion; @@ -306,6 +307,7 @@ GS_EXPORT NSRecursiveLock *gnustep_global_lock; #include @interface NSObject (TimedPerformers) ++ (void) cancelPreviousPerformRequestsWithTarget: (id)obj; + (void) cancelPreviousPerformRequestsWithTarget: (id)obj selector: (SEL)s object: (id)arg; diff --git a/Headers/gnustep/base/NSRunLoop.h b/Headers/gnustep/base/NSRunLoop.h index f5ed90454..e5ddbbfaf 100644 --- a/Headers/gnustep/base/NSRunLoop.h +++ b/Headers/gnustep/base/NSRunLoop.h @@ -67,6 +67,8 @@ GS_EXPORT NSString * const NSDefaultRunLoopMode; - (void) addPort: (NSPort*)port forMode: (NSString*)mode; +- (void) cancelPerformSelectorsWithTarget: (id)target; + - (void) cancelPerformSelector: (SEL)aSelector target: (id)target argument: (id)argument; diff --git a/Source/NSObject.m b/Source/NSObject.m index 02bddb936..86bcefcef 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -1494,6 +1494,14 @@ static BOOL double_release_check_enabled = NO; return NO; } +/** + * Returns YES if the receiver is aClass or a subclass of aClass. + */ ++ (BOOL) isSubclassOfClass: (Class)aClass +{ + return GSObjCIsKindOf(self, aClass); +} + /** * Causes the receiver to execute the method implementation corresponding * to aSelector and returns the result.
diff --git a/Source/NSRunLoop.m b/Source/NSRunLoop.m index b04a7be37..1ea0bf481 100644 --- a/Source/NSRunLoop.m +++ b/Source/NSRunLoop.m @@ -1192,6 +1192,39 @@ if (0) { @implementation NSObject (TimedPerformers) +/** + * Cancels any perform operations set up for the specified target + * in the current run loop. + */ ++ (void) cancelPreviousPerformRequestsWithTarget: (id)target +{ + NSMutableArray *perf = [[NSRunLoop currentRunLoop] _timedPerformers]; + unsigned count = [perf count]; + + if (count > 0) + { + GSTimedPerformer *array[count]; + + IF_NO_GC(RETAIN(target)); + [perf getObjects: array]; + while (count-- > 0) + { + GSTimedPerformer *p = array[count]; + + if (p->target == target) + { + [perf removeObjectAtIndex: count]; + } + } + RELEASE(target); + } +} + +/** + * Cancels any perform operations set up for the specified target + * in the current loop, but only if the vaslue of aSelector and argument + * with which the performs were set up exactly match those supplied. + */ + (void) cancelPreviousPerformRequestsWithTarget: (id)target selector: (SEL)aSelector object: (id)arg @@ -2087,6 +2120,45 @@ if (0) { forMode: (NSString*)mode]; } +/** + * Cancels any perform operations set up for the specified target + * in the receiver. + */ +- (void) cancelPerformSelectorsWithTarget: (id) target +{ + NSMapEnumerator enumerator; + GSRunLoopCtxt *context; + void *mode; + + enumerator = NSEnumerateMapTable(_contextMap); + + while (NSNextMapEnumeratorPair(&enumerator, &mode, (void**)&context)) + { + if (context != nil) + { + GSIArray performers = context->performers; + unsigned count = GSIArrayCount(performers); + + while (count--) + { + GSRunLoopPerformer *p; + + p = GSIArrayItemAtIndex(performers, count).obj; + if (p->target == target) + { + GSIArrayRemoveItemAtIndex(performers, count); + } + } + } + } + NSEndMapTableEnumeration(&enumerator); +} + +/** + * Cancels any perform operations set up for the specified target + * in the receiver, but only if the vaslue of aSelector and argument + * with which the performs were set up exactly match those supplied. + */ - (void) cancelPerformSelector: (SEL)aSelector target: (id) target argument: (id) argument