Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCollectionViewItem.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (hide annotations) (download)
Tue Nov 10 15:35:26 2009 UTC (14 years, 5 months ago) by masaki
File size: 2763 byte(s)
[New] CollectionViewItemの色を様々に変化させるために色々変更。
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    
12     @implementation XspfMCollectionViewItem
13    
14     - (id)copyWithZone:(NSZone *)zone
15     {
16     id result = [super copyWithZone:zone];
17     [result performSelector:@selector(setupBinding:) withObject:nil afterDelay:0.0];
18    
19     return result;
20     }
21    
22     - (void)dealloc
23     {
24     [collectionViewHolder removeObserver:self forKeyPath:@"isFirstResponder"];
25    
26     [thumbnail unbind:@"enabled2"];
27    
28     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
29     [nc removeObserver:self];
30    
31     [super dealloc];
32     }
33    
34     - (void)setSelected:(BOOL)flag
35     {
36     [super setSelected:flag];
37     [self coodinateColors];
38     }
39    
40     - (void)setupBinding:(id)obj
41     {
42     collectionViewHolder = [self collectionView];
43     [collectionViewHolder addObserver:self
44     forKeyPath:@"isFirstResponder"
45     options:NSKeyValueObservingOptionNew
46     context:NULL];
47    
48     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
49     [nc addObserver:self selector:@selector(applicationDidBecomeOrResignActive:)
50     name:NSApplicationDidBecomeActiveNotification
51     object:NSApp];
52     [nc addObserver:self selector:@selector(applicationDidBecomeOrResignActive:)
53     name:NSApplicationDidResignActiveNotification
54     object:NSApp];
55    
56     [self coodinateColors];
57     }
58     - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
59     {
60     if([keyPath isEqualToString:@"isFirstResponder"]) {
61     [self willChangeValueForKey:@"firstResponder"];
62     [self coodinateColors];
63     [self didChangeValueForKey:@"firstResponder"];
64     return;
65     }
66    
67     [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
68     }
69    
70     - (BOOL)isFirstResponder
71     {
72     return [[self collectionView] isFirstResponder];
73     }
74    
75     - (NSColor *)backgrounColor
76     {
77     if(![self isSelected]) {
78     return [NSColor whiteColor];
79     }
80     if([[self collectionView] isFirstResponder] && [NSApp isActive]) {
81     return [NSColor colorWithCalibratedRed:65/255.0
82     green:120/255.0
83     blue:211/255.0
84     alpha:1.0];
85     } else {
86     return [NSColor colorWithCalibratedRed:212/255.0
87     green:212/255.0
88     blue:212/255.0
89     alpha:1.0];
90     }
91    
92     }
93    
94     - (NSColor *)textColor
95     {
96     if([self isSelected] && [[self collectionView] isFirstResponder] && [NSApp isActive]) {
97     return [NSColor whiteColor];
98     }
99     return [NSColor blackColor];
100     }
101    
102     - (void)coodinateColors
103     {
104     [box setFillColor:[self backgrounColor]];
105     [box setBorderColor:[self backgrounColor]];
106    
107     [self willChangeValueForKey:@"textColor"];
108     [self didChangeValueForKey:@"textColor"];
109     }
110     - (void)applicationDidBecomeOrResignActive:(id)notification
111     {
112     [self coodinateColors];
113     }
114    
115     @end

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