source: releases/Pester/1.1a2/Source/NJRVoicePopUpButton.m

Last change on this file was 43, checked in by Nicholas Riley, 21 years ago

Pester 1.1a1.

English.lproj/InfoPlist.strings: Updated for 1.1a1.

English.lproj/MainMenu.nib: Placeholder for day names in popup menu, fixed up by code (this means you can still edit it from IB though). Added command-shift-T to both in/at cells (required, code removes one or the other as appropriate). Fixed up sizes of fields. Default to today (this will need fixing when we localized the word "today", but it's fine for now...).

English.lproj/Notifier.nib: Remove date formatter because we set a string directly now instead (could set formatter from code, but we don't).

NJRDateFormatter: many workarounds for Cocoa bugs: missing AM/PM, incorrect results with space before AM/PM, etc. Added class methods to do format manipulation and return localized formats which work for output (though not always for input; this class has an internal workaround for the AM/PM problem).

NJRFSObjectSelector: properly handle enabled attribute, store internally and report externally as appropriate. Previously, the button would become enabled if you dropped something on it even if it was supposed to be disabled.

NJRQTMediaPopUpButton: stop sound preview when button disabled.

NJRVoicePopUpButton: stop voice preview when button disabled.

PSAlarm: new method -dateString returns long date string. Maintain local copy of long date, short date and time formats, and locale, using NJRDateFormatter.

PSAlarmNotifierController: update to use -[PSAlarm dateString], -[PSAlarm timeString] for localization instead of using broken formatter.

PSAlarmSetController: update documentation for some more Cocoa bugs I need to file. Set time of day and date formatters with localized date formats from NJRDateFormatter (retain/release issue here?) Localize weekday popup for predefined dates. Localize static date display with NJRDateFormatter. Note a solution (thanks to Douglas Davidson) for figuring out which control is editing. Added command-shift-T key equivalent to toggle in/at. Properly work around bugs witih soundRepetitionCount flashing, except where it's impossible to do anything else.

Read Me.rtfd: Updated for 1.1a1.

VERSION: Updated for 1.1a1.

File size: 3.6 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// XXX says nothing instead of "Alarm!" any more if there's no alarm message specified
12
13@implementation NJRVoicePopUpButton
14
15- (void)_refreshVoiceList;
16{
17 NSMenu *menu;
18 NSMenuItem *item;
19 NSArray *voiceNames = [SUSpeaker voiceNames];
20
21 [self removeAllItems];
22 menu = [self menu];
23 [menu setAutoenablesItems: NO];
24 // XXX would be more elegant with surrogate support like my font popup menu
25 item = [menu addItemWithTitle: @"ÇunknownÈ" action: nil keyEquivalent: @""];
26 [item setEnabled: NO];
27 [menu addItem: [NSMenuItem separatorItem]];
28 if (voiceNames == nil || [voiceNames count] == 0) {
29 item = [menu addItemWithTitle: @"CanÕt locate voices" action: nil keyEquivalent: @""];
30 [item setEnabled: NO];
31 } else {
32 NSEnumerator *e = [voiceNames objectEnumerator];
33 NSString *voiceName;
34 while ( (voiceName = [e nextObject]) != nil) {
35 item = [menu addItemWithTitle: voiceName action: @selector(_previewVoice) keyEquivalent: @""];
36 [item setTarget: self];
37 }
38 }
39 if (_speaker == nil) [self selectItemWithTitle: [SUSpeaker defaultVoice]];
40}
41
42- (id)initWithFrame:(NSRect)frame;
43{
44 if ( (self = [super initWithFrame: frame]) != nil) {
45 [self _refreshVoiceList];
46 }
47 return self;
48}
49
50- (id)initWithCoder:(NSCoder *)coder;
51{
52 if ( (self = [super initWithCoder: coder]) != nil) {
53 [self _refreshVoiceList];
54 }
55 return self;
56}
57
58- (SUSpeaker *)_speaker;
59{
60 if (_speaker == nil) _speaker = [[SUSpeaker alloc] init];
61 return _speaker;
62}
63
64- (void)_invalidateVoiceSelection;
65{
66 [self _refreshVoiceList];
67 [self selectItemAtIndex: 0];
68}
69
70- (void)_previewVoice;
71{
72 NSString *voiceName = [self titleOfSelectedItem];
73 NSString *previewString = nil;
74 VoiceSpec voice;
75 OSStatus err = noErr;
76 VoiceDescription info;
77 short voiceIndex = [[SUSpeaker voiceNames] indexOfObject: voiceName] + 1;
78
79 [_speaker stopSpeaking];
80
81 if ( (err = GetIndVoice(voiceIndex, &voice)) != noErr) {
82 NSBeginAlertSheet(@"Voice not available", @"OK", nil, nil, [self window], nil, nil, nil, nil, @"The voice Ò%@Ó you selected could not be used. An error of type %ld occurred while attempting to retrieve voice information.", voiceName, err);
83 [self _invalidateVoiceSelection];
84 return;
85 }
86
87 if (_delegate != nil && [_delegate respondsToSelector: @selector(voicePopUpButton:previewStringForVoice:)]) {
88 previewString = [_delegate voicePopUpButton: self previewStringForVoice: voiceName];
89 }
90
91 if (previewString == nil) {
92 err = GetVoiceDescription(&voice, &info, sizeof(info));
93 if (err != noErr || info.comment[0] == 0)
94 previewString = voiceName;
95 else {
96 previewString = (NSString *)CFStringCreateWithPascalString(NULL, info.comment, kCFStringEncodingMacRoman);
97 [previewString autorelease];
98 }
99 }
100
101 [[self _speaker] setVoice: voiceIndex];
102 [_speaker speakText: previewString];
103}
104
105- (void)dealloc;
106{
107 [_speaker release];
108 [super dealloc];
109}
110
111- (IBAction)stopVoicePreview:(id)sender;
112{
113 [_speaker stopSpeaking];
114}
115
116- (void)setEnabled:(BOOL)flag;
117{
118 [super setEnabled: flag];
119 if (flag) ; // XXX [self stopVoicePreview: self]; // need to prohibit at startup
120 else [self stopVoicePreview: self];
121}
122
123- (void)setDelegate:(id)delegate;
124{
125 _delegate = delegate;
126}
127
128- (id)delegate;
129{
130 return _delegate;
131}
132
133@end
Note: See TracBrowser for help on using the repository browser.