blob: de2dfe41821a925119a0a2908f05337410e06ae4 [file] [log] [blame]
Alexandre Lision4e280d62015-09-09 15:56:30 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision4e280d62015-09-09 15:56:30 -04003 * 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 Kostiuk3c960bf2017-06-01 12:11:54 -040022@interface NSView (extension)
23@property NSVisualEffectView* vibrantView;
24@end;
25
Alexandre Lision4e280d62015-09-09 15:56:30 -040026@interface ContextualTableCellView()
27
28@property NSTrackingArea *trackingArea;
29
30@end
31
32@implementation ContextualTableCellView
33
Alexandre Lision4e280d62015-09-09 15:56:30 -040034- (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 Traczyk3b98eb82018-03-29 17:54:42 -040053 if (self.isMouseOver) {
54 return;
55 }
56
Alexandre Lision4e280d62015-09-09 15:56:30 -040057 for (NSView* item in self.contextualsControls) {
58 [item setHidden:YES];
Kateryna Kostiuk3c960bf2017-06-01 12:11:54 -040059 if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView)
60 [item.vibrantView setHidden:YES];
Alexandre Lision4e280d62015-09-09 15:56:30 -040061 }
62}
63
64- (void)mouseEntered:(NSEvent *)theEvent
65{
Andreas Traczyk3b98eb82018-03-29 17:54:42 -040066 self.isMouseOver = true;
67
Alexandre Lision21666f32015-09-22 17:04:36 -040068 if (self.activeState)
69 return;
70
Alexandre Lision4e280d62015-09-09 15:56:30 -040071 for (NSView* item in self.contextualsControls) {
72 [item setHidden:NO];
Kateryna Kostiuk3c960bf2017-06-01 12:11:54 -040073 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 Lision4e280d62015-09-09 15:56:30 -040097 }
98}
99
100- (void)mouseExited:(NSEvent *)theEvent
101{
Andreas Traczyk3b98eb82018-03-29 17:54:42 -0400102 self.isMouseOver = false;
103
Alexandre Lision4e280d62015-09-09 15:56:30 -0400104 for (NSView* item in self.contextualsControls) {
105 [item setHidden:YES];
Kateryna Kostiuk3c960bf2017-06-01 12:11:54 -0400106 if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView) {
107 [item.vibrantView setHidden:YES];
108 }
Alexandre Lision4e280d62015-09-09 15:56:30 -0400109 }
110}
111
112@end