PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/AppKit/CPWindow/_CPHUDWindowView.j

http://github.com/cacaodev/cappuccino
Unknown | 193 lines | 151 code | 42 blank | 0 comment | 0 complexity | 06687f364b2e422c35101f052985ae88 MD5 | raw file
  1/*
  2 * _CPHUDWindowView.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@import "CPButton.j"
 24@import "CPTextField.j"
 25@import "_CPTitleableWindowView.j"
 26
 27
 28@implementation _CPHUDWindowView : _CPTitleableWindowView
 29{
 30    CPView              _toolbarView;
 31    CPButton            _closeButton;
 32}
 33
 34+ (CPString)defaultThemeClass
 35{
 36    return @"hud-window-view";
 37}
 38
 39+ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
 40{
 41    /*
 42        This window view class draws a frame.
 43        So we have to inset the content rect to be inside the frame.
 44        The top coordinate has already been adjusted by _CPTitleableWindowView.
 45    */
 46    var contentRect = [super contentRectForFrameRect:aFrameRect];
 47
 48    contentRect.origin.x += 1;
 49    contentRect.size.width -= 2;
 50    contentRect.size.height -= 1;
 51
 52    return contentRect;
 53}
 54
 55- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
 56{
 57    var contentRect = [[self class] contentRectForFrameRect:aFrameRect];
 58
 59    if ([[[self window] toolbar] isVisible])
 60    {
 61        var toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
 62
 63        contentRect.origin.y += toolbarHeight;
 64        contentRect.size.height -= toolbarHeight;
 65    }
 66
 67    return contentRect;
 68}
 69
 70- (CGRect)frameRectForContentRect:(CGRect)aContentRect
 71{
 72    var frameRect = [[self class] frameRectForContentRect:aContentRect];
 73
 74    if ([[[self window] toolbar] isVisible])
 75    {
 76        var toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
 77
 78        frameRect.origin.y -= toolbarHeight;
 79        frameRect.size.height += toolbarHeight;
 80    }
 81
 82    return frameRect;
 83}
 84
 85- (id)initWithFrame:(CGRect)aFrame styleMask:(unsigned)aStyleMask
 86{
 87    self = [super initWithFrame:aFrame styleMask:aStyleMask];
 88
 89    if (self)
 90    {
 91        if (_styleMask & CPClosableWindowMask)
 92        {
 93            _closeButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
 94            [_closeButton setBordered:NO];
 95            [_closeButton setButtonType:CPMomentaryChangeButton];
 96            [self addSubview:_closeButton];
 97        }
 98
 99        [self setResizeIndicatorOffset:CGSizeMake(5.0, 5.0)];
100
101        [self tile];
102    }
103
104    return self;
105}
106
107- (void)viewDidMoveToWindow
108{
109    [_closeButton setTarget:[self window]];
110    [_closeButton setAction:@selector(performClose:)];
111}
112
113- (_CPToolbarView)toolbarView
114{
115    return _toolbarView;
116}
117
118- (CPColor)toolbarLabelColor
119{
120    return [CPColor whiteColor];
121}
122
123- (CPColor)toolbarLabelShadowColor
124{
125    return [CPColor blackColor];
126}
127
128- (CGSize)toolbarOffset
129{
130    return CGSizeMake(0.0, [[self class] titleBarHeight]);
131}
132
133- (void)tile
134{
135    [super tile];
136
137    var theWindow = [self window],
138        bounds = [self bounds],
139        width = CGRectGetWidth(bounds);
140
141    [_titleField setFrame:CGRectMake(20.0, 0, width - 40.0, [self toolbarOffset].height)];
142
143    var maxY = [self toolbarMaxY];
144    if ([_titleField isHidden])
145        maxY -= ([self toolbarOffset]).height;
146
147    var contentRect = CGRectMake(0.0, maxY, width, CGRectGetHeight(bounds) - maxY);
148
149    [[theWindow contentView] setFrame:contentRect];
150}
151
152- (void)_enableSheet:(BOOL)enable inWindow:(CPWindow)parentWindow
153{
154    // No need to call super, it just deals with the shadow view, which we don't want
155
156    [_closeButton setHidden:enable];
157    [_titleField setHidden:enable];
158
159    // resize the window
160    var theWindow = [self window],
161        frame = [theWindow frame],
162        dy = ([self toolbarOffset]).height;
163
164    if (enable)
165        dy = -dy;
166
167    var newHeight = CGRectGetMaxY(frame) + dy,
168        newWidth = CGRectGetMaxX(frame);
169
170    frame.size.height += dy;
171
172    [self setFrameSize:CGSizeMake(newWidth, newHeight)];
173    [self tile];
174    [theWindow setFrame:frame display:NO animate:NO];
175    [theWindow setMovableByWindowBackground:!enable];
176
177    [self setNeedsLayout];
178}
179
180- (void)layoutSubviews
181{
182    [super layoutSubviews];
183
184    if (_styleMask & CPClosableWindowMask)
185    {
186        [_closeButton setFrameOrigin:[self valueForThemeAttribute:@"close-image-origin"]];
187        [_closeButton setFrameSize:[self valueForThemeAttribute:@"close-image-size"]]
188        [_closeButton setImage:[self valueForThemeAttribute:@"close-image"]];
189        [_closeButton setAlternateImage:[self valueForThemeAttribute:@"close-active-image"]];
190    }
191}
192
193@end