2 // HMSourceListColoredView.m
5 // Created by Hori,Masaki on 2015/06/04.
6 // Copyright (c) 2015年 Hori,Masaki. All rights reserved.
9 #import "HMSourceListColoredView.h"
11 @interface HMSourceListColoredView ()
12 @property (strong, nonatomic) NSColor *backgroundColor;
13 @property (nonatomic, getter=isObservingKeyState) BOOL observingKeyState;
16 @implementation HMSourceListColoredView
17 - (instancetype)initWithFrame:(NSRect)frameRect
19 self = [super initWithFrame:frameRect];
20 if([NSVisualEffectView class]) {
21 NSVisualEffectView *view = [[NSVisualEffectView alloc] initWithFrame:self.frame];
22 return (HMSourceListColoredView *)view;
28 if (self.isObservingKeyState) {
29 [[NSNotificationCenter defaultCenter] removeObserver:self
30 name:NSWindowDidBecomeKeyNotification
31 object:[self window]];
32 [[NSNotificationCenter defaultCenter] removeObserver:self
33 name:NSWindowDidResignKeyNotification
34 object:[self window]];
38 - (void)viewDidMoveToWindow
40 NSTableView *tableView = [[NSTableView alloc] init];
41 [tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
42 _backgroundColor = [tableView backgroundColor];
43 [self addWindowKeyStateObservers];
46 - (void)addWindowKeyStateObservers
48 if (!self.isObservingKeyState) {
49 [[NSNotificationCenter defaultCenter] addObserver:self
50 selector:@selector(redisplay)
51 name:NSWindowDidBecomeKeyNotification
52 object:[self window]];
54 [[NSNotificationCenter defaultCenter] addObserver:self
55 selector:@selector(redisplay)
56 name:NSWindowDidResignKeyNotification
57 object:[self window]];
59 self.observingKeyState = YES;
64 [self setNeedsDisplay:YES];
67 - (void)drawRect:(NSRect)dirtyRect
69 [_backgroundColor setFill];
70 NSRectFill(dirtyRect);