blob: 8b8a3aaa55508df7f793e43fd793d03ac2a225be [file] [log] [blame]
Kateryna Kostiuk13b76882017-03-30 09:18:44 -04001/*
2 * Copyright (C) 2015-2017 Savoir-faire Linux Inc.
3 * Author: Kateryna Kostiuk <kateryna.kostiuk@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 "AccountMenuItemView.h"
21#import "NSColor+RingTheme.h"
22
23@implementation AccountMenuItemView
24
25- (instancetype)initWithFrame:(CGRect)frame
26{
27 self = [super initWithFrame:frame];
28 if (self) {
29 [self loadFromNib];
30 }
31 return self;
32}
33
34- (void)loadFromNib
35{
36 NSView *viewFromXib = nil;
37 NSArray *objectsFromXib = nil;
38 [[NSBundle mainBundle] loadNibNamed:@"AccountMenuItemView" owner:self topLevelObjects:&objectsFromXib];
39 for (id item in objectsFromXib) {
40 if ([item isKindOfClass:[NSView class]]) {
41 viewFromXib = item;
42 break;
43 }
44 }
45 if (viewFromXib != nil) {
46 self.frame = viewFromXib.frame;
47 self.containerView = viewFromXib;
48 [self addSubview:self.containerView];
49 }
50}
51
52- (BOOL)acceptsFirstMouse:(NSEvent *)event {
53 return YES;
54}
55
56-(void) mouseUp:(NSEvent *)theEvent {
57 NSMenu *menu = self.enclosingMenuItem.menu;
58 [menu cancelTracking];
59 [menu performActionForItemAtIndex:[menu indexOfItem:self.enclosingMenuItem]];
60 [super mouseUp:theEvent];
61}
62
63- (void) drawRect: (NSRect) rect {
64 NSMenuItem *menuItem = ([self enclosingMenuItem]);
65 BOOL isHighlighted = [menuItem isHighlighted];
66 if (isHighlighted) {
67 [[NSColor ringGreyHighlight] set];
68 [NSBezierPath fillRect:rect];
69 } else {
70 [super drawRect: rect];
71 }
72}
73
74@end