patch for kvo struct setters by Eric Wasylishen

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28793 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-10-11 04:57:34 +00:00
parent e4a6d046be
commit 70af2643ac
2 changed files with 130 additions and 0 deletions

View file

@ -1,3 +1,7 @@
2009-10-11 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSKeyValueObserving.m: add setters for common structures.
2009-10-10 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSString.h:

View file

@ -132,6 +132,10 @@ static inline void setup()
- (void) setterLongLong: (unsigned long long)val;
#endif
- (void) setterShort: (unsigned short)val;
- (void) setterRange: (NSRange)val;
- (void) setterPoint: (NSPoint)val;
- (void) setterSize: (NSSize)val;
- (void) setterRect: (NSRect)rect;
@end
/* An instance of this records all the information for a single observation.
@ -533,6 +537,32 @@ replacementForClass(Class c)
imp = [[GSKVOSetter class]
instanceMethodForSelector: @selector(setter:)];
break;
case _C_STRUCT_B:
if (strcmp(@encode(NSRange), type) == 0)
{
imp = [[GSKVOSetter class]
instanceMethodForSelector: @selector(setterRange:)];
}
else if (strcmp(@encode(NSPoint), type) == 0)
{
imp = [[GSKVOSetter class]
instanceMethodForSelector: @selector(setterPoint:)];
}
else if (strcmp(@encode(NSSize), type) == 0)
{
imp = [[GSKVOSetter class]
instanceMethodForSelector: @selector(setterSize:)];
}
else if (strcmp(@encode(NSRect), type) == 0)
{
imp = [[GSKVOSetter class]
instanceMethodForSelector: @selector(setterRect:)];
}
else
{
imp = 0;
}
break;
default:
imp = 0;
break;
@ -801,6 +831,102 @@ replacementForClass(Class c)
}
RELEASE(key);
}
- (void) setterRange: (NSRange)val
{
NSString *key;
Class c = [self class];
void (*imp)(id,SEL,NSRange);
imp = (void (*)(id,SEL,NSRange))[c instanceMethodForSelector: _cmd];
key = newKey(_cmd);
if ([c automaticallyNotifiesObserversForKey: key] == YES)
{
// pre setting code here
[self willChangeValueForKey: key];
(*imp)(self, _cmd, val);
// post setting code here
[self didChangeValueForKey: key];
}
else
{
(*imp)(self, _cmd, val);
}
RELEASE(key);
}
- (void) setterPoint: (NSPoint)val
{
NSString *key;
Class c = [self class];
void (*imp)(id,SEL,NSPoint);
imp = (void (*)(id,SEL,NSPoint))[c instanceMethodForSelector: _cmd];
key = newKey(_cmd);
if ([c automaticallyNotifiesObserversForKey: key] == YES)
{
// pre setting code here
[self willChangeValueForKey: key];
(*imp)(self, _cmd, val);
// post setting code here
[self didChangeValueForKey: key];
}
else
{
(*imp)(self, _cmd, val);
}
RELEASE(key);
}
- (void) setterSize: (NSSize)val
{
NSString *key;
Class c = [self class];
void (*imp)(id,SEL,NSSize);
imp = (void (*)(id,SEL,NSSize))[c instanceMethodForSelector: _cmd];
key = newKey(_cmd);
if ([c automaticallyNotifiesObserversForKey: key] == YES)
{
// pre setting code here
[self willChangeValueForKey: key];
(*imp)(self, _cmd, val);
// post setting code here
[self didChangeValueForKey: key];
}
else
{
(*imp)(self, _cmd, val);
}
RELEASE(key);
}
- (void) setterRect: (NSRect)val
{
NSString *key;
Class c = [self class];
void (*imp)(id,SEL,NSRect);
imp = (void (*)(id,SEL,NSRect))[c instanceMethodForSelector: _cmd];
key = newKey(_cmd);
if ([c automaticallyNotifiesObserversForKey: key] == YES)
{
// pre setting code here
[self willChangeValueForKey: key];
(*imp)(self, _cmd, val);
// post setting code here
[self didChangeValueForKey: key];
}
else
{
(*imp)(self, _cmd, val);
}
RELEASE(key);
}
@end