source: releases/Pester/1.1b5/Source/NJRVoicePopUpButton.m@ 545

Last change on this file since 545 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: 3.9 KB
Line 
1//
2// NJRVoicePopUpButton.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "NJRVoicePopUpButton.h"
10
11@implementation NJRVoicePopUpButton
12
13- (void)_refreshVoiceList;
14{
15 NSMenu *menu;
16 NSMenuItem *item;
17 NSArray *voiceNames = [SUSpeaker voiceNames];
18
19 [self removeAllItems];
20 menu = [self menu];
21 [menu setAutoenablesItems: NO];
22 // XXX would be more elegant with surrogate support like my font popup menu
23 item = [menu addItemWithTitle: @"«unknown»" action: nil keyEquivalent: @""];
24 [item setEnabled: NO];
25 [menu addItem: [NSMenuItem separatorItem]];
26 if (voiceNames == nil || [voiceNames count] == 0) {
27 item = [menu addItemWithTitle: NSLocalizedString(@"Can't locate voices", "Voice popup menu item surrogate for voice list if no voices are found") action: nil keyEquivalent: @""];
28 [item setEnabled: NO];
29 } else {
30 NSEnumerator *e = [voiceNames objectEnumerator];
31 NSString *voiceName;
32 while ( (voiceName = [e nextObject]) != nil) {
33 item = [menu addItemWithTitle: voiceName action: @selector(_previewVoice) keyEquivalent: @""];
34 [item setTarget: self];
35 }
36 }
37 if (_speaker == nil) [self selectItemWithTitle: [SUSpeaker defaultVoice]];
38}
39
40- (id)initWithFrame:(NSRect)frame;
41{
42 if ( (self = [super initWithFrame: frame]) != nil) {
43 [self _refreshVoiceList];
44 }
45 return self;
46}
47
48- (id)initWithCoder:(NSCoder *)coder;
49{
50 if ( (self = [super initWithCoder: coder]) != nil) {
51 [self _refreshVoiceList];
52 }
53 return self;
54}
55
56- (SUSpeaker *)_speaker;
57{
58 if (_speaker == nil) _speaker = [[SUSpeaker alloc] init];
59 return _speaker;
60}
61
62- (void)_invalidateVoiceSelection;
63{
64 [self _refreshVoiceList];
65 [self selectItemAtIndex: 0];
66}
67
68- (void)setVoice:(NSString *)voice;
69{
70 int voiceIdx = [self indexOfItemWithTitle: voice];
71 if (voiceIdx == -1) {
72 [self _invalidateVoiceSelection];
73 } else {
74 [self selectItemAtIndex: voiceIdx];
75 }
76}
77
78- (void)_previewVoice;
79{
80 NSString *voiceName = [self titleOfSelectedItem];
81 NSString *previewString = nil;
82 VoiceSpec voice;
83 OSStatus err = noErr;
84 VoiceDescription info;
85 short voiceIndex = [[SUSpeaker voiceNames] indexOfObject: voiceName] + 1;
86
87 [_speaker stopSpeaking];
88
89 if ( (err = GetIndVoice(voiceIndex, &voice)) != noErr) {
90 NSBeginAlertSheet(@"Voice not available", nil, nil, nil, [self window], nil, nil, nil, nil, NSLocalizedString(@"The voice '%@' you selected could not be used. An error of type %ld occurred while attempting to retrieve voice information.", "Message displayed in alert sheet when GetIndVoice returns an error"), voiceName, err);
91 [self _invalidateVoiceSelection];
92 return;
93 }
94
95 if (_delegate != nil && [_delegate respondsToSelector: @selector(voicePopUpButton:previewStringForVoice:)]) {
96 previewString = [_delegate voicePopUpButton: self previewStringForVoice: voiceName];
97 }
98
99 if (previewString == nil) {
100 err = GetVoiceDescription(&voice, &info, sizeof(info));
101 if (err != noErr || info.comment[0] == 0)
102 previewString = voiceName;
103 else {
104 previewString = (NSString *)CFStringCreateWithPascalString(NULL, info.comment, kCFStringEncodingMacRoman);
105 [previewString autorelease];
106 }
107 }
108
109 [[self _speaker] setVoice: voiceIndex];
110 [_speaker speakText: previewString];
111}
112
113- (void)dealloc;
114{
115 [_speaker release];
116 [super dealloc];
117}
118
119- (IBAction)stopVoicePreview:(id)sender;
120{
121 [_speaker stopSpeaking];
122}
123
124- (void)setEnabled:(BOOL)flag;
125{
126 [super setEnabled: flag];
127 if (flag) ; // XXX [self stopVoicePreview: self]; // need to prohibit at startup
128 else [self stopVoicePreview: self];
129}
130
131- (void)setDelegate:(id)delegate;
132{
133 _delegate = delegate;
134}
135
136- (id)delegate;
137{
138 return _delegate;
139}
140
141@end
Note: See TracBrowser for help on using the repository browser.