-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathOSAppPane.m
267 lines (161 loc) · 8.01 KB
/
OSAppPane.m
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#import "OSAppPane.h"
@implementation OSAppPane
@synthesize application = _application;
@synthesize appView = _appView;
@synthesize windowBar = _windowBar;
@synthesize windowBarOpen = _windowBarOpen;
@synthesize windowBarShadowView = _windowBarShadowView;
-(id)initWithDisplayIdentifier:(NSString*)displayIdentifier{
self.application = [[objc_getClass("SBApplicationController") sharedInstance] applicationWithDisplayIdentifier:displayIdentifier];
if(![super initWithName:self.application.displayName thumbnail:nil]){
return nil;
}
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.appView = [[self.application mainScreenContextHostManager] hostViewForRequester:@"WindowManager" enableAndOrderFront:true];
[self addSubview:self.appView];
self.windowBar = [[UIToolbar alloc] init];
self.windowBar.frame = CGRectMake(0, -44, self.frame.size.width, 44);
self.windowBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.windowBar.hidden = true;
self.windowBar.clipsToBounds = true;
NSMutableArray *items = [[NSMutableArray alloc] init];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(stopButtonPressed)];
UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithTitle:self.name style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *contractButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/OS Experience/168-1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(contractButtonPressed)];
[items addObject:closeButton];
[items addObject:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]];
[items addObject:title];
[items addObject:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]];
[items addObject:contractButton];
[self.windowBar setItems:items animated:false];
[items release];
[self addSubview:self.windowBar];
title.view.userInteractionEnabled = false;
[title release];
[closeButton release];
[contractButton release];
self.windowBarOpen = false;
self.windowBarShadowView = [[UIView alloc] initWithFrame:self.frame];
self.windowBarShadowView.backgroundColor = [UIColor blackColor];
self.windowBarShadowView.alpha = 0.0;
self.windowBarShadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[self.windowBarShadowView addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
[self addSubview:self.windowBarShadowView];
[self bringSubviewToFront:self.windowBar];
[self.windowBar release];
[self.windowBarShadowView release];
return self;
}
- (void)handleSingleTap:(UITapGestureRecognizer*)gesture{
[self setWindowBarHidden];
}
- (void)setWindowBarHidden{
CGRect frame = [[self windowBar] frame];
frame.origin.y = -frame.size.height;
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[[self windowBar] setFrame:frame];
self.windowBarShadowView.alpha = 0.0;
}completion:^(BOOL finished){
[[self windowBar] setHidden:true];
}];
[self setWindowBarOpen:false];
}
- (void)setWindowBarVisible{
[[self windowBar] setHidden:false];
CGRect frame = [[self windowBar] frame];
frame.origin.y = 0;
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[[self windowBar] setFrame:frame];
self.windowBarShadowView.alpha = 0.5;
}completion:^(BOOL finished){
}];
[self setWindowBarOpen:true];
}
- (void)dealloc{
self.application = nil;
self.appView = nil;
[self.windowBar release];
[self.windowBarShadowView release];
[super dealloc];
}
- (void)stopButtonPressed{
[self.application suspend];
}
- (void)contractButtonPressed{
CGAffineTransform appViewTransform = self.appView.transform;
OSAppWindow *window = [[OSAppWindow alloc] initWithApplication:self.application];
window.hidden = true;
[[[[OSPaneModel sharedInstance] firstDesktopPane] windows] addObject:window];
[[[OSPaneModel sharedInstance] firstDesktopPane] addSubview:window];
[window setDelegate:[[OSPaneModel sharedInstance] firstDesktopPane]];
[self addSubview:self.appView];
self.appView.transform = appViewTransform;
CGRect frame = self.appView.frame;
frame.origin = CGPointZero;
self.appView.frame = frame;
CGPoint animationViewOrigin = [self convertPoint:self.appView.frame.origin toView:[[OSViewController sharedInstance] view]];
[[[OSViewController sharedInstance] view] addSubview:self.appView];
self.windowBar.autoresizingMask = UIViewAutoresizingNone;
window.windowBar.autoresizingMask = UIViewAutoresizingNone;
window.windowBar.frame = self.windowBar.frame;
[window.windowBar layoutSubviews];
[[[OSViewController sharedInstance] view] addSubview:window.windowBar];
[[[OSViewController sharedInstance] view] addSubview:self.windowBar];
frame = self.appView.frame;
frame.origin = animationViewOrigin;
self.appView.frame = frame;
[UIView animateWithDuration:1.00 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
int appViewDegrees;
switch([self.application statusBarOrientation]){
case UIInterfaceOrientationPortrait:
appViewDegrees = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
appViewDegrees = 180;
break;
case UIInterfaceOrientationLandscapeLeft:
appViewDegrees = 90;
break;
case UIInterfaceOrientationLandscapeRight:
appViewDegrees = 270;
break;
}
self.appView.transform = CGAffineTransformMakeRotation(DegreesToRadians(appViewDegrees));
if UIDeviceOrientationIsLandscape([self.application statusBarOrientation]){
self.appView.transform = CGAffineTransformScale(self.appView.transform, (window.bounds.size.height - window.windowBar.bounds.size.height) / window.appView.bounds.size.width, window.bounds.size.width / window.appView.bounds.size.height);
}else{
self.appView.transform = CGAffineTransformScale(window.appView.transform, window.bounds.size.width / window.appView.bounds.size.width, (window.bounds.size.height - window.windowBar.bounds.size.height) / window.appView.bounds.size.height);
}
CGPoint origin = [self convertPoint:CGPointMake(window.frame.origin.x, window.frame.origin.y + window.windowBar.bounds.size.height) toView:[[OSViewController sharedInstance] view]];
CGRect appFrame = self.appView.frame;
appFrame.origin = origin;
self.appView.frame = appFrame;
window.windowBar.frame = CGRectMake(window.frame.origin.x, window.frame.origin.y, window.bounds.size.width, window.windowBar.bounds.size.height);
self.windowBar.frame = window.windowBar.frame;
self.windowBar.alpha = 0;
[self.windowBar layoutSubviews];
[window.windowBar layoutSubviews];
//Scroll OSSlider
CGRect bounds = [[OSSlider sharedInstance] bounds];
bounds.origin.x = [[OSPaneModel sharedInstance] indexOfPane:[[OSPaneModel sharedInstance] firstDesktopPane]] * [[OSSlider sharedInstance] bounds].size.width;
[[OSSlider sharedInstance] setBounds:bounds];
[[OSSlider sharedInstance] updateDockPosition];
[[OSThumbnailView sharedInstance] updateSelectedThumbnail];
}completion:^(BOOL finished){
CGRect appFrame = self.appView.frame;
appFrame.origin = CGPointMake(0, window.windowBar.bounds.size.height);
self.appView.frame = appFrame;
window.hidden = false;
[window addSubview:self.appView];
window.windowBar.frame = CGRectMake(0, 0, window.windowBar.bounds.size.width, window.windowBar.bounds.size.height);
[window addSubview:window.windowBar];
[self.windowBar removeFromSuperview];
window.windowBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[[[OSPaneModel sharedInstance] firstDesktopPane] setActiveWindow:window];
[[OSPaneModel sharedInstance] removePane:self];
[window release];
}];
}
@end