OSDN Git Service

UIを調整
[kcd/KCD.git] / KCD / HMSourceListColoredView.m
1 //
2 //  HMSourceListColoredView.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2015/06/04.
6 //  Copyright (c) 2015年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMSourceListColoredView.h"
10
11 @interface HMSourceListColoredView ()
12 @property (strong, nonatomic) NSColor *backgroundColor;
13 @property (nonatomic, getter=isObservingKeyState) BOOL observingKeyState;
14 @end
15
16 @implementation HMSourceListColoredView
17 - (instancetype)initWithFrame:(NSRect)frameRect
18 {
19         self = [super initWithFrame:frameRect];
20         if([NSVisualEffectView class]) {
21                 NSVisualEffectView *view = [[NSVisualEffectView alloc] initWithFrame:self.frame];
22                 return (HMSourceListColoredView *)view;
23         }
24         return self;
25 }
26 - (void)dealloc
27 {
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]];
35         }
36 }
37
38 - (void)viewDidMoveToWindow
39 {
40         NSTableView *tableView = [[NSTableView alloc] init];
41         [tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
42         _backgroundColor = [tableView backgroundColor];
43         [self addWindowKeyStateObservers];
44 }
45
46 - (void)addWindowKeyStateObservers
47 {
48         if (!self.isObservingKeyState) {
49                 [[NSNotificationCenter defaultCenter] addObserver:self
50                                                                                                  selector:@selector(redisplay)
51                                                                                                          name:NSWindowDidBecomeKeyNotification
52                                                                                                    object:[self window]];
53                 
54                 [[NSNotificationCenter defaultCenter] addObserver:self
55                                                                                                  selector:@selector(redisplay)
56                                                                                                          name:NSWindowDidResignKeyNotification
57                                                                                                    object:[self window]];
58         }
59         self.observingKeyState = YES;
60 }
61
62 - (void)redisplay
63 {
64         [self setNeedsDisplay:YES];
65 }
66
67 - (void)drawRect:(NSRect)dirtyRect
68 {
69         [_backgroundColor setFill];
70         NSRectFill(dirtyRect);
71 }
72
73 @end