1 /*****************************************************************************
2 * MainWindow.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2011 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Derk-Jan Hartman <hartman at videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #import "CompatibilityFixes.h"
28 #import "MainWindow.h"
30 #import "CoreInteraction.h"
31 #import "AudioEffects.h"
34 #import "controls.h" // TODO: remove me
35 #import "SideBarItem.h"
36 #import "MainWindowTitle.h"
37 #import <vlc_playlist.h>
38 #import <vlc_aout_intf.h>
40 #import <vlc_strings.h>
41 #import <vlc_services_discovery.h>
43 @implementation VLCMainWindow
44 static VLCMainWindow *_o_sharedInstance = nil;
46 + (VLCMainWindow *)sharedInstance
48 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
52 #pragma mark Initialization
56 if( _o_sharedInstance)
59 return _o_sharedInstance;
63 o_fspanel = [[VLCFSPanel alloc] init];
64 _o_sharedInstance = [super init];
67 return _o_sharedInstance;
70 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
71 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
73 b_dark_interface = config_GetInt( VLCIntf, "macosx-interfacestyle" );
77 #ifdef MAC_OS_X_VERSION_10_7
78 styleMask = NSBorderlessWindowMask | NSResizableWindowMask;
80 styleMask = NSBorderlessWindowMask;
84 self = [super initWithContentRect:contentRect styleMask:styleMask
85 backing:backingType defer:flag];
87 [[VLCMain sharedInstance] updateTogglePlaylistState];
89 /* we want to be moveable regardless of our style */
90 [self setMovableByWindowBackground: YES];
92 /* we don't want this window to be restored on relaunch */
94 [self setRestorable:NO];
99 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
101 /* We indeed want to prioritize Cocoa key equivalent against libvlc,
102 so we perform the menu equivalent now. */
103 if([[NSApp mainMenu] performKeyEquivalent:o_event])
106 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] || [(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event];
111 [[NSNotificationCenter defaultCenter] removeObserver: self];
112 config_PutInt( VLCIntf->p_libvlc, "volume", i_lastShownVolume );
113 [self saveFrameUsingName: [self frameAutosaveName]];
114 [o_sidebaritems release];
120 /* setup the styled interface */
121 b_nativeFullscreenMode = config_GetInt( VLCIntf, "macosx-nativefullscreenmode" );
122 i_lastShownVolume = -1;
124 [o_play_btn setToolTip: _NS("Play/Pause")];
125 [o_bwd_btn setToolTip: _NS("Backward")];
126 [o_fwd_btn setToolTip: _NS("Forward")];
127 [o_stop_btn setToolTip: _NS("Stop")];
128 [o_playlist_btn setToolTip: _NS("Show/Hide Playlist")];
129 [o_repeat_btn setToolTip: _NS("Repeat")];
130 [o_shuffle_btn setToolTip: _NS("Shuffle")];
131 [o_effects_btn setToolTip: _NS("Effects")];
132 [o_fullscreen_btn setToolTip: _NS("Toggle Fullscreen mode")];
133 [[o_search_fld cell] setPlaceholderString: _NS("Search")];
134 [o_volume_sld setToolTip: _NS("Volume")];
135 [o_volume_down_btn setToolTip: _NS("Mute")];
136 [o_volume_up_btn setToolTip: _NS("Full Volume")];
137 [o_time_sld setToolTip: _NS("Position")];
138 [o_dropzone_btn setTitle: _NS("Open media...")];
139 [o_dropzone_lbl setStringValue: _NS("Drop media here")];
141 if (!b_dark_interface) {
142 [o_bottombar_view setImage: [NSImage imageNamed:@"bottom-background"]];
143 [o_bwd_btn setImage: [NSImage imageNamed:@"back"]];
144 [o_bwd_btn setAlternateImage: [NSImage imageNamed:@"back-pressed"]];
145 o_play_img = [[NSImage imageNamed:@"play"] retain];
146 o_play_pressed_img = [[NSImage imageNamed:@"play-pressed"] retain];
147 o_pause_img = [[NSImage imageNamed:@"pause"] retain];
148 o_pause_pressed_img = [[NSImage imageNamed:@"pause-pressed"] retain];
149 [o_fwd_btn setImage: [NSImage imageNamed:@"forward"]];
150 [o_fwd_btn setAlternateImage: [NSImage imageNamed:@"forward-pressed"]];
151 [o_stop_btn setImage: [NSImage imageNamed:@"stop"]];
152 [o_stop_btn setAlternateImage: [NSImage imageNamed:@"stop-pressed"]];
153 [o_playlist_btn setImage: [NSImage imageNamed:@"playlist"]];
154 [o_playlist_btn setAlternateImage: [NSImage imageNamed:@"playlist-pressed"]];
155 o_repeat_img = [[NSImage imageNamed:@"repeat"] retain];
156 o_repeat_pressed_img = [[NSImage imageNamed:@"repeat-pressed"] retain];
157 o_repeat_all_img = [[NSImage imageNamed:@"repeat-all"] retain];
158 o_repeat_all_pressed_img = [[NSImage imageNamed:@"repeat-all-pressed"] retain];
159 o_repeat_one_img = [[NSImage imageNamed:@"repeat-one"] retain];
160 o_repeat_one_pressed_img = [[NSImage imageNamed:@"repeat-one-pressed"] retain];
161 o_shuffle_img = [[NSImage imageNamed:@"shuffle"] retain];
162 o_shuffle_pressed_img = [[NSImage imageNamed:@"shuffle-pressed"] retain];
163 o_shuffle_on_img = [[NSImage imageNamed:@"shuffle-blue"] retain];
164 o_shuffle_on_pressed_img = [[NSImage imageNamed:@"shuffle-blue-pressed"] retain];
165 [o_time_sld_background setImagesLeft: [NSImage imageNamed:@"progression-track-wrapper-left"] middle: [NSImage imageNamed:@"progression-track-wrapper-middle"] right: [NSImage imageNamed:@"progression-track-wrapper-right"]];
166 [o_volume_down_btn setImage: [NSImage imageNamed:@"volume-low"]];
167 [o_volume_track_view setImage: [NSImage imageNamed:@"volume-slider-track"]];
168 [o_volume_up_btn setImage: [NSImage imageNamed:@"volume-high"]];
169 if (OSX_LION && b_nativeFullscreenMode)
171 [o_effects_btn setImage: [NSImage imageNamed:@"effects-one-button"]];
172 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-one-button-blue"]];
176 [o_effects_btn setImage: [NSImage imageNamed:@"effects-double-buttons"]];
177 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-double-buttons-pressed"]];
179 [o_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-double-buttons"]];
180 [o_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-double-buttons-pressed"]];
181 [o_time_sld_fancygradient_view setImagesLeft:[NSImage imageNamed:@"progression-fill-left"] middle:[NSImage imageNamed:@"progression-fill-middle"] right:[NSImage imageNamed:@"progression-fill-right"]];
185 [o_bottombar_view setImage: [NSImage imageNamed:@"bottom-background_dark"]];
186 [o_bwd_btn setImage: [NSImage imageNamed:@"back_dark"]];
187 [o_bwd_btn setAlternateImage: [NSImage imageNamed:@"back-pressed_dark"]];
188 o_play_img = [[NSImage imageNamed:@"play_dark"] retain];
189 o_play_pressed_img = [[NSImage imageNamed:@"play-pressed_dark"] retain];
190 o_pause_img = [[NSImage imageNamed:@"pause_dark"] retain];
191 o_pause_pressed_img = [[NSImage imageNamed:@"pause-pressed_dark"] retain];
192 [o_fwd_btn setImage: [NSImage imageNamed:@"forward_dark"]];
193 [o_fwd_btn setAlternateImage: [NSImage imageNamed:@"forward-pressed_dark"]];
194 [o_stop_btn setImage: [NSImage imageNamed:@"stop_dark"]];
195 [o_stop_btn setAlternateImage: [NSImage imageNamed:@"stop-pressed_dark"]];
196 [o_playlist_btn setImage: [NSImage imageNamed:@"playlist_dark"]];
197 [o_playlist_btn setAlternateImage: [NSImage imageNamed:@"playlist-pressed_dark"]];
198 o_repeat_img = [[NSImage imageNamed:@"repeat_dark"] retain];
199 o_repeat_pressed_img = [[NSImage imageNamed:@"repeat-pressed_dark"] retain];
200 o_repeat_all_img = [[NSImage imageNamed:@"repeat-all-blue_dark"] retain];
201 o_repeat_all_pressed_img = [[NSImage imageNamed:@"repeat-all-blue-pressed_dark"] retain];
202 o_repeat_one_img = [[NSImage imageNamed:@"repeat-one-blue_dark"] retain];
203 o_repeat_one_pressed_img = [[NSImage imageNamed:@"repeat-one-blue-pressed_dark"] retain];
204 o_shuffle_img = [[NSImage imageNamed:@"shuffle_dark"] retain];
205 o_shuffle_pressed_img = [[NSImage imageNamed:@"shuffle-pressed_dark"] retain];
206 o_shuffle_on_img = [[NSImage imageNamed:@"shuffle-blue_dark"] retain];
207 o_shuffle_on_pressed_img = [[NSImage imageNamed:@"shuffle-blue-pressed_dark"] retain];
208 [o_time_fld setTextColor: [NSColor colorWithCalibratedRed:229.0 green:229.0 blue:229.0 alpha:100.0]];
209 [o_time_sld_background setImagesLeft: [NSImage imageNamed:@"progression-track-wrapper-left_dark"] middle: [NSImage imageNamed:@"progression-track-wrapper-middle_dark"] right: [NSImage imageNamed:@"progression-track-wrapper-right_dark"]];
210 [o_volume_down_btn setImage: [NSImage imageNamed:@"volume-low_dark"]];
211 [o_volume_track_view setImage: [NSImage imageNamed:@"volume-slider-track_dark"]];
212 [o_volume_up_btn setImage: [NSImage imageNamed:@"volume-high_dark"]];
213 if (OSX_LION && b_nativeFullscreenMode)
215 [o_effects_btn setImage: [NSImage imageNamed:@"effects-one-button_dark"]];
216 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-one-button-blue_dark"]];
220 [o_effects_btn setImage: [NSImage imageNamed:@"effects-double-buttons_dark"]];
221 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-double-buttons-pressed_dark"]];
223 [o_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-double-buttons_dark"]];
224 [o_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-double-buttons-pressed_dark"]];
225 [o_time_sld_fancygradient_view setImagesLeft:[NSImage imageNamed:@"progressbar-fill-left_dark"] middle:[NSImage imageNamed:@"progressbar-fill-middle_dark"] right:[NSImage imageNamed:@"progressbar-fill-right_dark"]];
227 [o_repeat_btn setImage: o_repeat_img];
228 [o_repeat_btn setAlternateImage: o_repeat_pressed_img];
229 [o_shuffle_btn setImage: o_shuffle_img];
230 [o_shuffle_btn setAlternateImage: o_shuffle_pressed_img];
231 [o_play_btn setImage: o_play_img];
232 [o_play_btn setAlternateImage: o_play_pressed_img];
234 /* interface builder action */
235 [self setDelegate: self];
236 [self setExcludedFromWindowsMenu: YES];
237 [self setAcceptsMouseMovedEvents: YES];
238 // Set that here as IB seems to be buggy
239 if (b_dark_interface)
240 [self setContentMinSize:NSMakeSize(500., (288. + [o_titlebar_view frame].size.height))];
242 [self setContentMinSize:NSMakeSize(500., 288.)];
243 [self setTitle: _NS("VLC media player")];
244 [o_playlist_btn setEnabled:NO];
245 o_temp_view = [[NSView alloc] init];
246 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
247 [o_dropzone_view setFrame: [o_playlist_table frame]];
248 [o_left_split_view setFrame: [o_sidebar_view frame]];
249 if (OSX_LION && b_nativeFullscreenMode)
251 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
253 float f_width = [o_fullscreen_btn frame].size.width;
255 #define moveItem( item ) \
256 frame = [item frame]; \
257 frame.origin.x = f_width + frame.origin.x; \
258 [item setFrame: frame]
260 moveItem( o_effects_btn );
261 moveItem( o_volume_up_btn );
262 moveItem( o_volume_sld );
263 moveItem( o_volume_track_view );
264 moveItem( o_volume_down_btn );
265 moveItem( o_time_fld );
266 moveItem( o_time_sld_background );
269 #define enlargeItem( item ) \
270 frame = [item frame]; \
271 frame.size.width = f_width + frame.size.width; \
272 [item setFrame: frame]
274 enlargeItem( o_time_sld );
275 enlargeItem( o_progress_bar );
276 enlargeItem( o_time_sld_background );
277 enlargeItem( o_time_sld_fancygradient_view );
280 [o_fullscreen_btn removeFromSuperviewWithoutNeedingDisplay];
283 [o_titlebar_view setFullscreenButtonHidden: YES];
287 /* the default small size of the search field is slightly different on Lion, let's work-around that */
289 frame = [o_search_fld frame];
290 frame.origin.y = frame.origin.y + 2.0;
291 frame.size.height = frame.size.height - 1.0;
292 [o_search_fld setFrame: frame];
295 /* create the sidebar */
296 o_sidebaritems = [[NSMutableArray alloc] init];
297 SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
298 SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
299 [playlistItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
300 SideBarItem *mycompItem = [SideBarItem itemWithTitle:_NS("MY COMPUTER") identifier:@"mycomputer"];
301 SideBarItem *devicesItem = [SideBarItem itemWithTitle:_NS("DEVICES") identifier:@"devices"];
302 SideBarItem *lanItem = [SideBarItem itemWithTitle:_NS("LOCAL NETWORK") identifier:@"localnetwork"];
303 SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
305 /* SD subnodes, inspired by the Qt4 intf */
306 char **ppsz_longnames;
308 char **ppsz_names = vlc_sd_GetNames( pl_Get( VLCIntf ), &ppsz_longnames, &p_categories );
310 msg_Err( VLCIntf, "no sd item found" ); //TODO
311 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
312 int *p_category = p_categories;
313 NSMutableArray *internetItems = [[NSMutableArray alloc] init];
314 NSMutableArray *devicesItems = [[NSMutableArray alloc] init];
315 NSMutableArray *lanItems = [[NSMutableArray alloc] init];
316 NSMutableArray *mycompItems = [[NSMutableArray alloc] init];
317 NSString *o_identifier;
318 for (; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++)
320 o_identifier = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
321 o_identifier = [[o_identifier componentsSeparatedByString:@"{"] objectAtIndex:0];
322 switch (*p_category) {
323 case SD_CAT_INTERNET:
325 [internetItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
326 if (!strncmp( *ppsz_name, "podcast", 7 ))
327 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
329 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
334 [devicesItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
335 [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
340 [lanItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
341 [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
344 case SD_CAT_MYCOMPUTER:
346 [mycompItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
347 if (!strncmp( *ppsz_name, "video_dir", 9 ))
348 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
349 else if (!strncmp( *ppsz_name, "audio_dir", 9 ))
350 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
351 else if (!strncmp( *ppsz_name, "picture_dir", 11 ))
352 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
354 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
358 msg_Warn( VLCIntf, "unknown SD type found, skipping (%s)", *ppsz_name );
363 free( *ppsz_longname );
365 [mycompItem setChildren: [NSArray arrayWithArray: mycompItems]];
366 [devicesItem setChildren: [NSArray arrayWithArray: devicesItems]];
367 [lanItem setChildren: [NSArray arrayWithArray: lanItems]];
368 [internetItem setChildren: [NSArray arrayWithArray: internetItems]];
369 [mycompItems release];
370 [devicesItems release];
372 [internetItems release];
374 free( ppsz_longnames );
375 free( p_categories );
377 [libraryItem setChildren: [NSArray arrayWithObject: playlistItem]];
378 [o_sidebaritems addObject: libraryItem];
379 if ([mycompItem hasChildren])
380 [o_sidebaritems addObject: mycompItem];
381 if ([devicesItem hasChildren])
382 [o_sidebaritems addObject: devicesItem];
383 if ([lanItem hasChildren])
384 [o_sidebaritems addObject: lanItem];
385 if ([internetItem hasChildren])
386 [o_sidebaritems addObject: internetItem];
388 [o_sidebar_view reloadData];
389 [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:YES];
391 if( b_dark_interface )
393 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
394 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
397 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
398 winrect = [self frame];
400 [o_titlebar_view setFrame: NSMakeRect( 0, winrect.size.height - f_titleBarHeight,
401 winrect.size.width, f_titleBarHeight )];
402 [[self contentView] addSubview: o_titlebar_view];
404 winrect.size.height = winrect.size.height + f_titleBarHeight;
405 [self setFrame: winrect display:NO animate:NO];
406 winrect = [o_split_view frame];
407 winrect.size.height = winrect.size.height - f_titleBarHeight;
408 [o_split_view setFrame: winrect];
409 [o_video_view setFrame: winrect];
410 previousSavedFrame = winrect;
413 [o_resize_view setImage: NULL];
415 if ([self styleMask] & NSResizableWindowMask)
416 [o_resize_view removeFromSuperviewWithoutNeedingDisplay];
421 [o_video_view setFrame: [o_split_view frame]];
425 #pragma mark Button Actions
427 - (IBAction)play:(id)sender
429 [[VLCCoreInteraction sharedInstance] play];
432 - (void)resetPreviousButton
434 if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35) {
435 // seems like no further event occured, so let's switch the playback item
436 [[VLCCoreInteraction sharedInstance] previous];
437 just_triggered_previous = NO;
441 - (void)resetBackwardSkip
443 // the user stopped skipping, so let's allow him to change the item
444 if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35)
445 just_triggered_previous = NO;
448 - (IBAction)bwd:(id)sender
450 if(!just_triggered_previous)
452 just_triggered_previous = YES;
453 [self performSelector:@selector(resetPreviousButton)
459 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
461 // we just skipped 3 "continous" events, otherwise we are too fast
462 [[VLCCoreInteraction sharedInstance] backward];
463 last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
464 [self performSelector:@selector(resetBackwardSkip)
471 - (void)resetNextButton
473 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35) {
474 // seems like no further event occured, so let's switch the playback item
475 [[VLCCoreInteraction sharedInstance] next];
476 just_triggered_next = NO;
480 - (void)resetForwardSkip
482 // the user stopped skipping, so let's allow him to change the item
483 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35)
484 just_triggered_next = NO;
487 - (IBAction)fwd:(id)sender
489 if(!just_triggered_next)
491 just_triggered_next = YES;
492 [self performSelector:@selector(resetNextButton)
498 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
500 // we just skipped 3 "continous" events, otherwise we are too fast
501 [[VLCCoreInteraction sharedInstance] forward];
502 last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
503 [self performSelector:@selector(resetForwardSkip)
510 - (IBAction)stop:(id)sender
512 [[VLCCoreInteraction sharedInstance] stop];
515 - (IBAction)togglePlaylist:(id)sender
519 if ([o_video_view isHidden] && [o_playlist_btn isEnabled]) {
520 [o_split_view setHidden: YES];
521 [o_video_view setHidden: NO];
525 [o_video_view setHidden: YES];
526 [o_split_view setHidden: NO];
531 [o_split_view setHidden: NO];
532 [o_playlist_table setHidden: NO];
533 [o_video_view setHidden: ![[VLCMain sharedInstance] activeVideoPlayback]];
539 [o_repeat_btn setImage: o_repeat_one_img];
540 [o_repeat_btn setAlternateImage: o_repeat_one_pressed_img];
545 [o_repeat_btn setImage: o_repeat_all_img];
546 [o_repeat_btn setAlternateImage: o_repeat_all_pressed_img];
551 [o_repeat_btn setImage: o_repeat_img];
552 [o_repeat_btn setAlternateImage: o_repeat_pressed_img];
555 - (IBAction)repeat:(id)sender
557 vlc_value_t looping,repeating;
558 intf_thread_t * p_intf = VLCIntf;
559 playlist_t * p_playlist = pl_Get( p_intf );
561 var_Get( p_playlist, "repeat", &repeating );
562 var_Get( p_playlist, "loop", &looping );
564 if( !repeating.b_bool && !looping.b_bool )
566 /* was: no repeating at all, switching to Repeat One */
567 [[VLCCoreInteraction sharedInstance] repeatOne];
570 else if( repeating.b_bool && !looping.b_bool )
572 /* was: Repeat One, switching to Repeat All */
573 [[VLCCoreInteraction sharedInstance] repeatAll];
578 /* was: Repeat All or bug in VLC, switching to Repeat Off */
579 [[VLCCoreInteraction sharedInstance] repeatOff];
587 playlist_t *p_playlist = pl_Get( VLCIntf );
588 b_value = var_GetBool( p_playlist, "random" );
590 [o_shuffle_btn setImage: o_shuffle_on_img];
591 [o_shuffle_btn setAlternateImage: o_shuffle_on_pressed_img];
595 [o_shuffle_btn setImage: o_shuffle_img];
596 [o_shuffle_btn setAlternateImage: o_shuffle_pressed_img];
600 - (IBAction)shuffle:(id)sender
602 [[VLCCoreInteraction sharedInstance] shuffle];
606 - (IBAction)timeSliderAction:(id)sender
609 input_thread_t * p_input;
611 switch( [[NSApp currentEvent] type] )
614 case NSLeftMouseDown:
615 case NSLeftMouseDragged:
616 f_updated = [sender floatValue];
622 p_input = pl_CurrentInput( VLCIntf );
623 if( p_input != NULL )
628 char psz_time[MSTRTIME_MAX_SIZE];
630 pos.f_float = f_updated / 10000.;
631 var_Set( p_input, "position", pos );
632 [o_time_sld setFloatValue: f_updated];
634 var_Get( p_input, "time", &time );
636 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
637 if( [o_time_fld timeRemaining] && dur != -1 )
639 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000) )];
642 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
644 [o_time_fld setStringValue: o_time];
645 [o_fspanel setStreamPos: f_updated andTime: o_time];
646 vlc_object_release( p_input );
648 [self drawFancyGradientEffectForTimeSlider];
651 - (IBAction)volumeAction:(id)sender
653 if (sender == o_volume_sld)
654 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
655 else if (sender == o_volume_down_btn)
656 [[VLCCoreInteraction sharedInstance] mute];
658 [[VLCCoreInteraction sharedInstance] setVolume: 400];
661 - (IBAction)effects:(id)sender
663 [[VLCMainMenu sharedInstance] showAudioEffects: sender];
666 - (IBAction)fullscreen:(id)sender
668 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
671 - (IBAction)dropzoneButtonAction:(id)sender
673 [[[VLCMain sharedInstance] open] openFileGeneric];
677 #pragma mark overwritten default functionality
678 - (BOOL)canBecomeKeyWindow
683 - (void)setTitle:(NSString *)title
685 if (b_dark_interface)
686 [o_titlebar_view setWindowTitle: title];
687 [super setTitle: title];
690 - (void)performZoom:(id)sender
692 if (b_dark_interface)
693 [self customZoom: sender];
695 [super performZoom: sender];
698 - (void)zoom:(id)sender
700 if (b_dark_interface)
701 [self customZoom: sender];
703 [super zoom: sender];
707 * Given a proposed frame rectangle, return a modified version
708 * which will fit inside the screen.
710 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
711 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
712 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
713 * Copyright (C) 1996 Free Software Foundation, Inc.
715 - (NSRect) customConstrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
717 NSRect screenRect = [screen visibleFrame];
720 /* Move top edge of the window inside the screen */
721 difference = NSMaxY (frameRect) - NSMaxY (screenRect);
724 frameRect.origin.y -= difference;
727 /* If the window is resizable, resize it (if needed) so that the
728 bottom edge is on the screen or can be on the screen when the user moves
730 difference = NSMaxY (screenRect) - NSMaxY (frameRect);
731 if (_styleMask & NSResizableWindowMask)
735 difference2 = screenRect.origin.y - frameRect.origin.y;
736 difference2 -= difference;
737 // Take in account the space between the top of window and the top of the
738 // screen which can be used to move the bottom of the window on the screen
741 frameRect.size.height -= difference2;
742 frameRect.origin.y += difference2;
745 /* Ensure that resizing doesn't makewindow smaller than minimum */
746 difference2 = [self minSize].height - frameRect.size.height;
749 frameRect.size.height += difference2;
750 frameRect.origin.y -= difference2;
760 Zooms the receiver. This method calls the delegate method
761 windowShouldZoom:toFrame: to determine if the window should
762 be allowed to zoom to full screen.
764 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
765 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
766 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
767 * Copyright (C) 1996 Free Software Foundation, Inc.
769 - (void) customZoom: (id)sender
771 NSRect maxRect = [[self screen] visibleFrame];
772 NSRect currentFrame = [self frame];
774 if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)])
776 maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
779 maxRect = [self customConstrainFrameRect: maxRect toScreen: [self screen]];
781 // Compare the new frame with the current one
782 if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
783 && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
784 && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
785 && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST))
787 // Already in zoomed mode, reset user frame, if stored
788 if ([self frameAutosaveName] != nil)
790 [self setFrame: previousSavedFrame display: YES animate: YES];
791 [self saveFrameUsingName: [self frameAutosaveName]];
796 if ([self frameAutosaveName] != nil)
798 [self saveFrameUsingName: [self frameAutosaveName]];
799 previousSavedFrame = [self frame];
802 [self setFrame: maxRect display: YES animate: YES];
805 - (void)windowResizedOrMoved:(NSNotification *)notification
807 [self saveFrameUsingName: [self frameAutosaveName]];
811 #pragma mark Update interface and respond to foreign events
814 [o_right_split_view addSubview: o_dropzone_view];
815 [o_dropzone_view setFrame: [o_playlist_table frame]];
816 [[o_playlist_table animator] setHidden:YES];
821 [o_dropzone_view removeFromSuperview];
822 [[o_playlist_table animator] setHidden: NO];
825 - (void)updateTimeSlider
827 input_thread_t * p_input;
828 p_input = pl_CurrentInput( VLCIntf );
834 char psz_time[MSTRTIME_MAX_SIZE];
837 var_Get( p_input, "position", &pos );
838 f_updated = 10000. * pos.f_float;
839 [o_time_sld setFloatValue: f_updated];
841 var_Get( p_input, "time", &time );
843 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
844 if( [o_time_fld timeRemaining] && dur != -1 )
846 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000))];
849 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
852 [o_time_sld setEnabled: NO];
853 [o_time_sld setHidden: YES];
855 [o_time_sld setEnabled: YES];
856 [o_time_sld setHidden: NO];
859 [o_time_fld setStringValue: o_time];
860 [o_time_fld setNeedsDisplay:YES];
861 [o_fspanel setStreamPos: f_updated andTime: o_time];
862 vlc_object_release( p_input );
866 [o_time_sld setFloatValue: 0.0];
867 [o_time_fld setStringValue: @"00:00"];
868 [o_time_sld setEnabled: NO];
869 [o_time_sld setHidden: YES];
872 [self performSelectorOnMainThread:@selector(drawFancyGradientEffectForTimeSlider) withObject:nil waitUntilDone:NO];
875 - (void)updateVolumeSlider
877 audio_volume_t i_volume;
878 playlist_t * p_playlist = pl_Get( VLCIntf );
880 i_volume = aout_VolumeGet( p_playlist );
882 if( i_volume != i_lastShownVolume )
884 i_lastShownVolume = i_volume;
885 int i_volume_step = 0;
886 i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" );
887 [o_volume_sld setFloatValue: (float)i_lastShownVolume / i_volume_step];
888 [o_fspanel setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
894 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
895 input_thread_t * p_input;
896 p_input = pl_CurrentInput( VLCIntf );
900 char *format = var_InheritString( VLCIntf, "input-title-format" );
901 char *formated = str_format_meta( p_input, format );
903 aString = [NSString stringWithUTF8String:formated];
906 char *uri = input_item_GetURI( input_GetItem( p_input ) );
908 NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
909 if ([o_url isFileURL])
910 [self setRepresentedURL: o_url];
912 [self setRepresentedURL: nil];
915 if ([aString isEqualToString:@""])
917 if ([o_url isFileURL])
918 aString = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
920 aString = [o_url absoluteString];
923 [self setTitle: aString];
924 [o_fspanel setStreamTitle: aString];
928 [self setTitle: _NS("VLC media player")];
929 [self setRepresentedURL: nil];
937 bool b_input = false;
938 bool b_plmul = false;
939 bool b_control = false;
940 bool b_seekable = false;
941 bool b_chapters = false;
943 playlist_t * p_playlist = pl_Get( VLCIntf );
946 b_plmul = playlist_CurrentSize( p_playlist ) > 1;
949 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
951 bool b_buffering = NO;
953 if( ( b_input = ( p_input != NULL ) ) )
955 /* seekable streams */
956 cachedInputState = input_GetState( p_input );
957 if ( cachedInputState == INIT_S || cachedInputState == OPENING_S )
960 /* seekable streams */
961 b_seekable = var_GetBool( p_input, "can-seek" );
963 /* check whether slow/fast motion is possible */
964 b_control = var_GetBool( p_input, "can-rate" );
966 /* chapters & titles */
967 //FIXME! b_chapters = p_input->stream.i_area_nb > 1;
969 if (cachedInputState == PLAYING_S || b_buffering == YES)
970 [self makeKeyAndOrderFront: nil];
971 vlc_object_release( p_input );
976 [o_progress_bar startAnimation:self];
977 [o_progress_bar setIndeterminate:YES];
978 [o_progress_bar setHidden:NO];
980 [o_progress_bar stopAnimation:self];
981 [o_progress_bar setHidden:YES];
984 [o_stop_btn setEnabled: b_input];
985 [o_fwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
986 [o_bwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
987 [[VLCMainMenu sharedInstance] setRateControlsEnabled: b_control];
989 [o_time_sld setEnabled: b_seekable];
990 [self updateTimeSlider];
991 [o_fspanel setSeekable: b_seekable];
994 if (playlist_CurrentSize( p_playlist ) >= 1)
1003 [o_play_btn setImage: o_pause_img];
1004 [o_play_btn setAlternateImage: o_pause_pressed_img];
1005 [o_play_btn setToolTip: _NS("Pause")];
1006 [o_fspanel setPause];
1011 [o_play_btn setImage: o_play_img];
1012 [o_play_btn setAlternateImage: o_play_pressed_img];
1013 [o_play_btn setToolTip: _NS("Play")];
1014 [o_fspanel setPlay];
1017 - (void)drawFancyGradientEffectForTimeSlider
1019 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1020 float f_value = ([o_time_sld frame].size.width - [o_time_sld frame].origin.x - [o_time_sld knobPosition]) * -1.0;
1023 NSRect oldFrame = [o_time_sld_fancygradient_view frame];
1024 if (f_value != oldFrame.size.width)
1026 [o_time_sld_fancygradient_view setHidden: NO];
1027 [o_time_sld_fancygradient_view setFrame: NSMakeRect( oldFrame.origin.x, oldFrame.origin.y, f_value, oldFrame.size.height )];
1028 [o_time_sld_fancygradient_view setNeedsDisplay:YES];
1033 [o_time_sld_fancygradient_view setHidden: YES];
1039 #pragma mark Video Output handling
1043 vout_thread_t *p_vout = getVout();
1044 if (config_GetInt( VLCIntf, "embedded-video" ))
1046 if ([o_video_view window] != self)
1048 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1049 [o_video_view setFrame: [o_split_view frame]];
1050 [[self contentView] addSubview:o_video_view positioned:NSWindowAbove relativeTo:nil];
1056 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1057 if (o_nonembedded_window)
1058 [o_nonembedded_window release];
1060 o_nonembedded_window = [[VLCWindow alloc] initWithContentRect:[o_video_view frame] styleMask: NSBorderlessWindowMask|NSResizableWindowMask backing:NSBackingStoreBuffered defer:YES];
1061 [o_nonembedded_window setFrame:[o_video_view frame] display:NO];
1062 [o_nonembedded_window setBackgroundColor: [NSColor blackColor]];
1063 [o_nonembedded_window setMovableByWindowBackground: YES];
1064 [o_nonembedded_window setCanBecomeKeyWindow: YES];
1065 [o_nonembedded_window setHasShadow:YES];
1066 [o_nonembedded_window setContentView: o_video_view];
1067 [o_nonembedded_window setLevel:NSNormalWindowLevel];
1068 [o_nonembedded_window useOptimizedDrawing: YES];
1069 [o_nonembedded_window center];
1070 [o_nonembedded_window makeKeyAndOrderFront:self];
1071 [o_nonembedded_window orderFront:self animate:YES];
1072 [o_nonembedded_window setReleasedWhenClosed:NO];
1073 b_nonembedded = YES;
1078 if( var_GetBool( p_vout, "video-on-top" ) )
1079 [[o_video_view window] setLevel: NSStatusWindowLevel];
1081 [[o_video_view window] setLevel: NSNormalWindowLevel];
1082 vlc_object_release( p_vout );
1084 return o_video_view;
1087 - (void)setVideoplayEnabled
1089 BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
1092 [o_playlist_btn setEnabled: b_videoPlayback];
1095 [o_playlist_btn setEnabled: NO];
1096 if (!b_videoPlayback)
1097 [o_nonembedded_window orderOut: nil];
1099 if( OSX_LION && b_nativeFullscreenMode )
1101 if( [NSApp presentationOptions] == NSApplicationPresentationFullScreen )
1102 [o_bottombar_view setHidden: b_videoPlayback];
1104 [o_bottombar_view setHidden: NO];
1105 if (!b_videoPlayback)
1106 [o_fspanel setNonActive: nil];
1110 - (void)resizeWindow
1112 if ( !b_fullscreen && !(OSX_LION && [NSApp presentationOptions] == NSApplicationPresentationFullScreen && b_nativeFullscreenMode) )
1114 NSPoint topleftbase;
1115 NSPoint topleftscreen;
1118 topleftbase.y = [self frame].size.height;
1119 topleftscreen = [self convertBaseToScreen: topleftbase];
1121 /* Calculate the window's new size */
1122 new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + nativeVideoSize.width;
1123 if (b_dark_interface)
1124 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + nativeVideoSize.height + [o_titlebar_view frame].size.height;
1126 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + nativeVideoSize.height;
1128 new_frame.origin.x = topleftscreen.x;
1129 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
1131 [[self animator] setFrame:new_frame display:YES];
1135 - (void)setNativeVideoSize:(NSSize)size
1137 if (size.width != nativeVideoSize.width || size.height != nativeVideoSize.height )
1139 nativeVideoSize = size;
1140 [self resizeWindow];
1145 #pragma mark Fullscreen support
1146 - (void)showFullscreenController
1148 if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback] )
1152 - (BOOL)isFullscreen
1154 return b_fullscreen;
1157 - (void)lockFullscreenAnimation
1159 [o_animation_lock lock];
1162 - (void)unlockFullscreenAnimation
1164 [o_animation_lock unlock];
1167 - (void)enterFullscreen
1169 NSMutableDictionary *dict1, *dict2;
1173 vout_thread_t *p_vout = getVout();
1174 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
1177 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
1179 [self lockFullscreenAnimation];
1183 msg_Dbg( VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode" );
1184 screen = [self screen];
1188 msg_Dbg( VLCIntf, "Using deepest screen" );
1189 screen = [NSScreen deepestScreen];
1193 vlc_object_release( p_vout );
1195 screen_rect = [screen frame];
1197 [o_fullscreen_btn setState: YES];
1199 [NSCursor setHiddenUntilMouseMoves: YES];
1201 if( blackout_other_displays )
1202 [screen blackoutOtherScreens];
1204 /* Make sure we don't see the window flashes in float-on-top mode */
1205 i_originalLevel = [self level];
1206 [self setLevel:NSNormalWindowLevel];
1208 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
1209 if (!o_fullscreen_window)
1211 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
1213 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
1214 rect.origin.x += [self frame].origin.x;
1215 rect.origin.y += [self frame].origin.y;
1216 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
1217 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
1218 [o_fullscreen_window setCanBecomeKeyWindow: YES];
1220 if (![self isVisible] || [self alphaValue] == 0.0)
1222 /* We don't animate if we are not visible, instead we
1223 * simply fade the display */
1224 CGDisplayFadeReservationToken token;
1226 if( blackout_other_displays )
1228 CGAcquireDisplayFadeReservation( kCGMaxDisplayReservationInterval, &token );
1229 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1232 if ([screen isMainScreen])
1235 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1237 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1240 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1241 [o_temp_view setFrame:[o_video_view frame]];
1242 [o_fullscreen_window setContentView:o_video_view];
1244 [o_fullscreen_window makeKeyAndOrderFront:self];
1245 [o_fullscreen_window orderFront:self animate:YES];
1247 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
1248 [o_fullscreen_window setLevel:NSNormalWindowLevel];
1250 if( blackout_other_displays )
1252 CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1253 CGReleaseDisplayFadeReservation( token );
1256 /* Will release the lock */
1257 [self hasBecomeFullscreen];
1262 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1263 NSDisableScreenUpdates();
1264 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1265 [o_temp_view setFrame:[o_video_view frame]];
1266 [o_fullscreen_window setContentView:o_video_view];
1267 [o_fullscreen_window makeKeyAndOrderFront:self];
1268 NSEnableScreenUpdates();
1271 /* We are in fullscreen (and no animation is running) */
1274 /* Make sure we are hidden */
1275 [super orderOut: self];
1276 [self unlockFullscreenAnimation];
1280 if (o_fullscreen_anim1)
1282 [o_fullscreen_anim1 stopAnimation];
1283 [o_fullscreen_anim1 release];
1285 if (o_fullscreen_anim2)
1287 [o_fullscreen_anim2 stopAnimation];
1288 [o_fullscreen_anim2 release];
1291 if ([screen isMainScreen])
1294 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1296 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1299 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
1300 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
1302 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
1303 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
1305 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1306 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1307 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
1309 /* Strategy with NSAnimation allocation:
1310 - Keep at most 2 animation at a time
1311 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
1313 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
1314 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
1319 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1320 [o_fullscreen_anim1 setDuration: 0.3];
1321 [o_fullscreen_anim1 setFrameRate: 30];
1322 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1323 [o_fullscreen_anim2 setDuration: 0.2];
1324 [o_fullscreen_anim2 setFrameRate: 30];
1326 [o_fullscreen_anim2 setDelegate: self];
1327 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
1329 [o_fullscreen_anim1 startAnimation];
1330 /* fullscreenAnimation will be unlocked when animation ends */
1333 - (void)hasBecomeFullscreen
1335 [o_fullscreen_window makeFirstResponder: o_video_view];
1337 [o_fullscreen_window makeKeyWindow];
1338 [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
1340 /* tell the fspanel to move itself to front next time it's triggered */
1341 [o_fspanel setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
1342 [o_fspanel setActive: nil];
1344 if([self isVisible])
1345 [super orderOut: self];
1347 [o_fspanel setActive: nil];
1350 [self unlockFullscreenAnimation];
1353 - (void)leaveFullscreen
1355 [self leaveFullscreenAndFadeOut: NO];
1358 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
1360 NSMutableDictionary *dict1, *dict2;
1362 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
1364 [self lockFullscreenAnimation];
1367 [o_fullscreen_btn setState: NO];
1369 /* We always try to do so */
1370 if (!(OSX_LION && b_nativeFullscreenMode))
1371 [NSScreen unblackoutScreens];
1372 vout_thread_t *p_vout = getVout();
1375 if( var_GetBool( p_vout, "video-on-top" ) )
1376 [[o_video_view window] setLevel: NSStatusWindowLevel];
1378 [[o_video_view window] setLevel: NSNormalWindowLevel];
1379 vlc_object_release( p_vout );
1381 [[o_video_view window] makeKeyAndOrderFront: nil];
1383 /* Don't do anything if o_fullscreen_window is already closed */
1384 if (!o_fullscreen_window)
1386 [self unlockFullscreenAnimation];
1392 /* We don't animate if we are not visible, instead we
1393 * simply fade the display */
1394 CGDisplayFadeReservationToken token;
1396 if( blackout_other_displays )
1398 CGAcquireDisplayFadeReservation( kCGMaxDisplayReservationInterval, &token );
1399 CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1402 [o_fspanel setNonActive: nil];
1404 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
1406 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
1408 /* Will release the lock */
1409 [self hasEndedFullscreen];
1411 /* Our window is hidden, and might be faded. We need to workaround that, so note it
1413 b_window_is_invisible = YES;
1415 if( blackout_other_displays )
1417 CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1418 CGReleaseDisplayFadeReservation( token );
1424 [self setAlphaValue: 0.0];
1425 [self orderFront: self];
1426 [[o_video_view window] orderFront: self];
1428 [o_fspanel setNonActive: nil];
1430 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
1432 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
1434 if (o_fullscreen_anim1)
1436 [o_fullscreen_anim1 stopAnimation];
1437 [o_fullscreen_anim1 release];
1439 if (o_fullscreen_anim2)
1441 [o_fullscreen_anim2 stopAnimation];
1442 [o_fullscreen_anim2 release];
1445 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
1446 frame.origin.x += [self frame].origin.x;
1447 frame.origin.y += [self frame].origin.y;
1449 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
1450 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
1451 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1453 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
1456 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1457 [o_fullscreen_anim2 setDuration: 0.3];
1458 [o_fullscreen_anim2 setFrameRate: 30];
1460 [o_fullscreen_anim2 setDelegate: self];
1462 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
1464 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1465 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1466 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
1468 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
1471 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1472 [o_fullscreen_anim1 setDuration: 0.2];
1473 [o_fullscreen_anim1 setFrameRate: 30];
1474 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
1476 /* Make sure o_fullscreen_window is the frontmost window */
1477 [o_fullscreen_window orderFront: self];
1479 [o_fullscreen_anim1 startAnimation];
1480 /* fullscreenAnimation will be unlocked when animation ends */
1483 - (void)hasEndedFullscreen
1485 /* This function is private and should be only triggered at the end of the fullscreen change animation */
1486 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1487 NSDisableScreenUpdates();
1488 [o_video_view retain];
1489 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1490 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
1491 [o_video_view release];
1492 [o_video_view setFrame:[o_temp_view frame]];
1493 [self makeFirstResponder: o_video_view];
1494 if ([self isVisible])
1495 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
1496 [o_fullscreen_window orderOut: self];
1497 NSEnableScreenUpdates();
1499 [o_fullscreen_window release];
1500 o_fullscreen_window = nil;
1501 [self setLevel:i_originalLevel];
1503 [self unlockFullscreenAnimation];
1506 - (void)animationDidEnd:(NSAnimation*)animation
1508 NSArray *viewAnimations;
1509 if( o_makekey_anim == animation )
1511 [o_makekey_anim release];
1514 if ([animation currentValue] < 1.0)
1517 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
1518 viewAnimations = [o_fullscreen_anim2 viewAnimations];
1519 if ([viewAnimations count] >=1 &&
1520 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
1522 /* Fullscreen ended */
1523 [self hasEndedFullscreen];
1527 /* Fullscreen started */
1528 [self hasBecomeFullscreen];
1532 - (void)orderOut: (id)sender
1534 /* Make sure we leave fullscreen */
1535 if (!(OSX_LION && b_nativeFullscreenMode))
1536 [self leaveFullscreenAndFadeOut: YES];
1538 [super orderOut: sender];
1541 - (void)makeKeyAndOrderFront: (id)sender
1544 * when we exit fullscreen and fade out, we may endup in
1545 * having a window that is faded. We can't have it fade in unless we
1548 if(!b_window_is_invisible)
1550 /* Make sure we don't do it too much */
1551 [super makeKeyAndOrderFront: sender];
1555 [super setAlphaValue:0.0f];
1556 [super makeKeyAndOrderFront: sender];
1558 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
1559 [dict setObject:self forKey:NSViewAnimationTargetKey];
1560 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1562 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
1565 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
1566 [o_makekey_anim setDuration: 0.1];
1567 [o_makekey_anim setFrameRate: 30];
1568 [o_makekey_anim setDelegate: self];
1570 [o_makekey_anim startAnimation];
1571 b_window_is_invisible = NO;
1573 /* fullscreenAnimation will be unlocked when animation ends */
1576 /* Make sure setFrame gets executed on main thread especially if we are animating.
1577 * (Thus we won't block the video output thread) */
1578 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
1580 struct { NSRect frame; BOOL display; BOOL animate;} args;
1584 args.display = display;
1585 args.animate = animate;
1587 packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
1589 [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
1590 withObject: packedargs waitUntilDone: YES];
1593 - (void)setFrameOnMainThread:(NSData*)packedargs
1595 struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
1599 /* Make sure we don't block too long and set up a non blocking animation */
1600 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
1601 self, NSViewAnimationTargetKey,
1602 [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
1603 [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
1605 NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
1607 [anim setAnimationBlockingMode: NSAnimationNonblocking];
1608 [anim setDuration: 0.4];
1609 [anim setFrameRate: 30];
1610 [anim startAnimation];
1615 [super setFrame:args->frame display:args->display animate:args->animate];
1620 #pragma mark Lion's native fullscreen handling
1621 - (void)windowWillEnterFullScreen:(NSNotification *)notification
1623 [o_video_view setFrame: [[self contentView] frame]];
1624 [NSCursor setHiddenUntilMouseMoves: YES];
1626 [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
1628 if (b_dark_interface)
1630 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
1633 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1634 winrect = [self frame];
1636 winrect.size.height = winrect.size.height - f_titleBarHeight;
1637 [self setFrame: winrect display:NO animate:NO];
1638 winrect = [o_split_view frame];
1639 winrect.size.height = winrect.size.height + f_titleBarHeight;
1640 [o_split_view setFrame: winrect];
1644 - (void)windowWillExitFullScreen:(NSNotification *)notification
1646 [o_video_view setFrame: [o_split_view frame]];
1647 [NSCursor setHiddenUntilMouseMoves: NO];
1648 [o_fspanel setNonActive: nil];
1651 if (b_dark_interface)
1654 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1655 winrect = [self frame];
1657 [o_titlebar_view setFrame: NSMakeRect( 0, winrect.size.height - f_titleBarHeight,
1658 winrect.size.width, f_titleBarHeight )];
1659 [[self contentView] addSubview: o_titlebar_view];
1661 winrect.size.height = winrect.size.height + f_titleBarHeight;
1662 [self setFrame: winrect display:NO animate:NO];
1663 winrect = [o_split_view frame];
1664 winrect.size.height = winrect.size.height - f_titleBarHeight;
1665 [o_split_view setFrame: winrect];
1666 [o_video_view setFrame: winrect];
1671 #pragma mark split view delegate
1672 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
1674 if (dividerIndex == 0)
1680 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
1682 if (dividerIndex == 0)
1683 return ([self frame].size.width - 300.0);
1689 #pragma mark Side Bar Data handling
1690 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1691 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
1693 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1695 return [o_sidebaritems count];
1698 return [[item children] count];
1703 - (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
1705 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1707 return [o_sidebaritems objectAtIndex:index];
1710 return [[item children] objectAtIndex:index];
1715 - (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
1717 return [item title];
1720 - (void)sourceList:(PXSourceList*)aSourceList setObjectValue:(id)object forItem:(id)item
1722 [item setTitle:object];
1725 - (BOOL)sourceList:(PXSourceList*)aSourceList isItemExpandable:(id)item
1727 return [item hasChildren];
1731 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasBadge:(id)item
1733 if ([[item identifier] isEqualToString: @"playlist"])
1736 return [item hasBadge];
1740 - (NSInteger)sourceList:(PXSourceList*)aSourceList badgeValueForItem:(id)item
1742 if ([[item identifier] isEqualToString: @"playlist"]) {
1743 playlist_t * p_playlist = pl_Get( VLCIntf );
1744 NSInteger i_playlist_size;
1747 i_playlist_size = playlist_CurrentSize( p_playlist );
1750 return i_playlist_size;
1752 return [item badgeValue];
1756 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasIcon:(id)item
1758 return [item hasIcon];
1762 - (NSImage*)sourceList:(PXSourceList*)aSourceList iconForItem:(id)item
1767 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
1769 if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
1770 NSMenu * m = [[NSMenu alloc] init];
1772 [m addItemWithTitle:[item title] action:nil keyEquivalent:@""];
1773 return [m autorelease];
1779 #pragma mark Side Bar Delegate Methods
1780 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1781 - (BOOL)sourceList:(PXSourceList*)aSourceList isGroupAlwaysExpanded:(id)group
1783 if([[group identifier] isEqualToString:@"library"])
1789 - (void)sourceListSelectionDidChange:(NSNotification *)notification
1791 NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
1793 //Set the label text to represent the new selection
1794 if([selectedIndexes count]==1) {
1795 NSString *title = [[o_sidebar_view itemAtRow:[selectedIndexes firstIndex]] title];
1797 [o_chosen_category_lbl setStringValue:title];
1800 [o_chosen_category_lbl setStringValue:@"(none)"];