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