mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Previously, windows with no minimum size could be resized by the user such that the content view was completely hidden, and then resized such that the window was effectively turned inside out. This obviously needed to be fixed. Now, when the user resizes a window, each _CPWindowView subclass is asked for the minimum resize size, with the size being additively set by each subclass. This minimum size takes into account things like the title bar, divider line, and close button, and always leaves at least 2px height for the content view. The user-requested size is then pinned to the minimum resize size. In the process of fixing this bug, I discovered in the Cocoa docs that the CPWindow -setFrame: methods should ignore minSize and maxSize. Other changes: - Take the divider height into account in contentRectForFrameRect for titled windows. - Use _CG macros and fix formatting. Closes #1753
125 lines
3.7 KiB
Plaintext
125 lines
3.7 KiB
Plaintext
/*
|
|
* _CPTitleableWindowView.j
|
|
* AppKit
|
|
*
|
|
* Created by Alexander Ljungberg.
|
|
* Copyright 2012, SlevenBits Ltd.
|
|
*
|
|
* 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 "CPTextField.j"
|
|
@import "_CPWindowView.j"
|
|
|
|
|
|
@implementation _CPTitleableWindowView : _CPWindowView
|
|
{
|
|
CPTextField _titleField;
|
|
}
|
|
|
|
+ (int)titleBarHeight
|
|
{
|
|
return [[CPTheme defaultTheme] valueForAttributeWithName:@"title-bar-height" forClass:[self class]];
|
|
}
|
|
|
|
+ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
|
|
{
|
|
var contentRect = CGRectMakeCopy(aFrameRect),
|
|
titleBarHeight = [self titleBarHeight];
|
|
|
|
contentRect.origin.y += titleBarHeight;
|
|
contentRect.size.height -= titleBarHeight;
|
|
|
|
return contentRect;
|
|
}
|
|
|
|
+ (CGRect)frameRectForContentRect:(CGRect)aContentRect
|
|
{
|
|
var frameRect = CGRectMakeCopy(aContentRect),
|
|
titleBarHeight = [self titleBarHeight];
|
|
|
|
frameRect.origin.y -= titleBarHeight;
|
|
frameRect.size.height += titleBarHeight;
|
|
|
|
return frameRect;
|
|
}
|
|
|
|
- (id)initWithFrame:(CGRect)aFrame styleMask:(unsigned)aStyleMask
|
|
{
|
|
self = [super initWithFrame:aFrame styleMask:aStyleMask];
|
|
|
|
if (self)
|
|
{
|
|
_titleField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
|
|
|
|
[_titleField setHitTests:NO];
|
|
[_titleField setStringValue:@"Untitled"];
|
|
[_titleField sizeToFit];
|
|
[_titleField setAutoresizingMask:CPViewWidthSizable];
|
|
[_titleField setStringValue:@""];
|
|
|
|
[_titleField setFrame:CGRectMake(20.0, 3.0, CGRectGetWidth([self bounds]) - 40.0, CGRectGetHeight([_titleField frame]))];
|
|
|
|
[self addSubview:_titleField];
|
|
|
|
[self setNeedsLayout];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)setTitle:(CPString)aTitle
|
|
{
|
|
[_titleField setStringValue:aTitle];
|
|
}
|
|
|
|
- (void)tile
|
|
{
|
|
[super tile];
|
|
|
|
var theWindow = [self window],
|
|
bounds = [self bounds],
|
|
width = CGRectGetWidth(bounds);
|
|
|
|
// The vertical alignment of the title is set by the theme, so just give it all available space. By default
|
|
// the title will vertically centre within.
|
|
[_titleField setFrame:_CGRectMake(20.0, 0, width - 40.0, [[self class] titleBarHeight])];
|
|
}
|
|
|
|
- (void)layoutSubviews
|
|
{
|
|
[super layoutSubviews];
|
|
|
|
[self setBackgroundColor:[self valueForThemeAttribute:@"bezel-color"]];
|
|
|
|
[_titleField setTextColor:[self currentValueForThemeAttribute:@"title-text-color"]];
|
|
[_titleField setFont:[self currentValueForThemeAttribute:@"title-font"]];
|
|
[_titleField setAlignment:[self currentValueForThemeAttribute:@"title-alignment"]];
|
|
[_titleField setVerticalAlignment:[self currentValueForThemeAttribute:@"title-vertical-alignment"]];
|
|
[_titleField setLineBreakMode:[self currentValueForThemeAttribute:@"title-line-break-mode"]];
|
|
[_titleField setTextShadowColor:[self currentValueForThemeAttribute:@"title-text-shadow-color"]];
|
|
[_titleField setTextShadowOffset:[self currentValueForThemeAttribute:@"title-text-shadow-offset"]];
|
|
}
|
|
|
|
- (CGSize)_minimumResizeSize
|
|
{
|
|
var size = [super _minimumResizeSize];
|
|
|
|
size.height += [[self class] titleBarHeight];
|
|
return size;
|
|
}
|
|
|
|
@end
|