API  0.9.6
 All Classes Files Functions Variables Macros Groups Pages
CPShadowView.j
Go to the documentation of this file.
1 /*
2  * CPShadowView.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 
24 
25 
28 
31 
32 var LIGHT_LEFT_INSET = 3.0,
36 
41 
45 @implementation CPShadowView : CPView
46 {
47  CPShadowWeight _weight;
48 }
49 
50 + (void)initialize
51 {
52  if (self !== [CPShadowView class])
53  return;
54 
55  var bundle = [CPBundle bundleForClass:[self class]];
56 
58  [@"CPShadowView/CPShadowViewLightTopLeft.png", 9.0, 9.0, bundle],
59  [@"CPShadowView/CPShadowViewLightTop.png", 1.0, 9.0, bundle],
60  [@"CPShadowView/CPShadowViewLightTopRight.png", 9.0, 9.0, bundle],
61 
62  [@"CPShadowView/CPShadowViewLightLeft.png", 9.0, 1.0, bundle],
63  nil,
64  [@"CPShadowView/CPShadowViewLightRight.png", 9.0, 1.0, bundle],
65 
66  [@"CPShadowView/CPShadowViewLightBottomLeft.png", 9.0, 9.0, bundle],
67  [@"CPShadowView/CPShadowViewLightBottom.png", 1.0, 9.0, bundle],
68  [@"CPShadowView/CPShadowViewLightBottomRight.png", 9.0, 9.0, bundle]
69  ]);
70 
72  [@"CPShadowView/CPShadowViewHeavyTopLeft.png", 17.0, 17.0, bundle],
73  [@"CPShadowView/CPShadowViewHeavyTop.png", 1.0, 17.0, bundle],
74  [@"CPShadowView/CPShadowViewHeavyTopRight.png", 17.0, 17.0, bundle],
75 
76  [@"CPShadowView/CPShadowViewHeavyLeft.png", 17.0, 1.0, bundle],
77  nil,
78  [@"CPShadowView/CPShadowViewHeavyRight.png", 17.0, 1.0, bundle],
79 
80  [@"CPShadowView/CPShadowViewHeavyBottomLeft.png", 17.0, 17.0, bundle],
81  [@"CPShadowView/CPShadowViewHeavyBottom.png", 1.0, 17.0, bundle],
82  [@"CPShadowView/CPShadowViewHeavyBottomRight.png", 17.0, 17.0, bundle]
83  ]);
84 }
85 
86 + (id)shadowViewEnclosingView:(CPView)aView
87 {
88  return [self shadowViewEnclosingView:aView withWeight:CPLightShadow];
89 }
90 
91 + (id)shadowViewEnclosingView:(CPView)aView withWeight:(CPShadowWeight)aWeight
92 {
93  var shadowView = [[self alloc] initWithFrame:[aView frame]];
94 
95  if (shadowView)
96  {
97  [shadowView setWeight:aWeight];
98 
99  var size = [shadowView frame].size,
100  width = size.width - [shadowView leftInset] - [shadowView rightInset],
101  height = size.height - [shadowView topInset] - [shadowView bottomInset],
102  enclosingView = [aView superview];
103 
104  [shadowView setHitTests:[aView hitTests]];
105  [shadowView setAutoresizingMask:[aView autoresizingMask]];
106  [aView removeFromSuperview];
107  [shadowView addSubview:aView];
108  [aView setFrame:CGRectMake([shadowView leftInset], [shadowView topInset], width, height)]
109  [enclosingView addSubview:shadowView];
110  }
111 
112  return shadowView;
113 }
114 
115 - (id)initWithFrame:(CGRect)aFrame
116 {
117  self = [super initWithFrame:aFrame];
118 
119  if (self)
120  {
121  _weight = CPLightShadow;
122 
123  [self setBackgroundColor:CPShadowViewLightBackgroundColor];
124 
125  [self setHitTests:NO];
126  }
127 
128  return self;
129 }
130 
131 - (void)setWeight:(CPShadowWeight)aWeight
132 {
133  if (_weight == aWeight)
134  return;
135 
136  _weight = aWeight;
137 
138  if (_weight == CPLightShadow)
139  [self setBackgroundColor:CPShadowViewLightBackgroundColor];
140 
141  else
142  [self setBackgroundColor:CPShadowViewHeavyBackgroundColor];
143 }
144 
145 - (float)leftInset
146 {
147  return _weight == CPLightShadow ? LIGHT_LEFT_INSET : HEAVY_LEFT_INSET;
148 }
149 
150 - (float)rightInset
151 {
152  return _weight == CPLightShadow ? LIGHT_RIGHT_INSET : HEAVY_RIGHT_INSET;
153 }
154 
155 - (float)topInset
156 {
157  return _weight == CPLightShadow ? LIGHT_TOP_INSET : HEAVY_TOP_INSET;
158 }
159 
160 - (float)bottomInset
161 {
163 }
164 
165 - (float)horizontalInset
166 {
167  if (_weight == CPLightShadow)
169 
171 }
172 
173 - (float)verticalInset
174 {
175  if (_weight == CPLightShadow)
177 
179 }
180 
181 + (CGRect)frameForContentFrame:(CGRect)aFrame withWeight:(CPShadowWeight)aWeight
182 {
183  if (aWeight == CPLightShadow)
184  return CGRectMake(_CGRectGetMinX(aFrame) - LIGHT_LEFT_INSET, _CGRectGetMinY(aFrame) - LIGHT_TOP_INSET, _CGRectGetWidth(aFrame) + LIGHT_LEFT_INSET + LIGHT_RIGHT_INSET, _CGRectGetHeight(aFrame) + LIGHT_TOP_INSET + LIGHT_BOTTOM_INSET);
185  else
186  return CGRectMake(_CGRectGetMinX(aFrame) - HEAVY_LEFT_INSET, _CGRectGetMinY(aFrame) - HEAVY_TOP_INSET, _CGRectGetWidth(aFrame) + HEAVY_LEFT_INSET + HEAVY_RIGHT_INSET, _CGRectGetHeight(aFrame) + HEAVY_TOP_INSET + HEAVY_BOTTOM_INSET);
187 }
188 
189 - (CGRect)frameForContentFrame:(CGRect)aFrame
190 {
191  return [[self class] frameForContentFrame:aFrame withWeight:_weight];
192 }
193 
194 - (void)setFrameForContentFrame:(CGRect)aFrame
195 {
196  [self setFrame:[self frameForContentFrame:aFrame]];
197 }
198 
199 @end