PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/Tools/nib2cib/NSTableColumn.j

http://github.com/cacaodev/cappuccino
Unknown | 164 lines | 125 code | 39 blank | 0 comment | 0 complexity | 01dee0e796aa948a0a4f24e7cdef7535 MD5 | raw file
  1/*
  2 * NSTableColumn.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/CPLevelIndicator.j>
 24@import <AppKit/CPTableColumn.j>
 25@import <AppKit/CPTableHeaderView.j>
 26@import <AppKit/CPButton.j>
 27
 28@import "NSButton.j"
 29@import "NSImageView.j"
 30@import "NSLevelIndicator.j"
 31@import "NSTextField.j"
 32
 33@class Converter
 34@class Nib2Cib
 35
 36var IBDefaultFontSizeTableHeader = 11.0;
 37
 38@implementation CPTableColumn (NSCoding)
 39
 40- (id)NS_initWithCoder:(CPCoder)aCoder
 41{
 42    self = [self init];
 43
 44    if (self)
 45    {
 46        _identifier = [aCoder decodeObjectForKey:@"NSIdentifier"];
 47
 48        var dataViewCell = [aCoder decodeObjectForKey:@"NSDataCell"],
 49            viewClass = nil;
 50
 51        if ([dataViewCell isKindOfClass:[NSImageCell class]])
 52            viewClass = CPImageView;
 53        else if ([dataViewCell isKindOfClass:[NSTextFieldCell class]])
 54            viewClass = CPTextField;
 55        else if ([dataViewCell isKindOfClass:[NSButtonCell class]])
 56            viewClass = CPButton;
 57        else if ([dataViewCell isKindOfClass:[NSLevelIndicatorCell class]])
 58            viewClass = CPLevelIndicator;
 59
 60        if (viewClass)
 61            _dataView = [self makeDataViewOfClass:viewClass withCell:dataViewCell];
 62
 63        [_dataView setValue:[dataViewCell alignment] forThemeAttribute:@"alignment"];
 64
 65        var headerCell = [aCoder decodeObjectForKey:@"NSHeaderCell"],
 66            headerView = [[_CPTableColumnHeaderView alloc] initWithFrame:CGRectMakeZero()],
 67            theme = [Nib2Cib defaultTheme];
 68
 69        [headerView setStringValue:[headerCell objectValue]];
 70        [headerView setFont:[headerCell font]];
 71        [headerView setAlignment:[headerCell alignment]];
 72
 73        if ([[headerCell font] familyName] === IBDefaultFontFace && [[headerCell font] size] == IBDefaultFontSizeTableHeader)
 74        {
 75            [headerView setTextColor:[theme valueForAttributeWithName:@"text-color" forClass:_CPTableColumnHeaderView]];
 76            [headerView setFont:[theme valueForAttributeWithName:@"font" forClass:_CPTableColumnHeaderView]];
 77        }
 78
 79        [self setHeaderView:headerView];
 80
 81        _width = [aCoder decodeFloatForKey:@"NSWidth"];
 82        _minWidth = [aCoder decodeFloatForKey:@"NSMinWidth"];
 83        _maxWidth = [aCoder decodeFloatForKey:@"NSMaxWidth"];
 84
 85        _resizingMask = [aCoder decodeIntForKey:@"NSResizingMask"];
 86        _isHidden = [aCoder decodeBoolForKey:@"NSHidden"];
 87
 88        _isEditable = [aCoder decodeBoolForKey:@"NSIsEditable"];
 89
 90        _sortDescriptorPrototype = [aCoder decodeObjectForKey:@"NSSortDescriptorPrototype"];
 91    }
 92
 93    return self;
 94}
 95
 96- (id)makeDataViewOfClass:(Class)aClass withCell:(NSCell)aCell
 97{
 98    var dataView = [[aClass alloc] initWithFrame:CGRectMakeZero()];
 99
100    // Set the theme state to make sure the data view's theme attributes are correct
101    [dataView setThemeState:CPThemeStateTableDataView];
102    [dataView NS_initWithCell:aCell];
103
104    if (aClass === CPTextField)
105    {
106        // Text cells have to have their font replaced
107        [[Converter sharedConverter] replaceFontForObject:dataView];
108
109        // If a text cell has a custom color, we have to set the selected color,
110        // otherwise it defaults to the custom color.
111        var textColor = [aCell textColor],
112            defaultColor = [self valueForDataViewThemeAttribute:@"text-color" inState:CPThemeStateNormal];
113
114        if (![textColor isEqual:defaultColor])
115        {
116            var selectedColor = [self valueForDataViewThemeAttribute:@"text-color" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView)];
117
118            [dataView setValue:selectedColor forThemeAttribute:@"text-color" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView)];
119            [dataView setValue:textColor forThemeAttribute:@"text-color" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView, CPThemeStateEditing)];
120        }
121    }
122
123    return dataView;
124}
125
126- (id)valueForDataViewThemeAttribute:(CPString)attribute inState:(int)state
127{
128    var themes = [[Nib2Cib sharedNib2Cib] themes];
129
130    for (var i = 0; i < themes.length; ++i)
131    {
132        var value = [themes[i] valueForAttributeWithName:attribute inState:state forClass:CPTextField];
133
134        if (value)
135            return value;
136    }
137
138    return nil;
139}
140
141@end
142
143@implementation NSTableColumn : CPTableColumn
144{
145}
146
147- (id)initWithCoder:(CPCoder)aCoder
148{
149    return [self NS_initWithCoder:aCoder];
150}
151
152- (Class)classForKeyedArchiver
153{
154    return [CPTableColumn class];
155}
156
157@end
158
159
160@implementation NSTableHeaderCell : NSActionCell
161{
162}
163
164@end