Skip to content
Browse files

Added target action support to the switch

  • Loading branch information...
1 parent 3eb3067 commit a0f0cbfe352fe6c4ff05c40c291a368b7463f705 @mcormier committed Apr 3, 2010
Showing with 19 additions and 11 deletions.
  1. +10 −1 src/framework/mondoSwitch/MondoSwitch.h
  2. +9 −10 src/framework/mondoSwitch/MondoSwitch.m
View
11 src/framework/mondoSwitch/MondoSwitch.h
@@ -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
View
19 src/framework/mondoSwitch/MondoSwitch.m
@@ -13,7 +13,7 @@
@implementation MondoSwitch
-@synthesize on=_on;
+@synthesize on, target, action;
#pragma mark -
@@ -40,7 +40,6 @@ - (void)awakeFromNib {
[self setupLayers];
}
-
-(NSGradient*)gradient {
if( !_bgGradient) {
// Create a basic gradient for the background
@@ -114,6 +113,7 @@ - (void) dealloc {
PPRelease(mainLayer);
PPRelease(buttonLayer);
PPRelease(_bgGradient);
+ PPRelease(target);
[super dealloc];
}
@@ -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 -

0 comments on commit a0f0cbf

Please sign in to comment.
Something went wrong with that request. Please try again.