Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTMovieWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 371 - (hide annotations) (download)
Sun Mar 4 01:23:08 2012 UTC (12 years, 1 month ago) by masakih
File size: 24484 byte(s)
[Mod] XspfQTMovieWindowControllerにプロパティ

1 masaki 2 //
2 masaki 72 // XspfQTMovieWindowController.m
3 masaki 2 // XspfQT
4     //
5     // Created by Hori,Masaki on 08/08/31.
6     //
7    
8 masakih 312 /*
9 masakih 316 This source code is release under the New BSD License.
10 masakih 371 Copyright (c) 2008-2010,2012, masakih
11 masakih 312 All rights reserved.
12    
13 masakih 316 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14     限り、再頒布および使用が許可されます。
15    
16     1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17     めること。
18     2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19     示、本条件一覧、および下記免責条項を含めること。
20     3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21     コントリビューターの名前を使用してはならない。
22     本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23     明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24     も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25     も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26     厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27     可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28     サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29     されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30     て、一切責任を負わないものとします。
31 masakih 312 -------------------------------------------------------------------
32 masakih 371 Copyright (c) 2008-2010,2012, masakih
33 masakih 312 All rights reserved.
34    
35 masakih 316 Redistribution and use in source and binary forms, with or without
36     modification, are permitted provided that the following conditions
37     are met:
38 masakih 312
39 masakih 316 1, Redistributions of source code must retain the above copyright
40     notice, this list of conditions and the following disclaimer.
41     2, Redistributions in binary form must reproduce the above copyright
42     notice, this list of conditions and the following disclaimer in
43     the documentation and/or other materials provided with the
44     distribution.
45     3, The names of its contributors may be used to endorse or promote
46     products derived from this software without specific prior
47     written permission.
48     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
52     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53     INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59     POSSIBILITY OF SUCH DAMAGE.
60 masakih 312 */
61    
62 masaki 224 #import <Carbon/Carbon.h>
63    
64 masaki 72 #import "XspfQTMovieWindowController.h"
65     #import "XspfQTDocument.h"
66 masaki 306 #import "HMXSPFComponent.h"
67 masaki 72 #import "XspfQTFullScreenWindow.h"
68 masaki 144 #import "XspfQTMovieWindow.h"
69 masaki 2
70 masaki 299
71     #pragma mark #### Global Variables ####
72     /********* Global variables *******/
73     NSString *XspfQTMovieDidStartNotification = @"XspfQTMovieDidStartNotification";
74     NSString *XspfQTMovieDidPauseNotification = @"XspfQTMovieDidPauseNotification";
75    
76 masakih 371 @interface XspfQTMovieWindowController()
77     @property BOOL fullScreenMode;
78 masaki 299
79 masakih 371 @property (readonly) XspfQTDocument *qtDocument;
80     @property (readonly) XspfQTMovieWindow *qtWindow;
81     @end
82    
83 masaki 72 @interface XspfQTMovieWindowController (Private)
84 masaki 45 - (NSSize)windowSizeWithoutQTView;
85 masaki 17 - (void)sizeTofitWidnow;
86 masaki 2 - (NSSize)fitSizeToSize:(NSSize)toSize;
87     - (NSWindow *)fullscreenWindow;
88 masaki 151 - (void)movieDidStart;
89     - (void)movieDidPause;
90 masakih 338
91     - (void)hideMenuBar;
92     - (void)showMenuBar;
93 masaki 2 @end
94 masakih 340 #ifndef MAC_OS_X_VERSION_10_6
95 masakih 338 @interface NSApplication (XspfQT)
96     typedef NSUInteger NSApplicationPresentationOptions;
97     - (NSApplicationPresentationOptions)presentationOptions;
98     - (void)setPresentationOptions:(NSApplicationPresentationOptions)newOptions;
99     enum {
100     NSApplicationPresentationDefault = 0,
101     NSApplicationPresentationAutoHideDock = (1 << 0), // Dock appears when moused to
102     NSApplicationPresentationHideDock = (1 << 1), // Dock is entirely unavailable
103    
104     NSApplicationPresentationAutoHideMenuBar = (1 << 2), // Menu Bar appears when moused to
105     NSApplicationPresentationHideMenuBar = (1 << 3), // Menu Bar is entirely unavailable
106    
107     NSApplicationPresentationDisableAppleMenu = (1 << 4), // all Apple menu items are disabled
108     NSApplicationPresentationDisableProcessSwitching = (1 << 5), // Cmd+Tab UI is disabled
109     NSApplicationPresentationDisableForceQuit = (1 << 6), // Cmd+Opt+Esc panel is disabled
110     NSApplicationPresentationDisableSessionTermination = (1 << 7), // PowerKey panel and Restart/Shut Down/Log Out disabled
111     NSApplicationPresentationDisableHideApplication = (1 << 8), // Application "Hide" menu item is disabled
112     NSApplicationPresentationDisableMenuBarTransparency = (1 << 9) // Menu Bar's transparent appearance is disabled
113     };
114     @end
115     #endif
116 masaki 2
117 masaki 72 @implementation XspfQTMovieWindowController
118 masakih 371 @synthesize qtMovie = _qtMovie;
119     @synthesize fullScreenMode = _fullScreenMode;
120 masaki 2
121 masaki 10 #pragma mark ### Static variables ###
122 masaki 132 static const float sVolumeDelta = 0.1;
123 masaki 200 static const NSTimeInterval sUpdateTimeInterval = 0.5;
124 masaki 171 static NSString *const kQTMovieKeyPath = @"playingMovie";
125 masaki 40 static NSString *const kIsPlayedKeyPath = @"trackList.isPlayed";
126 masaki 135 static NSString *const kVolumeKeyPath = @"qtMovie.volume";
127 masaki 2
128 masaki 10 - (id)init
129 masaki 2 {
130 masaki 151 self = [super initWithWindowNibName:@"XspfQTDocument"];
131 masaki 2
132     return self;
133     }
134    
135     - (void)dealloc
136     {
137     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
138     [nc removeObserver:self];
139 masaki 49
140 masakih 371 self.qtMovie = nil;
141 masaki 2
142     [fullscreenWindow release];
143 masaki 151 [self movieDidPause];
144 masaki 10 [prevMouseMovedDate release];
145 masaki 76
146 masaki 2 [super dealloc];
147     }
148     - (void)awakeFromNib
149     {
150 masaki 3 prevMouseMovedDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain];
151 masakih 354 [[self window] setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
152 masaki 3
153 masakih 371 XspfQTDocument *doc = self.qtDocument;
154 masaki 151
155 masaki 100 [doc addObserver:self
156     forKeyPath:kQTMovieKeyPath
157     options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
158     context:NULL];
159     [doc addObserver:self
160     forKeyPath:kIsPlayedKeyPath
161     options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
162     context:NULL];
163 masaki 2
164 masaki 100 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
165     [nc addObserver:self
166     selector:@selector(documentWillClose:)
167     name:XspfQTDocumentWillCloseNotification
168     object:doc];
169    
170 masakih 371 doc.trackList.selectionIndex = 0;
171 masaki 17 [self sizeTofitWidnow];
172 masaki 2 [self play];
173     }
174 masaki 10
175 masaki 62 - (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
176     {
177 masaki 70 id title1 = [self valueForKeyPath:@"document.trackList.title"];
178     id title2 = [self valueForKeyPath:@"document.trackList.currentTrack.title"];
179     if(title1 && title2) {
180 masaki 62 return [NSString stringWithFormat:@"%@ - %@",
181 masaki 70 title1, title2];
182 masaki 62 }
183 masaki 116 if(title2) {
184     return [NSString stringWithFormat:@"%@ - %@",
185     displayName, title2];
186     }
187 masaki 62 return displayName;
188     }
189 masakih 344 - (IBAction)showWindow:(id)sender
190     {
191 masakih 371 if(!self.fullScreenMode) {
192 masakih 344 [super showWindow:sender];
193     return;
194     }
195     }
196 masaki 62
197 masaki 10 #pragma mark ### KVO & KVC ###
198 masaki 2 - (void)observeValueForKeyPath:(NSString *)keyPath
199     ofObject:(id)object
200     change:(NSDictionary *)change
201     context:(void *)context
202     {
203 masaki 49 if([keyPath isEqualToString:kQTMovieKeyPath]) {
204 masaki 2 id new = [change objectForKey:NSKeyValueChangeNewKey];
205 masakih 371 self.qtMovie = new;
206 masaki 2 return;
207     }
208 masaki 49 if([keyPath isEqualToString:kIsPlayedKeyPath]) {
209 masaki 14 id new = [change objectForKey:NSKeyValueChangeNewKey];
210     if([new boolValue]) {
211 masaki 151 [self movieDidStart];
212 masaki 14 } else {
213 masaki 151 [self movieDidPause];
214 masaki 14 }
215     return;
216     }
217 masaki 2 }
218    
219     - (void)setQtMovie:(QTMovie *)qt
220     {
221 masakih 371 if(_qtMovie == qt) return;
222     if([_qtMovie isEqual:qt]) return;
223 masaki 62 if(qt == (id)[NSNull null]) qt = nil;
224 masaki 2
225     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
226    
227 masakih 371 if(_qtMovie) {
228     [nc removeObserver:self name:nil object:_qtMovie];
229 masaki 2 }
230     if(qt) {
231 masaki 151 [nc addObserver:self selector:@selector(movieDidEndNotification:) name:QTMovieDidEndNotification object:qt];
232 masaki 2 }
233 masaki 3
234 masakih 371 if(_qtMovie) {
235     [qt setVolume:[_qtMovie volume]];
236     [qt setMuted:[_qtMovie muted]];
237 masaki 3 }
238 masakih 371 [_qtMovie autorelease];
239     _qtMovie = [qt retain];
240 masaki 49
241 masakih 371 if(!_qtMovie) return;
242 masaki 49
243 masaki 2 [self synchronizeWindowTitleWithDocumentName];
244 masaki 17 [self sizeTofitWidnow];
245 masaki 2 [self play];
246     }
247     - (QTMovie *)qtMovie
248     {
249 masakih 371 return _qtMovie;
250 masaki 2 }
251 masakih 371 - (XspfQTDocument *)qtDocument
252     {
253     return (XspfQTDocument *)self.document;
254     }
255     - (XspfQTMovieWindow *)qtWindow
256     {
257     return (XspfQTMovieWindow *)self.window;
258     }
259 masaki 2
260 masaki 10 #pragma mark ### Other functions ###
261 masaki 151 // Area size without QTMovieView.
262 masaki 45 - (NSSize)windowSizeWithoutQTView
263     {
264     if(windowSizeWithoutQTView.width == 0
265     && windowSizeWithoutQTView.height == 0) {
266 masakih 371 QTMovie *curMovie = self.qtMovie;
267 masaki 45 if(!curMovie) return windowSizeWithoutQTView;
268    
269     NSSize qtViewSize = [qtView frame].size;
270 masakih 371 NSSize currentWindowSize = [self.window frame].size;
271 masaki 45
272     windowSizeWithoutQTView = NSMakeSize(currentWindowSize.width - qtViewSize.width,
273     currentWindowSize.height - qtViewSize.height);
274     }
275    
276     return windowSizeWithoutQTView;
277     }
278 masaki 17 - (void)sizeTofitWidnow
279     {
280 masakih 371 if(self.fullScreenMode) return;
281 masakih 361
282 masakih 371 id window = self.window;
283 masaki 17 NSRect frame = [window frame];
284     NSSize newSize = [self fitSizeToSize:frame.size];
285 masaki 19 frame.origin.y += frame.size.height - newSize.height;
286 masaki 17 frame.size = newSize;
287    
288 masaki 19 [window setFrame:frame display:YES animate:YES];
289 masaki 17 }
290 masaki 2 - (NSSize)fitSizeToSize:(NSSize)toSize
291     {
292 masakih 371 QTMovie *curMovie = self.qtMovie;
293 masaki 2 if(!curMovie) return toSize;
294    
295 masaki 45 NSSize delta = [self windowSizeWithoutQTView];
296 masaki 2
297     NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
298 masaki 107 if(movieSize.width == 0) return toSize;
299 masaki 2
300     float targetViewWidth = toSize.width - delta.width;
301     float targetViewHeight = targetViewWidth * (movieSize.height / movieSize.width);
302    
303     targetViewWidth += delta.width;
304     targetViewHeight += delta.height;
305    
306 masaki 107 return NSMakeSize(targetViewWidth, targetViewHeight);
307 masaki 2 }
308    
309 masaki 134 - (NSSize)windowSizeFromMovieSize:(NSSize)movieSize
310     {
311    
312     //
313 masaki 135
314     return NSZeroSize;
315 masaki 134 }
316    
317     - (void)setMovieSize:(NSSize)movieSize
318     {
319 masakih 371 NSRect newFrame = [self.window frame];
320 masaki 139 NSSize newSize;
321    
322     newSize = [self windowSizeWithoutQTView];
323     newSize.width += movieSize.width;
324     newSize.height += movieSize.height;
325    
326     newFrame.origin.y -= newSize.height - newFrame.size.height;
327     newFrame.size = newSize;
328    
329 masakih 371 [self.window setFrame:newFrame display:YES animate:YES];
330 masaki 134 }
331 masaki 151 - (void)movieDidStart
332 masaki 135 {
333     [playButton setTitle:@"||"];
334 masaki 299
335     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
336     [nc postNotificationName:XspfQTMovieDidStartNotification object:self];
337 masaki 135 }
338    
339 masaki 151 - (void)movieDidPause
340 masaki 135 {
341     [playButton setTitle:@">"];
342 masaki 299
343     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
344     [nc postNotificationName:XspfQTMovieDidPauseNotification object:self];
345 masaki 135 }
346 masaki 2 - (void)play
347     {
348     [qtView performSelectorOnMainThread:@selector(play:) withObject:self waitUntilDone:NO];
349     }
350 masaki 14 - (void)pause
351     {
352     [qtView performSelectorOnMainThread:@selector(pause:) withObject:self waitUntilDone:NO];
353     }
354 masaki 56 - (void)stop
355     {
356     [qtView performSelectorOnMainThread:@selector(pause:) withObject:self waitUntilDone:YES];
357     }
358 masaki 3 - (void)enterFullScreen
359 masaki 2 {
360 masakih 337 NSWindow *fullscreen = [self fullscreenWindow];
361 masaki 3
362 masaki 156 normalModeSavedFrame = [qtView frame];
363 masaki 17
364 masakih 371 XspfQTMovieWindow *player = self.qtWindow;
365 masaki 17
366 masakih 338 [self hideMenuBar];
367 masaki 17
368 masakih 361 NSRect newFrame = [qtView frame];
369     newFrame.origin = [player convertBaseToScreen:newFrame.origin];
370     newFrame.origin = [fullscreen convertScreenToBase:newFrame.origin];
371     [qtView setFrame:newFrame];
372 masaki 143
373 masakih 361 [[fullscreen contentView] addSubview:qtView];
374 masakih 337 [fullscreen makeKeyAndOrderFront:self];
375     [fullscreen makeFirstResponder:qtView];
376 masaki 143
377 masakih 361 [[qtView animator] setFrame:[[NSScreen mainScreen] frame]];
378    
379     [self performSelector:@selector(resizeToFull:) withObject:nil afterDelay:0.1];
380     }
381     - (void)resizeToFull:(id)obj
382     {
383    
384 masakih 371 [self.window orderOut:self];
385 masakih 337
386 masakih 361 [fullscreenWindow makeKeyAndOrderFront:self];
387 masaki 2 }
388 masaki 3 - (void)exitFullScreen
389 masaki 2 {
390 masakih 371 XspfQTMovieWindow *player = self.qtWindow;
391 masaki 144 NSRect originalWFrame = [player frame];
392    
393     // calculate new Window frame.
394     NSRect windowRect = originalWFrame;
395 masakih 371 NSSize movieSize = [[self.qtMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
396 masaki 144 if(movieSize.width != 0) {
397 masaki 156 CGFloat newViewHeight = normalModeSavedFrame.size.width * (movieSize.height / movieSize.width);
398 masaki 144
399     windowRect.size.height = newViewHeight + windowSizeWithoutQTView.height;
400 masakih 361 windowRect.origin.y -= windowRect.size.height - originalWFrame.size.height;
401 masaki 144 }
402 masakih 361
403     [player setFrame:windowRect display:NO];
404     [player orderWindow:NSWindowBelow relativeTo:[fullscreenWindow windowNumber]];
405 masaki 144
406 masaki 151 // move QTView.
407 masaki 17 [qtView retain];
408     {
409 masakih 361 NSRect movieViewFrame = [[player contentView] frame];
410     movieViewFrame.size.height -= [controllerView frame].size.height;
411     movieViewFrame.origin.y = [controllerView frame].size.height;
412     movieViewFrame.origin = [player convertBaseToScreen:movieViewFrame.origin];
413     movieViewFrame.origin = [fullscreenWindow convertScreenToBase:movieViewFrame.origin];
414     [[qtView animator] setFrame:movieViewFrame];
415 masaki 17 }
416     [qtView release];
417 masakih 361
418     NSTimeInterval delay = [[NSAnimationContext currentContext] duration] + 0.07;
419     [self performSelector:@selector(resizeFullscreenWindow:) withObject:nil afterDelay:delay];
420     }
421     - (void)resizeFullscreenWindow:(id)obj
422     {
423 masakih 371 XspfQTMovieWindow *player = self.qtWindow;
424 masaki 17
425 masakih 361 NSRect r = [qtView frame];
426     r.origin.x = 0;
427     r.origin.y = [controllerView frame].size.height;
428     [qtView setFrame:r];
429     [[player contentView] addSubview:qtView];
430 masaki 154 [fullscreenWindow orderOut:self];
431 masaki 107
432 masakih 361 [self showMenuBar];
433 masaki 144
434 masakih 361 [player makeKeyAndOrderFront:self];
435     [player makeFirstResponder:qtView];
436 masaki 3 }
437 masaki 10
438     - (NSWindow *)fullscreenWindow
439     {
440     if(fullscreenWindow) return fullscreenWindow;
441    
442     NSRect mainScreenRect = [[NSScreen mainScreen] frame];
443 masaki 72 fullscreenWindow = [[XspfQTFullScreenWindow alloc] initWithContentRect:mainScreenRect
444 masaki 132 styleMask:NSBorderlessWindowMask
445     backing:NSBackingStoreBuffered
446     defer:YES];
447 masaki 10 [fullscreenWindow setReleasedWhenClosed:NO];
448 masakih 361 [fullscreenWindow setBackgroundColor:[[NSColor blackColor] colorWithAlphaComponent:0.5]];
449 masaki 10 [fullscreenWindow setDelegate:self];
450 masaki 49 [fullscreenWindow setWindowController:self];
451 masakih 361 [fullscreenWindow setOpaque:NO];
452 masaki 10
453 masakih 361 if([fullscreenWindow respondsToSelector:@selector(setAnimationBehavior:)]) {
454     [fullscreenWindow setAnimationBehavior:NSWindowAnimationBehaviorNone];
455     }
456    
457 masaki 10 return fullscreenWindow;
458     }
459 masakih 338 - (void)hideMenuBar
460     {
461     if(![NSApp respondsToSelector:@selector(setPresentationOptions:)]) {
462     SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
463     return;
464     }
465    
466     NSApplicationPresentationOptions currentPresentation = [NSApp presentationOptions];
467     [NSApp setPresentationOptions:
468     currentPresentation | (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
469     }
470     - (void)showMenuBar
471     {
472     if(![NSApp respondsToSelector:@selector(setPresentationOptions:)]) {
473     [NSMenu setMenuBarVisible:YES];
474     return;
475     }
476    
477     NSApplicationPresentationOptions currentPresentation = [NSApp presentationOptions];
478     [NSApp setPresentationOptions:
479 masakih 339 currentPresentation & ~(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
480 masakih 338 }
481 masaki 10 #pragma mark ### Actions ###
482 masaki 14 - (IBAction)togglePlayAndPause:(id)sender
483     {
484     if([[self valueForKeyPath:@"document.trackList.isPlayed"] boolValue]) {
485     [self pause];
486     } else {
487     [self play];
488     }
489     }
490 masakih 355 - (IBAction)gotoBeginning:(id)sender
491     {
492     [qtView gotoBeginning:sender];
493     }
494 masaki 14
495 masaki 3 - (IBAction)turnUpVolume:(id)sender
496     {
497 masaki 135 NSNumber *cv = [self valueForKeyPath:kVolumeKeyPath];
498 masaki 3 cv = [NSNumber numberWithFloat:[cv floatValue] + sVolumeDelta];
499 masaki 135 [self setValue:cv forKeyPath:kVolumeKeyPath];
500 masaki 3 }
501     - (IBAction)turnDownVolume:(id)sender
502     {
503 masaki 135 NSNumber *cv = [self valueForKeyPath:kVolumeKeyPath];
504 masaki 3 cv = [NSNumber numberWithFloat:[cv floatValue] - sVolumeDelta];
505 masaki 135 [self setValue:cv forKeyPath:kVolumeKeyPath];
506 masaki 3 }
507     - (IBAction)toggleFullScreenMode:(id)sender
508     {
509 masakih 371 if([self.window respondsToSelector:@selector(toggleFullScreen:)]) {
510     [self.window toggleFullScreen:self];
511 masakih 354 return;
512     }
513    
514 masakih 371 if(self.fullScreenMode) {
515 masaki 3 [self exitFullScreen];
516 masakih 371 self.fullScreenMode = NO;
517 masaki 2 } else {
518 masaki 3 [self enterFullScreen];
519 masakih 371 self.fullScreenMode = YES;
520 masaki 2 }
521     }
522    
523 masaki 4 - (IBAction)forwardTagValueSecends:(id)sender
524     {
525     if(![sender respondsToSelector:@selector(tag)]) return;
526    
527     int tag = [sender tag];
528     if(tag == 0) return;
529    
530 masakih 371 QTTime current = [self.qtMovie currentTime];
531 masaki 4 NSTimeInterval cur;
532     if(!QTGetTimeInterval(current, &cur)) return;
533    
534     QTTime new = QTMakeTimeWithTimeInterval(cur + tag);
535 masakih 371 [self.qtMovie setCurrentTime:new];
536 masaki 4 }
537     - (IBAction)backwardTagValueSecends:(id)sender
538     {
539     if(![sender respondsToSelector:@selector(tag)]) return;
540    
541     int tag = [sender tag];
542     if(tag == 0) return;
543    
544 masakih 371 QTTime current = [self.qtMovie currentTime];
545 masaki 4 NSTimeInterval cur;
546     if(!QTGetTimeInterval(current, &cur)) return;
547    
548     QTTime new = QTMakeTimeWithTimeInterval(cur - tag);
549 masakih 371 [self.qtMovie setCurrentTime:new];
550 masaki 4 }
551 masaki 24 - (IBAction)nextTrack:(id)sender
552     {
553 masaki 49 [qtView pause:sender];
554 masakih 371 [self.qtDocument.trackList next];
555 masaki 24 }
556     - (IBAction)previousTrack:(id)sender
557     {
558 masaki 49 [qtView pause:sender];
559 masakih 371 [self.qtDocument.trackList previous];
560 masaki 24 }
561 masakih 355 - (IBAction)gotoBeginningOrPreviousTrack:(id)sender
562     {
563 masakih 371 QTTime current = [self.qtMovie currentTime];
564 masakih 355 NSTimeInterval cur;
565     if(!QTGetTimeInterval(current, &cur)) return;
566    
567 masakih 371 QTTime duration = [self.qtMovie duration];
568 masakih 355 NSTimeInterval dur;
569     if(!QTGetTimeInterval(duration, &dur)) return;
570    
571     if(cur > (dur * 0.01)) {
572     [self gotoBeginning:sender];
573     } else {
574     [self previousTrack:sender];
575     }
576     }
577 masaki 4
578 masakih 329 - (IBAction)gotoThumbnailFrame:(id)sender
579     {
580 masakih 371 HMXSPFComponent *trackList = self.qtDocument.trackList;
581     HMXSPFComponent *thumbnailTrack = trackList.thumbnailTrack;
582     NSTimeInterval time = trackList.thumbnailTimeInterval;
583 masakih 329
584     NSUInteger num = [trackList indexOfChild:thumbnailTrack];
585     if(num == NSNotFound) return;
586    
587 masakih 371 trackList.selectionIndex = num;
588 masakih 329
589     QTTime new = QTMakeTimeWithTimeInterval(time);
590 masakih 371 [self.qtMovie setCurrentTime:new];
591 masakih 329 }
592    
593 masaki 134 - (IBAction)normalSize:(id)sender
594     {
595 masakih 371 if(self.fullScreenMode) return;
596 masaki 134
597 masakih 371 QTMovie *curMovie = self.qtMovie;
598 masaki 134 if(!curMovie) return;
599    
600     NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
601     if(movieSize.width == 0) return;
602    
603     [self setMovieSize:movieSize];
604     }
605     - (IBAction)halfSize:(id)sender
606     {
607 masakih 371 if(self.fullScreenMode) return;
608 masaki 134
609 masakih 371 QTMovie *curMovie = self.qtMovie;
610 masaki 134 if(!curMovie) return;
611    
612     NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
613     if(movieSize.width == 0) return;
614    
615     movieSize.width *= 0.5;
616     movieSize.height *= 0.5;
617    
618     [self setMovieSize:movieSize];
619     }
620     - (IBAction)doubleSize:(id)sender
621     {
622 masakih 371 if(self.fullScreenMode) return;
623 masaki 134
624 masakih 371 QTMovie *curMovie = self.qtMovie;
625 masaki 134 if(!curMovie) return;
626    
627     NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
628     if(movieSize.width == 0) return;
629    
630     movieSize.width *= 2;
631     movieSize.height *= 2;
632    
633     [self setMovieSize:movieSize];
634     }
635 masaki 135 - (IBAction)screenSize:(id)sender
636     {
637 masakih 371 if(self.fullScreenMode) return;
638 masakih 319
639     NSSize screenSize = [[NSScreen mainScreen] visibleFrame].size;
640     NSSize windowDecorationSize = [self windowSizeWithoutQTView];
641 masakih 371 NSRect windowFrame = [self.window frame];
642 masakih 319 NSSize movieSize = windowFrame.size;
643     NSSize newSize;
644    
645     movieSize.width -= windowDecorationSize.width;
646     movieSize.height -= windowDecorationSize.height;
647     screenSize.height -= windowDecorationSize.height;
648    
649     if(movieSize.height == 0) return;
650    
651     newSize.height = screenSize.height;
652     newSize.width = newSize.height * (movieSize.width / movieSize.height);
653    
654     newSize.height += windowDecorationSize.height;
655     newSize.width += windowDecorationSize.width;
656    
657     windowFrame.size = newSize;
658     windowFrame.origin.y = [[NSScreen mainScreen] visibleFrame].origin.y;
659 masakih 371 [self.window setFrame:windowFrame display:YES animate:YES];
660 masaki 135 }
661 masaki 134
662 masaki 10 #pragma mark ### Notification & Timer ###
663 masaki 151 - (void)movieDidEndNotification:(id)notification
664 masaki 2 {
665 masakih 371 [self.qtDocument.trackList next];
666 masaki 2 }
667 masaki 298
668     // call from XspfQTMovieTimer.
669 masaki 2 - (void)updateTimeIfNeeded:(id)timer
670     {
671 masakih 371 QTMovie *qt = self.qtMovie;
672 masaki 2 if(qt) {
673 masaki 10 // force update time indicator.
674 masaki 2 [qt willChangeValueForKey:@"currentTime"];
675     [qt didChangeValueForKey:@"currentTime"];
676     }
677 masaki 3
678     // Hide cursor and controller, if mouse didn't move for 3 seconds.
679     NSPoint mouse = [NSEvent mouseLocation];
680     if(!NSEqualPoints(prevMouse, mouse)) {
681     prevMouse = mouse;
682     [prevMouseMovedDate autorelease];
683     prevMouseMovedDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain];
684 masakih 371 } else if(self.fullScreenMode && [prevMouseMovedDate timeIntervalSinceNow] < -3.0 ) {
685 masaki 3 [NSCursor setHiddenUntilMouseMoves:YES];
686     //
687     // hide controller.
688     }
689 masaki 2 }
690    
691 masaki 10 #pragma mark ### NSResponder ###
692 masaki 2 - (void)cancelOperation:(id)sender
693     {
694 masakih 371 if(self.fullScreenMode) {
695 masaki 2 [self toggleFullScreenMode:self];
696     }
697     }
698    
699 masaki 10 #pragma mark ### NSMenu valivation ###
700     - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
701     {
702 masakih 329 SEL action = [menuItem action];
703     if(action == @selector(toggleFullScreenMode:)) {
704 masakih 371 if(self.fullScreenMode) {
705 masaki 10 [menuItem setTitle:NSLocalizedString(@"Exit Full Screen", @"Exit Full Screen")];
706     } else {
707     [menuItem setTitle:NSLocalizedString(@"Full Screen", @"Full Screen")];
708     }
709     return YES;
710     }
711    
712 masakih 329 if(action == @selector(gotoThumbnailFrame:)) {
713 masakih 371 if(!self.qtDocument.trackList.thumbnailTrack) return NO;
714 masakih 329 }
715    
716     if(action == @selector(normalSize:)
717     || action == @selector(halfSize:)
718     || action == @selector(doubleSize:)
719     || action == @selector(screenSize:)) {
720 masakih 371 if(self.fullScreenMode) {
721 masaki 139 return NO;
722     } else {
723     return YES;
724     }
725     }
726    
727 masaki 10 return YES;
728     }
729    
730 masaki 100 #pragma mark ### XspfQTDocument Notification ###
731     - (void)documentWillClose:(NSNotification *)notification
732 masaki 2 {
733 masaki 100 id doc = [notification object];
734 masaki 272
735 masakih 371 if(self.fullScreenMode) {
736 masaki 2 [self toggleFullScreenMode:self];
737     }
738 masaki 100
739     [doc removeObserver:self forKeyPath:kQTMovieKeyPath];
740     [doc removeObserver:self forKeyPath:kIsPlayedKeyPath];
741    
742     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
743     [nc removeObserver:self name:XspfQTDocumentWillCloseNotification object:doc];
744 masaki 2 }
745    
746 masaki 10 #pragma mark ### NSWindow Delegate ###
747 masaki 2 - (BOOL)windowShouldClose:(id)sender
748     {
749     [qtView pause:self];
750 masakih 371 self.qtMovie = nil;
751 masaki 298
752 masaki 2 return YES;
753     }
754     - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
755     {
756 masakih 371 if(self.fullScreenMode) return frameSize;
757 masaki 156 if(isChangingFullScreen) return frameSize;
758 masaki 143
759 masaki 2 return [self fitSizeToSize:frameSize];
760     }
761 masaki 16 - (void)windowDidMove:(NSNotification *)notification
762     {
763     if(fullscreenWindow && [notification object] == fullscreenWindow) {
764     NSRect r = [fullscreenWindow frame];
765 masaki 45 if(!NSEqualPoints(r.origin, NSZeroPoint)) {
766 masaki 16 [fullscreenWindow setFrameOrigin:NSZeroPoint];
767     }
768     }
769     }
770 masakih 354 - (void)hideController:(id)sender
771     {
772     for(NSView *view in [controllerView subviews]) {
773     [view setHidden:YES];
774     }
775     }
776     - (void)showController:(id)sender
777     {
778     for(NSView *view in [controllerView subviews]) {
779     [view setHidden:NO];
780     }
781     }
782     - (void)windowWillEnterFullScreen:(NSNotification *)notification
783     {
784 masakih 371 self.fullScreenMode = YES;
785 masakih 354
786 masakih 371 NSSize windowContentSize = [self.window.contentView frame].size;
787 masakih 354 NSRect qtViewFrame = [qtView frame];
788     qtViewFrame.size = windowContentSize;
789     qtViewFrame.origin = NSZeroPoint;
790     [qtView setFrame:qtViewFrame];
791    
792     [self hideController:nil];
793     }
794    
795     - (void)windowWillExitFullScreen:(NSNotification *)notification
796     {
797 masakih 371 NSRect windowContentRect = [self.window.contentView frame];
798 masakih 354 NSSize controllerSize= [controllerView frame].size;
799     windowContentRect.size.height -= controllerSize.height;
800     windowContentRect.origin.y = controllerSize.height;
801     [qtView setFrame:windowContentRect];
802     [self showController:nil];
803    
804 masakih 371 self.fullScreenMode = NO;
805 masakih 354 }
806 masakih 361 - (void)windowDidExitFullScreen:(NSNotification *)notification
807     {
808     [self sizeTofitWidnow];
809     }
810 masakih 354
811    
812 masaki 2 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26