Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCollectionViewItem.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (hide annotations) (download)
Wed Nov 11 14:21:59 2009 UTC (14 years, 5 months ago) by masaki
File size: 2986 byte(s)
[Fix] 選択色の変更が上手くいってなかったので修正。
1 masaki 56 //
2     // XspfMCollectionViewItem.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/10.
6     // Copyright 2009 masakih. All rights reserved.
7     //
8    
9     #import "XspfMCollectionViewItem.h"
10    
11 masaki 57 #import "XspfMCollectionItemBox.h"
12 masaki 56
13 masaki 57
14 masaki 56 @implementation XspfMCollectionViewItem
15    
16     - (id)copyWithZone:(NSZone *)zone
17     {
18     id result = [super copyWithZone:zone];
19 masaki 57
20 masaki 56 [result performSelector:@selector(setupBinding:) withObject:nil afterDelay:0.0];
21    
22     return result;
23     }
24    
25     - (void)dealloc
26     {
27     [collectionViewHolder removeObserver:self forKeyPath:@"isFirstResponder"];
28 masaki 57
29 masaki 56 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
30     [nc removeObserver:self];
31    
32     [super dealloc];
33     }
34    
35     - (void)setSelected:(BOOL)flag
36     {
37     [super setSelected:flag];
38     [self coodinateColors];
39     }
40    
41     - (void)setupBinding:(id)obj
42     {
43     collectionViewHolder = [self collectionView];
44     [collectionViewHolder addObserver:self
45     forKeyPath:@"isFirstResponder"
46     options:NSKeyValueObservingOptionNew
47     context:NULL];
48    
49     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
50     [nc addObserver:self selector:@selector(applicationDidBecomeOrResignActive:)
51     name:NSApplicationDidBecomeActiveNotification
52     object:NSApp];
53     [nc addObserver:self selector:@selector(applicationDidBecomeOrResignActive:)
54     name:NSApplicationDidResignActiveNotification
55     object:NSApp];
56    
57     [self coodinateColors];
58     }
59     - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
60     {
61     if([keyPath isEqualToString:@"isFirstResponder"]) {
62     [self willChangeValueForKey:@"firstResponder"];
63     [self coodinateColors];
64     [self didChangeValueForKey:@"firstResponder"];
65     return;
66     }
67    
68     [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
69     }
70 masaki 57 - (void)setView:(NSView *)view
71     {
72     [super setView:view];
73    
74     if(view) {
75     id views = [view subviews];
76     for(id view in views) {
77     if([view isKindOfClass:[XspfMCollectionItemBox class]]) {
78     [view setCollectionViewItem:self];
79     }
80     }
81     }
82     }
83    
84 masaki 56 - (BOOL)isFirstResponder
85     {
86     return [[self collectionView] isFirstResponder];
87     }
88    
89 masaki 57 - (NSColor *)backgroundColor
90 masaki 56 {
91     if(![self isSelected]) {
92     return [NSColor whiteColor];
93     }
94 masaki 57 if([self isFirstResponder] && [NSApp isActive]) {
95 masaki 56 return [NSColor colorWithCalibratedRed:65/255.0
96     green:120/255.0
97     blue:211/255.0
98     alpha:1.0];
99     } else {
100     return [NSColor colorWithCalibratedRed:212/255.0
101     green:212/255.0
102     blue:212/255.0
103     alpha:1.0];
104     }
105    
106     }
107    
108     - (NSColor *)textColor
109     {
110 masaki 57 if([self isSelected] && [self isFirstResponder] && [NSApp isActive]) {
111 masaki 56 return [NSColor whiteColor];
112     }
113     return [NSColor blackColor];
114     }
115    
116     - (void)coodinateColors
117     {
118 masaki 57 [self willChangeValueForKey:@"backgroundColor"];
119     [self didChangeValueForKey:@"backgroundColor"];
120 masaki 56
121     [self willChangeValueForKey:@"textColor"];
122     [self didChangeValueForKey:@"textColor"];
123     }
124     - (void)applicationDidBecomeOrResignActive:(id)notification
125     {
126     [self coodinateColors];
127     }
128    
129     @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26