API  1.0.0
CPTabViewItem.j
Go to the documentation of this file.
1 /*
2  * CPTabViewItem.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 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 
24 
25 /*
26  The tab is currently selected.
27  @global
28  @group CPTabState
29 */
31 /*
32  The tab is currently in the background (not selected).
33  @global
34  @group CPTabState
35 */
37 /*
38  The tab of this item is currently being pressed by the user.
39  @global
40  @group CPTabState
41 */
43 
50 @implementation CPTabViewItem : CPObject
51 {
52  id _identifier;
53  CPString _label;
54  CPInteger _tag;
55 
56  CPView _view;
57  CPView _auxiliaryView;
58 
59  CPTabView _tabView;
60  unsigned _tabState; // Looks like it is not yet implemented
61 
62  CPImage _image;
63  CPViewController _viewController;
64 
65  BOOL _enabled;
66  BOOL _selected;
67  CGRect _tabRect;
68  float _width;
69 }
70 
71 /*
72 
73 */
74 + (CPTabViewItem)tabViewItemWithViewController:(CPViewController)aViewController
75 {
76  var item = [[CPTabViewItem alloc] init];
77  [item setViewController:aViewController];
78 
79  return item;
80 }
81 
82 - (id)init
83 {
84  return [self initWithIdentifier:@""];
85 }
86 
87 - (void)_init
88 {
89  _tag = 0;
90  _viewController = nil;
91  _image = nil;
92  _tabState = 0;
93  _tabView = nil;
94  _enabled = YES;
95  _selected = NO;
96  _tabRect = CGRectMakeZero();
97  _width = 0;
98 }
99 
104 - (id)initWithIdentifier:(id)anIdentifier
105 {
106  self = [super init];
107 
108  [self _init];
109 
110  _identifier = anIdentifier;
111  _label = nil;
112  _view = nil;
113  //_auxiliaryView = nil;
114 
115  return self;
116 }
117 
118 // Working With Labels
123 - (void)setLabel:(CPString)aLabel
124 {
125  if ([aLabel isEqualToString:_label])
126  return;
127 
128  _label = aLabel;
129  [_tabView tileWithChangedItem:self];
130 }
131 
136 {
137  return _label;
138 }
139 
140 // Working With Images
145 - (void)setImage:(CPImage)anImage
146 {
147  if ([anImage isEqual:_image])
148  return;
149 
150  _image = anImage;
151  [_tabView tileWithChangedItem:self];
152 }
153 
157 - (CPImage)image
158 {
159  return _image;
160 }
161 
162 // Checking the Tab Display State
166 - (CPTabState)tabState
167 {
168  return _tabState;
169 }
170 
171 // Assigning an Identifier Object
176 - (void)setIdentifier:(id)anIdentifier
177 {
178  _identifier = anIdentifier;
179 }
180 
185 {
186  return _identifier;
187 }
188 
189 // Assigning a View
193 - (void)setView:(CPView)aView
194 {
195  if (_view == aView)
196  return;
197 
198  _view = aView;
199 
200  if ([_tabView selectedTabViewItem] == self)
201  [_tabView _displayItemView:_view];
202 }
203 
207 - (CPView)view
208 {
209  if (!_view && _viewController)
210  return [_viewController view]; // The view controller loads here.
211 
212  return _view;
213 }
214 
215 // Assigning an Auxiliary View
220 - (void)setAuxiliaryView:(CPView)anAuxiliaryView
221 {
222  _auxiliaryView = anAuxiliaryView;
223 }
224 
228 - (CPView)auxiliaryView
229 {
230  return _auxiliaryView;
231 }
232 
233 // Accessing the Parent Tab View
237 - (CPTabView)tabView
238 {
239  return _tabView;
240 }
241 
245 - (void)_setTabView:(CPTabView)aView
246 {
247  _tabView = aView;
248 }
249 
254 - (void)setViewController:(CPViewController)aViewController
255 {
256  _viewController = aViewController;
257 
258  var identifier = [aViewController cibName],
259  title = [_viewController title];
260 
261  if (identifier)
262  _identifier = identifier;
263 
264  if (title)
265  [self setLabel:title];
266 
267  if ([_tabView selectedTabViewItem] == self)
268  [_tabView _loadTabViewItem:self];
269 }
270 
271 @end
272 
273 var CPTabViewItemIdentifierKey = "CPTabViewItemIdentifierKey",
274  CPTabViewItemLabelKey = "CPTabViewItemLabelKey",
275  CPTabViewItemImageKey = "CPTabViewItemImageKey",
276  CPTabViewItemViewKey = "CPTabViewItemViewKey",
277  CPTabViewItemAuxViewKey = "CPTabViewItemAuxViewKey";
278 
279 
281 
282 - (id)initWithCoder:(CPCoder)aCoder
283 {
284  self = [super init];
285 
286  if (self)
287  {
288  [self _init];
289 
290  _identifier = [aCoder decodeObjectForKey:CPTabViewItemIdentifierKey];
291  _label = [aCoder decodeObjectForKey:CPTabViewItemLabelKey];
292  _image = [aCoder decodeObjectForKey:CPTabViewItemImageKey];
293 
294  _view = [aCoder decodeObjectForKey:CPTabViewItemViewKey];
295  _auxiliaryView = [aCoder decodeObjectForKey:CPTabViewItemAuxViewKey];
296  }
297 
298  return self;
299 }
300 
301 - (void)encodeWithCoder:(CPCoder)aCoder
302 {
303  [aCoder encodeObject:_identifier forKey:CPTabViewItemIdentifierKey];
304  [aCoder encodeObject:_label forKey:CPTabViewItemLabelKey];
305  [aCoder encodeObject:_image forKey:CPTabViewItemImageKey];
306 
307  [aCoder encodeObject:_view forKey:CPTabViewItemViewKey];
308  [aCoder encodeObject:_auxiliaryView forKey:CPTabViewItemAuxViewKey];
309 }
310 
311 @end
312 
314 
318 - (CPInteger)tag
319 {
320  return _tag;
321 }
322 
326 - (void)setTag:(CPInteger)aValue
327 {
328  _tag = aValue;
329 }
330 
334 - (CPImage)image
335 {
336  return _image;
337 }
338 
342 - (void)setImage:(CPImage)aValue
343 {
344  _image = aValue;
345 }
346 
350 - (CPViewController)viewController
351 {
352  return _viewController;
353 }
354 
358 - (BOOL)enabled
359 {
360  return _enabled;
361 }
362 
366 - (void)setEnabled:(BOOL)aValue
367 {
368  _enabled = aValue;
369 }
370 
374 - (BOOL)selected
375 {
376  return _selected;
377 }
378 
382 - (void)setSelected:(BOOL)aValue
383 {
384  _selected = aValue;
385 }
386 
390 - (CGRect)frame
391 {
392  return _tabRect;
393 }
394 
398 - (void)setFrame:(CGRect)aValue
399 {
400  _tabRect = aValue;
401 }
402 
406 - (float)width
407 {
408  return _width;
409 }
410 
414 - (void)setWidth:(float)aValue
415 {
416  _width = aValue;
417 }
418 
419 @end
var CPTabViewItemImageKey
id init()
Definition: CALayer.j:126
FrameUpdater prototype identifier
CGRect frame
var isEqual
BOOL selected
CPString label
int width
CPBackgroundTab
Definition: CPTabViewItem.j:36
CPPressedTab
Definition: CPTabViewItem.j:42
BOOL enabled
An immutable string (collection of characters).
Definition: CPString.h:2
Definition: CPImage.h:2
id initWithIdentifier:(id anIdentifier)
int tag
CPSelectedTab
Definition: CPTabViewItem.j:30
var CPTabViewItemViewKey
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
var CPTabViewItemLabelKey
id init()
Definition: CPObject.j:145
void setLabel:(CPString aLabel)
var CPTabViewItemIdentifierKey
var CPTabViewItemAuxViewKey
id alloc()
Definition: CPObject.j:130
Definition: CPView.j:137