source: releases/Pester/1.1b5/Source/NJRHotKey.m@ 678

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

English.lproj/MainMenu.nib: Modernize menu and alarm set dialog
layout. Use keyed archiving (10.2+) nib format.

Info-Pester.plist: Moved from old PBX project.

NJRFSObjectSelector.m: Bug fixes from code sent to Joey: remove
incorrect usage of tryToPerform:with:; fix logic error in menu
construction. Work around Cocoa's deciding that the menu font size
needs adjustment when it doesn't - so the menu font size now matches
the button font size, though the position is still off. Don't pop up
a menu if we're disabled. Use IconRefs for menu icons, though not
(yet) for the button icon.

NJRHistoryTrackingComboBox.m: Remove item height adjustment
workaround; it now makes the items too tall.

NJRHotKey.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyField.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyManager.m: Add a missing [super dealloc] caught by current
GCC.

NJRIntervalField.m: Fix some type errors.

NJRQTMediaPopUpButton.m: Replace SoundFileManager SPI usage, which
doesn't work in Leopard anyway, with manual enumeration of system
sounds. Start migration to QTKit. Use IconRefs for menu icons.

NJRReadMeController.m: Change source encoding to UTF-8.

NJRSoundManager.m: Fix a type error.

NJRVoicePopUpButton.m: Change source encoding to UTF-8.

NSMenuItem-NJRExtensions.[hm]: Code from ICeCoffEE to use IconRefs for
menu item icons.

PSAlarm.m: Change source encoding to UTF-8.

PSAlarms.m: Fix a signedness mismatch.

PSAlarmsController.m: Change source encoding to UTF-8.

PSAlarmSetController.m: Set keyboard focus after unchecking "Do
script:" and "Play" checkboxes.

PSAlerts.m: Add a missing [super dealloc] caught by current GCC. Fix
a memory leak in property list serialization.

PSPowerManager.[hm]: There's now API for scheduling wakeups; use it
(the old code asserted on startup). To fix: removing scheduled
wakeup. Fix a small type-checking error.

PSPreferencesController.m: Add a missing [super dealloc] caught by
current GCC.

PSScriptAlert.m: Change source encoding to UTF-8.

PSTimeDateEditor.m: Fix a tiny, and one-time, memory leak.

PSTimer.m: Update for new PSPowerManager API.

Pester.pbproj: Deleted; now supporting OS X 10.4+ (up from 10.1,
aiee.)

Pester.xcodeproj: Xcode 2.4+ project, upgraded targets, etc.

SoundFileManager.h: Deleted; this SPI no longer exists in Leopard and
possibly earlier.

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 NS_DURING
96 hotKeyCharacters = [[dict objectForKey: PLCharacters] retain];
97 hotKeyModifierFlags = [[dict objectForKey: PLModifierFlags] unsignedIntValue];
98 hotKeyCode = [[dict objectForKey: PLKeyCode] unsignedShortValue];
99 NS_HANDLER
100 NS_ENDHANDLER
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.