Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 85 lines (77 sloc) 1.545 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
//
// SCSwitchButton.m
// SCSwitchButton
//
// Created by Vincent on 1/7/11.
// Copyright 2011 Vincent S. Wang. All rights reserved.
//

#import "SCSwitchButton.h"
#import "SCSwitchButtonCell.h"

@implementation SCSwitchButton

+ (void)initialize
{
[self setCellClass:[SCSwitchButtonCell class]];
}

- (void)awakeFromNib
{
[[self class] setCellClass:[SCSwitchButtonCell class]];
}

- (void)keyDown:(NSEvent *)event
{
unichar character = [[event characters] characterAtIndex:0UL];
switch (character)
{
case NSLeftArrowFunctionKey:
case NSRightArrowFunctionKey:
//Do nothing (yet). We'll handle this in keyUp:.
break;
default:
[super keyDown:event];
break;
}
}

- (void)keyUp:(NSEvent *)event
{
unichar character = [[event characters] characterAtIndex:0UL];
switch (character)
{
case NSLeftArrowFunctionKey:
switch ([self state])
{
case NSOffState:
NSBeep();
break;
case NSMixedState:
[self setState:NSOffState];
break;
case NSOnState:
if ([self allowsMixedState])
[self setState:NSMixedState];
else
[self setState:NSOffState];
break;
}
break;
case NSRightArrowFunctionKey:
switch ([self state])
{
case NSOffState:
if ([self allowsMixedState])
[self setState:NSMixedState];
else
[self setState:NSOnState];
break;
case NSMixedState:
[self setState:NSOnState];
break;
case NSOnState:
NSBeep();
break;
}
break;
default:
[super keyUp:event];
break;
}
}

@end
Something went wrong with that request. Please try again.