From 42a0cfaa9e949cf149f9f27424e484c8db3cf683 Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 4 Oct 2006 13:36:56 +0000 Subject: [PATCH] Make sure tooltip window starts off on screen. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23756 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 +++++ Source/GSToolTips.h | 1 + Source/GSToolTips.m | 59 +++++++++++++++++++++++++++++++++++---------- Source/NSView.m | 9 ++++--- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca5193307..ba1abd7ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-10-04 Richard Frith-Macdonald + + * Source/GSToolTips.h: create tool tip wondow fully on screen + * Source/GSToolTips.m: ditto + * Source/NSView.m: very minor tooltip efficiency tweak. + 2006-10-04 Enrico Sersale * Source/NSView.m: In -setToolTip: sets the has_tooltips flag. diff --git a/Source/GSToolTips.h b/Source/GSToolTips.h index 9efe87287..e5dde1864 100644 --- a/Source/GSToolTips.h +++ b/Source/GSToolTips.h @@ -38,6 +38,7 @@ NSTrackingRectTag toolTipTag; NSTimer *timer; NSWindow *window; + NSSize offset; BOOL restoreMouseMoved; } diff --git a/Source/GSToolTips.m b/Source/GSToolTips.m index 3ddfbdf71..d15a98641 100644 --- a/Source/GSToolTips.m +++ b/Source/GSToolTips.m @@ -29,6 +29,7 @@ #include "AppKit/NSBezierPath.h" #include "AppKit/NSView.h" #include "AppKit/NSWindow.h" +#include "AppKit/NSScreen.h" #include "GNUstepGUI/GSTrackingRect.h" #include "GSToolTips.h" @@ -92,8 +93,6 @@ typedef struct NSView_struct @defs(NSView) } *NSViewPtr; - - @implementation GSToolTips static NSMapTable *viewsMap = 0; @@ -251,8 +250,8 @@ static NSMapTable *viewsMap = 0; mouseLocation = [NSEvent mouseLocation]; - origin = NSMakePoint(mouseLocation.x + 8, - mouseLocation.y - 16 - [window frame].size.height); + origin = NSMakePoint(mouseLocation.x + offset.width, + mouseLocation.y + offset.height); [window setFrameOrigin: origin]; } @@ -455,7 +454,8 @@ static NSMapTable *viewsMap = 0; NSAttributedString *toolTipText = nil; NSSize textSize; NSPoint mouseLocation = [NSEvent mouseLocation]; - NSRect windowRect; + NSRect visible; + NSRect rect; NSColor *color; NSMutableDictionary *attributes; @@ -467,15 +467,48 @@ static NSMapTable *viewsMap = 0; attributes: attributes]; textSize = [toolTipText size]; - // Window - windowRect = NSMakeRect(mouseLocation.x + 8, - mouseLocation.y - 16 - (textSize.height+3), - textSize.width + 4, textSize.height + 4); + /* Create window just off the current mouse position + * Constrain it to be on screen, shrinking if necessary. + */ + rect = NSMakeRect(mouseLocation.x + 8, + mouseLocation.y - 16 - (textSize.height+3), + textSize.width + 4, textSize.height + 4); + visible = [[NSScreen mainScreen] visibleFrame]; + if (NSMaxY(rect) > NSMaxY(visible)) + { + rect.origin.y -= (NSMaxY(rect) - NSMaxY(visible)); + } + if (NSMinY(rect) < NSMinY(visible)) + { + rect.origin.y += (NSMinY(visible) - NSMinY(rect)); + } + if (NSMaxY(rect) > NSMaxY(visible)) + { + rect.origin.y = visible.origin.y; + rect.size.height = visible.size.height; + } + + if (NSMaxX(rect) > NSMaxX(visible)) + { + rect.origin.x -= (NSMaxX(rect) - NSMaxX(visible)); + } + if (NSMinX(rect) < NSMinX(visible)) + { + rect.origin.x += (NSMinX(visible) - NSMinX(rect)); + } + if (NSMaxX(rect) > NSMaxX(visible)) + { + rect.origin.x = visible.origin.x; + rect.size.width = visible.size.width; + } + offset.height = rect.origin.y - mouseLocation.y; + offset.width = rect.origin.x - mouseLocation.x; + + window = [[NSWindow alloc] initWithContentRect: rect + styleMask: NSBorderlessWindowMask + backing: NSBackingStoreRetained + defer: YES]; - window = [[NSWindow alloc] initWithContentRect: windowRect - styleMask: NSBorderlessWindowMask - backing: NSBackingStoreRetained - defer: YES]; color = [NSColor colorWithDeviceRed: 1.0 green: 1.0 blue: 0.90 alpha: 1.0]; [window setBackgroundColor: color]; diff --git a/Source/NSView.m b/Source/NSView.m index 770f6349d..04f5120c5 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -4351,10 +4351,13 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) - (void) setToolTip: (NSString *)string { - GSToolTips *tt = [GSToolTips tipsForView: self]; + if (_rFlags.has_tooltips == 1 || [string length] > 0) + { + GSToolTips *tt = [GSToolTips tipsForView: self]; - _rFlags.has_tooltips = 1; - [tt setToolTip: string]; + _rFlags.has_tooltips = 1; + [tt setToolTip: string]; + } } - (NSString *) toolTip