source: releases/Pester/1.1b7/Source/NJRHotKey.m@ 567

Last change on this file since 567 was 366, checked in by Nicholas Riley, 17 years ago

Info-Pester.plist: Updated for build 23.

NJRHotKey.m: Cosmetic cleanup.

PSAlarm.[hm]: Fix -[PSAlarm time] to work properly, though it no
longer has any clients.

PSSnoozeUntilController.m: Fix snooze until time being off by an hour
as displayed, or if edited, in some time zones.

PSSpeechAlert.m: Display the voice name instead of its identifier in
the description.

Pester.xcodeproj: Misc.

release-notes.html: Updated for build 23.

File size: 2.8 KB
Line 
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 [super dealloc];
42}
43
44#pragma mark accessing
45
46- (NSString *)characters;
47{
48 return hotKeyCharacters;
49}
50
51- (unsigned)modifierFlags;
52{
53 return hotKeyModifierFlags;
54}
55
56- (long)modifiers;
57{
58 static long modifierMap[5][2] = {
59 { NSCommandKeyMask, cmdKey },
60 { NSAlternateKeyMask, optionKey },
61 { NSControlKeyMask, controlKey },
62 { NSShiftKeyMask, shiftKey },
63 { 0, 0 }
64 };
65
66 long modifiers = 0;
67 int i;
68
69 for (i = 0 ; modifierMap[i][0] != 0 ; i++)
70 if (hotKeyModifierFlags & modifierMap[i][0])
71 modifiers |= modifierMap[i][1];
72
73 return modifiers;
74}
75
76- (unsigned short)keyCode;
77{
78 return hotKeyCode;
79}
80
81#pragma mark property list serialization (Pester 1.1)
82
83- (NSDictionary *)propertyListRepresentation;
84{
85 return [NSDictionary dictionaryWithObjectsAndKeys:
86 hotKeyCharacters, PLCharacters,
87 [NSNumber numberWithUnsignedInt: hotKeyModifierFlags], PLModifierFlags,
88 [NSNumber numberWithUnsignedShort: hotKeyCode], PLKeyCode,
89 nil];
90}
91
92- (id)initWithPropertyList:(NSDictionary *)dict;
93{
94 if ( (self = [self init]) != nil) {
95 @try {
96 hotKeyCharacters = [[dict objectForKey: PLCharacters] retain];
97 hotKeyModifierFlags = [[dict objectForKey: PLModifierFlags] unsignedIntValue];
98 hotKeyCode = [[dict objectForKey: PLKeyCode] unsignedShortValue];
99 } @catch (NSException *exception) {
100 }
101 if (hotKeyCharacters == nil || hotKeyCode == 0) {
102 [self release];
103 self = nil;
104 }
105 }
106 return self;
107}
108
109- (NSString *)keyGlyphs;
110{
111 return [[hotKeyCharacters keyEquivalentAttributedStringWithModifierFlags: hotKeyModifierFlags] string];
112}
113
114@end
Note: See TracBrowser for help on using the repository browser.