Added themable support for shadow window

This commit is contained in:
Alexandre Wilhelm committed 2013-01-09 14:21:41 -08:00
1 parent 6ddb891c29
commit 2309e18eb7
3 files changed
+81 -49

No files matched your search

+12 -47
View File
@@ -192,13 +192,13 @@ CPWindowShadowStyleStandard = 0;
CPWindowShadowStyleMenu = 1;
CPWindowShadowStylePanel = 2;
var SHADOW_MARGIN_LEFT = 20.0,
SHADOW_MARGIN_RIGHT = 19.0,
SHADOW_MARGIN_TOP = 10.0,
SHADOW_MARGIN_BOTTOM = 10.0,
SHADOW_DISTANCE = 5.0,
_CPWindowShadowColor = nil;
// var SHADOW_MARGIN_LEFT = 20.0,
// SHADOW_MARGIN_RIGHT = 19.0,
// SHADOW_MARGIN_TOP = 10.0,
// SHADOW_MARGIN_BOTTOM = 10.0,
// SHADOW_DISTANCE = 5.0,
//
// _CPWindowShadowColor = nil;
var CPWindowSaveImage = nil,
CPWindowSavingImage = nil,
@@ -831,21 +831,7 @@ CPTexturedBackgroundWindowMask
[_windowView setFrameSize:size];
if (_hasShadow)
{
// if the shadow would be taller/wider than the window height,
// make it the same as the window height. this allows views to
// become 0, 0 with no shadow on them and makes the sheet
// animation look nicer
var shadowSize = _CGSizeMake(size.width, size.height);
if (size.width >= (SHADOW_MARGIN_LEFT + SHADOW_MARGIN_RIGHT))
shadowSize.width += SHADOW_MARGIN_LEFT + SHADOW_MARGIN_RIGHT;
if (size.height >= (SHADOW_MARGIN_BOTTOM + SHADOW_MARGIN_TOP + SHADOW_DISTANCE))
shadowSize.height += SHADOW_MARGIN_BOTTOM + SHADOW_MARGIN_TOP + SHADOW_DISTANCE;
[_shadowView setFrameSize:shadowSize];
}
[_shadowView setNeedsLayout];
if (!_isAnimating)
[[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidResizeNotification object:self];
@@ -1218,33 +1204,11 @@ CPTexturedBackgroundWindowMask
if (_hasShadow && !_shadowView)
{
var bounds = [_windowView bounds];
_shadowView = [[_CPShadowWindowView alloc] initWithFrame:CGRectMakeZero()];
_shadowView = [[CPView alloc] initWithFrame:CGRectMake(-SHADOW_MARGIN_LEFT, -SHADOW_MARGIN_TOP + SHADOW_DISTANCE,
SHADOW_MARGIN_LEFT + CGRectGetWidth(bounds) + SHADOW_MARGIN_RIGHT, SHADOW_MARGIN_TOP + CGRectGetHeight(bounds) + SHADOW_MARGIN_BOTTOM)];
if (!_CPWindowShadowColor)
{
var bundle = [CPBundle bundleForClass:[CPWindow class]];
_CPWindowShadowColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow0.png"] size:CGSizeMake(20.0, 19.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow1.png"] size:CGSizeMake(1.0, 19.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow2.png"] size:CGSizeMake(19.0, 19.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow3.png"] size:CGSizeMake(20.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow5.png"] size:CGSizeMake(19.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow6.png"] size:CGSizeMake(20.0, 18.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow7.png"] size:CGSizeMake(1.0, 18.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow8.png"] size:CGSizeMake(19.0, 18.0)]
]]];
}
[_shadowView setBackgroundColor:_CPWindowShadowColor];
[_shadowView setWindowView:_windowView];
[_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[_shadowView setNeedsLayout];
#if PLATFORM(DOM)
CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
@@ -3360,5 +3324,6 @@ CPCustomWindowShadowStyle = 3;
@import "_CPBorderlessBridgeWindowView.j"
@import "_CPAttachedWindowView.j"
@import "_CPModalWindowView.j"
@import "_CPShadowWindowView.j"
@import "CPDragServer.j"
@import "CPView.j"
+67
View File
@@ -0,0 +1,67 @@
/*
* _CPShadowWindowView.j
* AppKit
*
* Created by Alexandre Wilhelm.
* 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 "_CPWindowView.j"
@implementation _CPShadowWindowView : CPView
{
_CPWindowView _windowView @accessors(setter=setWindowView:);
}
- (id)init
{
if (self = [super init])
{
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
var shadowInset = [_windowView valueForThemeAttribute:@"shadow-inset"],
bounds = [_windowView bounds],
size = [_windowView frameSize];
var shadowSize = _CGSizeMake(size.width, size.height);
// if the shadow would be taller/wider than the window height,
// make it the same as the window height. this allows views to
// become 0, 0 with no shadow on them and makes the sheet
// animation look nicer
if (size.width >= (shadowInset.left + shadowInset.right))
shadowSize.width += shadowInset.left + shadowInset.right;
else
shadowSize.width = shadowInset.left + CGRectGetWidth(bounds) + shadowInset.right;
if (size.height >= (shadowInset.bottom + shadowInset.top + [_windowView valueForThemeAttribute:@"shadow-distance"]))
shadowSize.height += shadowInset.bottom + shadowInset.top + [_windowView valueForThemeAttribute:@"shadow-distance"];
else
shadowSize.height = shadowInset.top + CGRectGetHeight(bounds) + shadowInset.bottom;
[self setFrame:CGRectMake(-shadowInset.left, -shadowInset.top + [_windowView valueForThemeAttribute:@"shadow-distance"], shadowSize.width, shadowSize.height)];
[self setBackgroundColor:[_windowView valueForThemeAttribute:@"window-shadow-color"]];
}
@end
+2 -2
View File
@@ -60,8 +60,8 @@
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[CGSizeMakeZero(), [CPNull null], [CPColor blackColor], [CPNull null],[CPNull null], [CPNull null], [CPNull null], [CPNull null] , [CPColor blackColor], [CPFont systemFontOfSize:CPFontCurrentSystemSize], [CPNull null], _CGSizeMakeZero(), CPCenterTextAlignment, CPLineBreakByTruncatingTail, CPTopVerticalTextAlignment]
forKeys:[@"size-indicator", @"resize-indicator", @"attached-sheet-shadow-color", @"close-image-origin",@"close-image-size",@"close-image", @"close-active-image", @"bezel-color",@"title-text-color", @"title-font", @"title-text-shadow-color", @"title-text-shadow-offset", @"title-alignment", @"title-line-break-mode", @"title-vertical-alignment"]];
return [CPDictionary dictionaryWithObjects:[CGInsetMakeZero(), 5, [CPColor clearColor], CGSizeMakeZero(), [CPNull null], [CPColor blackColor], [CPNull null],[CPNull null], [CPNull null], [CPNull null], [CPNull null] , [CPColor blackColor], [CPFont systemFontOfSize:CPFontCurrentSystemSize], [CPNull null], _CGSizeMakeZero(), CPCenterTextAlignment, CPLineBreakByTruncatingTail, CPTopVerticalTextAlignment]
forKeys:[@"shadow-inset", @"shadow-distance", @"window-shadow-color",@"size-indicator", @"resize-indicator", @"attached-sheet-shadow-color", @"close-image-origin",@"close-image-size",@"close-image", @"close-active-image", @"bezel-color",@"title-text-color", @"title-font", @"title-text-shadow-color", @"title-text-shadow-offset", @"title-alignment", @"title-line-break-mode", @"title-vertical-alignment"]];
}
- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect