diff --git a/Source/GSToolTips.m b/Source/GSToolTips.m index 342155ad8..b18376c31 100644 --- a/Source/GSToolTips.m +++ b/Source/GSToolTips.m @@ -42,6 +42,7 @@ #import "GSToolTips.h" #import "GSFastEnumeration.h" + @interface NSWindow (GNUstepPrivate) + (void) _setToolTipVisible: (GSToolTips*)t; @@ -122,30 +123,99 @@ } @end +@interface GSTTView : NSView +{ + NSAttributedString *_text; +} +- (void)setText: (NSAttributedString *)text; +@end + +@implementation GSTTView +- (id)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + if (self) + { + [self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + } + return self; +} + +- (void)setText:(NSAttributedString *)text +{ + if (_text != text) + { + ASSIGN(_text, text); + [self setNeedsDisplay: YES]; + } +} + +- (void)drawRect:(id)dirtyRect +{ + if (_text) + { + NSRect bounds = [self bounds]; + NSRect frame = [self frame]; + NSRect textRect = NSInsetRect(frame, 2, 2); + +#if 1 // THIS DOESN'T WORK ON winlib - 2 SIDES OF THE RECT ARE MISSING!!! + // WILL DEBUG THIS AFTER CHECKING IN A WORKING VERSION + NSBezierPath *path = [NSBezierPath bezierPathWithRect:bounds]; + [[NSColor blackColor] setStroke]; + [path stroke]; +#else + { + NSRectEdge sides[] = {NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge}; + NSColor *black = [NSColor blackColor]; + NSColor *colors[] = {black, black, black, black}; + NSDrawColorTiledRects(bounds, bounds, sides, colors, 4); + } +#endif + [_text drawInRect: textRect]; + } +} +@end + @interface GSTTPanel : NSPanel // Tooltip panel that will not try to become main or key - (BOOL) canBecomeKeyWindow; - (BOOL) canBecomeMainWindow; - +- (void) setToolTipText: (NSAttributedString*)text; @end @implementation GSTTPanel -- (BOOL) canBecomeKeyWindow +- (id) initWithContentRect: (NSRect)contentRect + styleMask: (unsigned int)aStyle + backing: (NSBackingStoreType)bufferingType + defer: (BOOL)flag; +{ + self = [super initWithContentRect:contentRect styleMask:aStyle backing:bufferingType defer:flag]; + if (self) + { + [self setContentView:[[[GSTTView alloc] initWithFrame: contentRect] autorelease]]; + } + return(self); +} + +- (void)setToolTipText:(NSAttributedString *)text +{ + [(GSTTView*)([self contentView]) setText:text]; +} + +- (BOOL) canBecomeKeyWindow { return NO; } -- (BOOL) canBecomeMainWindow +- (BOOL) canBecomeMainWindow { return NO; } @end - @interface GSToolTips (Private) -- (void) _drawText: (NSAttributedString *)text; - (void) _endDisplay; - (void) _timedOut: (NSTimer *)timer; @end @@ -170,12 +240,12 @@ static BOOL restoreMouseMoved; + (void) initialize { viewsMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, - NSObjectMapValueCallBacks, 8); + NSObjectMapValueCallBacks, 8); window = [[GSTTPanel alloc] initWithContentRect: NSMakeRect(0,0,100,25) - styleMask: NSBorderlessWindowMask - backing: NSBackingStoreRetained - defer: YES]; + styleMask: NSBorderlessWindowMask + backing: NSBackingStoreRetained + defer: YES]; [window setBackgroundColor: [NSColor colorWithDeviceRed: 1.0 green: 1.0 blue: 0.90 alpha: 1.0]]; @@ -183,6 +253,8 @@ static BOOL restoreMouseMoved; [window setExcludedFromWindowsMenu: YES]; [window setLevel: NSStatusWindowLevel]; [window setAutodisplay: NO]; + [window setOneShot: YES]; + [window setTitle:@"GSToolTips"]; } + (void) removeTipsForView: (NSView*)aView @@ -253,8 +325,8 @@ static BOOL restoreMouseMoved; { if (rect->owner == self) { - count++; - } + count++; + } } return count; } @@ -361,21 +433,21 @@ static BOOL restoreMouseMoved; if (rect->owner == self) { GSTTProvider *provider = (GSTTProvider *)rect->user_data; - NSRect frame; + NSRect frame; - if (rect->tag == toolTipTag) - { - frame = [view bounds]; - } - else - { - // FIXME is this the thing to do with tooltips other than - // the main one (which we know should cover the whole view)? - frame = [provider viewRect]; - } - frame = [view convertRect: frame toView: nil]; - [rect reset: frame inside: NO]; - } + if (rect->tag == toolTipTag) + { + frame = [view bounds]; + } + else + { + // FIXME is this the thing to do with tooltips other than + // the main one (which we know should cover the whole view)? + frame = [provider viewRect]; + } + frame = [view convertRect: frame toView: nil]; + [rect reset: frame inside: NO]; + } } } @@ -391,10 +463,10 @@ static BOOL restoreMouseMoved; { if (rect->owner == self) { - RELEASE((GSTTProvider*)rect->user_data); - rect->user_data = 0; - [view removeTrackingRect: rect->tag]; - } + RELEASE((GSTTProvider*)rect->user_data); + rect->user_data = 0; + [view removeTrackingRect: rect->tag]; + } } toolTipTag = -1; } @@ -431,12 +503,12 @@ static BOOL restoreMouseMoved; while ((rect = [enumerator nextObject]) != nil) { if (rect->tag == tag && rect->owner == self) - { - RELEASE((GSTTProvider*)rect->user_data); - rect->user_data = 0; - [view removeTrackingRect: tag]; - return; - } + { + RELEASE((GSTTProvider*)rect->user_data); + rect->user_data = 0; + [view removeTrackingRect: tag]; + return; + } } } @@ -446,10 +518,10 @@ static BOOL restoreMouseMoved; { if (toolTipTag != -1) { - [self _endDisplay]; - [self removeToolTip: toolTipTag]; - toolTipTag = -1; - } + [self _endDisplay]; + [self removeToolTip: toolTipTag]; + toolTipTag = -1; + } } else { @@ -457,31 +529,31 @@ static BOOL restoreMouseMoved; if (toolTipTag == -1) { - NSRect rect; + NSRect rect; - rect = [view bounds]; - provider = [[GSTTProvider alloc] initWithObject: string - userData: nil - rect: rect]; - toolTipTag = [view addTrackingRect: rect - owner: self - userData: provider - assumeInside: NO]; - } + rect = [view bounds]; + provider = [[GSTTProvider alloc] initWithObject: string + userData: nil + rect: rect]; + toolTipTag = [view addTrackingRect: rect + owner: self + userData: provider + assumeInside: NO]; + } else { - NSEnumerator *enumerator; - GSTrackingRect *rect; + NSEnumerator *enumerator; + GSTrackingRect *rect; - enumerator = [((NSViewPtr)view)->_tracking_rects objectEnumerator]; - while ((rect = [enumerator nextObject]) != nil) - { - if (rect->tag == toolTipTag && rect->owner == self) - { - [((GSTTProvider*)rect->user_data) setObject: string]; - } - } - } + enumerator = [((NSViewPtr)view)->_tracking_rects objectEnumerator]; + while ((rect = [enumerator nextObject]) != nil) + { + if (rect->tag == toolTipTag && rect->owner == self) + { + [((GSTTProvider*)rect->user_data) setObject: string]; + } + } + } } } @@ -505,26 +577,6 @@ static BOOL restoreMouseMoved; @implementation GSToolTips (Private) -- (void) _drawText: (NSAttributedString *)text -{ - NSRectEdge sides[] = {NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge}; - NSColor *black = [NSColor blackColor]; - NSColor *colors[] = {black, black, black, black}; - NSRect bounds = [[window contentView] bounds]; - NSRect textRect; - - textRect = [window frame]; - textRect.origin.x = 2; - textRect.origin.y = -2; - - [[window contentView] lockFocus]; - - [text drawInRect: textRect]; - NSDrawColorTiledRects(bounds, bounds, sides, colors, 4); - - [[window contentView] unlockFocus]; -} - - (void) _endDisplay { if (isOpening) @@ -539,15 +591,19 @@ static BOOL restoreMouseMoved; if (timer != nil && timedObject == self) { if ([timer isValid]) - { - [timer invalidate]; - } + { + [timer invalidate]; + } timer = nil; timedObject = nil; } if (window != nil) { +#if 0 + [window close]; +#else [window orderOut:self]; +#endif } if (restoreMouseMoved == YES) { @@ -605,6 +661,9 @@ static BOOL restoreMouseMoved; [self _endDisplay]; } + if ((toolTipString == nil) || ([toolTipString length] == 0)) + return; + size = [[NSUserDefaults standardUserDefaults] floatForKey: @"NSToolTipsFontSize"]; @@ -659,11 +718,9 @@ static BOOL restoreMouseMoved; offset.width = rect.origin.x - mouseLocation.x; isOpening = YES; + [window setToolTipText:toolTipText]; [window setFrame:rect display:NO]; - [window orderFront: nil]; - [window display]; - [self _drawText: toolTipText]; - [window flushWindow]; + [window orderFront:self]; isOpening = NO; RELEASE(toolTipText); diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 2f625c65b..9b35d7a64 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -1750,6 +1750,7 @@ many times. { GSDisplayServer *srv = GSServerForWindow(self); BOOL display = NO; + BOOL redisplay = NO; if (YES == [[NSUserDefaults standardUserDefaults] boolForKey: @"GSBackgroundApp"]) @@ -1790,6 +1791,8 @@ many times. [self _initBackendWindow]; display = YES; } + else + redisplay = (_f.visible == NO); } /* If a hide on deactivate window is explicitly ordered in or out while @@ -1800,12 +1803,12 @@ many times. [NSApp _setWindow: self inactive: NO]; } +#if 1 // Draw content before backend window ordering if (display) - [_wv display]; - else if (place != NSWindowOut) - [_wv displayIfNeeded]; - + [self display]; +#endif + /* The backend will keep us below the current key window unless we force it not too */ if ((otherWin == 0 @@ -1815,9 +1818,10 @@ many times. otherWin = -1; [srv orderwindow: place : otherWin : _windowNum]; - if (display) + + if (redisplay) [self display]; - + if (place != NSWindowOut) { /* @@ -1838,10 +1842,10 @@ many times. BOOL isFileName; NSString *aString; - aString = [NSString stringWithFormat: @"%@ -- %@", - [_representedFilename lastPathComponent], - [_representedFilename stringByDeletingLastPathComponent]]; - isFileName = [_windowTitle isEqual: aString]; + aString = [NSString stringWithFormat: @"%@ -- %@", + [_representedFilename lastPathComponent], + [_representedFilename stringByDeletingLastPathComponent]]; + isFileName = [_windowTitle isEqual: aString]; [NSApp addWindowsItem: self title: _windowTitle @@ -1854,6 +1858,11 @@ many times. [srv setinputfocus: _windowNum]; } _f.visible = YES; +#if 1 + [self displayIfNeeded]; +#else +// [self display]; +#endif } else if ([self isOneShot]) { @@ -2370,7 +2379,7 @@ many times. - (void) display { - if (_gstate == 0 || _f.visible == NO) + if (_gstate == 0) return; [_wv display]; @@ -2385,9 +2394,7 @@ many times. if (_f.views_need_display) { - [_wv displayIfNeeded]; - [self discardCachedImage]; - _f.views_need_display = NO; + [self display]; } } @@ -5695,3 +5702,4 @@ NSWindow* GSWindowWithNumber(int num) return (NSWindow*)NSMapGet(windowmaps, (void*)(intptr_t)num); return nil; } +