Develop and Download Open Source Software

Browse Subversion Repository

Contents of /XspfQT/XspfQTMovieWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log


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

1 //
2 // XspfQTMovieWindowController.m
3 // XspfQT
4 //
5 // Created by Hori,Masaki on 08/08/31.
6 //
7
8 /*
9 This source code is release under the New BSD License.
10 Copyright (c) 2008-2010,2012, masakih
11 All rights reserved.
12
13 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14 限り、再頒布および使用が許可されます。
15
16 1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17 めること。
18 2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19 示、本条件一覧、および下記免責条項を含めること。
20 3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21 コントリビューターの名前を使用してはならない。
22 本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23 明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24 も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25 も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26 厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27 可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28 サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29 されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30 て、一切責任を負わないものとします。
31 -------------------------------------------------------------------
32 Copyright (c) 2008-2010,2012, masakih
33 All rights reserved.
34
35 Redistribution and use in source and binary forms, with or without
36 modification, are permitted provided that the following conditions
37 are met:
38
39 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 */
61
62 #import <Carbon/Carbon.h>
63
64 #import "XspfQTMovieWindowController.h"
65 #import "XspfQTDocument.h"
66 #import "HMXSPFComponent.h"
67 #import "XspfQTFullScreenWindow.h"
68 #import "XspfQTMovieWindow.h"
69
70
71 #pragma mark #### Global Variables ####
72 /********* Global variables *******/
73 NSString *XspfQTMovieDidStartNotification = @"XspfQTMovieDidStartNotification";
74 NSString *XspfQTMovieDidPauseNotification = @"XspfQTMovieDidPauseNotification";
75
76 @interface XspfQTMovieWindowController()
77 @property BOOL fullScreenMode;
78
79 @property (readonly) XspfQTDocument *qtDocument;
80 @property (readonly) XspfQTMovieWindow *qtWindow;
81 @end
82
83 @interface XspfQTMovieWindowController (Private)
84 - (NSSize)windowSizeWithoutQTView;
85 - (void)sizeTofitWidnow;
86 - (NSSize)fitSizeToSize:(NSSize)toSize;
87 - (NSWindow *)fullscreenWindow;
88 - (void)movieDidStart;
89 - (void)movieDidPause;
90
91 - (void)hideMenuBar;
92 - (void)showMenuBar;
93 @end
94 #ifndef MAC_OS_X_VERSION_10_6
95 @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
117 @implementation XspfQTMovieWindowController
118 @synthesize qtMovie = _qtMovie;
119 @synthesize fullScreenMode = _fullScreenMode;
120
121 #pragma mark ### Static variables ###
122 static const float sVolumeDelta = 0.1;
123 static const NSTimeInterval sUpdateTimeInterval = 0.5;
124 static NSString *const kQTMovieKeyPath = @"playingMovie";
125 static NSString *const kIsPlayedKeyPath = @"trackList.isPlayed";
126 static NSString *const kVolumeKeyPath = @"qtMovie.volume";
127
128 - (id)init
129 {
130 self = [super initWithWindowNibName:@"XspfQTDocument"];
131
132 return self;
133 }
134
135 - (void)dealloc
136 {
137 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
138 [nc removeObserver:self];
139
140 self.qtMovie = nil;
141
142 [fullscreenWindow release];
143 [self movieDidPause];
144 [prevMouseMovedDate release];
145
146 [super dealloc];
147 }
148 - (void)awakeFromNib
149 {
150 prevMouseMovedDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain];
151 [[self window] setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
152
153 XspfQTDocument *doc = self.qtDocument;
154
155 [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
164 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
165 [nc addObserver:self
166 selector:@selector(documentWillClose:)
167 name:XspfQTDocumentWillCloseNotification
168 object:doc];
169
170 doc.trackList.selectionIndex = 0;
171 [self sizeTofitWidnow];
172 [self play];
173 }
174
175 - (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
176 {
177 id title1 = [self valueForKeyPath:@"document.trackList.title"];
178 id title2 = [self valueForKeyPath:@"document.trackList.currentTrack.title"];
179 if(title1 && title2) {
180 return [NSString stringWithFormat:@"%@ - %@",
181 title1, title2];
182 }
183 if(title2) {
184 return [NSString stringWithFormat:@"%@ - %@",
185 displayName, title2];
186 }
187 return displayName;
188 }
189 - (IBAction)showWindow:(id)sender
190 {
191 if(!self.fullScreenMode) {
192 [super showWindow:sender];
193 return;
194 }
195 }
196
197 #pragma mark ### KVO & KVC ###
198 - (void)observeValueForKeyPath:(NSString *)keyPath
199 ofObject:(id)object
200 change:(NSDictionary *)change
201 context:(void *)context
202 {
203 if([keyPath isEqualToString:kQTMovieKeyPath]) {
204 id new = [change objectForKey:NSKeyValueChangeNewKey];
205 self.qtMovie = new;
206 return;
207 }
208 if([keyPath isEqualToString:kIsPlayedKeyPath]) {
209 id new = [change objectForKey:NSKeyValueChangeNewKey];
210 if([new boolValue]) {
211 [self movieDidStart];
212 } else {
213 [self movieDidPause];
214 }
215 return;
216 }
217 }
218
219 - (void)setQtMovie:(QTMovie *)qt
220 {
221 if(_qtMovie == qt) return;
222 if([_qtMovie isEqual:qt]) return;
223 if(qt == (id)[NSNull null]) qt = nil;
224
225 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
226
227 if(_qtMovie) {
228 [nc removeObserver:self name:nil object:_qtMovie];
229 }
230 if(qt) {
231 [nc addObserver:self selector:@selector(movieDidEndNotification:) name:QTMovieDidEndNotification object:qt];
232 }
233
234 if(_qtMovie) {
235 [qt setVolume:[_qtMovie volume]];
236 [qt setMuted:[_qtMovie muted]];
237 }
238 [_qtMovie autorelease];
239 _qtMovie = [qt retain];
240
241 if(!_qtMovie) return;
242
243 [self synchronizeWindowTitleWithDocumentName];
244 [self sizeTofitWidnow];
245 [self play];
246 }
247 - (QTMovie *)qtMovie
248 {
249 return _qtMovie;
250 }
251 - (XspfQTDocument *)qtDocument
252 {
253 return (XspfQTDocument *)self.document;
254 }
255 - (XspfQTMovieWindow *)qtWindow
256 {
257 return (XspfQTMovieWindow *)self.window;
258 }
259
260 #pragma mark ### Other functions ###
261 // Area size without QTMovieView.
262 - (NSSize)windowSizeWithoutQTView
263 {
264 if(windowSizeWithoutQTView.width == 0
265 && windowSizeWithoutQTView.height == 0) {
266 QTMovie *curMovie = self.qtMovie;
267 if(!curMovie) return windowSizeWithoutQTView;
268
269 NSSize qtViewSize = [qtView frame].size;
270 NSSize currentWindowSize = [self.window frame].size;
271
272 windowSizeWithoutQTView = NSMakeSize(currentWindowSize.width - qtViewSize.width,
273 currentWindowSize.height - qtViewSize.height);
274 }
275
276 return windowSizeWithoutQTView;
277 }
278 - (void)sizeTofitWidnow
279 {
280 if(self.fullScreenMode) return;
281
282 id window = self.window;
283 NSRect frame = [window frame];
284 NSSize newSize = [self fitSizeToSize:frame.size];
285 frame.origin.y += frame.size.height - newSize.height;
286 frame.size = newSize;
287
288 [window setFrame:frame display:YES animate:YES];
289 }
290 - (NSSize)fitSizeToSize:(NSSize)toSize
291 {
292 QTMovie *curMovie = self.qtMovie;
293 if(!curMovie) return toSize;
294
295 NSSize delta = [self windowSizeWithoutQTView];
296
297 NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
298 if(movieSize.width == 0) return toSize;
299
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 return NSMakeSize(targetViewWidth, targetViewHeight);
307 }
308
309 - (NSSize)windowSizeFromMovieSize:(NSSize)movieSize
310 {
311
312 //
313
314 return NSZeroSize;
315 }
316
317 - (void)setMovieSize:(NSSize)movieSize
318 {
319 NSRect newFrame = [self.window frame];
320 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 [self.window setFrame:newFrame display:YES animate:YES];
330 }
331 - (void)movieDidStart
332 {
333 [playButton setTitle:@"||"];
334
335 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
336 [nc postNotificationName:XspfQTMovieDidStartNotification object:self];
337 }
338
339 - (void)movieDidPause
340 {
341 [playButton setTitle:@">"];
342
343 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
344 [nc postNotificationName:XspfQTMovieDidPauseNotification object:self];
345 }
346 - (void)play
347 {
348 [qtView performSelectorOnMainThread:@selector(play:) withObject:self waitUntilDone:NO];
349 }
350 - (void)pause
351 {
352 [qtView performSelectorOnMainThread:@selector(pause:) withObject:self waitUntilDone:NO];
353 }
354 - (void)stop
355 {
356 [qtView performSelectorOnMainThread:@selector(pause:) withObject:self waitUntilDone:YES];
357 }
358 - (void)enterFullScreen
359 {
360 NSWindow *fullscreen = [self fullscreenWindow];
361
362 normalModeSavedFrame = [qtView frame];
363
364 XspfQTMovieWindow *player = self.qtWindow;
365
366 [self hideMenuBar];
367
368 NSRect newFrame = [qtView frame];
369 newFrame.origin = [player convertBaseToScreen:newFrame.origin];
370 newFrame.origin = [fullscreen convertScreenToBase:newFrame.origin];
371 [qtView setFrame:newFrame];
372
373 [[fullscreen contentView] addSubview:qtView];
374 [fullscreen makeKeyAndOrderFront:self];
375 [fullscreen makeFirstResponder:qtView];
376
377 [[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 [self.window orderOut:self];
385
386 [fullscreenWindow makeKeyAndOrderFront:self];
387 }
388 - (void)exitFullScreen
389 {
390 XspfQTMovieWindow *player = self.qtWindow;
391 NSRect originalWFrame = [player frame];
392
393 // calculate new Window frame.
394 NSRect windowRect = originalWFrame;
395 NSSize movieSize = [[self.qtMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
396 if(movieSize.width != 0) {
397 CGFloat newViewHeight = normalModeSavedFrame.size.width * (movieSize.height / movieSize.width);
398
399 windowRect.size.height = newViewHeight + windowSizeWithoutQTView.height;
400 windowRect.origin.y -= windowRect.size.height - originalWFrame.size.height;
401 }
402
403 [player setFrame:windowRect display:NO];
404 [player orderWindow:NSWindowBelow relativeTo:[fullscreenWindow windowNumber]];
405
406 // move QTView.
407 [qtView retain];
408 {
409 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 }
416 [qtView release];
417
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 XspfQTMovieWindow *player = self.qtWindow;
424
425 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 [fullscreenWindow orderOut:self];
431
432 [self showMenuBar];
433
434 [player makeKeyAndOrderFront:self];
435 [player makeFirstResponder:qtView];
436 }
437
438 - (NSWindow *)fullscreenWindow
439 {
440 if(fullscreenWindow) return fullscreenWindow;
441
442 NSRect mainScreenRect = [[NSScreen mainScreen] frame];
443 fullscreenWindow = [[XspfQTFullScreenWindow alloc] initWithContentRect:mainScreenRect
444 styleMask:NSBorderlessWindowMask
445 backing:NSBackingStoreBuffered
446 defer:YES];
447 [fullscreenWindow setReleasedWhenClosed:NO];
448 [fullscreenWindow setBackgroundColor:[[NSColor blackColor] colorWithAlphaComponent:0.5]];
449 [fullscreenWindow setDelegate:self];
450 [fullscreenWindow setWindowController:self];
451 [fullscreenWindow setOpaque:NO];
452
453 if([fullscreenWindow respondsToSelector:@selector(setAnimationBehavior:)]) {
454 [fullscreenWindow setAnimationBehavior:NSWindowAnimationBehaviorNone];
455 }
456
457 return fullscreenWindow;
458 }
459 - (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 currentPresentation & ~(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
480 }
481 #pragma mark ### Actions ###
482 - (IBAction)togglePlayAndPause:(id)sender
483 {
484 if([[self valueForKeyPath:@"document.trackList.isPlayed"] boolValue]) {
485 [self pause];
486 } else {
487 [self play];
488 }
489 }
490 - (IBAction)gotoBeginning:(id)sender
491 {
492 [qtView gotoBeginning:sender];
493 }
494
495 - (IBAction)turnUpVolume:(id)sender
496 {
497 NSNumber *cv = [self valueForKeyPath:kVolumeKeyPath];
498 cv = [NSNumber numberWithFloat:[cv floatValue] + sVolumeDelta];
499 [self setValue:cv forKeyPath:kVolumeKeyPath];
500 }
501 - (IBAction)turnDownVolume:(id)sender
502 {
503 NSNumber *cv = [self valueForKeyPath:kVolumeKeyPath];
504 cv = [NSNumber numberWithFloat:[cv floatValue] - sVolumeDelta];
505 [self setValue:cv forKeyPath:kVolumeKeyPath];
506 }
507 - (IBAction)toggleFullScreenMode:(id)sender
508 {
509 if([self.window respondsToSelector:@selector(toggleFullScreen:)]) {
510 [self.window toggleFullScreen:self];
511 return;
512 }
513
514 if(self.fullScreenMode) {
515 [self exitFullScreen];
516 self.fullScreenMode = NO;
517 } else {
518 [self enterFullScreen];
519 self.fullScreenMode = YES;
520 }
521 }
522
523 - (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 QTTime current = [self.qtMovie currentTime];
531 NSTimeInterval cur;
532 if(!QTGetTimeInterval(current, &cur)) return;
533
534 QTTime new = QTMakeTimeWithTimeInterval(cur + tag);
535 [self.qtMovie setCurrentTime:new];
536 }
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 QTTime current = [self.qtMovie currentTime];
545 NSTimeInterval cur;
546 if(!QTGetTimeInterval(current, &cur)) return;
547
548 QTTime new = QTMakeTimeWithTimeInterval(cur - tag);
549 [self.qtMovie setCurrentTime:new];
550 }
551 - (IBAction)nextTrack:(id)sender
552 {
553 [qtView pause:sender];
554 [self.qtDocument.trackList next];
555 }
556 - (IBAction)previousTrack:(id)sender
557 {
558 [qtView pause:sender];
559 [self.qtDocument.trackList previous];
560 }
561 - (IBAction)gotoBeginningOrPreviousTrack:(id)sender
562 {
563 QTTime current = [self.qtMovie currentTime];
564 NSTimeInterval cur;
565 if(!QTGetTimeInterval(current, &cur)) return;
566
567 QTTime duration = [self.qtMovie duration];
568 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
578 - (IBAction)gotoThumbnailFrame:(id)sender
579 {
580 HMXSPFComponent *trackList = self.qtDocument.trackList;
581 HMXSPFComponent *thumbnailTrack = trackList.thumbnailTrack;
582 NSTimeInterval time = trackList.thumbnailTimeInterval;
583
584 NSUInteger num = [trackList indexOfChild:thumbnailTrack];
585 if(num == NSNotFound) return;
586
587 trackList.selectionIndex = num;
588
589 QTTime new = QTMakeTimeWithTimeInterval(time);
590 [self.qtMovie setCurrentTime:new];
591 }
592
593 - (IBAction)normalSize:(id)sender
594 {
595 if(self.fullScreenMode) return;
596
597 QTMovie *curMovie = self.qtMovie;
598 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 if(self.fullScreenMode) return;
608
609 QTMovie *curMovie = self.qtMovie;
610 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 if(self.fullScreenMode) return;
623
624 QTMovie *curMovie = self.qtMovie;
625 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 - (IBAction)screenSize:(id)sender
636 {
637 if(self.fullScreenMode) return;
638
639 NSSize screenSize = [[NSScreen mainScreen] visibleFrame].size;
640 NSSize windowDecorationSize = [self windowSizeWithoutQTView];
641 NSRect windowFrame = [self.window frame];
642 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 [self.window setFrame:windowFrame display:YES animate:YES];
660 }
661
662 #pragma mark ### Notification & Timer ###
663 - (void)movieDidEndNotification:(id)notification
664 {
665 [self.qtDocument.trackList next];
666 }
667
668 // call from XspfQTMovieTimer.
669 - (void)updateTimeIfNeeded:(id)timer
670 {
671 QTMovie *qt = self.qtMovie;
672 if(qt) {
673 // force update time indicator.
674 [qt willChangeValueForKey:@"currentTime"];
675 [qt didChangeValueForKey:@"currentTime"];
676 }
677
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 } else if(self.fullScreenMode && [prevMouseMovedDate timeIntervalSinceNow] < -3.0 ) {
685 [NSCursor setHiddenUntilMouseMoves:YES];
686 //
687 // hide controller.
688 }
689 }
690
691 #pragma mark ### NSResponder ###
692 - (void)cancelOperation:(id)sender
693 {
694 if(self.fullScreenMode) {
695 [self toggleFullScreenMode:self];
696 }
697 }
698
699 #pragma mark ### NSMenu valivation ###
700 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
701 {
702 SEL action = [menuItem action];
703 if(action == @selector(toggleFullScreenMode:)) {
704 if(self.fullScreenMode) {
705 [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 if(action == @selector(gotoThumbnailFrame:)) {
713 if(!self.qtDocument.trackList.thumbnailTrack) return NO;
714 }
715
716 if(action == @selector(normalSize:)
717 || action == @selector(halfSize:)
718 || action == @selector(doubleSize:)
719 || action == @selector(screenSize:)) {
720 if(self.fullScreenMode) {
721 return NO;
722 } else {
723 return YES;
724 }
725 }
726
727 return YES;
728 }
729
730 #pragma mark ### XspfQTDocument Notification ###
731 - (void)documentWillClose:(NSNotification *)notification
732 {
733 id doc = [notification object];
734
735 if(self.fullScreenMode) {
736 [self toggleFullScreenMode:self];
737 }
738
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 }
745
746 #pragma mark ### NSWindow Delegate ###
747 - (BOOL)windowShouldClose:(id)sender
748 {
749 [qtView pause:self];
750 self.qtMovie = nil;
751
752 return YES;
753 }
754 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
755 {
756 if(self.fullScreenMode) return frameSize;
757 if(isChangingFullScreen) return frameSize;
758
759 return [self fitSizeToSize:frameSize];
760 }
761 - (void)windowDidMove:(NSNotification *)notification
762 {
763 if(fullscreenWindow && [notification object] == fullscreenWindow) {
764 NSRect r = [fullscreenWindow frame];
765 if(!NSEqualPoints(r.origin, NSZeroPoint)) {
766 [fullscreenWindow setFrameOrigin:NSZeroPoint];
767 }
768 }
769 }
770 - (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 self.fullScreenMode = YES;
785
786 NSSize windowContentSize = [self.window.contentView frame].size;
787 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 NSRect windowContentRect = [self.window.contentView frame];
798 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 self.fullScreenMode = NO;
805 }
806 - (void)windowDidExitFullScreen:(NSNotification *)notification
807 {
808 [self sizeTofitWidnow];
809 }
810
811
812 @end

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