PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Tools/nib2cib/NSBox.j

http://github.com/cacaodev/cappuccino
Unknown | 98 lines | 78 code | 20 blank | 0 comment | 0 complexity | ed92d1b7905d672be5a0e4bdc7ca9252 MD5 | raw file
 1/*
 2 * NSBox.j
 3 * nib2cib
 4 *
 5 * Created by Aparajita Fishman.
 6 *
 7 * This library is free software; you can redistribute it and/or
 8 * modify it under the terms of the GNU Lesser General Public
 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22@import <AppKit/CPBox.j>
23
24
25@implementation CPBox (NSCoding)
26
27- (id)NS_initWithCoder:(CPCoder)aCoder
28{
29    self = [super NS_initWithCoder:aCoder];
30
31    if (self)
32    {
33        _boxType       = [aCoder decodeIntForKey:@"NSBoxType"];
34        _borderType    = [aCoder decodeIntForKey:@"NSBorderType"];
35
36        var borderColor = [aCoder decodeObjectForKey:@"NSBorderColor2"],
37            fillColor = [aCoder decodeObjectForKey:@"NSFillColor2"],
38            cornerRadius = [aCoder decodeFloatForKey:@"NSCornerRadius2"],
39            borderWidth = [aCoder decodeFloatForKey:@"NSBorderWidth2"],
40            contentMargin = [aCoder decodeSizeForKey:@"NSOffsets"];
41
42        // small hack to position the box pixel perfect
43        var frame = [self frame];
44
45        // The primary and secondary boxes have a well-like look both in Cocoa and Cappuccino, but there
46        // are some sizing differences. Regular custom boxes have no size differences.
47        if (_boxType !== CPBoxSeparator && (_boxType === CPBoxPrimary || _boxType === CPBoxSecondary))
48        {
49            frame.origin.y += 4;
50            frame.origin.x += 4;
51            frame.size.width -= 8;
52            frame.size.height -= 6;
53        }
54
55        [self setFrame:frame];
56
57        if (_boxType !== CPBoxPrimary && _boxType !== CPBoxSecondary)
58        {
59            // Primary and secondary boxes have a fixed look that can't be customised, but for a CPBoxCustom
60            // all of these parameters can be changed.
61            if (borderColor)
62                [self setBorderColor:borderColor];
63
64            if (fillColor)
65                [self setFillColor:fillColor];
66
67            [self setCornerRadius:cornerRadius];
68            [self setBorderWidth:borderWidth];
69            [self setContentViewMargins:contentMargin];
70        }
71
72        _title         = [[aCoder decodeObjectForKey:@"NSTitleCell"] objectValue] || @"";
73        _titlePosition = [aCoder decodeObjectForKey:@"NSTitlePosition"];
74
75        if (_titlePosition === undefined)
76            _titlePosition = CPAtTop;
77    }
78
79    return self;
80}
81
82@end
83
84@implementation NSBox : CPBox
85{
86}
87
88- (id)initWithCoder:(CPCoder)aCoder
89{
90    return [self NS_initWithCoder:aCoder];
91}
92
93- (Class)classForKeyedArchiver
94{
95    return [CPBox class];
96}
97
98@end