2009-02-09 05:53:38 +00:00
|
|
|
#import "ToolTipWindow.h"
|
|
|
|
|
|
|
|
@implementation ToolTipWindow
|
|
|
|
|
|
|
|
- (void)setBackgroundColor:(NSColor *)bgColor
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
backgroundColor = bgColor;
|
2009-02-09 05:53:38 +00:00
|
|
|
}
|
|
|
|
- (NSColor *)backgroundColor
|
|
|
|
{
|
|
|
|
return backgroundColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)suggestedSizeForTooltip:(id)tooltip
|
|
|
|
{
|
|
|
|
NSSize tipSize = NSZeroSize;
|
|
|
|
|
|
|
|
if ([tooltip isKindOfClass:[NSAttributedString class]]) {
|
|
|
|
tipSize = [tooltip size];
|
|
|
|
}
|
|
|
|
else if ([tooltip isKindOfClass:[NSString class]]){
|
|
|
|
tipSize = [tooltip sizeWithAttributes:textAttributes];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NSEqualSizes(tipSize, NSZeroSize))
|
|
|
|
tipSize.width += 4;
|
|
|
|
|
|
|
|
return tipSize;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super initWithContentRect:NSMakeRect(0,0,0,0)
|
|
|
|
styleMask:NSBorderlessWindowMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
|
|
|
|
|
|
|
{ // window setup...
|
|
|
|
[self setAlphaValue:0.90];
|
|
|
|
[self setOpaque:NO];
|
|
|
|
[self setHasShadow:YES];
|
|
|
|
[self setBackgroundColor:[NSColor colorWithDeviceRed:1.0 green:0.96 blue:0.76 alpha:1.0]];
|
|
|
|
[self setLevel:NSStatusWindowLevel];
|
|
|
|
[self setHidesOnDeactivate:YES];
|
|
|
|
[self setIgnoresMouseEvents:YES];
|
|
|
|
[self setReleasedWhenClosed:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // textfield setup...
|
|
|
|
NSTextField *field = [[NSTextField alloc] initWithFrame:NSMakeRect(0,0,0,0)];
|
|
|
|
|
|
|
|
[field setEditable:NO];
|
|
|
|
[field setSelectable:NO];
|
|
|
|
[field setBezeled:NO];
|
|
|
|
[field setBordered:NO];
|
|
|
|
[field setDrawsBackground:NO];
|
|
|
|
[field setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
|
|
[self setContentView:field];
|
|
|
|
[self setFrame:[self frameRectForContentRect:[field frame]] display:NO];
|
|
|
|
|
|
|
|
[field setStringValue:@" "]; // Just having at least 1 char to allow the next message...
|
2016-05-05 20:05:39 +00:00
|
|
|
textAttributes = [[field attributedStringValue] attributesAtIndex:0 effectiveRange:nil];
|
2009-02-09 05:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
if (closeTimer) {
|
|
|
|
[closeTimer invalidate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)toolTip { return tooltipObject; }
|
|
|
|
|
|
|
|
- (void)setToolTip:(id)tip
|
|
|
|
{
|
|
|
|
id contentView = [self contentView];
|
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
tooltipObject = tip;
|
2009-02-09 05:53:38 +00:00
|
|
|
|
|
|
|
if ([contentView isKindOfClass:[NSTextField class]]) {
|
|
|
|
if ([tip isKindOfClass:[NSString class]]) [contentView setStringValue:tip];
|
|
|
|
else
|
|
|
|
if ([tip isKindOfClass:[NSAttributedString class]]) [contentView setAttributedStringValue:tip];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)orderFrontForDuration:(NSTimeInterval)duration
|
|
|
|
{
|
|
|
|
[self orderFront:nil];
|
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
if (closeTimer) { [closeTimer invalidate]; }
|
2009-02-09 05:53:38 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
closeTimer = [NSTimer timerWithTimeInterval:duration target:self selector:@selector(close) userInfo:nil repeats:NO];
|
2009-02-09 06:16:16 +00:00
|
|
|
[[NSRunLoop currentRunLoop] addTimer:closeTimer forMode:NSRunLoopCommonModes];
|
2009-02-09 05:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)orderFront
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
if (closeTimer) { [closeTimer invalidate]; closeTimer = nil; }
|
2009-02-09 05:53:38 +00:00
|
|
|
|
|
|
|
[super orderFront:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *)description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"TooltipWindow:\n%@", [[self contentView] stringValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|