mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 22:00:46 +00:00
Add reverse value change methods for bindings.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25935 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
efdf40b451
commit
ce957cc6e2
4 changed files with 88 additions and 154 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2008-01-13 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/GSBindingHelpers.h,
|
||||||
|
* Source/NSKeyValueBinding.m: Add reverse value change methods.
|
||||||
|
* Source/NSControl.m (-sendAction:to:): Send value change for binding.
|
||||||
|
|
||||||
2008-01-08 22:35-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
2008-01-08 22:35-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
* Headers/AppKit/NSSegmentedCell.h: Added rect ivar to cache frame.
|
* Headers/AppKit/NSSegmentedCell.h: Added rect ivar to cache frame.
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by: Chris Farber <chris@chrisfarber.net>
|
Written by: Chris Farber <chris@chrisfarber.net>
|
||||||
Date: 2007
|
Date: 2007
|
||||||
|
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||||
|
Date: Decembre 2007
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -43,7 +45,10 @@
|
||||||
|
|
||||||
+ (void) exposeBinding: (NSString *)binding forClass: (Class)clazz;
|
+ (void) exposeBinding: (NSString *)binding forClass: (Class)clazz;
|
||||||
+ (NSArray *) exposedBindingsForClass: (Class)clazz;
|
+ (NSArray *) exposedBindingsForClass: (Class)clazz;
|
||||||
+ (NSDictionary *) infoForBinding: (NSString *)binding forObject: (id)anObject;
|
+ (GSKeyValueBinding *) getBinding: (NSString *)binding
|
||||||
|
forObject: (id)anObject;
|
||||||
|
+ (NSDictionary *) infoForBinding: (NSString *)binding
|
||||||
|
forObject: (id)anObject;
|
||||||
+ (void) unbind: (NSString *)binding forObject: (id)anObject;
|
+ (void) unbind: (NSString *)binding forObject: (id)anObject;
|
||||||
+ (void) unbindAllForObject: (id)anObject;
|
+ (void) unbindAllForObject: (id)anObject;
|
||||||
|
|
||||||
|
@ -54,10 +59,13 @@
|
||||||
options: (NSDictionary *)options
|
options: (NSDictionary *)options
|
||||||
fromObject: (id)source;
|
fromObject: (id)source;
|
||||||
- (void) setValueFor: (NSString *)binding;
|
- (void) setValueFor: (NSString *)binding;
|
||||||
|
- (void) reverseSetValueFor: (NSString *)binding;
|
||||||
|
|
||||||
/* Transforms the value with a value transformer, if specified and available,
|
/* Transforms the value with a value transformer, if specified and available,
|
||||||
* and takes care of any placeholders
|
* and takes care of any placeholders
|
||||||
*/
|
*/
|
||||||
- (id) transformValue: (id)value withOptions: (NSDictionary *)options;
|
- (id) transformValue: (id)value withOptions: (NSDictionary *)options;
|
||||||
|
- (id) reverseTransformValue: (id)value withOptions: (NSDictionary *)options;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -635,7 +635,8 @@ static NSNotificationCenter *nc;
|
||||||
{
|
{
|
||||||
if (_cell == aCell)
|
if (_cell == aCell)
|
||||||
{
|
{
|
||||||
[_cell drawWithFrame: _bounds inView: self];
|
[_cell drawWithFrame: _bounds
|
||||||
|
inView: self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,8 +647,8 @@ static NSNotificationCenter *nc;
|
||||||
{
|
{
|
||||||
if (_cell == aCell)
|
if (_cell == aCell)
|
||||||
{
|
{
|
||||||
[_cell drawInteriorWithFrame: _bounds
|
[_cell drawInteriorWithFrame: _bounds
|
||||||
inView: self];
|
inView: self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,6 +702,13 @@ static NSNotificationCenter *nc;
|
||||||
*/
|
*/
|
||||||
- (BOOL) sendAction: (SEL)theAction to: (id)theTarget
|
- (BOOL) sendAction: (SEL)theAction to: (id)theTarget
|
||||||
{
|
{
|
||||||
|
GSKeyValueBinding *theBinding;
|
||||||
|
|
||||||
|
theBinding = [GSKeyValueBinding getBinding: NSValueBinding
|
||||||
|
forObject: self];
|
||||||
|
if (theBinding != nil)
|
||||||
|
[theBinding reverseSetValueFor: @"objectValue"];
|
||||||
|
|
||||||
if (theAction)
|
if (theAction)
|
||||||
return [NSApp sendAction: theAction to: theTarget from: self];
|
return [NSApp sendAction: theAction to: theTarget from: self];
|
||||||
else
|
else
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
Written by: Chris Farber <chris@chrisfarber.net>
|
Written by: Chris Farber <chris@chrisfarber.net>
|
||||||
Date: 2007
|
Date: 2007
|
||||||
|
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||||
|
Date: Decembre 2007
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -131,16 +133,6 @@ BOOL GSBindingResolveMultipleValueBool(NSString *key, NSDictionary *bindings,
|
||||||
void GSBindingInvokeAction(NSString *targetKey, NSString *argumentKey,
|
void GSBindingInvokeAction(NSString *targetKey, NSString *argumentKey,
|
||||||
NSDictionary *bindings);
|
NSDictionary *bindings);
|
||||||
|
|
||||||
NSArray *GSBindingExposeMultipleValueBindings(
|
|
||||||
NSArray *bindingNames,
|
|
||||||
NSMutableDictionary *bindingList);
|
|
||||||
|
|
||||||
NSArray *GSBindingExposePatternBindings(
|
|
||||||
NSArray *bindingNames,
|
|
||||||
NSMutableDictionary *bindingList);
|
|
||||||
|
|
||||||
id GSBindingReverseTransformedValue(id value, NSDictionary *options);
|
|
||||||
|
|
||||||
@implementation GSKeyValueBinding
|
@implementation GSKeyValueBinding
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
|
@ -185,7 +177,8 @@ id GSBindingReverseTransformedValue(id value, NSDictionary *options);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSDictionary *) infoForBinding: (NSString *)binding forObject: (id)anObject
|
+ (GSKeyValueBinding *) getBinding: (NSString *)binding
|
||||||
|
forObject: (id)anObject
|
||||||
{
|
{
|
||||||
NSMutableDictionary *bindings;
|
NSMutableDictionary *bindings;
|
||||||
GSKeyValueBinding *theBinding;
|
GSKeyValueBinding *theBinding;
|
||||||
|
@ -201,10 +194,23 @@ id GSBindingReverseTransformedValue(id value, NSDictionary *options);
|
||||||
}
|
}
|
||||||
[bindingLock unlock];
|
[bindingLock unlock];
|
||||||
|
|
||||||
|
return theBinding;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary *) infoForBinding: (NSString *)binding
|
||||||
|
forObject: (id)anObject
|
||||||
|
{
|
||||||
|
GSKeyValueBinding *theBinding;
|
||||||
|
|
||||||
|
theBinding = [self getBinding: binding forObject: anObject];
|
||||||
|
if (theBinding == nil)
|
||||||
|
return nil;
|
||||||
|
|
||||||
return theBinding->info;
|
return theBinding->info;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) unbind: (NSString *)binding forObject: (id)anObject
|
+ (void) unbind: (NSString *)binding
|
||||||
|
forObject: (id)anObject
|
||||||
{
|
{
|
||||||
NSMutableDictionary *bindings;
|
NSMutableDictionary *bindings;
|
||||||
id observedObject;
|
id observedObject;
|
||||||
|
@ -323,6 +329,22 @@ id GSBindingReverseTransformedValue(id value, NSDictionary *options);
|
||||||
[src setValue: newValue forKey: binding];
|
[src setValue: newValue forKey: binding];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) reverseSetValueFor: (NSString *)binding
|
||||||
|
{
|
||||||
|
id newValue;
|
||||||
|
id dest;
|
||||||
|
NSString *keyPath;
|
||||||
|
NSDictionary *options;
|
||||||
|
|
||||||
|
dest = [info objectForKey: NSObservedObjectKey];
|
||||||
|
keyPath = [info objectForKey: NSObservedKeyPathKey];
|
||||||
|
options = [info objectForKey: NSOptionsKey];
|
||||||
|
|
||||||
|
newValue = [src valueForKeyPath: binding];
|
||||||
|
newValue = [self reverseTransformValue: newValue withOptions: options];
|
||||||
|
[dest setValue: newValue forKey: keyPath];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) observeValueForKeyPath: (NSString *)keyPath
|
- (void) observeValueForKeyPath: (NSString *)keyPath
|
||||||
ofObject: (id)object
|
ofObject: (id)object
|
||||||
change: (NSDictionary *)change
|
change: (NSDictionary *)change
|
||||||
|
@ -411,6 +433,33 @@ id GSBindingReverseTransformedValue(id value, NSDictionary *options);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) reverseTransformValue: (id)value withOptions: (NSDictionary *)options
|
||||||
|
{
|
||||||
|
NSString *valueTransformerName;
|
||||||
|
NSValueTransformer *valueTransformer;
|
||||||
|
|
||||||
|
valueTransformerName = [options objectForKey:
|
||||||
|
NSValueTransformerNameBindingOption];
|
||||||
|
if (valueTransformerName != nil)
|
||||||
|
{
|
||||||
|
valueTransformer = [NSValueTransformer valueTransformerForName:
|
||||||
|
valueTransformerName];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
valueTransformer = [options objectForKey:
|
||||||
|
NSValueTransformerBindingOption];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((valueTransformer != nil) && [[valueTransformer class]
|
||||||
|
allowsReverseTransformation])
|
||||||
|
{
|
||||||
|
value = [valueTransformer reverseTransformedValue: value];
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GSKeyValueOrBinding : GSKeyValueBinding
|
@implementation GSKeyValueOrBinding : GSKeyValueBinding
|
||||||
|
@ -551,140 +600,3 @@ void GSBindingInvokeAction(NSString *targetKey, NSString *argumentKey,
|
||||||
}
|
}
|
||||||
[invocation invoke];
|
[invocation invoke];
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSBindingLock()
|
|
||||||
{
|
|
||||||
[bindingLock lock];
|
|
||||||
}
|
|
||||||
|
|
||||||
void GSBindingReleaseLock()
|
|
||||||
{
|
|
||||||
[bindingLock unlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMutableDictionary *GSBindingListForObject(id object)
|
|
||||||
{
|
|
||||||
NSMutableDictionary *list;
|
|
||||||
|
|
||||||
if (!objectTable)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
list = (NSMutableDictionary *)NSMapGet(objectTable, (void *)object);
|
|
||||||
if (list == nil)
|
|
||||||
{
|
|
||||||
list = [NSMutableDictionary new];
|
|
||||||
NSMapInsert(objectTable, (void *)object, (void *)list);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSArray *GSBindingExposeMultipleValueBindings(
|
|
||||||
NSArray *bindingNames,
|
|
||||||
NSMutableDictionary *bindingList)
|
|
||||||
{
|
|
||||||
NSEnumerator *nameEnum;
|
|
||||||
NSString *name;
|
|
||||||
NSString *numberedName;
|
|
||||||
NSMutableArray *additionalBindings;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
additionalBindings = [NSMutableArray array];
|
|
||||||
nameEnum = [bindingNames objectEnumerator];
|
|
||||||
while ((name = [nameEnum nextObject]))
|
|
||||||
{
|
|
||||||
count = 1;
|
|
||||||
numberedName = name;
|
|
||||||
while ([bindingList objectForKey: numberedName] != nil)
|
|
||||||
{
|
|
||||||
numberedName = [NSString stringWithFormat: @"%@%i", name, ++count];
|
|
||||||
[additionalBindings addObject: numberedName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return additionalBindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NSArray *GSBindingExposePatternBindings(
|
|
||||||
NSArray *bindingNames,
|
|
||||||
NSMutableDictionary *bindingList)
|
|
||||||
{
|
|
||||||
NSEnumerator *nameEnum;
|
|
||||||
NSString *name;
|
|
||||||
NSString *numberedName;
|
|
||||||
NSMutableArray *additionalBindings;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
additionalBindings = [NSMutableArray array];
|
|
||||||
nameEnum = [bindingNames objectEnumerator];
|
|
||||||
while ((name = [nameEnum nextObject]))
|
|
||||||
{
|
|
||||||
count = 1;
|
|
||||||
numberedName = [NSString stringWithFormat:@"%@1", name];
|
|
||||||
while ([bindingList objectForKey: numberedName] != nil)
|
|
||||||
{
|
|
||||||
numberedName = [NSString stringWithFormat:@"%@%i", name, ++count];
|
|
||||||
[additionalBindings addObject: numberedName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return additionalBindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
id GSBindingReverseTransformedValue(id value, NSDictionary *options)
|
|
||||||
{
|
|
||||||
NSValueTransformer *valueTransformer;
|
|
||||||
NSString *valueTransformerName;
|
|
||||||
|
|
||||||
valueTransformerName = [options objectForKey:
|
|
||||||
NSValueTransformerNameBindingOption];
|
|
||||||
valueTransformer = [NSValueTransformer valueTransformerForName:
|
|
||||||
valueTransformerName];
|
|
||||||
if (valueTransformer && [[valueTransformer class]
|
|
||||||
allowsReverseTransformation])
|
|
||||||
{
|
|
||||||
value = [valueTransformer reverseTransformedValue: value];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@interface _GSStateMarker : NSObject
|
|
||||||
{
|
|
||||||
NSString * description;
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation _GSStateMarker
|
|
||||||
|
|
||||||
- (id) initWithType: (int)type
|
|
||||||
{
|
|
||||||
if (type == 0)
|
|
||||||
{
|
|
||||||
description = @"<MULTIPLE VALUES MARKER>";
|
|
||||||
}
|
|
||||||
else if (type == 1)
|
|
||||||
{
|
|
||||||
description = @"<NO SELECTION MARKER>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
description = @"<NOT APPLICABLE MARKER>";
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) valueForKey: (NSString *)key
|
|
||||||
{
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) retain { return self; }
|
|
||||||
- (oneway void) release {}
|
|
||||||
|
|
||||||
- (NSString *) description
|
|
||||||
{
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue