API  1.0.0
CPCollectionViewItem.j
Go to the documentation of this file.
1 /*
2  * CPCollectionViewItem.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2009, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
27 @implementation CPCollectionViewItem : CPViewController
28 {
29  BOOL _isSelected;
30  CPData _cachedArchive;
31 }
32 
33 - (id)copy
34 {
35  var cibName = [self cibName],
36  copy;
37 
38  if (cibName)
39  {
40  copy = [[[self class] alloc] initWithCibName:cibName bundle:[self cibBundle]];
41  }
42  else
43  {
44  if (!_cachedArchive)
45  _cachedArchive = [CPKeyedArchiver archivedDataWithRootObject:self];
46 
47  copy = [CPKeyedUnarchiver unarchiveObjectWithData:_cachedArchive];
48 
49  // copy connections
50  }
51 
52  [copy setRepresentedObject:[self representedObject]];
53  [copy setSelected:_isSelected];
54 
55  return copy;
56 }
57 
58 // Setting the Represented Object
63 - (void)setRepresentedObject:(id)anObject
64 {
65  [super setRepresentedObject:anObject];
66 
67  var view = [self view];
68 
69  if ([view respondsToSelector:@selector(setRepresentedObject:)])
70  [view setRepresentedObject:[self representedObject]];
71 }
72 
73 // Modifying the Selection
78 - (void)setSelected:(BOOL)shouldBeSelected
79 {
80  shouldBeSelected = !!shouldBeSelected;
81 
82  if (_isSelected === shouldBeSelected)
83  return;
84 
85  _isSelected = shouldBeSelected;
86 
87  var view = [self view];
88 
89  if ([view respondsToSelector:@selector(setSelected:)])
90  [view setSelected:[self isSelected]];
91 }
92 
96 - (BOOL)isSelected
97 {
98  return _isSelected;
99 }
100 
101 // Parent Collection View
105 - (CPCollectionView)collectionView
106 {
107  return [_view superview];
108 }
109 
110 @end
A Cappuccino wrapper for any data type.
Definition: CPData.h:2
Unarchives objects created using CPKeyedArchiver.
Implements keyed archiving of object graphs (e.g. for storing data).
id unarchiveObjectWithData:(CPData aData)
Class class()
Definition: CPObject.j:179
void setRepresentedObject:(id aValue)
CPData archivedDataWithRootObject:(id anObject)