TEMPORARY updaste for cairo and tooltips

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@35669 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2012-10-11 21:03:00 +00:00
parent 4c16370ff9
commit f59b23c3fe
2 changed files with 166 additions and 101 deletions

View file

@ -42,6 +42,7 @@
#import "GSToolTips.h" #import "GSToolTips.h"
#import "GSFastEnumeration.h" #import "GSFastEnumeration.h"
@interface NSWindow (GNUstepPrivate) @interface NSWindow (GNUstepPrivate)
+ (void) _setToolTipVisible: (GSToolTips*)t; + (void) _setToolTipVisible: (GSToolTips*)t;
@ -122,30 +123,99 @@
} }
@end @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 @interface GSTTPanel : NSPanel
// Tooltip panel that will not try to become main or key // Tooltip panel that will not try to become main or key
- (BOOL) canBecomeKeyWindow; - (BOOL) canBecomeKeyWindow;
- (BOOL) canBecomeMainWindow; - (BOOL) canBecomeMainWindow;
- (void) setToolTipText: (NSAttributedString*)text;
@end @end
@implementation GSTTPanel @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; return NO;
} }
- (BOOL) canBecomeMainWindow - (BOOL) canBecomeMainWindow
{ {
return NO; return NO;
} }
@end @end
@interface GSToolTips (Private) @interface GSToolTips (Private)
- (void) _drawText: (NSAttributedString *)text;
- (void) _endDisplay; - (void) _endDisplay;
- (void) _timedOut: (NSTimer *)timer; - (void) _timedOut: (NSTimer *)timer;
@end @end
@ -170,12 +240,12 @@ static BOOL restoreMouseMoved;
+ (void) initialize + (void) initialize
{ {
viewsMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, viewsMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSObjectMapValueCallBacks, 8); NSObjectMapValueCallBacks, 8);
window = [[GSTTPanel alloc] initWithContentRect: NSMakeRect(0,0,100,25) window = [[GSTTPanel alloc] initWithContentRect: NSMakeRect(0,0,100,25)
styleMask: NSBorderlessWindowMask styleMask: NSBorderlessWindowMask
backing: NSBackingStoreRetained backing: NSBackingStoreRetained
defer: YES]; defer: YES];
[window setBackgroundColor: [window setBackgroundColor:
[NSColor colorWithDeviceRed: 1.0 green: 1.0 blue: 0.90 alpha: 1.0]]; [NSColor colorWithDeviceRed: 1.0 green: 1.0 blue: 0.90 alpha: 1.0]];
@ -183,6 +253,8 @@ static BOOL restoreMouseMoved;
[window setExcludedFromWindowsMenu: YES]; [window setExcludedFromWindowsMenu: YES];
[window setLevel: NSStatusWindowLevel]; [window setLevel: NSStatusWindowLevel];
[window setAutodisplay: NO]; [window setAutodisplay: NO];
[window setOneShot: YES];
[window setTitle:@"GSToolTips"];
} }
+ (void) removeTipsForView: (NSView*)aView + (void) removeTipsForView: (NSView*)aView
@ -253,8 +325,8 @@ static BOOL restoreMouseMoved;
{ {
if (rect->owner == self) if (rect->owner == self)
{ {
count++; count++;
} }
} }
return count; return count;
} }
@ -361,21 +433,21 @@ static BOOL restoreMouseMoved;
if (rect->owner == self) if (rect->owner == self)
{ {
GSTTProvider *provider = (GSTTProvider *)rect->user_data; GSTTProvider *provider = (GSTTProvider *)rect->user_data;
NSRect frame; NSRect frame;
if (rect->tag == toolTipTag) if (rect->tag == toolTipTag)
{ {
frame = [view bounds]; frame = [view bounds];
} }
else else
{ {
// FIXME is this the thing to do with tooltips other than // FIXME is this the thing to do with tooltips other than
// the main one (which we know should cover the whole view)? // the main one (which we know should cover the whole view)?
frame = [provider viewRect]; frame = [provider viewRect];
} }
frame = [view convertRect: frame toView: nil]; frame = [view convertRect: frame toView: nil];
[rect reset: frame inside: NO]; [rect reset: frame inside: NO];
} }
} }
} }
@ -391,10 +463,10 @@ static BOOL restoreMouseMoved;
{ {
if (rect->owner == self) if (rect->owner == self)
{ {
RELEASE((GSTTProvider*)rect->user_data); RELEASE((GSTTProvider*)rect->user_data);
rect->user_data = 0; rect->user_data = 0;
[view removeTrackingRect: rect->tag]; [view removeTrackingRect: rect->tag];
} }
} }
toolTipTag = -1; toolTipTag = -1;
} }
@ -431,12 +503,12 @@ static BOOL restoreMouseMoved;
while ((rect = [enumerator nextObject]) != nil) while ((rect = [enumerator nextObject]) != nil)
{ {
if (rect->tag == tag && rect->owner == self) if (rect->tag == tag && rect->owner == self)
{ {
RELEASE((GSTTProvider*)rect->user_data); RELEASE((GSTTProvider*)rect->user_data);
rect->user_data = 0; rect->user_data = 0;
[view removeTrackingRect: tag]; [view removeTrackingRect: tag];
return; return;
} }
} }
} }
@ -446,10 +518,10 @@ static BOOL restoreMouseMoved;
{ {
if (toolTipTag != -1) if (toolTipTag != -1)
{ {
[self _endDisplay]; [self _endDisplay];
[self removeToolTip: toolTipTag]; [self removeToolTip: toolTipTag];
toolTipTag = -1; toolTipTag = -1;
} }
} }
else else
{ {
@ -457,31 +529,31 @@ static BOOL restoreMouseMoved;
if (toolTipTag == -1) if (toolTipTag == -1)
{ {
NSRect rect; NSRect rect;
rect = [view bounds]; rect = [view bounds];
provider = [[GSTTProvider alloc] initWithObject: string provider = [[GSTTProvider alloc] initWithObject: string
userData: nil userData: nil
rect: rect]; rect: rect];
toolTipTag = [view addTrackingRect: rect toolTipTag = [view addTrackingRect: rect
owner: self owner: self
userData: provider userData: provider
assumeInside: NO]; assumeInside: NO];
} }
else else
{ {
NSEnumerator *enumerator; NSEnumerator *enumerator;
GSTrackingRect *rect; GSTrackingRect *rect;
enumerator = [((NSViewPtr)view)->_tracking_rects objectEnumerator]; enumerator = [((NSViewPtr)view)->_tracking_rects objectEnumerator];
while ((rect = [enumerator nextObject]) != nil) while ((rect = [enumerator nextObject]) != nil)
{ {
if (rect->tag == toolTipTag && rect->owner == self) if (rect->tag == toolTipTag && rect->owner == self)
{ {
[((GSTTProvider*)rect->user_data) setObject: string]; [((GSTTProvider*)rect->user_data) setObject: string];
} }
} }
} }
} }
} }
@ -505,26 +577,6 @@ static BOOL restoreMouseMoved;
@implementation GSToolTips (Private) @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 - (void) _endDisplay
{ {
if (isOpening) if (isOpening)
@ -539,15 +591,19 @@ static BOOL restoreMouseMoved;
if (timer != nil && timedObject == self) if (timer != nil && timedObject == self)
{ {
if ([timer isValid]) if ([timer isValid])
{ {
[timer invalidate]; [timer invalidate];
} }
timer = nil; timer = nil;
timedObject = nil; timedObject = nil;
} }
if (window != nil) if (window != nil)
{ {
#if 0
[window close];
#else
[window orderOut:self]; [window orderOut:self];
#endif
} }
if (restoreMouseMoved == YES) if (restoreMouseMoved == YES)
{ {
@ -605,6 +661,9 @@ static BOOL restoreMouseMoved;
[self _endDisplay]; [self _endDisplay];
} }
if ((toolTipString == nil) || ([toolTipString length] == 0))
return;
size = [[NSUserDefaults standardUserDefaults] size = [[NSUserDefaults standardUserDefaults]
floatForKey: @"NSToolTipsFontSize"]; floatForKey: @"NSToolTipsFontSize"];
@ -659,11 +718,9 @@ static BOOL restoreMouseMoved;
offset.width = rect.origin.x - mouseLocation.x; offset.width = rect.origin.x - mouseLocation.x;
isOpening = YES; isOpening = YES;
[window setToolTipText:toolTipText];
[window setFrame:rect display:NO]; [window setFrame:rect display:NO];
[window orderFront: nil]; [window orderFront:self];
[window display];
[self _drawText: toolTipText];
[window flushWindow];
isOpening = NO; isOpening = NO;
RELEASE(toolTipText); RELEASE(toolTipText);

View file

@ -1750,6 +1750,7 @@ many times.
{ {
GSDisplayServer *srv = GSServerForWindow(self); GSDisplayServer *srv = GSServerForWindow(self);
BOOL display = NO; BOOL display = NO;
BOOL redisplay = NO;
if (YES == [[NSUserDefaults standardUserDefaults] if (YES == [[NSUserDefaults standardUserDefaults]
boolForKey: @"GSBackgroundApp"]) boolForKey: @"GSBackgroundApp"])
@ -1790,6 +1791,8 @@ many times.
[self _initBackendWindow]; [self _initBackendWindow];
display = YES; display = YES;
} }
else
redisplay = (_f.visible == NO);
} }
/* If a hide on deactivate window is explicitly ordered in or out while /* If a hide on deactivate window is explicitly ordered in or out while
@ -1800,12 +1803,12 @@ many times.
[NSApp _setWindow: self inactive: NO]; [NSApp _setWindow: self inactive: NO];
} }
#if 1
// Draw content before backend window ordering // Draw content before backend window ordering
if (display) if (display)
[_wv display]; [self display];
else if (place != NSWindowOut) #endif
[_wv displayIfNeeded];
/* The backend will keep us below the current key window unless we /* The backend will keep us below the current key window unless we
force it not too */ force it not too */
if ((otherWin == 0 if ((otherWin == 0
@ -1815,9 +1818,10 @@ many times.
otherWin = -1; otherWin = -1;
[srv orderwindow: place : otherWin : _windowNum]; [srv orderwindow: place : otherWin : _windowNum];
if (display)
if (redisplay)
[self display]; [self display];
if (place != NSWindowOut) if (place != NSWindowOut)
{ {
/* /*
@ -1838,10 +1842,10 @@ many times.
BOOL isFileName; BOOL isFileName;
NSString *aString; NSString *aString;
aString = [NSString stringWithFormat: @"%@ -- %@", aString = [NSString stringWithFormat: @"%@ -- %@",
[_representedFilename lastPathComponent], [_representedFilename lastPathComponent],
[_representedFilename stringByDeletingLastPathComponent]]; [_representedFilename stringByDeletingLastPathComponent]];
isFileName = [_windowTitle isEqual: aString]; isFileName = [_windowTitle isEqual: aString];
[NSApp addWindowsItem: self [NSApp addWindowsItem: self
title: _windowTitle title: _windowTitle
@ -1854,6 +1858,11 @@ many times.
[srv setinputfocus: _windowNum]; [srv setinputfocus: _windowNum];
} }
_f.visible = YES; _f.visible = YES;
#if 1
[self displayIfNeeded];
#else
// [self display];
#endif
} }
else if ([self isOneShot]) else if ([self isOneShot])
{ {
@ -2370,7 +2379,7 @@ many times.
- (void) display - (void) display
{ {
if (_gstate == 0 || _f.visible == NO) if (_gstate == 0)
return; return;
[_wv display]; [_wv display];
@ -2385,9 +2394,7 @@ many times.
if (_f.views_need_display) if (_f.views_need_display)
{ {
[_wv displayIfNeeded]; [self display];
[self discardCachedImage];
_f.views_need_display = NO;
} }
} }
@ -5695,3 +5702,4 @@ NSWindow* GSWindowWithNumber(int num)
return (NSWindow*)NSMapGet(windowmaps, (void*)(intptr_t)num); return (NSWindow*)NSMapGet(windowmaps, (void*)(intptr_t)num);
return nil; return nil;
} }