forked from nickjs/Cappuccino-Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPLightbox.j
130 lines (99 loc) · 3.31 KB
/
CPLightbox.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* CPLightbox.j
* CappuccinoExtensions
*
* Created by Nicholas Small.
* Copyright 2009-2010, 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 <Foundation/CPObject.j>
var SharedLightbox;
@implementation CPLightbox : CPObject
{
CPColor _backgroundColor;
CPWindow _backgroundWindow;
CPWindow _modalWindow;
CPWindow _sheetWindow;
}
+ (id)sharedLightbox
{
if (!SharedLightbox)
SharedLightbox = [[CPLightbox alloc] init];
return SharedLightbox;
}
- (id)init
{
self = [super init];
if (self)
_backgroundColor = [CPColor colorWithCalibratedRed:209.0/255.0 green:216.0/255.0 blue:227.0/255.0 alpha:0.7];
return self;
}
- (void)runModalForWindow:(CPWindow)aWindow
{
if (_modalWindow || _sheetWindow)
[self stopModal];
_modalWindow = aWindow;
[self _show];
[CPApp runModalForWindow:_modalWindow];
if (![_modalWindow autoresizingMask])
[_modalWindow setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
}
- (void)runSheetForWindow:(CPWindow)aWindow
{
if (_modalWindow || _sheetWindow)
[self stopModal];
_sheetWindow = aWindow;
[self _show];
[CPApp runModalForWindow:_sheetWindow];
var frame = [_sheetWindow frame];
[_sheetWindow setFrameOrigin:CGPointMake(CGRectGetMinX(frame), -CGRectGetHeight(frame))];
[_sheetWindow setFrame:CGRectMake(CGRectGetMinX(frame), -26.0, CGRectGetWidth(frame), CGRectGetHeight(frame)) display:YES animate:YES];
if (![_sheetWindow autoresizingMask])
[_sheetWindow setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin];
}
- (void)stopModal
{
[CPApp stopModal];
[(_modalWindow || _sheetWindow) orderOut:self];
[self _hide];
_modalWindow = nil;
_sheetWindow = nil;
}
- (CPColor)backgroundColor
{
return _backgroundColor;
}
- (void)setBackgroundColor:(CPColor)aColor
{
_backgroundColor = aColor;
[_backgroundWindow setBackgroundColor:_backgroundColor];
}
- (void)_show
{
if (!_backgroundWindow)
{
_backgroundWindow = [[CPWindow alloc] initWithContentRect:[[CPPlatformWindow primaryPlatformWindow] contentBounds] styleMask:CPBorderlessWindowMask];
[_backgroundWindow setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
var contentView = [_backgroundWindow contentView];
[contentView setBackgroundColor:_backgroundColor];
}
[_backgroundWindow orderFront:self];
}
- (void)_hide
{
[_backgroundWindow orderOut:self];
}
@end