2005-06-29 15:53:00 +00:00
|
|
|
#import "TrackingSlider.h"
|
|
|
|
#import "TrackingCell.h"
|
|
|
|
|
|
|
|
@implementation TrackingSlider
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
static NSString *TrackingSliderValueObservationContext = @"TrackingSliderValueObservationContext";
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id)initWithFrame:(NSRect)frameRect {
|
2009-02-22 22:28:09 +00:00
|
|
|
self = [super initWithFrame:frameRect];
|
2022-02-07 05:49:27 +00:00
|
|
|
if(self) {
|
2009-02-22 22:28:09 +00:00
|
|
|
bindingInfo = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id)initWithCoder:(NSCoder *)decoder {
|
2009-02-22 22:28:09 +00:00
|
|
|
self = [super initWithCoder:decoder];
|
2022-02-07 05:49:27 +00:00
|
|
|
if(self) {
|
2009-02-22 22:28:09 +00:00
|
|
|
bindingInfo = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
return self;
|
2005-06-29 15:53:00 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
|
|
|
if([TrackingSliderValueObservationContext isEqual:(__bridge id)(context)]) {
|
|
|
|
if(![self isTracking]) {
|
2009-02-22 22:28:09 +00:00
|
|
|
id value = [change objectForKey:NSKeyValueChangeNewKey];
|
|
|
|
[self setDoubleValue:[value doubleValue]];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2009-02-22 22:28:09 +00:00
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)bind:(NSString *)binding toObject:(id)observableController withKeyPath:(NSString *)keyPath options:(NSDictionary *)options {
|
|
|
|
if([binding isEqualToString:@"value"]) {
|
|
|
|
[observableController addObserver:self forKeyPath:keyPath options:(NSKeyValueObservingOptionNew)context:(__bridge void *_Nullable)(TrackingSliderValueObservationContext)];
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
NSDictionary *bindingsData = [NSDictionary dictionaryWithObjectsAndKeys:
|
2022-02-07 05:49:27 +00:00
|
|
|
observableController, NSObservedObjectKey,
|
|
|
|
[keyPath copy], NSObservedKeyPathKey,
|
|
|
|
[options copy], NSOptionsKey, nil];
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
[bindingInfo setObject:bindingsData forKey:binding];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2009-02-22 22:28:09 +00:00
|
|
|
[super bind:binding toObject:observableController withKeyPath:keyPath options:options];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)unbind:(NSString *)binding {
|
|
|
|
if([binding isEqualToString:@"value"]) {
|
2009-02-22 22:28:09 +00:00
|
|
|
NSDictionary *info = [bindingInfo objectForKey:binding];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
NSString *keyPath = [info objectForKey:NSObservedKeyPathKey];
|
|
|
|
id observedObject = [info objectForKey:NSObservedObjectKey];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
[observedObject removeObserver:self forKeyPath:keyPath];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2009-02-22 22:28:09 +00:00
|
|
|
[super unbind:binding];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)isTracking {
|
2009-02-22 22:28:09 +00:00
|
|
|
return [[self cell] isTracking];
|
|
|
|
}
|
|
|
|
|
2005-06-29 15:53:00 +00:00
|
|
|
@end
|