From 97aa34218f0370ba8b672d3f905df0ed8de9ac85 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 21 May 2019 23:15:16 +0200 Subject: [PATCH] Remove custom ToolTip implementation now present in GUI --- ChangeLog | 6 + Framework/PCButton.m | 345 +------------------------------ Headers/ProjectCenter/PCButton.h | 15 +- 3 files changed, 21 insertions(+), 345 deletions(-) diff --git a/ChangeLog b/ChangeLog index d801ad05..a26c1792 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-05-22 Riccardo Mottola + + * Framework/PCButton.m + * Headers/ProjectCenter/PCButton.h + Remove custom ToolTip implementation now present in GUI. + 2018-08-19 Riccardo Mottola * Modules/Projects/Framework/PCFrameworkProject.h diff --git a/Framework/PCButton.m b/Framework/PCButton.m index cd013e4e..dafd2a3a 100644 --- a/Framework/PCButton.m +++ b/Framework/PCButton.m @@ -1,11 +1,12 @@ /* GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html - Copyright (C) 2003-2014 Free Software Foundation + Copyright (C) 2003-2019 Free Software Foundation Authors: Serg Stoyan + Riccardo Mottola - This file is part of GNUstep. + This file is part of ProjectCenter. This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public @@ -26,7 +27,6 @@ #import #import -#import @implementation PCButton @@ -37,346 +37,23 @@ @implementation PCButton - (id)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; - [_cell setGradientType:NSGradientConcaveWeak]; - [_cell setImageDimsWhenDisabled:YES]; - [self setImagePosition:NSImageOnly]; - [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - [self setRefusesFirstResponder:YES]; - - _hasTooltips = NO; - ttTimer = nil; - ttWindow = nil; - ttTitleAttrs = [[NSMutableDictionary alloc] init]; - [ttTitleAttrs setObject:[NSFont systemFontOfSize:10.0] - forKey:NSFontAttributeName]; - ttBackground = [NSColor colorWithDeviceRed:1.0 green:1.0 blue:0.90 alpha:1.0]; - RETAIN(ttBackground); - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(_updateTrackingRects:) - name:NSViewFrameDidChangeNotification - object:[[self window] contentView]]; - + if (self) + { + [_cell setGradientType:NSGradientConcaveWeak]; + [_cell setImageDimsWhenDisabled:YES]; + [self setImagePosition:NSImageOnly]; + [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + [self setRefusesFirstResponder:YES]; + } return self; } - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - if (_hasTooltips) - { - [self removeAllToolTips]; - RELEASE(ttTitleAttrs); - RELEASE(ttBackground); - RELEASE(ttWindow); - } - [super dealloc]; } -- (oneway void)release -{ - // If retain count is number of tracking rects + superview retain, - // remove tracking rects. It seems that tracking rects retain this object. - if (_hasTooltips && [self retainCount] == [_tracking_rects count] + 1) - { - [self removeAllToolTips]; - } - - [super release]; -} - -// ============================================================================ -// ==== Private methods -// ============================================================================ - -- (void)_updateTrackingRects:(NSNotification *)aNotif -{ - NSTrackingRectTag tag; - NSRect rect; - NSString *string = nil; - int i, j; - GSTrackingRect *tr = nil; - - if (_hasTooltips == NO) - { - return; - } - - j = [_tracking_rects count]; - for (i = 0; i < j; i++) - { - tr = [_tracking_rects objectAtIndex:i]; - - // Save tooltip string for next addTrackingRect:::: - string = [(NSString *)tr->user_data copy]; - - [self removeTrackingRect:tr->tag]; - -// NSLog(@"PCButton: tr: %i data: %@", tr->tag, tr->user_data); - - rect = [self frame]; - rect.origin.x = 0; - rect.origin.y = 0; - tag = [self addTrackingRect:rect - owner:self - userData:string - assumeInside:NO]; - - if (tr->tag == mainToolTip) - { - mainToolTip = tag; - } - - RELEASE(string); - } -} - -- (void)_invalidateTimer -{ - if (ttTimer == nil) - { - return; - } - -// NSLog(@"_invalidateTimer"); - if ([ttTimer isValid]) - { - [ttTimer invalidate]; - } - ttTimer = nil; -} - -- (void)_closeToolTipWindow -{ - if (ttWindow) - { - [ttWindow close]; - ttWindow = nil; - } -} - -- (void)_drawToolTip:(NSAttributedString *)title -{ - NSRectEdge sides[] = {NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge}; - NSColor *black = [NSColor blackColor]; - NSColor *colors[] = {black, black, black, black}; - NSRect bounds = [[ttWindow contentView] bounds]; - NSRect titleRect; - - titleRect = [ttWindow frame]; - titleRect.origin.x = 2; - titleRect.origin.y = -2; - - [[ttWindow contentView] lockFocus]; - - [title drawInRect:titleRect]; - NSDrawColorTiledRects(bounds, bounds, sides, colors, 4); - - [[ttWindow contentView] unlockFocus]; -} - -- (void)_showTooltip:(NSTimer *)timer -{ - NSString *ttText = [timer userInfo]; - - [self _invalidateTimer]; - -// NSLog(@"showTooltip: %@", ttText); -// NSLog(@"toolTips: %@", toolTips); - - if (ttWindow == nil) - { - NSAttributedString *attributedTitle = nil; - NSSize titleSize; - NSPoint mouseLocation = [NSEvent mouseLocation]; - NSRect windowRect; - - attributedTitle = - [[NSAttributedString alloc] initWithString:ttText - attributes:ttTitleAttrs]; - titleSize = [attributedTitle size]; - - // Window - windowRect = NSMakeRect(mouseLocation.x + 8, - mouseLocation.y - 16 - (titleSize.height+3), - titleSize.width + 4, titleSize.height + 4); - - ttWindow = [[NSWindow alloc] initWithContentRect:windowRect - styleMask:NSBorderlessWindowMask - backing:NSBackingStoreRetained - defer:YES]; - [ttWindow setBackgroundColor:ttBackground]; - [ttWindow setReleasedWhenClosed:YES]; - [ttWindow setExcludedFromWindowsMenu:YES]; - [ttWindow setLevel:NSStatusWindowLevel]; - - [ttWindow orderFront:nil]; - - [self _drawToolTip:attributedTitle]; - RELEASE(attributedTitle); - } -} - -// ============================================================================ -// ==== Tool Tips -// ============================================================================ - -/*- (void)mouseEntered:(NSEvent *)theEvent -{ - NSLog (@"mouseEntered"); - - if (ttTimer == nil) - { - ttTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 - target:self - selector:@selector(_showTooltip:) - userInfo:[theEvent userData] - repeats:YES]; - [[self window] setAcceptsMouseMovedEvents:YES]; - } -} - -- (void)mouseExited:(NSEvent *)theEvent -{ -// NSLog (@"mouseExited"); - [self _invalidateTimer]; - [self _closeToolTipWindow]; - [[self window] setAcceptsMouseMovedEvents:NO]; -} - -- (void)mouseDown:(NSEvent *)theEvent -{ -// NSLog (@"mouseDown"); - [self _invalidateTimer]; - [self _closeToolTipWindow]; - - [super mouseDown:theEvent]; -} - -- (void)mouseMoved:(NSEvent *)theEvent -{ - NSPoint mouseLocation; - NSPoint origin; - -// NSLog(@"mouseMoved"); - if (ttWindow == nil) - { - return; - } - mouseLocation = [NSEvent mouseLocation]; - - origin = NSMakePoint(mouseLocation.x + 8, - mouseLocation.y - 16 - [ttWindow frame].size.height); - - [ttWindow setFrameOrigin:origin]; -} - -// NSView methods -- (NSToolTipTag)addToolTipRect:(NSRect)aRect - owner:(id)anObject - userData:(void *)data -{ - SEL ownerSelector; - NSTrackingRectTag tag; - - if (NSEqualRects(aRect,NSZeroRect) || ttTimer != nil) - { - return -1; - } - - ownerSelector = @selector(view:stringForToolTip:point:userData:); - if (![anObject respondsToSelector:ownerSelector] - && ![anObject isKindOfClass:[NSString class]]) - { - return -1; - } - - // Set rect tracking - tag = [self addTrackingRect:aRect - owner:self - userData:data - assumeInside:NO]; - - return tag; -} - -- (void)removeAllToolTips -{ - int i, j; - GSTrackingRect *tr = nil; - - if (_hasTooltips == NO) - { - return; - } - [self _invalidateTimer]; - [self _closeToolTipWindow]; - - j = [_tracking_rects count]; - for (i = 0; i < j; i++) - { - tr = [_tracking_rects objectAtIndex:i]; - [self removeTrackingRect:tr->tag]; - } - - mainToolTip = -1; - _hasTooltips = NO; -} - -- (void)removeToolTip:(NSToolTipTag)tag -{ - [self removeTrackingRect:tag]; -} - -- (void)setToolTip:(NSString *)string -{ - NSTrackingRectTag tag; - NSRect rect; - - if (string == nil) // Remove old tooltip - { - if (_hasTooltips) - { - [self _invalidateTimer]; - [self _closeToolTipWindow]; - [self removeToolTip:mainToolTip]; - mainToolTip = -1; - _hasTooltips = NO; - } - } - else - { -// NSLog(@"setToolTip"); - rect = [self frame]; - rect.origin.x = 0; - rect.origin.y = 0; - tag = [self addTrackingRect:rect - owner:self - userData:string - assumeInside:NO]; - _hasTooltips = YES; - } -} - -- (NSString *)toolTip -{ - NSEnumerator *enumerator = [_tracking_rects objectEnumerator]; - GSTrackingRect *tr = nil; - - while ((tr = [enumerator nextObject])) - { - if (tr->tag == mainToolTip) - { - return tr->user_data; - } - } - - return nil; -}*/ @end diff --git a/Headers/ProjectCenter/PCButton.h b/Headers/ProjectCenter/PCButton.h index 4ed1bb5e..0119ce5f 100644 --- a/Headers/ProjectCenter/PCButton.h +++ b/Headers/ProjectCenter/PCButton.h @@ -1,11 +1,12 @@ /* GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html - Copyright (C) 2003-2004 Free Software Foundation + Copyright (C) 2003-2019 Free Software Foundation Authors: Serg Stoyan + Riccardo Mottola - This file is part of GNUstep. + This file is part of ProjectCenter. This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public @@ -25,7 +26,7 @@ #ifndef _PCButton_h_ #define _PCButton_h_ -#import +#import /* * Button @@ -33,14 +34,6 @@ @interface PCButton : NSButton { - NSToolTipTag mainToolTip; - - NSTimer *ttTimer; - NSWindow *ttWindow; - NSMutableDictionary *ttTitleAttrs; - NSColor *ttBackground; - - BOOL _hasTooltips; } @end