Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | |
| 20 | #import "ContextualTableCellView.h" |
| 21 | |
Kateryna Kostiuk | 3c960bf | 2017-06-01 12:11:54 -0400 | [diff] [blame] | 22 | @interface NSView (extension) |
| 23 | @property NSVisualEffectView* vibrantView; |
| 24 | @end; |
| 25 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 26 | @interface ContextualTableCellView() |
| 27 | |
| 28 | @property NSTrackingArea *trackingArea; |
| 29 | |
| 30 | @end |
| 31 | |
| 32 | @implementation ContextualTableCellView |
| 33 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 34 | - (void)updateTrackingAreas { |
| 35 | [super updateTrackingAreas]; |
| 36 | [self ensureTrackingArea]; |
| 37 | if (![[self trackingAreas] containsObject:_trackingArea]) { |
| 38 | [self addTrackingArea:_trackingArea]; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | - (void)ensureTrackingArea { |
| 43 | if (_trackingArea == nil) { |
| 44 | _trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect |
| 45 | options:NSTrackingInVisibleRect |
| 46 | | NSTrackingActiveAlways |
| 47 | | NSTrackingMouseEnteredAndExited owner:self userInfo:nil]; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | - (void)prepareForReuse |
| 52 | { |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 53 | if (self.isMouseOver) { |
| 54 | return; |
| 55 | } |
| 56 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 57 | for (NSView* item in self.contextualsControls) { |
| 58 | [item setHidden:YES]; |
Kateryna Kostiuk | 3c960bf | 2017-06-01 12:11:54 -0400 | [diff] [blame] | 59 | if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView) |
| 60 | [item.vibrantView setHidden:YES]; |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | - (void)mouseEntered:(NSEvent *)theEvent |
| 65 | { |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 66 | self.isMouseOver = true; |
| 67 | |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 68 | if (self.activeState) |
| 69 | return; |
| 70 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 71 | for (NSView* item in self.contextualsControls) { |
| 72 | [item setHidden:NO]; |
Kateryna Kostiuk | 3c960bf | 2017-06-01 12:11:54 -0400 | [diff] [blame] | 73 | if(!self.shouldBlurParentView) |
| 74 | { |
| 75 | break; |
| 76 | } |
| 77 | if([item respondsToSelector:@selector(vibrantView)] && !item.vibrantView) { |
| 78 | NSRect frame = CGRectMake(item.frame.origin.x - 20 , item.frame.origin.y - 50, item.frame.size.width + 53, item.frame.size.height + 100); |
| 79 | NSVisualEffectView *vibrantView = [[NSVisualEffectView alloc] |
| 80 | initWithFrame:frame]; |
| 81 | vibrantView.appearance = [NSAppearance |
| 82 | appearanceNamed:NSAppearanceNameVibrantLight]; |
| 83 | vibrantView.material = NSVisualEffectMaterialAppearanceBased; |
| 84 | vibrantView.blendingMode = NSVisualEffectBlendingModeWithinWindow; |
| 85 | [vibrantView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 86 | vibrantView.alphaValue = 0.7; |
| 87 | if([item respondsToSelector:@selector(setVibrantView:)]) { |
| 88 | item.vibrantView = vibrantView; |
| 89 | } |
| 90 | [self addSubview: item.vibrantView]; |
| 91 | [self addSubview:item]; |
| 92 | |
| 93 | } |
| 94 | if([item respondsToSelector:@selector(vibrantView)] && item.vibrantView) { |
| 95 | [item.vibrantView setHidden:NO]; |
| 96 | } |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | - (void)mouseExited:(NSEvent *)theEvent |
| 101 | { |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 102 | self.isMouseOver = false; |
| 103 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 104 | for (NSView* item in self.contextualsControls) { |
| 105 | [item setHidden:YES]; |
Kateryna Kostiuk | 3c960bf | 2017-06-01 12:11:54 -0400 | [diff] [blame] | 106 | if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView) { |
| 107 | [item.vibrantView setHidden:YES]; |
| 108 | } |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | @end |