blob: d188b86b62e665a4c4b945f37997bd6d92d94fb5 [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];
Kateryna Kostiukd73f9602018-07-24 13:51:28 -040049 [self.accountAvatar setWantsLayer:YES];
50 self.accountAvatar.layer.cornerRadius = self.accountAvatar.frame.size.width * 0.5;
51 self.accountAvatar.layer.masksToBounds = YES;
52 [self.accountStatus setWantsLayer:YES];
53 [self.accountAvatar.layer setBackgroundColor:[[NSColor ringGreyLight] CGColor]];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040054 }
55}
56
57- (BOOL)acceptsFirstMouse:(NSEvent *)event {
58 return YES;
59}
60
61-(void) mouseUp:(NSEvent *)theEvent {
62 NSMenu *menu = self.enclosingMenuItem.menu;
63 [menu cancelTracking];
64 [menu performActionForItemAtIndex:[menu indexOfItem:self.enclosingMenuItem]];
65 [super mouseUp:theEvent];
66}
67
68- (void) drawRect: (NSRect) rect {
69 NSMenuItem *menuItem = ([self enclosingMenuItem]);
70 BOOL isHighlighted = [menuItem isHighlighted];
71 if (isHighlighted) {
Kateryna Kostiukd7e2e102018-10-01 13:33:38 -040072 [self.backgroundView setFillColor:[NSColor whiteColor]];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040073 } else {
Kateryna Kostiukd7e2e102018-10-01 13:33:38 -040074 [self.backgroundView setFillColor:[NSColor ringGreyHighlight]];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040075 }
Kateryna Kostiukd7e2e102018-10-01 13:33:38 -040076 [super drawRect: rect];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040077}
78
79@end