source: trunk/Cocoa/Pester/Source/NJRHotKey.m@ 336

Last change on this file since 336 was 133, checked in by Nicholas Riley, 22 years ago

VERSION: Updated for 1.1b4.

PSMovieAlertController.[hm]: Set output volume from alert; save and
restore output volume (bug 27).

PSBeepAlert.[hm]: Save and set volume, disabled pending a
synchronous equivalent to NSBeep().

NJRQTMediaPopUpButton.[hm]: Save movieHasAudio (does not include
beeps, pending the above fix, since they don't permit volume
adjustment). savedVolume indicates whether the volume has been saved
but not restored yet; outputVolume stores the set volume (eventually
incorporated into a PSMediaAlert).

PSMediaAlert.[hm]: Stores repetitions and volume information for audio
alerts. New superclass of PSBeepAlert and PSMovieAlert.

PSPreferencesController.m: Fixed bug where hot keys still appeared
even after they couldn't be set - last of bug 29. Add Command-comma
to the list of disallowed equivalents, as it's reserved for
Preferences now (still a bug - it'll show the entire set key
equivalent at the left side of the window when you press
command-comma; ah well.)

Volume [0123].png: Volume-indicating small icons from QuickTime 6.

NJRSoundManager.[hm]: Interface to volume saving, restoring, setting -
necessary because the QuickTime call to SetDefaultOutputVolume sets
the right channel volume only (bug 27).

PSVolumeController.h: Controller for volume popup window (bug 27).
Not your average NSWindowController, but it works. Keyboard control
of volume is still necessary; filed as bug 31.

PSAlarmSetController.[hm]: Added references to sound volume button and
showVolume: action. Added volume setting support (bug 27); mostly
similar interface to calendar, though we need direct calls to
NJRSoundManager to restore sound volume at times. Only enable sound
volume button if selected media file has audio component (and isn't the
system alert sound, which I discussed above). Take advantage of
PSMediaAlert to factor some code in _readAlerts:. Save and restore
volume as part of alerts.

Read Me.rtfd: Updated release notes; fixed some bizarre text
formatting problems; search/replace "* " bullet-space with "*\t"
bullet-tab to improve alignment in release notes.

PSMovieAlert.[hm]: Factored code into PSMediaAlert. Describe output
volume as percentage of maximum.

NJRHotKey.m: Fixed some odd spacing left over from Ecky's code.

PSApplication.m: Restore saved output volume on quit.

English.lproj/MainMenu.nib: Added volume button.

English.lproj/Volume.nib: Volume nib (bug 27).

PSCalendarController.m: Removed casts from a copy/paste error. Fixed
variable names in some code inherited from my TextExtras incremental
search modifications - it's not always a text field now.

File size: 2.8 KB
RevLine 
[131]1//
2// NJRHotKey.m
3// Pester
4//
5// Created by Nicholas Riley on Tue Apr 01 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "NJRHotKey.h"
10#import "NSString-NJRExtensions.h"
11
12#include <Carbon/Carbon.h>
13
14// property list keys
15static NSString * const PLCharacters = @"characters"; // NSString
16static NSString * const PLModifierFlags = @"modifierFlags"; // NSNumber
17static NSString * const PLKeyCode = @"keyCode"; // NSNumber
18
19@implementation NJRHotKey
20
21#pragma mark initialize-release
22
23+ (NJRHotKey *)hotKeyWithCharacters:(NSString *)characters modifierFlags:(unsigned)modifierFlags keyCode:(unsigned short)keyCode;
24{
25 return [[[self alloc] initWithCharacters: characters modifierFlags: modifierFlags keyCode: keyCode] autorelease];
26}
27
28- (id)initWithCharacters:(NSString *)characters modifierFlags:(unsigned)modifierFlags keyCode:(unsigned short)keyCode;
29{
30 if ( (self = [self init]) != nil) {
31 hotKeyCharacters = [characters retain];
32 hotKeyModifierFlags = modifierFlags;
33 hotKeyCode = keyCode;
34 }
35 return self;
36}
37
38- (void)dealloc;
39{
40 [hotKeyCharacters release];
41}
42
43#pragma mark accessing
44
45- (NSString *)characters;
46{
47 return hotKeyCharacters;
48}
49
50- (unsigned)modifierFlags;
51{
52 return hotKeyModifierFlags;
53}
54
55- (long)modifiers;
56{
57 static long modifierMap[5][2] = {
58 { NSCommandKeyMask, cmdKey },
59 { NSAlternateKeyMask, optionKey },
60 { NSControlKeyMask, controlKey },
61 { NSShiftKeyMask, shiftKey },
62 { 0, 0 }
63 };
64
65 long modifiers = 0;
66 int i;
67
[133]68 for (i = 0 ; modifierMap[i][0] != 0 ; i++)
69 if (hotKeyModifierFlags & modifierMap[i][0])
[131]70 modifiers |= modifierMap[i][1];
71
72 return modifiers;
73}
74
75- (unsigned short)keyCode;
76{
77 return hotKeyCode;
78}
79
80#pragma mark property list serialization (Pester 1.1)
81
82- (NSDictionary *)propertyListRepresentation;
83{
84 return [NSDictionary dictionaryWithObjectsAndKeys:
85 hotKeyCharacters, PLCharacters,
86 [NSNumber numberWithUnsignedInt: hotKeyModifierFlags], PLModifierFlags,
87 [NSNumber numberWithUnsignedShort: hotKeyCode], PLKeyCode,
88 nil];
89}
90
91- (id)initWithPropertyList:(NSDictionary *)dict;
92{
93 if ( (self = [self init]) != nil) {
94 NS_DURING
95 hotKeyCharacters = [[dict objectForKey: PLCharacters] retain];
96 hotKeyModifierFlags = [[dict objectForKey: PLModifierFlags] unsignedIntValue];
97 hotKeyCode = [[dict objectForKey: PLKeyCode] unsignedShortValue];
98 NS_HANDLER
99 NS_ENDHANDLER
100 if (hotKeyCharacters == nil || hotKeyCode == 0) {
101 [self release];
102 self = nil;
103 }
104 }
105 return self;
106}
107
108- (NSString *)keyGlyphs;
109{
110 return [[hotKeyCharacters keyEquivalentAttributedStringWithModifierFlags: hotKeyModifierFlags] string];
111}
112
113@end
Note: See TracBrowser for help on using the repository browser.