blob: cf5aa03c9de0bc2752b38dbbe05e68ecf6e531b1 [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
34
35- (void)updateTrackingAreas {
36 [super updateTrackingAreas];
37 [self ensureTrackingArea];
38 if (![[self trackingAreas] containsObject:_trackingArea]) {
39 [self addTrackingArea:_trackingArea];
40 }
41}
42
43- (void)ensureTrackingArea {
44 if (_trackingArea == nil) {
45 _trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
46 options:NSTrackingInVisibleRect
47 | NSTrackingActiveAlways
48 | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
49 }
50}
51
52- (void)prepareForReuse
53{
54 for (NSView* item in self.contextualsControls) {
55 [item setHidden:YES];
Kateryna Kostiuk3c960bf2017-06-01 12:11:54 -040056 if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView)
57 [item.vibrantView setHidden:YES];
Alexandre Lision4e280d62015-09-09 15:56:30 -040058 }
59}
60
61- (void)mouseEntered:(NSEvent *)theEvent
62{
Alexandre Lision21666f32015-09-22 17:04:36 -040063 if (self.activeState)
64 return;
65
Alexandre Lision4e280d62015-09-09 15:56:30 -040066 for (NSView* item in self.contextualsControls) {
67 [item setHidden:NO];
Kateryna Kostiuk3c960bf2017-06-01 12:11:54 -040068 if(!self.shouldBlurParentView)
69 {
70 break;
71 }
72 if([item respondsToSelector:@selector(vibrantView)] && !item.vibrantView) {
73 NSRect frame = CGRectMake(item.frame.origin.x - 20 , item.frame.origin.y - 50, item.frame.size.width + 53, item.frame.size.height + 100);
74 NSVisualEffectView *vibrantView = [[NSVisualEffectView alloc]
75 initWithFrame:frame];
76 vibrantView.appearance = [NSAppearance
77 appearanceNamed:NSAppearanceNameVibrantLight];
78 vibrantView.material = NSVisualEffectMaterialAppearanceBased;
79 vibrantView.blendingMode = NSVisualEffectBlendingModeWithinWindow;
80 [vibrantView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
81 vibrantView.alphaValue = 0.7;
82 if([item respondsToSelector:@selector(setVibrantView:)]) {
83 item.vibrantView = vibrantView;
84 }
85 [self addSubview: item.vibrantView];
86 [self addSubview:item];
87
88 }
89 if([item respondsToSelector:@selector(vibrantView)] && item.vibrantView) {
90 [item.vibrantView setHidden:NO];
91 }
Alexandre Lision4e280d62015-09-09 15:56:30 -040092 }
93}
94
95- (void)mouseExited:(NSEvent *)theEvent
96{
97 for (NSView* item in self.contextualsControls) {
98 [item setHidden:YES];
Kateryna Kostiuk3c960bf2017-06-01 12:11:54 -040099 if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView) {
100 [item.vibrantView setHidden:YES];
101 }
Alexandre Lision4e280d62015-09-09 15:56:30 -0400102 }
103}
104
105@end