On Jul 18, 2005, at 12:56 PM, Luc Vandal wrote:
I have a toolbar and each item has a tooltip. Is there a way to know
when a tooltip will be displayed? I need to know because our
application has to speak and say the tooltip's content. In our case,
we cannot use the accessibility stuff.
I needed an enhancement so users could disable tooltips entirely. I
added an item to the main menu Help "View Tool Tips", which is checked
by default (you can use bindings). It tweaks a private AppKit
subclass, but it's safe and works fine thru Tiger. I just modified it
for speech (disclaimer, untested, written in Mail.app)...
//
// SKWBase_NSToolTipManager
// SKWBase
//
// Created by Shaun Wexler on 6/21/04.
// Copyright (c) 2004 SKW Development. All rights reserved.
//
static BOOL toolTipsEnabled = YES;
static BOOL speaksToolTips = NO;
@interface NSApplication (SKWToolTipAdditions)
- (BOOL)toolTipsEnabled;
- (void)setToolTipsEnabled:(BOOL)enabled;
- (BOOL)speaksToolTips;
- (void)setSpeaksToolTips:(BOOL)speaks;
@end
@implementation NSApplication (SKWToolTipAdditions)
- (BOOL)toolTipsEnabled
{
return toolTipsEnabled;
}
- (void)setToolTipsEnabled:(BOOL)enabled
{
toolTipsEnabled = enabled;
[[NSUserDefaults standardUserDefaults] setBool:!enabled
forKey:@"SKWToolTipsDisabled"];
}
- (BOOL)speaksToolTips
{
return speaksToolTips;
}
- (void)setSpeaksToolTips:(BOOL)speaks
{
speaksToolTips = speaks;
[[NSUserDefaults standardUserDefaults] setBool:speaks
forKey:@"SKWToolTipsSpeechEnabled"];
}
@end
@interface NSToolTip : NSObject
{
NSView *view;
NSCell *cell;
NSString *string;
id owner;
void *data;
int trackingNum;
BOOL ownerIsDisplayDelegate;
struct _NSRect trackingRect;
}
- (void)dealloc;
- (id)description;
@end
@interface NSToolTipManager : NSObject
{
NSWindow *toolTipWindow;
NSMutableArray *toolTips;
double toolTipDelay;
NSDate *timeToolTipRemovedFromScreen;
CFRunLoopTimerRef toolTipDisplayTimer;
NSToolTip *currentDisplayedToolTip;
NSToolTip *currentFadingToolTip;
float currentFadeValue;
NSTimer *fadeTimer;
NSWindow *lastToolTipWindow;
}
- (void)displayToolTip:(id)toolTip;
@end
@interface SKWToolTipManager : NSToolTipManager
- (void)displayToolTip:(id)toolTip;
@end
@implementation SKWToolTipManager
+ (void)load
{
Class toolTipManagerClass = NSClassFromString(@"NSToolTipManager");
if (toolTipManagerClass != Nil) {
[self poseAsClass:toolTipManagerClass];
toolTipsEnabled = [[NSUserDefaults standardUserDefaults]
boolForKey:@"SKWToolTipsDisabled"];
speaksToolTips = [[NSUserDefaults standardUserDefaults]
boolForKey:@"SKWToolTipsSpeechEnabled"];
}
}
static NSSpeechSynthesizer *speechSynthesizer = nil;
- (void)displayToolTip:(id)toolTip
{
if ([NSApp toolTipsEnabled]) {
[super displayToolTip:toolTip];
}
if ([NSApp speaksToolTips]) {
if (!speechSynthesizer) {
speechSynthesizer = [[NSSpeechSynthesizer alloc] init];
[speechSynthesizer setDelegate:self];
}
[speechSynthesizer startSpeakingString:toolTip->string];
}
}
- (void)orderOutToolTip
{
[speechSynthesizer stopSpeaking];
}
- (void)abortToolTip
{
[speechSynthesizer stopSpeaking];
}
- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
didFinishSpeaking:(BOOL)finishedSpeaking
{
if (finishedSpeaking && sender == speechSynthesizer) {
speechSynthesizer = nil;
[sender release];
}
}
@end
--
Shaun Wexler
MacFOH
http://www.macfoh.com
My amp goes to eleven.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden