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
This commit is contained in:
Richard Frith-MacDonald 2006-10-04 13:36:56 +00:00
parent b9fd9f40ea
commit ac3da2c4ca
4 changed files with 59 additions and 16 deletions

View file

@ -1,3 +1,9 @@
2006-10-04 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <enrico@fibernet.ro>
* Source/NSView.m: In -setToolTip: sets the has_tooltips flag.

View file

@ -38,6 +38,7 @@
NSTrackingRectTag toolTipTag;
NSTimer *timer;
NSWindow *window;
NSSize offset;
BOOL restoreMouseMoved;
}

View file

@ -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];

View file

@ -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