| 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 |
312 |
Copyright (c) 2008-2010, masakih |
| 11 |
|
|
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 |
|
|
Copyright (c) 2008-2010, masakih |
| 33 |
|
|
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 |
|
|
|
| 77 |
masaki |
72 |
@interface XspfQTMovieWindowController (Private) |
| 78 |
masaki |
45 |
- (NSSize)windowSizeWithoutQTView; |
| 79 |
masaki |
17 |
- (void)sizeTofitWidnow; |
| 80 |
masaki |
2 |
- (NSSize)fitSizeToSize:(NSSize)toSize; |
| 81 |
|
|
- (NSWindow *)fullscreenWindow; |
| 82 |
masaki |
151 |
- (void)movieDidStart; |
| 83 |
|
|
- (void)movieDidPause; |
| 84 |
masakih |
338 |
|
| 85 |
|
|
- (void)hideMenuBar; |
| 86 |
|
|
- (void)showMenuBar; |
| 87 |
masaki |
2 |
@end |
| 88 |
masakih |
338 |
#ifndef NSApplicationPresentationOptions |
| 89 |
|
|
@interface NSApplication (XspfQT) |
| 90 |
|
|
typedef NSUInteger NSApplicationPresentationOptions; |
| 91 |
|
|
- (NSApplicationPresentationOptions)presentationOptions; |
| 92 |
|
|
- (void)setPresentationOptions:(NSApplicationPresentationOptions)newOptions; |
| 93 |
|
|
enum { |
| 94 |
|
|
NSApplicationPresentationDefault = 0, |
| 95 |
|
|
NSApplicationPresentationAutoHideDock = (1 << 0), // Dock appears when moused to |
| 96 |
|
|
NSApplicationPresentationHideDock = (1 << 1), // Dock is entirely unavailable |
| 97 |
|
|
|
| 98 |
|
|
NSApplicationPresentationAutoHideMenuBar = (1 << 2), // Menu Bar appears when moused to |
| 99 |
|
|
NSApplicationPresentationHideMenuBar = (1 << 3), // Menu Bar is entirely unavailable |
| 100 |
|
|
|
| 101 |
|
|
NSApplicationPresentationDisableAppleMenu = (1 << 4), // all Apple menu items are disabled |
| 102 |
|
|
NSApplicationPresentationDisableProcessSwitching = (1 << 5), // Cmd+Tab UI is disabled |
| 103 |
|
|
NSApplicationPresentationDisableForceQuit = (1 << 6), // Cmd+Opt+Esc panel is disabled |
| 104 |
|
|
NSApplicationPresentationDisableSessionTermination = (1 << 7), // PowerKey panel and Restart/Shut Down/Log Out disabled |
| 105 |
|
|
NSApplicationPresentationDisableHideApplication = (1 << 8), // Application "Hide" menu item is disabled |
| 106 |
|
|
NSApplicationPresentationDisableMenuBarTransparency = (1 << 9) // Menu Bar's transparent appearance is disabled |
| 107 |
|
|
}; |
| 108 |
|
|
@end |
| 109 |
|
|
#endif |
| 110 |
masaki |
2 |
|
| 111 |
masaki |
72 |
@implementation XspfQTMovieWindowController |
| 112 |
masaki |
2 |
|
| 113 |
masaki |
10 |
#pragma mark ### Static variables ### |
| 114 |
masaki |
132 |
static const float sVolumeDelta = 0.1; |
| 115 |
masaki |
200 |
static const NSTimeInterval sUpdateTimeInterval = 0.5; |
| 116 |
masaki |
171 |
static NSString *const kQTMovieKeyPath = @"playingMovie"; |
| 117 |
masaki |
40 |
static NSString *const kIsPlayedKeyPath = @"trackList.isPlayed"; |
| 118 |
masaki |
135 |
static NSString *const kVolumeKeyPath = @"qtMovie.volume"; |
| 119 |
masaki |
2 |
|
| 120 |
masaki |
10 |
- (id)init |
| 121 |
masaki |
2 |
{ |
| 122 |
masaki |
151 |
self = [super initWithWindowNibName:@"XspfQTDocument"]; |
| 123 |
masaki |
2 |
|
| 124 |
|
|
return self; |
| 125 |
|
|
} |
| 126 |
|
|
|
| 127 |
|
|
- (void)dealloc |
| 128 |
|
|
{ |
| 129 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 130 |
|
|
[nc removeObserver:self]; |
| 131 |
masaki |
49 |
|
| 132 |
|
|
[self setQtMovie:nil]; |
| 133 |
masaki |
2 |
|
| 134 |
|
|
[fullscreenWindow release]; |
| 135 |
masaki |
151 |
[self movieDidPause]; |
| 136 |
masaki |
10 |
[prevMouseMovedDate release]; |
| 137 |
masaki |
76 |
|
| 138 |
masaki |
2 |
[super dealloc]; |
| 139 |
|
|
} |
| 140 |
|
|
- (void)awakeFromNib |
| 141 |
|
|
{ |
| 142 |
masaki |
3 |
prevMouseMovedDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain]; |
| 143 |
|
|
|
| 144 |
masaki |
100 |
id doc = [self document]; |
| 145 |
masaki |
151 |
|
| 146 |
masaki |
100 |
[doc addObserver:self |
| 147 |
|
|
forKeyPath:kQTMovieKeyPath |
| 148 |
|
|
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld |
| 149 |
|
|
context:NULL]; |
| 150 |
|
|
[doc addObserver:self |
| 151 |
|
|
forKeyPath:kIsPlayedKeyPath |
| 152 |
|
|
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld |
| 153 |
|
|
context:NULL]; |
| 154 |
masaki |
2 |
|
| 155 |
masaki |
100 |
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 156 |
|
|
[nc addObserver:self |
| 157 |
|
|
selector:@selector(documentWillClose:) |
| 158 |
|
|
name:XspfQTDocumentWillCloseNotification |
| 159 |
|
|
object:doc]; |
| 160 |
|
|
|
| 161 |
masaki |
177 |
[[doc trackList] setSelectionIndex:0]; |
| 162 |
masaki |
17 |
[self sizeTofitWidnow]; |
| 163 |
masaki |
2 |
[self play]; |
| 164 |
|
|
} |
| 165 |
masaki |
10 |
|
| 166 |
masaki |
62 |
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName |
| 167 |
|
|
{ |
| 168 |
masaki |
70 |
id title1 = [self valueForKeyPath:@"document.trackList.title"]; |
| 169 |
|
|
id title2 = [self valueForKeyPath:@"document.trackList.currentTrack.title"]; |
| 170 |
|
|
if(title1 && title2) { |
| 171 |
masaki |
62 |
return [NSString stringWithFormat:@"%@ - %@", |
| 172 |
masaki |
70 |
title1, title2]; |
| 173 |
masaki |
62 |
} |
| 174 |
masaki |
116 |
if(title2) { |
| 175 |
|
|
return [NSString stringWithFormat:@"%@ - %@", |
| 176 |
|
|
displayName, title2]; |
| 177 |
|
|
} |
| 178 |
masaki |
62 |
return displayName; |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
masaki |
10 |
#pragma mark ### KVO & KVC ### |
| 182 |
masaki |
2 |
- (void)observeValueForKeyPath:(NSString *)keyPath |
| 183 |
|
|
ofObject:(id)object |
| 184 |
|
|
change:(NSDictionary *)change |
| 185 |
|
|
context:(void *)context |
| 186 |
|
|
{ |
| 187 |
masaki |
49 |
if([keyPath isEqualToString:kQTMovieKeyPath]) { |
| 188 |
masaki |
2 |
id new = [change objectForKey:NSKeyValueChangeNewKey]; |
| 189 |
masaki |
49 |
[self setQtMovie:new]; |
| 190 |
masaki |
2 |
return; |
| 191 |
|
|
} |
| 192 |
masaki |
49 |
if([keyPath isEqualToString:kIsPlayedKeyPath]) { |
| 193 |
masaki |
14 |
id new = [change objectForKey:NSKeyValueChangeNewKey]; |
| 194 |
|
|
if([new boolValue]) { |
| 195 |
masaki |
151 |
[self movieDidStart]; |
| 196 |
masaki |
14 |
} else { |
| 197 |
masaki |
151 |
[self movieDidPause]; |
| 198 |
masaki |
14 |
} |
| 199 |
|
|
return; |
| 200 |
|
|
} |
| 201 |
masaki |
2 |
} |
| 202 |
|
|
|
| 203 |
|
|
- (void)setQtMovie:(QTMovie *)qt |
| 204 |
|
|
{ |
| 205 |
|
|
if(qtMovie == qt) return; |
| 206 |
|
|
if([qtMovie isEqual:qt]) return; |
| 207 |
masaki |
62 |
if(qt == (id)[NSNull null]) qt = nil; |
| 208 |
masaki |
2 |
|
| 209 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 210 |
|
|
|
| 211 |
|
|
if(qtMovie) { |
| 212 |
|
|
[nc removeObserver:self name:nil object:qtMovie]; |
| 213 |
|
|
} |
| 214 |
|
|
if(qt) { |
| 215 |
masaki |
151 |
[nc addObserver:self selector:@selector(movieDidEndNotification:) name:QTMovieDidEndNotification object:qt]; |
| 216 |
masaki |
2 |
} |
| 217 |
masaki |
3 |
|
| 218 |
|
|
if(qtMovie) { |
| 219 |
|
|
[qt setVolume:[qtMovie volume]]; |
| 220 |
|
|
[qt setMuted:[qtMovie muted]]; |
| 221 |
|
|
} |
| 222 |
masaki |
2 |
[qtMovie autorelease]; |
| 223 |
|
|
qtMovie = [qt retain]; |
| 224 |
masaki |
49 |
|
| 225 |
|
|
if(!qtMovie) return; |
| 226 |
|
|
|
| 227 |
masaki |
2 |
[self synchronizeWindowTitleWithDocumentName]; |
| 228 |
masaki |
17 |
[self sizeTofitWidnow]; |
| 229 |
masaki |
2 |
[self play]; |
| 230 |
|
|
} |
| 231 |
|
|
- (QTMovie *)qtMovie |
| 232 |
|
|
{ |
| 233 |
|
|
return qtMovie; |
| 234 |
|
|
} |
| 235 |
|
|
|
| 236 |
masaki |
10 |
#pragma mark ### Other functions ### |
| 237 |
masaki |
151 |
// Area size without QTMovieView. |
| 238 |
masaki |
45 |
- (NSSize)windowSizeWithoutQTView |
| 239 |
|
|
{ |
| 240 |
|
|
if(windowSizeWithoutQTView.width == 0 |
| 241 |
|
|
&& windowSizeWithoutQTView.height == 0) { |
| 242 |
|
|
QTMovie *curMovie = [self qtMovie]; |
| 243 |
|
|
if(!curMovie) return windowSizeWithoutQTView; |
| 244 |
|
|
|
| 245 |
|
|
NSSize qtViewSize = [qtView frame].size; |
| 246 |
|
|
NSSize currentWindowSize = [[self window] frame].size; |
| 247 |
|
|
|
| 248 |
|
|
windowSizeWithoutQTView = NSMakeSize(currentWindowSize.width - qtViewSize.width, |
| 249 |
|
|
currentWindowSize.height - qtViewSize.height); |
| 250 |
|
|
} |
| 251 |
|
|
|
| 252 |
|
|
return windowSizeWithoutQTView; |
| 253 |
|
|
} |
| 254 |
masaki |
17 |
- (void)sizeTofitWidnow |
| 255 |
|
|
{ |
| 256 |
|
|
id window = [self window]; |
| 257 |
|
|
NSRect frame = [window frame]; |
| 258 |
|
|
NSSize newSize = [self fitSizeToSize:frame.size]; |
| 259 |
masaki |
19 |
frame.origin.y += frame.size.height - newSize.height; |
| 260 |
masaki |
17 |
frame.size = newSize; |
| 261 |
|
|
|
| 262 |
masaki |
19 |
[window setFrame:frame display:YES animate:YES]; |
| 263 |
masaki |
17 |
} |
| 264 |
masaki |
2 |
- (NSSize)fitSizeToSize:(NSSize)toSize |
| 265 |
|
|
{ |
| 266 |
|
|
QTMovie *curMovie = [self qtMovie]; |
| 267 |
|
|
if(!curMovie) return toSize; |
| 268 |
|
|
|
| 269 |
masaki |
45 |
NSSize delta = [self windowSizeWithoutQTView]; |
| 270 |
masaki |
2 |
|
| 271 |
|
|
NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; |
| 272 |
masaki |
107 |
if(movieSize.width == 0) return toSize; |
| 273 |
masaki |
2 |
|
| 274 |
|
|
float targetViewWidth = toSize.width - delta.width; |
| 275 |
|
|
float targetViewHeight = targetViewWidth * (movieSize.height / movieSize.width); |
| 276 |
|
|
|
| 277 |
|
|
targetViewWidth += delta.width; |
| 278 |
|
|
targetViewHeight += delta.height; |
| 279 |
|
|
|
| 280 |
masaki |
107 |
return NSMakeSize(targetViewWidth, targetViewHeight); |
| 281 |
masaki |
2 |
} |
| 282 |
|
|
|
| 283 |
masaki |
134 |
- (NSSize)windowSizeFromMovieSize:(NSSize)movieSize |
| 284 |
|
|
{ |
| 285 |
|
|
|
| 286 |
|
|
// |
| 287 |
masaki |
135 |
|
| 288 |
|
|
return NSZeroSize; |
| 289 |
masaki |
134 |
} |
| 290 |
|
|
|
| 291 |
|
|
- (void)setMovieSize:(NSSize)movieSize |
| 292 |
|
|
{ |
| 293 |
masaki |
139 |
NSRect newFrame = [[self window] frame]; |
| 294 |
|
|
NSSize newSize; |
| 295 |
|
|
|
| 296 |
|
|
newSize = [self windowSizeWithoutQTView]; |
| 297 |
|
|
newSize.width += movieSize.width; |
| 298 |
|
|
newSize.height += movieSize.height; |
| 299 |
|
|
|
| 300 |
|
|
newFrame.origin.y -= newSize.height - newFrame.size.height; |
| 301 |
|
|
newFrame.size = newSize; |
| 302 |
|
|
|
| 303 |
|
|
NSWindow *w = [self window]; |
| 304 |
|
|
[w setFrame:newFrame display:YES animate:YES]; |
| 305 |
masaki |
134 |
} |
| 306 |
masaki |
151 |
- (void)movieDidStart |
| 307 |
masaki |
135 |
{ |
| 308 |
|
|
[playButton setTitle:@"||"]; |
| 309 |
masaki |
299 |
|
| 310 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 311 |
|
|
[nc postNotificationName:XspfQTMovieDidStartNotification object:self]; |
| 312 |
masaki |
135 |
} |
| 313 |
|
|
|
| 314 |
masaki |
151 |
- (void)movieDidPause |
| 315 |
masaki |
135 |
{ |
| 316 |
|
|
[playButton setTitle:@">"]; |
| 317 |
masaki |
299 |
|
| 318 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 319 |
|
|
[nc postNotificationName:XspfQTMovieDidPauseNotification object:self]; |
| 320 |
masaki |
135 |
} |
| 321 |
masaki |
2 |
- (void)play |
| 322 |
|
|
{ |
| 323 |
|
|
[qtView performSelectorOnMainThread:@selector(play:) withObject:self waitUntilDone:NO]; |
| 324 |
|
|
} |
| 325 |
masaki |
14 |
- (void)pause |
| 326 |
|
|
{ |
| 327 |
|
|
[qtView performSelectorOnMainThread:@selector(pause:) withObject:self waitUntilDone:NO]; |
| 328 |
|
|
} |
| 329 |
masaki |
56 |
- (void)stop |
| 330 |
|
|
{ |
| 331 |
|
|
[qtView performSelectorOnMainThread:@selector(pause:) withObject:self waitUntilDone:YES]; |
| 332 |
|
|
} |
| 333 |
masaki |
3 |
- (void)enterFullScreen |
| 334 |
masaki |
2 |
{ |
| 335 |
masakih |
337 |
NSWindow *fullscreen = [self fullscreenWindow]; |
| 336 |
masaki |
3 |
|
| 337 |
masaki |
156 |
normalModeSavedFrame = [qtView frame]; |
| 338 |
masaki |
17 |
|
| 339 |
masaki |
144 |
XspfQTMovieWindow *player = (XspfQTMovieWindow *)[self window]; |
| 340 |
masaki |
143 |
NSRect originalWFrame = [player frame]; |
| 341 |
masaki |
17 |
|
| 342 |
masakih |
338 |
[self hideMenuBar]; |
| 343 |
masaki |
17 |
|
| 344 |
masaki |
143 |
NSRect newWFrame = [[NSScreen mainScreen] frame]; |
| 345 |
|
|
|
| 346 |
masaki |
148 |
newWFrame.size.width += windowSizeWithoutQTView.width; |
| 347 |
|
|
newWFrame.size.height += windowSizeWithoutQTView.height; |
| 348 |
|
|
newWFrame.origin.y -= windowSizeWithoutQTView.height; |
| 349 |
masaki |
143 |
|
| 350 |
masaki |
156 |
isChangingFullScreen = YES; |
| 351 |
|
|
[player setIsChangingFullScreen:YES]; |
| 352 |
masaki |
147 |
|
| 353 |
masaki |
143 |
[player setFrame:newWFrame display:YES animate:YES]; |
| 354 |
masaki |
147 |
|
| 355 |
masaki |
156 |
[player setIsChangingFullScreen:NO]; |
| 356 |
|
|
isChangingFullScreen = NO; |
| 357 |
masaki |
143 |
|
| 358 |
masakih |
337 |
[fullscreen setContentView:qtView]; |
| 359 |
|
|
[fullscreen makeKeyAndOrderFront:self]; |
| 360 |
masaki |
143 |
|
| 361 |
masakih |
337 |
[fullscreen makeFirstResponder:qtView]; |
| 362 |
masaki |
143 |
|
| 363 |
|
|
[player orderOut:self]; |
| 364 |
|
|
[player setFrame:originalWFrame display:NO]; |
| 365 |
masakih |
337 |
|
| 366 |
|
|
[fullscreen makeKeyAndOrderFront:self]; |
| 367 |
masaki |
2 |
} |
| 368 |
masaki |
3 |
- (void)exitFullScreen |
| 369 |
masaki |
2 |
{ |
| 370 |
masaki |
144 |
XspfQTMovieWindow *player = (XspfQTMovieWindow *)[self window]; |
| 371 |
|
|
NSRect originalWFrame = [player frame]; |
| 372 |
|
|
|
| 373 |
|
|
// calculate new Window frame. |
| 374 |
|
|
NSRect windowRect = originalWFrame; |
| 375 |
|
|
NSSize movieSize = [[[self qtMovie] attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; |
| 376 |
|
|
if(movieSize.width != 0) { |
| 377 |
masaki |
156 |
CGFloat newViewHeight = normalModeSavedFrame.size.width * (movieSize.height / movieSize.width); |
| 378 |
masaki |
144 |
|
| 379 |
|
|
windowRect.size.height = newViewHeight + windowSizeWithoutQTView.height; |
| 380 |
|
|
windowRect.origin.y -= windowRect.size.height - originalWFrame.size.height + [player titlebarHeight]; |
| 381 |
|
|
} |
| 382 |
|
|
|
| 383 |
masaki |
156 |
isChangingFullScreen = YES; |
| 384 |
|
|
[player setIsChangingFullScreen:YES]; |
| 385 |
masaki |
144 |
|
| 386 |
|
|
// caluculate screen size window frame. |
| 387 |
|
|
NSRect screenWFrame = [[NSScreen mainScreen] frame]; |
| 388 |
|
|
screenWFrame.size.width += windowSizeWithoutQTView.width; |
| 389 |
|
|
screenWFrame.size.height += windowSizeWithoutQTView.height; |
| 390 |
|
|
screenWFrame.origin.y -= windowSizeWithoutQTView.height; |
| 391 |
|
|
[player setFrame:screenWFrame display:NO]; |
| 392 |
|
|
|
| 393 |
masaki |
156 |
isChangingFullScreen = NO; |
| 394 |
masaki |
144 |
|
| 395 |
masaki |
151 |
// move QTView. |
| 396 |
masaki |
17 |
[qtView retain]; |
| 397 |
|
|
{ |
| 398 |
masaki |
154 |
// [qtView removeFromSuperview]; |
| 399 |
masaki |
144 |
NSRect fViewRec = [qtView frame]; |
| 400 |
masaki |
154 |
|
| 401 |
|
|
// for do not flushing qtview. |
| 402 |
|
|
[fullscreenWindow setContentView:[[[NSView alloc] initWithFrame:fViewRec] autorelease]]; |
| 403 |
|
|
|
| 404 |
masaki |
144 |
fViewRec.origin.y += windowSizeWithoutQTView.height - [player titlebarHeight]; |
| 405 |
|
|
[qtView setFrame:fViewRec]; |
| 406 |
|
|
[[player contentView] addSubview:qtView]; |
| 407 |
masaki |
17 |
} |
| 408 |
|
|
[qtView release]; |
| 409 |
|
|
|
| 410 |
masaki |
191 |
[player makeKeyAndOrderFront:self]; |
| 411 |
masaki |
144 |
[player makeFirstResponder:qtView]; |
| 412 |
masaki |
132 |
|
| 413 |
masaki |
154 |
[fullscreenWindow orderOut:self]; |
| 414 |
masaki |
107 |
|
| 415 |
masaki |
144 |
[player setFrame:windowRect display:YES animate:YES]; |
| 416 |
|
|
|
| 417 |
masakih |
338 |
[self showMenuBar]; |
| 418 |
masaki |
156 |
[player setIsChangingFullScreen:NO]; |
| 419 |
masaki |
3 |
} |
| 420 |
masaki |
10 |
|
| 421 |
|
|
- (NSWindow *)fullscreenWindow |
| 422 |
|
|
{ |
| 423 |
|
|
if(fullscreenWindow) return fullscreenWindow; |
| 424 |
|
|
|
| 425 |
|
|
NSRect mainScreenRect = [[NSScreen mainScreen] frame]; |
| 426 |
masaki |
72 |
fullscreenWindow = [[XspfQTFullScreenWindow alloc] initWithContentRect:mainScreenRect |
| 427 |
masaki |
132 |
styleMask:NSBorderlessWindowMask |
| 428 |
|
|
backing:NSBackingStoreBuffered |
| 429 |
|
|
defer:YES]; |
| 430 |
masaki |
10 |
[fullscreenWindow setReleasedWhenClosed:NO]; |
| 431 |
|
|
[fullscreenWindow setBackgroundColor:[NSColor blackColor]]; |
| 432 |
|
|
[fullscreenWindow setDelegate:self]; |
| 433 |
masaki |
49 |
[fullscreenWindow setWindowController:self]; |
| 434 |
masaki |
10 |
|
| 435 |
|
|
return fullscreenWindow; |
| 436 |
|
|
} |
| 437 |
masakih |
338 |
- (void)hideMenuBar |
| 438 |
|
|
{ |
| 439 |
|
|
if(![NSApp respondsToSelector:@selector(setPresentationOptions:)]) { |
| 440 |
|
|
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
| 441 |
|
|
return; |
| 442 |
|
|
} |
| 443 |
|
|
|
| 444 |
|
|
NSApplicationPresentationOptions currentPresentation = [NSApp presentationOptions]; |
| 445 |
|
|
[NSApp setPresentationOptions: |
| 446 |
|
|
currentPresentation | (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)]; |
| 447 |
|
|
} |
| 448 |
|
|
- (void)showMenuBar |
| 449 |
|
|
{ |
| 450 |
|
|
if(![NSApp respondsToSelector:@selector(setPresentationOptions:)]) { |
| 451 |
|
|
[NSMenu setMenuBarVisible:YES]; |
| 452 |
|
|
return; |
| 453 |
|
|
} |
| 454 |
|
|
|
| 455 |
|
|
NSApplicationPresentationOptions currentPresentation = [NSApp presentationOptions]; |
| 456 |
|
|
[NSApp setPresentationOptions: |
| 457 |
|
|
currentPresentation ^ (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)]; |
| 458 |
|
|
} |
| 459 |
masaki |
10 |
#pragma mark ### Actions ### |
| 460 |
masaki |
14 |
- (IBAction)togglePlayAndPause:(id)sender |
| 461 |
|
|
{ |
| 462 |
|
|
if([[self valueForKeyPath:@"document.trackList.isPlayed"] boolValue]) { |
| 463 |
|
|
[self pause]; |
| 464 |
|
|
} else { |
| 465 |
|
|
[self play]; |
| 466 |
|
|
} |
| 467 |
|
|
} |
| 468 |
|
|
|
| 469 |
masaki |
3 |
- (IBAction)turnUpVolume:(id)sender |
| 470 |
|
|
{ |
| 471 |
masaki |
135 |
NSNumber *cv = [self valueForKeyPath:kVolumeKeyPath]; |
| 472 |
masaki |
3 |
cv = [NSNumber numberWithFloat:[cv floatValue] + sVolumeDelta]; |
| 473 |
masaki |
135 |
[self setValue:cv forKeyPath:kVolumeKeyPath]; |
| 474 |
masaki |
3 |
} |
| 475 |
|
|
- (IBAction)turnDownVolume:(id)sender |
| 476 |
|
|
{ |
| 477 |
masaki |
135 |
NSNumber *cv = [self valueForKeyPath:kVolumeKeyPath]; |
| 478 |
masaki |
3 |
cv = [NSNumber numberWithFloat:[cv floatValue] - sVolumeDelta]; |
| 479 |
masaki |
135 |
[self setValue:cv forKeyPath:kVolumeKeyPath]; |
| 480 |
masaki |
3 |
} |
| 481 |
|
|
- (IBAction)toggleFullScreenMode:(id)sender |
| 482 |
|
|
{ |
| 483 |
masaki |
10 |
if(fullScreenMode) { |
| 484 |
masaki |
3 |
[self exitFullScreen]; |
| 485 |
masaki |
10 |
fullScreenMode = NO; |
| 486 |
masaki |
2 |
} else { |
| 487 |
masaki |
3 |
[self enterFullScreen]; |
| 488 |
masaki |
10 |
fullScreenMode = YES; |
| 489 |
masaki |
2 |
} |
| 490 |
|
|
} |
| 491 |
|
|
|
| 492 |
masaki |
4 |
- (IBAction)forwardTagValueSecends:(id)sender |
| 493 |
|
|
{ |
| 494 |
|
|
if(![sender respondsToSelector:@selector(tag)]) return; |
| 495 |
|
|
|
| 496 |
|
|
int tag = [sender tag]; |
| 497 |
|
|
if(tag == 0) return; |
| 498 |
|
|
|
| 499 |
|
|
QTTime current = [[self qtMovie] currentTime]; |
| 500 |
|
|
NSTimeInterval cur; |
| 501 |
|
|
if(!QTGetTimeInterval(current, &cur)) return; |
| 502 |
|
|
|
| 503 |
|
|
QTTime new = QTMakeTimeWithTimeInterval(cur + tag); |
| 504 |
masaki |
9 |
[[self qtMovie] setCurrentTime:new]; |
| 505 |
masaki |
4 |
} |
| 506 |
|
|
- (IBAction)backwardTagValueSecends:(id)sender |
| 507 |
|
|
{ |
| 508 |
|
|
if(![sender respondsToSelector:@selector(tag)]) return; |
| 509 |
|
|
|
| 510 |
|
|
int tag = [sender tag]; |
| 511 |
|
|
if(tag == 0) return; |
| 512 |
|
|
|
| 513 |
|
|
QTTime current = [[self qtMovie] currentTime]; |
| 514 |
|
|
NSTimeInterval cur; |
| 515 |
|
|
if(!QTGetTimeInterval(current, &cur)) return; |
| 516 |
|
|
|
| 517 |
|
|
QTTime new = QTMakeTimeWithTimeInterval(cur - tag); |
| 518 |
masaki |
9 |
[[self qtMovie] setCurrentTime:new]; |
| 519 |
masaki |
4 |
} |
| 520 |
masaki |
24 |
- (IBAction)nextTrack:(id)sender |
| 521 |
|
|
{ |
| 522 |
masaki |
49 |
[qtView pause:sender]; |
| 523 |
masaki |
24 |
[[[self document] trackList] next]; |
| 524 |
|
|
} |
| 525 |
|
|
- (IBAction)previousTrack:(id)sender |
| 526 |
|
|
{ |
| 527 |
masaki |
49 |
[qtView pause:sender]; |
| 528 |
masaki |
24 |
[[[self document] trackList] previous]; |
| 529 |
|
|
} |
| 530 |
masaki |
4 |
|
| 531 |
masakih |
329 |
- (IBAction)gotoThumbnailFrame:(id)sender |
| 532 |
|
|
{ |
| 533 |
|
|
HMXSPFComponent *trackList = [[self document] trackList]; |
| 534 |
|
|
HMXSPFComponent *thumbnailTrack = [trackList thumbnailTrack]; |
| 535 |
|
|
NSTimeInterval time = [trackList thumbnailTimeInterval]; |
| 536 |
|
|
|
| 537 |
|
|
NSUInteger num = [trackList indexOfChild:thumbnailTrack]; |
| 538 |
|
|
if(num == NSNotFound) return; |
| 539 |
|
|
|
| 540 |
|
|
[trackList setSelectionIndex:num]; |
| 541 |
|
|
|
| 542 |
|
|
QTTime new = QTMakeTimeWithTimeInterval(time); |
| 543 |
|
|
[[self qtMovie] setCurrentTime:new]; |
| 544 |
|
|
} |
| 545 |
|
|
|
| 546 |
masaki |
134 |
- (IBAction)normalSize:(id)sender |
| 547 |
|
|
{ |
| 548 |
|
|
if(fullScreenMode) return; |
| 549 |
|
|
|
| 550 |
|
|
QTMovie *curMovie = [self qtMovie]; |
| 551 |
|
|
if(!curMovie) return; |
| 552 |
|
|
|
| 553 |
|
|
NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; |
| 554 |
|
|
if(movieSize.width == 0) return; |
| 555 |
|
|
|
| 556 |
|
|
[self setMovieSize:movieSize]; |
| 557 |
|
|
} |
| 558 |
|
|
- (IBAction)halfSize:(id)sender |
| 559 |
|
|
{ |
| 560 |
|
|
if(fullScreenMode) return; |
| 561 |
|
|
|
| 562 |
|
|
QTMovie *curMovie = [self qtMovie]; |
| 563 |
|
|
if(!curMovie) return; |
| 564 |
|
|
|
| 565 |
|
|
NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; |
| 566 |
|
|
if(movieSize.width == 0) return; |
| 567 |
|
|
|
| 568 |
|
|
movieSize.width *= 0.5; |
| 569 |
|
|
movieSize.height *= 0.5; |
| 570 |
|
|
|
| 571 |
|
|
[self setMovieSize:movieSize]; |
| 572 |
|
|
} |
| 573 |
|
|
- (IBAction)doubleSize:(id)sender |
| 574 |
|
|
{ |
| 575 |
|
|
if(fullScreenMode) return; |
| 576 |
|
|
|
| 577 |
|
|
QTMovie *curMovie = [self qtMovie]; |
| 578 |
|
|
if(!curMovie) return; |
| 579 |
|
|
|
| 580 |
|
|
NSSize movieSize = [[curMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; |
| 581 |
|
|
if(movieSize.width == 0) return; |
| 582 |
|
|
|
| 583 |
|
|
movieSize.width *= 2; |
| 584 |
|
|
movieSize.height *= 2; |
| 585 |
|
|
|
| 586 |
|
|
[self setMovieSize:movieSize]; |
| 587 |
|
|
} |
| 588 |
masaki |
135 |
- (IBAction)screenSize:(id)sender |
| 589 |
|
|
{ |
| 590 |
masakih |
319 |
if(fullScreenMode) return; |
| 591 |
|
|
|
| 592 |
|
|
NSSize screenSize = [[NSScreen mainScreen] visibleFrame].size; |
| 593 |
|
|
NSSize windowDecorationSize = [self windowSizeWithoutQTView]; |
| 594 |
|
|
NSRect windowFrame = [[self window] frame]; |
| 595 |
|
|
NSSize movieSize = windowFrame.size; |
| 596 |
|
|
NSSize newSize; |
| 597 |
|
|
|
| 598 |
|
|
movieSize.width -= windowDecorationSize.width; |
| 599 |
|
|
movieSize.height -= windowDecorationSize.height; |
| 600 |
|
|
screenSize.height -= windowDecorationSize.height; |
| 601 |
|
|
|
| 602 |
|
|
if(movieSize.height == 0) return; |
| 603 |
|
|
|
| 604 |
|
|
newSize.height = screenSize.height; |
| 605 |
|
|
newSize.width = newSize.height * (movieSize.width / movieSize.height); |
| 606 |
|
|
|
| 607 |
|
|
newSize.height += windowDecorationSize.height; |
| 608 |
|
|
newSize.width += windowDecorationSize.width; |
| 609 |
|
|
|
| 610 |
|
|
windowFrame.size = newSize; |
| 611 |
|
|
windowFrame.origin.y = [[NSScreen mainScreen] visibleFrame].origin.y; |
| 612 |
|
|
[[self window] setFrame:windowFrame display:YES animate:YES]; |
| 613 |
masaki |
135 |
} |
| 614 |
masaki |
134 |
|
| 615 |
masaki |
10 |
#pragma mark ### Notification & Timer ### |
| 616 |
masaki |
151 |
- (void)movieDidEndNotification:(id)notification |
| 617 |
masaki |
2 |
{ |
| 618 |
|
|
[[[self document] trackList] next]; |
| 619 |
|
|
} |
| 620 |
masaki |
298 |
|
| 621 |
|
|
// call from XspfQTMovieTimer. |
| 622 |
masaki |
2 |
- (void)updateTimeIfNeeded:(id)timer |
| 623 |
|
|
{ |
| 624 |
|
|
QTMovie *qt = [self qtMovie]; |
| 625 |
|
|
if(qt) { |
| 626 |
masaki |
10 |
// force update time indicator. |
| 627 |
masaki |
2 |
[qt willChangeValueForKey:@"currentTime"]; |
| 628 |
|
|
[qt didChangeValueForKey:@"currentTime"]; |
| 629 |
|
|
} |
| 630 |
masaki |
3 |
|
| 631 |
|
|
// Hide cursor and controller, if mouse didn't move for 3 seconds. |
| 632 |
|
|
NSPoint mouse = [NSEvent mouseLocation]; |
| 633 |
|
|
if(!NSEqualPoints(prevMouse, mouse)) { |
| 634 |
|
|
prevMouse = mouse; |
| 635 |
|
|
[prevMouseMovedDate autorelease]; |
| 636 |
|
|
prevMouseMovedDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain]; |
| 637 |
masaki |
10 |
} else if(fullScreenMode && [prevMouseMovedDate timeIntervalSinceNow] < -3.0 ) { |
| 638 |
masaki |
3 |
[NSCursor setHiddenUntilMouseMoves:YES]; |
| 639 |
|
|
// |
| 640 |
|
|
// hide controller. |
| 641 |
|
|
} |
| 642 |
masaki |
2 |
} |
| 643 |
|
|
|
| 644 |
masaki |
10 |
#pragma mark ### NSResponder ### |
| 645 |
masaki |
2 |
- (void)cancelOperation:(id)sender |
| 646 |
|
|
{ |
| 647 |
masaki |
10 |
if(fullScreenMode) { |
| 648 |
masaki |
2 |
[self toggleFullScreenMode:self]; |
| 649 |
|
|
} |
| 650 |
|
|
} |
| 651 |
|
|
|
| 652 |
masaki |
10 |
#pragma mark ### NSMenu valivation ### |
| 653 |
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem |
| 654 |
|
|
{ |
| 655 |
masakih |
329 |
SEL action = [menuItem action]; |
| 656 |
|
|
if(action == @selector(toggleFullScreenMode:)) { |
| 657 |
masaki |
10 |
if(fullScreenMode) { |
| 658 |
|
|
[menuItem setTitle:NSLocalizedString(@"Exit Full Screen", @"Exit Full Screen")]; |
| 659 |
|
|
} else { |
| 660 |
|
|
[menuItem setTitle:NSLocalizedString(@"Full Screen", @"Full Screen")]; |
| 661 |
|
|
} |
| 662 |
|
|
return YES; |
| 663 |
|
|
} |
| 664 |
|
|
|
| 665 |
masakih |
329 |
if(action == @selector(gotoThumbnailFrame:)) { |
| 666 |
|
|
if(![[[self document] trackList] thumbnailTrack]) return NO; |
| 667 |
|
|
} |
| 668 |
|
|
|
| 669 |
|
|
if(action == @selector(normalSize:) |
| 670 |
|
|
|| action == @selector(halfSize:) |
| 671 |
|
|
|| action == @selector(doubleSize:) |
| 672 |
|
|
|| action == @selector(screenSize:)) { |
| 673 |
masaki |
139 |
if(fullScreenMode) { |
| 674 |
|
|
return NO; |
| 675 |
|
|
} else { |
| 676 |
|
|
return YES; |
| 677 |
|
|
} |
| 678 |
|
|
} |
| 679 |
|
|
|
| 680 |
masaki |
10 |
return YES; |
| 681 |
|
|
} |
| 682 |
|
|
|
| 683 |
masaki |
100 |
#pragma mark ### XspfQTDocument Notification ### |
| 684 |
|
|
- (void)documentWillClose:(NSNotification *)notification |
| 685 |
masaki |
2 |
{ |
| 686 |
masaki |
100 |
id doc = [notification object]; |
| 687 |
masaki |
272 |
|
| 688 |
masaki |
10 |
if(fullScreenMode) { |
| 689 |
masaki |
2 |
[self toggleFullScreenMode:self]; |
| 690 |
|
|
} |
| 691 |
masaki |
100 |
|
| 692 |
|
|
[doc removeObserver:self forKeyPath:kQTMovieKeyPath]; |
| 693 |
|
|
[doc removeObserver:self forKeyPath:kIsPlayedKeyPath]; |
| 694 |
|
|
|
| 695 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 696 |
|
|
[nc removeObserver:self name:XspfQTDocumentWillCloseNotification object:doc]; |
| 697 |
masaki |
2 |
} |
| 698 |
|
|
|
| 699 |
masaki |
10 |
#pragma mark ### NSWindow Delegate ### |
| 700 |
masaki |
2 |
- (BOOL)windowShouldClose:(id)sender |
| 701 |
|
|
{ |
| 702 |
|
|
[qtView pause:self]; |
| 703 |
|
|
[self setQtMovie:nil]; |
| 704 |
masaki |
298 |
|
| 705 |
masaki |
2 |
return YES; |
| 706 |
|
|
} |
| 707 |
|
|
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize |
| 708 |
|
|
{ |
| 709 |
masaki |
156 |
if(isChangingFullScreen) return frameSize; |
| 710 |
masaki |
143 |
|
| 711 |
masaki |
2 |
return [self fitSizeToSize:frameSize]; |
| 712 |
|
|
} |
| 713 |
masaki |
16 |
- (void)windowDidMove:(NSNotification *)notification |
| 714 |
|
|
{ |
| 715 |
|
|
if(fullscreenWindow && [notification object] == fullscreenWindow) { |
| 716 |
|
|
NSRect r = [fullscreenWindow frame]; |
| 717 |
masaki |
45 |
if(!NSEqualPoints(r.origin, NSZeroPoint)) { |
| 718 |
masaki |
16 |
[fullscreenWindow setFrameOrigin:NSZeroPoint]; |
| 719 |
|
|
} |
| 720 |
|
|
} |
| 721 |
|
|
} |
| 722 |
masaki |
2 |
@end |