280north / cappuccino

Web Application Framework in JavaScript and Objective-J

This URL has Read+Write access

cappuccino / Tools / nib2cib / NSCell.j
100644 101 lines (84 sloc) 3.635 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* NSCell.j
* nib2cib
*
* Portions based on NSCell.m (09/09/2008) in Cocotron (http://www.cocotron.org/)
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
*
* Created by Francisco Tolmasky.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
 
@import <Foundation/CPObject.j>
 
@import "NSFont.j"
 
 
@implementation NSCell : CPObject
{
    int _state @accessors(readonly, getter=state);
    BOOL _isHighlighted @accessors(readonly, getter=isHighlighted);
    BOOL _isEnabled @accessors(readonly, getter=isEnabled);
    BOOL _isEditable @accessors(readonly, getter=isEditable);
    BOOL _isBordered @accessors(readonly, getter=isBordered);
    BOOL _isBezeled @accessors(readonly, getter=isBezeled);
    BOOL _isSelectable @accessors(readonly, getter=isSelectable);
    BOOL _isScrollable @accessors(readonly, getter=isScrollable);
    BOOL _isContinuous @accessors(readonly, getter=isContinuous);
    BOOL _wraps @accessors(readonly, getter=wraps);
    CPTextAlignment _alignment @accessors(readonly, getter=alignment);
    CPControlSize _controlSize @accessors(readonly, getter=controlSize);
    id _objectValue @accessors(readonly, getter=objectValue);
    CPFont _font @accessors(readonly, getter=font);
}
 
- (id)initWithCoder:(CPCoder)aCoder
{
    self = [super init];
    
    if (self)
    {
        var flags = [aCoder decodeIntForKey:@"NSCellFlags"],
            flags2 = [aCoder decodeIntForKey:@"NSCellFlags2"];
 
        _state = (flags & 0x80000000) ? CPOnState : CPOffState;
        _isHighlighted = (flags & 0x40000000) ? YES : NO;
        _isEnabled = (flags & 0x20000000) ? NO : YES;
        _isEditable = (flags & 0x10000000) ? YES : NO;
        _isBordered = (flags & 0x00800000) ? YES : NO;
        _isBezeled = (flags & 0x00400000) ? YES : NO;
        _isSelectable = (flags & 0x00200000) ? YES : NO;
        _isScrollable = (flags & 0x00100000) ? YES : NO;
        _isContinuous = (flags & 0x00080100) ? YES : NO;
        _wraps = (flags & 0x00100000) ? NO : YES;
        _alignment = (flags2 & 0x1c000000) >> 26;
        _controlSize = (flags2 & 0xE0000) >> 17;
 
        _objectValue = [aCoder decodeObjectForKey:@"NSContents"];
        _font = [aCoder decodeObjectForKey:@"NSSupport"];
    }
    
    return self;
}
 
- (id)replacementObjectForCoder:(CPCoder)aCoder
{
    return nil;
}
 
- (CPString)stringValue
{
    if ([_objectValue isKindOfClass:[CPString class]])
        return _objectValue;
        
    if ([_objectValue respondsToSelector:@selector(attributedStringValue)])
        return [_objectValue attributedStringValue];
        
    return "";
}
 
@end
 
 
@implementation NSActionCell : NSCell
{
}
 
@end