PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Tools/nib2cib/NSSegmentedControl.j

http://github.com/cacaodev/cappuccino
Unknown | 159 lines | 121 code | 38 blank | 0 comment | 0 complexity | 23d68ec901a823d99d8a4a54cd0ad86e MD5 | raw file
  1/*
  2 * NSSegmentedControl.j
  3 * nib2cib
  4 *
  5 * Created by Thomas Robinson.
  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@import <AppKit/CPSegmentedControl.j>
 24
 25@import "NSCell.j"
 26
 27@class Nib2Cib
 28
 29
 30@implementation CPSegmentedControl (CPCoding)
 31
 32- (id)NS_initWithCoder:(CPCoder)aCoder
 33{
 34    _segments = [];
 35    _themeStates = [];
 36
 37    return [super NS_initWithCoder:aCoder];
 38}
 39
 40- (void)NS_initWithCell:(NSCell)cell
 41{
 42    [super NS_initWithCell:cell];
 43
 44    _segments           = [cell segments];
 45    _selectedSegment    = [cell selectedSegment];
 46    _segmentStyle       = [cell segmentStyle];
 47    _trackingMode       = [cell trackingMode];
 48
 49    [self setValue:CPCenterTextAlignment forThemeAttribute:@"alignment"];
 50
 51    // HACK
 52    for (var i = 0; i < _segments.length; i++)
 53    {
 54        _themeStates[i] = _segments[i].selected ? CPThemeStateSelected : CPThemeStateNormal;
 55        [self tileWithChangedSegment:i];
 56    }
 57
 58    [self setEnabled:[cell isEnabled]];
 59}
 60
 61@end
 62
 63@implementation NSSegmentedControl : CPSegmentedControl
 64{
 65}
 66
 67- (id)initWithCoder:(CPCoder)aCoder
 68{
 69    self = [self NS_initWithCoder:aCoder];
 70
 71    if (self)
 72    {
 73        var cell = [aCoder decodeObjectForKey:@"NSCell"];
 74        [self NS_initWithCell:cell];
 75        [self _adjustNib2CibSize];
 76    }
 77
 78    return self;
 79}
 80
 81- (Class)classForKeyedArchiver
 82{
 83    return [CPSegmentedControl class];
 84}
 85
 86@end
 87
 88@implementation NSSegmentedCell : NSActionCell
 89{
 90    CPArray                 _segments           @accessors(readonly, getter=segments);
 91    int                     _selectedSegment    @accessors(readonly, getter=selectedSegment);
 92    int                     _segmentStyle       @accessors(readonly, getter=segmentStyle);
 93    CPSegmentSwitchTracking _trackingMode       @accessors(readonly, getter=trackingMode);
 94}
 95
 96- (id)initWithCoder:(CPCoder)aCoder
 97{
 98    if (self = [super initWithCoder:aCoder])
 99    {
100        _segments           = [aCoder decodeObjectForKey:"NSSegmentImages"];
101        _selectedSegment    = [aCoder decodeObjectForKey:"NSSelectedSegment"];
102
103        if (_selectedSegment === nil)
104            _selectedSegment = -1;
105
106        _segmentStyle       = [aCoder decodeIntForKey:"NSSegmentStyle"];
107        _trackingMode       = [aCoder decodeIntForKey:"NSTrackingMode"];
108
109        if (_trackingMode == CPSegmentSwitchTrackingSelectOne && _selectedSegment == -1)
110            _selectedSegment = 0;
111    }
112
113    return self;
114}
115
116@end
117
118
119@implementation _CPSegmentItem (CPCoding)
120
121- (id)NS_initWithCoder:(CPCoder)aCoder
122{
123    if (self = [super init])
124    {
125        image       = [aCoder decodeObjectForKey:"NSSegmentItemImage"];
126        label       = [aCoder decodeObjectForKey:"NSSegmentItemLabel"];
127        menu        = [aCoder decodeObjectForKey:"NSSegmentItemMenu"];
128        selected    = [aCoder decodeBoolForKey:"NSSegmentItemSelected"];
129        enabled     = ![aCoder decodeBoolForKey:"NSSegmentItemDisabled"];
130        tag         = [aCoder decodeIntForKey:"NSSegmentItemTag"];
131        width       = [aCoder decodeIntForKey:"NSSegmentItemWidth"];
132
133        frame       = CGRectMakeZero();
134
135        // NSSegmentItemImageScaling
136        // NSSegmentItemTooltip
137    }
138
139    return self;
140}
141
142@end
143
144@implementation NSSegmentItem : _CPSegmentItem
145{
146}
147
148- (id)initWithCoder:(CPCoder)aCoder
149{
150    return [self NS_initWithCoder:aCoder];
151}
152
153- (Class)classForKeyedArchiver
154{
155    return [_CPSegmentItem class];
156}
157
158@end
159