Skip to content

Commit

Permalink
Added target action support to the switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcormier committed Apr 3, 2010
1 parent 3eb3067 commit a0f0cbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/framework/mondoSwitch/MondoSwitch.h
Expand Up @@ -35,11 +35,20 @@
@private
MondoSwitchButtonCALayer *buttonLayer;
CALayer *mainLayer;
BOOL _on;
BOOL on;

id target;
SEL action;
}

@property(nonatomic, getter=isOn) BOOL on;

-(void)setOn:(BOOL)on animated:(BOOL)animated;

// FIXME: If an NSControl was extended instead of an NSView these definitions
// wouldn't be required.
@property(retain) id target;
@property SEL action;


@end
19 changes: 9 additions & 10 deletions src/framework/mondoSwitch/MondoSwitch.m
Expand Up @@ -13,7 +13,7 @@

@implementation MondoSwitch

@synthesize on=_on;
@synthesize on, target, action;


#pragma mark -
Expand All @@ -40,7 +40,6 @@ - (void)awakeFromNib {
[self setupLayers];
}


-(NSGradient*)gradient {
if( !_bgGradient) {
// Create a basic gradient for the background
Expand Down Expand Up @@ -114,6 +113,7 @@ - (void) dealloc {
PPRelease(mainLayer);
PPRelease(buttonLayer);
PPRelease(_bgGradient);
PPRelease(target);
[super dealloc];
}

Expand Down Expand Up @@ -154,16 +154,15 @@ - (void)drawRect:(NSRect)dirtyRect {
#pragma mark -
#pragma mark propertyMethods

-(void)setOn:(BOOL)on {
if (_on == on) { return; }
_on = on;
[buttonLayer setOn:on];
-(void)setOn:(BOOL)newState {
[self setOn:newState animated:YES];
}

-(void)setOn:(BOOL)on animated:(BOOL)animated {
if (_on == on) { return; }
_on = on;
[buttonLayer setOn:on animated:animated];
-(void)setOn:(BOOL)newState animated:(BOOL)animated {
if (on == newState) { return; }
on = newState;
[target performSelector:action];
[buttonLayer setOn:newState animated:animated];
}

#pragma mark -
Expand Down

0 comments on commit a0f0cbf

Please sign in to comment.