* Source/GSToolTips.m: Use separate view to draw tooltip text.

Patch by Marcian Lytwyn <marcian.lytwyn@advcsi.com>


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35674 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2012-10-12 16:36:20 +00:00
parent 70baebe674
commit 8c0d5b3dff
2 changed files with 72 additions and 27 deletions

View file

@ -1,3 +1,8 @@
2012-10-12 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSToolTips.m: Use separate view to draw tooltip text.
Patch by Marcian Lytwyn <marcian.lytwyn@advcsi.com>
2012-10-12 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSInfoPanel.m (value_from_info_plist_for_key): Use

View file

@ -115,6 +115,51 @@
}
@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)
{
NSRectEdge sides[] = {NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge};
NSColor *black = [NSColor blackColor];
NSColor *colors[] = {black, black, black, black};
NSRect bounds = [self bounds];
NSRect frame = [self frame];
NSRect textRect = NSInsetRect(frame, 2, 2);
NSDrawColorTiledRects(bounds, bounds, sides, colors, 4);
[_text drawInRect: textRect];
}
}
@end
@interface GSTTPanel : NSPanel
// Tooltip panel that will not try to become main or key
- (BOOL) canBecomeKeyWindow;
@ -124,6 +169,22 @@
@implementation GSTTPanel
- (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;
}
- (BOOL) canBecomeKeyWindow
{
return NO;
@ -138,7 +199,6 @@
@interface GSToolTips (Private)
- (void) _drawText: (NSAttributedString *)text;
- (void) _endDisplay;
- (void) _timedOut: (NSTimer *)timer;
@end
@ -155,8 +215,10 @@ typedef NSView* NSViewPtr;
static NSMapTable *viewsMap = 0;
static NSTimer *timer = nil;
static GSToolTips *timedObject = nil;
static GSTTPanel *window = nil; // Having a single stored panel for tooltips greatly reduces callback interaction from MS-Windows
static BOOL isOpening = NO; // Prevent Windows callback API from attempting to dismiss tooltip as its in the process of appearing
// Having a single stored panel for tooltips greatly reduces callback interaction from MS-Windows
static GSTTPanel *window = nil;
// Prevent Windows callback API from attempting to dismiss tooltip as its in the process of appearing
static BOOL isOpening = NO;
static NSSize offset;
static BOOL restoreMouseMoved;
@ -467,26 +529,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)
@ -623,11 +665,9 @@ static BOOL restoreMouseMoved;
offset.width = rect.origin.x - mouseLocation.x;
isOpening = YES;
[window setFrame:rect display:NO];
[(GSTTView*)([window contentView]) setText: toolTipText];
[window setFrame: rect display: NO];
[window orderFront: nil];
[window display];
[self _drawText: toolTipText];
[window flushWindow];
isOpening = NO;
RELEASE(toolTipText);