Last change
on this file since 612 was 595, checked in by Nicholas Riley, 15 years ago |
Keyboard-accessible and better-behaving volume slider.
|
File size:
1.1 KB
|
Line | |
---|
1 | //
|
---|
2 | // NJRMenuSlider.m
|
---|
3 | //
|
---|
4 | // Created by Nicholas Riley on 12/6/09.
|
---|
5 | // Copyright 2009 Nicholas Riley. All rights reserved.
|
---|
6 | //
|
---|
7 |
|
---|
8 | #import "NJRMenuSlider.h"
|
---|
9 |
|
---|
10 | // modeled after AppleVolumeItemView in SystemUIServer (but much simpler)
|
---|
11 | @implementation NJRMenuSlider
|
---|
12 |
|
---|
13 | - (void)viewDidMoveToWindow;
|
---|
14 | {
|
---|
15 | [super viewDidMoveToWindow];
|
---|
16 | [[self window] makeFirstResponder: self];
|
---|
17 | }
|
---|
18 |
|
---|
19 | - (void)keyDown:(NSEvent *)theEvent;
|
---|
20 | {
|
---|
21 | double value;
|
---|
22 |
|
---|
23 | // XXX is there a way to call rather than emulate the standard behavior?
|
---|
24 | switch ([[theEvent charactersIgnoringModifiers] characterAtIndex: 0]) {
|
---|
25 | case NSUpArrowFunctionKey:
|
---|
26 | value = MIN([self doubleValue] + ([self maxValue] - [self minValue]) / 10, [self maxValue]);
|
---|
27 | break;
|
---|
28 | case NSDownArrowFunctionKey:
|
---|
29 | value = MAX([self doubleValue] - ([self maxValue] - [self minValue]) / 10, [self minValue]);
|
---|
30 | break;
|
---|
31 | case NSPageUpFunctionKey:
|
---|
32 | value = [self maxValue];
|
---|
33 | break;
|
---|
34 | case NSPageDownFunctionKey:
|
---|
35 | value = [self minValue];
|
---|
36 | break;
|
---|
37 | default:
|
---|
38 | [super keyDown: theEvent];
|
---|
39 | return;
|
---|
40 | }
|
---|
41 |
|
---|
42 | [self setDoubleValue: value];
|
---|
43 | [self sendAction: [self action] to: [self target]];
|
---|
44 | }
|
---|
45 |
|
---|
46 | @end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.