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 );
268 #define enlargeItem( item ) \
269 frame = [item frame]; \
270 frame.size.width = f_width + frame.size.width; \
271 [item setFrame: frame]
273 enlargeItem( o_time_sld );
274 enlargeItem( o_progress_bar );
275 enlargeItem( o_time_sld_background );
276 enlargeItem( o_time_sld_fancygradient_view );
279 [o_fullscreen_btn removeFromSuperviewWithoutNeedingDisplay];
282 [o_titlebar_view setFullscreenButtonHidden: YES];
286 /* the default small size of the search field is slightly different on Lion, let's work-around that */
288 frame = [o_search_fld frame];
289 frame.origin.y = frame.origin.y + 2.0;
290 frame.size.height = frame.size.height - 1.0;
291 [o_search_fld setFrame: frame];
294 /* create the sidebar */
295 o_sidebaritems = [[NSMutableArray alloc] init];
296 SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
297 SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
298 [playlistItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
299 SideBarItem *mycompItem = [SideBarItem itemWithTitle:_NS("MY COMPUTER") identifier:@"mycomputer"];
300 SideBarItem *devicesItem = [SideBarItem itemWithTitle:_NS("DEVICES") identifier:@"devices"];
301 SideBarItem *lanItem = [SideBarItem itemWithTitle:_NS("LOCAL NETWORK") identifier:@"localnetwork"];
302 SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
304 /* SD subnodes, inspired by the Qt4 intf */
305 char **ppsz_longnames;
307 char **ppsz_names = vlc_sd_GetNames( pl_Get( VLCIntf ), &ppsz_longnames, &p_categories );
309 msg_Err( VLCIntf, "no sd item found" ); //TODO
310 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
311 int *p_category = p_categories;
312 NSMutableArray *internetItems = [[NSMutableArray alloc] init];
313 NSMutableArray *devicesItems = [[NSMutableArray alloc] init];
314 NSMutableArray *lanItems = [[NSMutableArray alloc] init];
315 NSMutableArray *mycompItems = [[NSMutableArray alloc] init];
316 NSString *o_identifier;
317 for (; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++)
319 o_identifier = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
320 o_identifier = [[o_identifier componentsSeparatedByString:@"{"] objectAtIndex:0];
321 switch (*p_category) {
322 case SD_CAT_INTERNET:
324 [internetItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
325 if (!strncmp( *ppsz_name, "podcast", 7 ))
326 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
328 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
333 [devicesItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
334 [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
339 [lanItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
340 [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
343 case SD_CAT_MYCOMPUTER:
345 [mycompItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
346 if (!strncmp( *ppsz_name, "video_dir", 9 ))
347 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
348 else if (!strncmp( *ppsz_name, "audio_dir", 9 ))
349 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
350 else if (!strncmp( *ppsz_name, "picture_dir", 11 ))
351 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
353 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
357 msg_Warn( VLCIntf, "unknown SD type found, skipping (%s)", *ppsz_name );
362 free( *ppsz_longname );
364 [mycompItem setChildren: [NSArray arrayWithArray: mycompItems]];
365 [devicesItem setChildren: [NSArray arrayWithArray: devicesItems]];
366 [lanItem setChildren: [NSArray arrayWithArray: lanItems]];
367 [internetItem setChildren: [NSArray arrayWithArray: internetItems]];
368 [mycompItems release];
369 [devicesItems release];
371 [internetItems release];
373 free( ppsz_longnames );
374 free( p_categories );
376 [libraryItem setChildren: [NSArray arrayWithObject: playlistItem]];
377 [o_sidebaritems addObject: libraryItem];
378 if ([mycompItem hasChildren])
379 [o_sidebaritems addObject: mycompItem];
380 if ([devicesItem hasChildren])
381 [o_sidebaritems addObject: devicesItem];
382 if ([lanItem hasChildren])
383 [o_sidebaritems addObject: lanItem];
384 if ([internetItem hasChildren])
385 [o_sidebaritems addObject: internetItem];
387 [o_sidebar_view reloadData];
388 [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:YES];
390 if( b_dark_interface )
392 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
393 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
395 [self setBackgroundColor: [NSColor clearColor]];
396 [self setOpaque: NO];
399 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
400 winrect = [self frame];
402 [o_titlebar_view setFrame: NSMakeRect( 0, winrect.size.height - f_titleBarHeight,
403 winrect.size.width, f_titleBarHeight )];
404 [[self contentView] addSubview: o_titlebar_view];
406 winrect.size.height = winrect.size.height + f_titleBarHeight;
407 [self setFrame: winrect display:NO animate:NO];
408 winrect = [o_split_view frame];
409 winrect.size.height = winrect.size.height - f_titleBarHeight;
410 [o_split_view setFrame: winrect];
411 [o_video_view setFrame: winrect];
412 previousSavedFrame = winrect;
415 [o_resize_view setImage: NULL];
417 if ([self styleMask] & NSResizableWindowMask)
418 [o_resize_view removeFromSuperviewWithoutNeedingDisplay];
423 [o_video_view setFrame: [o_split_view frame]];
427 #pragma mark Button Actions
429 - (IBAction)play:(id)sender
431 [[VLCCoreInteraction sharedInstance] play];
434 - (void)resetPreviousButton
436 if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35) {
437 // seems like no further event occured, so let's switch the playback item
438 [[VLCCoreInteraction sharedInstance] previous];
439 just_triggered_previous = NO;
443 - (void)resetBackwardSkip
445 // the user stopped skipping, so let's allow him to change the item
446 if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35)
447 just_triggered_previous = NO;
450 - (IBAction)bwd:(id)sender
452 if(!just_triggered_previous)
454 just_triggered_previous = YES;
455 [self performSelector:@selector(resetPreviousButton)
461 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
463 // we just skipped 3 "continous" events, otherwise we are too fast
464 [[VLCCoreInteraction sharedInstance] backward];
465 last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
466 [self performSelector:@selector(resetBackwardSkip)
473 - (void)resetNextButton
475 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35) {
476 // seems like no further event occured, so let's switch the playback item
477 [[VLCCoreInteraction sharedInstance] next];
478 just_triggered_next = NO;
482 - (void)resetForwardSkip
484 // the user stopped skipping, so let's allow him to change the item
485 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35)
486 just_triggered_next = NO;
489 - (IBAction)fwd:(id)sender
491 if(!just_triggered_next)
493 just_triggered_next = YES;
494 [self performSelector:@selector(resetNextButton)
500 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
502 // we just skipped 3 "continous" events, otherwise we are too fast
503 [[VLCCoreInteraction sharedInstance] forward];
504 last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
505 [self performSelector:@selector(resetForwardSkip)
512 - (IBAction)stop:(id)sender
514 [[VLCCoreInteraction sharedInstance] stop];
517 - (IBAction)togglePlaylist:(id)sender
521 if ([o_video_view isHidden] && [o_playlist_btn isEnabled]) {
522 [o_split_view setHidden: YES];
523 [o_video_view setHidden: NO];
524 NSLog( @"showing pl" );
528 [o_video_view setHidden: YES];
529 [o_split_view setHidden: NO];
530 NSLog( @"show vout" );
535 [o_split_view setHidden: NO];
536 [o_playlist_table setHidden: NO];
537 [o_video_view setHidden: ![[VLCMain sharedInstance] activeVideoPlayback]];
543 [o_repeat_btn setImage: o_repeat_one_img];
544 [o_repeat_btn setAlternateImage: o_repeat_one_pressed_img];
549 [o_repeat_btn setImage: o_repeat_all_img];
550 [o_repeat_btn setAlternateImage: o_repeat_all_pressed_img];
555 [o_repeat_btn setImage: o_repeat_img];
556 [o_repeat_btn setAlternateImage: o_repeat_pressed_img];
559 - (IBAction)repeat:(id)sender
561 vlc_value_t looping,repeating;
562 intf_thread_t * p_intf = VLCIntf;
563 playlist_t * p_playlist = pl_Get( p_intf );
565 var_Get( p_playlist, "repeat", &repeating );
566 var_Get( p_playlist, "loop", &looping );
568 if( !repeating.b_bool && !looping.b_bool )
570 /* was: no repeating at all, switching to Repeat One */
571 [[VLCCoreInteraction sharedInstance] repeatOne];
574 else if( repeating.b_bool && !looping.b_bool )
576 /* was: Repeat One, switching to Repeat All */
577 [[VLCCoreInteraction sharedInstance] repeatAll];
582 /* was: Repeat All or bug in VLC, switching to Repeat Off */
583 [[VLCCoreInteraction sharedInstance] repeatOff];
591 playlist_t *p_playlist = pl_Get( VLCIntf );
592 b_value = var_GetBool( p_playlist, "random" );
594 [o_shuffle_btn setImage: o_shuffle_on_img];
595 [o_shuffle_btn setAlternateImage: o_shuffle_on_pressed_img];
599 [o_shuffle_btn setImage: o_shuffle_img];
600 [o_shuffle_btn setAlternateImage: o_shuffle_pressed_img];
604 - (IBAction)shuffle:(id)sender
606 [[VLCCoreInteraction sharedInstance] shuffle];
610 - (IBAction)timeSliderAction:(id)sender
613 input_thread_t * p_input;
615 switch( [[NSApp currentEvent] type] )
618 case NSLeftMouseDown:
619 case NSLeftMouseDragged:
620 f_updated = [sender floatValue];
626 p_input = pl_CurrentInput( VLCIntf );
627 if( p_input != NULL )
632 char psz_time[MSTRTIME_MAX_SIZE];
634 pos.f_float = f_updated / 10000.;
635 var_Set( p_input, "position", pos );
636 [o_time_sld setFloatValue: f_updated];
638 var_Get( p_input, "time", &time );
640 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
641 if( [o_time_fld timeRemaining] && dur != -1 )
643 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000) )];
646 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
648 [o_time_fld setStringValue: o_time];
649 [o_fspanel setStreamPos: f_updated andTime: o_time];
650 vlc_object_release( p_input );
652 [self drawFancyGradientEffectForTimeSlider];
655 - (IBAction)volumeAction:(id)sender
657 if (sender == o_volume_sld)
658 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
659 else if (sender == o_volume_down_btn)
660 [[VLCCoreInteraction sharedInstance] mute];
662 [[VLCCoreInteraction sharedInstance] setVolume: 400];
665 - (IBAction)effects:(id)sender
667 [[VLCMainMenu sharedInstance] showAudioEffects: sender];
670 - (IBAction)fullscreen:(id)sender
672 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
675 - (IBAction)dropzoneButtonAction:(id)sender
677 [[[VLCMain sharedInstance] open] openFileGeneric];
681 #pragma mark overwritten default functionality
682 - (BOOL)canBecomeKeyWindow
687 - (void)setTitle:(NSString *)title
689 if (b_dark_interface)
690 [o_titlebar_view setWindowTitle: title];
691 [super setTitle: title];
694 - (void)performZoom:(id)sender
696 if (b_dark_interface)
697 [self customZoom: sender];
699 [super performZoom: sender];
702 - (void)zoom:(id)sender
704 if (b_dark_interface)
705 [self customZoom: sender];
707 [super zoom: sender];
711 * Given a proposed frame rectangle, return a modified version
712 * which will fit inside the screen.
714 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
715 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
716 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
717 * Copyright (C) 1996 Free Software Foundation, Inc.
719 - (NSRect) customConstrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
721 NSRect screenRect = [screen visibleFrame];
724 /* Move top edge of the window inside the screen */
725 difference = NSMaxY (frameRect) - NSMaxY (screenRect);
728 frameRect.origin.y -= difference;
731 /* If the window is resizable, resize it (if needed) so that the
732 bottom edge is on the screen or can be on the screen when the user moves
734 difference = NSMaxY (screenRect) - NSMaxY (frameRect);
735 if (_styleMask & NSResizableWindowMask)
739 difference2 = screenRect.origin.y - frameRect.origin.y;
740 difference2 -= difference;
741 // Take in account the space between the top of window and the top of the
742 // screen which can be used to move the bottom of the window on the screen
745 frameRect.size.height -= difference2;
746 frameRect.origin.y += difference2;
749 /* Ensure that resizing doesn't makewindow smaller than minimum */
750 difference2 = [self minSize].height - frameRect.size.height;
753 frameRect.size.height += difference2;
754 frameRect.origin.y -= difference2;
764 Zooms the receiver. This method calls the delegate method
765 windowShouldZoom:toFrame: to determine if the window should
766 be allowed to zoom to full screen.
768 * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
769 * Authors: Scott Christley <scottc@net-community.com>, Venkat Ajjanagadde <venkat@ocbi.com>,
770 * Felipe A. Rodriguez <far@ix.netcom.com>, Richard Frith-Macdonald <richard@brainstorm.co.uk>
771 * Copyright (C) 1996 Free Software Foundation, Inc.
773 - (void) customZoom: (id)sender
775 NSRect maxRect = [[self screen] visibleFrame];
776 NSRect currentFrame = [self frame];
778 if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)])
780 maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
783 maxRect = [self customConstrainFrameRect: maxRect toScreen: [self screen]];
785 // Compare the new frame with the current one
786 if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
787 && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
788 && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
789 && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST))
791 // Already in zoomed mode, reset user frame, if stored
792 if ([self frameAutosaveName] != nil)
794 [self setFrame: previousSavedFrame display: YES animate: YES];
795 [self saveFrameUsingName: [self frameAutosaveName]];
800 if ([self frameAutosaveName] != nil)
802 [self saveFrameUsingName: [self frameAutosaveName]];
803 previousSavedFrame = [self frame];
806 [self setFrame: maxRect display: YES animate: YES];
809 - (void)windowResizedOrMoved:(NSNotification *)notification
811 [self saveFrameUsingName: [self frameAutosaveName]];
815 #pragma mark Update interface and respond to foreign events
818 [o_right_split_view addSubview: o_dropzone_view];
819 [o_dropzone_view setFrame: [o_playlist_table frame]];
820 [[o_playlist_table animator] setHidden:YES];
825 [o_dropzone_view removeFromSuperview];
826 [[o_playlist_table animator] setHidden: NO];
829 - (void)updateTimeSlider
831 input_thread_t * p_input;
832 p_input = pl_CurrentInput( VLCIntf );
838 char psz_time[MSTRTIME_MAX_SIZE];
841 var_Get( p_input, "position", &pos );
842 f_updated = 10000. * pos.f_float;
843 [o_time_sld setFloatValue: f_updated];
845 var_Get( p_input, "time", &time );
847 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
848 if( [o_time_fld timeRemaining] && dur != -1 )
850 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000))];
853 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
856 [o_time_sld setEnabled: NO];
857 [o_time_sld setHidden: YES];
859 [o_time_sld setEnabled: YES];
860 [o_time_sld setHidden: NO];
863 [o_time_fld setStringValue: o_time];
864 [o_time_fld setNeedsDisplay:YES];
865 [o_fspanel setStreamPos: f_updated andTime: o_time];
866 vlc_object_release( p_input );
870 [o_time_sld setFloatValue: 0.0];
871 [o_time_fld setStringValue: @"00:00"];
872 [o_time_sld setEnabled: NO];
873 [o_time_sld setHidden: YES];
876 [self performSelectorOnMainThread:@selector(drawFancyGradientEffectForTimeSlider) withObject:nil waitUntilDone:NO];
879 - (void)updateVolumeSlider
881 audio_volume_t i_volume;
882 playlist_t * p_playlist = pl_Get( VLCIntf );
884 i_volume = aout_VolumeGet( p_playlist );
886 if( i_volume != i_lastShownVolume )
888 i_lastShownVolume = i_volume;
889 int i_volume_step = 0;
890 i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" );
891 [o_volume_sld setFloatValue: (float)i_lastShownVolume / i_volume_step];
892 [o_fspanel setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
898 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
899 input_thread_t * p_input;
900 p_input = pl_CurrentInput( VLCIntf );
904 char *format = var_InheritString( VLCIntf, "input-title-format" );
905 char *formated = str_format_meta( p_input, format );
907 aString = [NSString stringWithUTF8String:formated];
910 char *uri = input_item_GetURI( input_GetItem( p_input ) );
912 NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
913 if ([o_url isFileURL])
914 [self setRepresentedURL: o_url];
916 [self setRepresentedURL: nil];
919 if ([aString isEqualToString:@""])
921 if ([o_url isFileURL])
922 aString = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
924 aString = [o_url absoluteString];
927 [self setTitle: aString];
928 [o_fspanel setStreamTitle: aString];
932 [self setTitle: _NS("VLC media player")];
933 [self setRepresentedURL: nil];
941 bool b_input = false;
942 bool b_plmul = false;
943 bool b_control = false;
944 bool b_seekable = false;
945 bool b_chapters = false;
947 playlist_t * p_playlist = pl_Get( VLCIntf );
950 b_plmul = playlist_CurrentSize( p_playlist ) > 1;
953 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
955 bool b_buffering = NO;
957 if( ( b_input = ( p_input != NULL ) ) )
959 /* seekable streams */
960 cachedInputState = input_GetState( p_input );
961 if ( cachedInputState == INIT_S || cachedInputState == OPENING_S )
964 /* seekable streams */
965 b_seekable = var_GetBool( p_input, "can-seek" );
967 /* check whether slow/fast motion is possible */
968 b_control = var_GetBool( p_input, "can-rate" );
970 /* chapters & titles */
971 //FIXME! b_chapters = p_input->stream.i_area_nb > 1;
973 if (cachedInputState == PLAYING_S || b_buffering == YES)
974 [self makeKeyAndOrderFront: nil];
975 vlc_object_release( p_input );
980 [o_progress_bar startAnimation:self];
981 [o_progress_bar setIndeterminate:YES];
982 [o_progress_bar setHidden:NO];
984 [o_progress_bar stopAnimation:self];
985 [o_progress_bar setHidden:YES];
988 [o_stop_btn setEnabled: b_input];
989 [o_fwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
990 [o_bwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
991 [[VLCMainMenu sharedInstance] setRateControlsEnabled: b_control];
993 [o_time_sld setEnabled: b_seekable];
994 [self updateTimeSlider];
995 [o_fspanel setSeekable: b_seekable];
998 if (playlist_CurrentSize( p_playlist ) >= 1)
1001 [self showDropZone];
1007 [o_play_btn setImage: o_pause_img];
1008 [o_play_btn setAlternateImage: o_pause_pressed_img];
1009 [o_play_btn setToolTip: _NS("Pause")];
1010 [o_fspanel setPause];
1015 [o_play_btn setImage: o_play_img];
1016 [o_play_btn setAlternateImage: o_play_pressed_img];
1017 [o_play_btn setToolTip: _NS("Play")];
1018 [o_fspanel setPlay];
1021 - (void)drawFancyGradientEffectForTimeSlider
1023 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1024 float f_value = ([o_time_sld frame].size.width - [o_time_sld frame].origin.x - [o_time_sld knobPosition]) * -1.0;
1027 NSRect oldFrame = [o_time_sld_fancygradient_view frame];
1028 if (f_value != oldFrame.size.width)
1030 [o_time_sld_fancygradient_view setHidden: NO];
1031 [o_time_sld_fancygradient_view setFrame: NSMakeRect( oldFrame.origin.x, oldFrame.origin.y, f_value, oldFrame.size.height )];
1032 [o_time_sld_fancygradient_view setNeedsDisplay:YES];
1037 [o_time_sld_fancygradient_view setHidden: YES];
1043 #pragma mark Video Output handling
1047 vout_thread_t *p_vout = getVout();
1048 if (config_GetInt( VLCIntf, "embedded-video" ))
1050 if ([o_video_view window] != self)
1052 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1053 [o_video_view setFrame: [o_split_view frame]];
1054 [[self contentView] addSubview:o_video_view positioned:NSWindowAbove relativeTo:nil];
1060 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1061 if (o_nonembedded_window)
1062 [o_nonembedded_window release];
1064 o_nonembedded_window = [[VLCWindow alloc] initWithContentRect:[o_video_view frame] styleMask: NSBorderlessWindowMask|NSResizableWindowMask backing:NSBackingStoreBuffered defer:YES];
1065 [o_nonembedded_window setFrame:[o_video_view frame] display:NO];
1066 [o_nonembedded_window setBackgroundColor: [NSColor blackColor]];
1067 [o_nonembedded_window setMovableByWindowBackground: YES];
1068 [o_nonembedded_window setCanBecomeKeyWindow: YES];
1069 [o_nonembedded_window setHasShadow:YES];
1070 [o_nonembedded_window setContentView: o_video_view];
1071 [o_nonembedded_window setLevel:NSNormalWindowLevel];
1072 [o_nonembedded_window useOptimizedDrawing: YES];
1073 [o_nonembedded_window center];
1074 [o_nonembedded_window makeKeyAndOrderFront:self];
1075 [o_nonembedded_window orderFront:self animate:YES];
1076 [o_nonembedded_window setReleasedWhenClosed:NO];
1077 b_nonembedded = YES;
1082 if( var_GetBool( p_vout, "video-on-top" ) )
1083 [[o_video_view window] setLevel: NSStatusWindowLevel];
1085 [[o_video_view window] setLevel: NSNormalWindowLevel];
1086 vlc_object_release( p_vout );
1088 return o_video_view;
1091 - (void)setVideoplayEnabled
1093 BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
1096 [o_playlist_btn setEnabled: b_videoPlayback];
1099 [o_playlist_btn setEnabled: NO];
1100 if (!b_videoPlayback)
1101 [o_nonembedded_window orderOut: nil];
1103 if( OSX_LION && b_nativeFullscreenMode )
1105 if( [NSApp presentationOptions] == NSApplicationPresentationFullScreen )
1106 [o_bottombar_view setHidden: b_videoPlayback];
1108 [o_bottombar_view setHidden: NO];
1109 if (!b_videoPlayback)
1110 [o_fspanel setNonActive: nil];
1114 - (void)resizeWindow
1116 if ( !b_fullscreen && !(OSX_LION && [NSApp presentationOptions] == NSApplicationPresentationFullScreen && b_nativeFullscreenMode) )
1118 NSPoint topleftbase;
1119 NSPoint topleftscreen;
1122 topleftbase.y = [self frame].size.height;
1123 topleftscreen = [self convertBaseToScreen: topleftbase];
1125 /* Calculate the window's new size */
1126 new_frame.size.width = [self frame].size.width - [o_video_view frame].size.width + nativeVideoSize.width;
1127 if (b_dark_interface)
1128 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + nativeVideoSize.height + [o_titlebar_view frame].size.height;
1130 new_frame.size.height = [self frame].size.height - [o_video_view frame].size.height + nativeVideoSize.height;
1132 new_frame.origin.x = topleftscreen.x;
1133 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
1135 [[self animator] setFrame:new_frame display:YES];
1139 - (void)setNativeVideoSize:(NSSize)size
1141 if (size.width != nativeVideoSize.width || size.height != nativeVideoSize.height )
1143 nativeVideoSize = size;
1144 [self resizeWindow];
1149 #pragma mark Fullscreen support
1150 - (void)showFullscreenController
1152 if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback] )
1156 - (BOOL)isFullscreen
1158 return b_fullscreen;
1161 - (void)lockFullscreenAnimation
1163 [o_animation_lock lock];
1166 - (void)unlockFullscreenAnimation
1168 [o_animation_lock unlock];
1171 - (void)enterFullscreen
1173 NSMutableDictionary *dict1, *dict2;
1177 vout_thread_t *p_vout = getVout();
1178 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
1181 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
1183 [self lockFullscreenAnimation];
1187 msg_Dbg( VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode" );
1188 screen = [self screen];
1192 msg_Dbg( VLCIntf, "Using deepest screen" );
1193 screen = [NSScreen deepestScreen];
1197 vlc_object_release( p_vout );
1199 screen_rect = [screen frame];
1201 [o_fullscreen_btn setState: YES];
1203 [NSCursor setHiddenUntilMouseMoves: YES];
1205 if( blackout_other_displays )
1206 [screen blackoutOtherScreens];
1208 /* Make sure we don't see the window flashes in float-on-top mode */
1209 i_originalLevel = [self level];
1210 [self setLevel:NSNormalWindowLevel];
1212 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
1213 if (!o_fullscreen_window)
1215 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
1217 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
1218 rect.origin.x += [self frame].origin.x;
1219 rect.origin.y += [self frame].origin.y;
1220 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
1221 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
1222 [o_fullscreen_window setCanBecomeKeyWindow: YES];
1224 if (![self isVisible] || [self alphaValue] == 0.0)
1226 /* We don't animate if we are not visible, instead we
1227 * simply fade the display */
1228 CGDisplayFadeReservationToken token;
1230 if( blackout_other_displays )
1232 CGAcquireDisplayFadeReservation( kCGMaxDisplayReservationInterval, &token );
1233 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1236 if ([screen isMainScreen])
1239 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1241 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1244 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1245 [o_temp_view setFrame:[o_video_view frame]];
1246 [o_fullscreen_window setContentView:o_video_view];
1248 [o_fullscreen_window makeKeyAndOrderFront:self];
1249 [o_fullscreen_window orderFront:self animate:YES];
1251 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
1252 [o_fullscreen_window setLevel:NSNormalWindowLevel];
1254 if( blackout_other_displays )
1256 CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1257 CGReleaseDisplayFadeReservation( token );
1260 /* Will release the lock */
1261 [self hasBecomeFullscreen];
1266 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1267 NSDisableScreenUpdates();
1268 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1269 [o_temp_view setFrame:[o_video_view frame]];
1270 [o_fullscreen_window setContentView:o_video_view];
1271 [o_fullscreen_window makeKeyAndOrderFront:self];
1272 NSEnableScreenUpdates();
1275 /* We are in fullscreen (and no animation is running) */
1278 /* Make sure we are hidden */
1279 [super orderOut: self];
1280 [self unlockFullscreenAnimation];
1284 if (o_fullscreen_anim1)
1286 [o_fullscreen_anim1 stopAnimation];
1287 [o_fullscreen_anim1 release];
1289 if (o_fullscreen_anim2)
1291 [o_fullscreen_anim2 stopAnimation];
1292 [o_fullscreen_anim2 release];
1295 if ([screen isMainScreen])
1298 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1300 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1303 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
1304 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
1306 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
1307 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
1309 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1310 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1311 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
1313 /* Strategy with NSAnimation allocation:
1314 - Keep at most 2 animation at a time
1315 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
1317 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
1318 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
1323 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1324 [o_fullscreen_anim1 setDuration: 0.3];
1325 [o_fullscreen_anim1 setFrameRate: 30];
1326 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1327 [o_fullscreen_anim2 setDuration: 0.2];
1328 [o_fullscreen_anim2 setFrameRate: 30];
1330 [o_fullscreen_anim2 setDelegate: self];
1331 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
1333 [o_fullscreen_anim1 startAnimation];
1334 /* fullscreenAnimation will be unlocked when animation ends */
1337 - (void)hasBecomeFullscreen
1339 [o_fullscreen_window makeFirstResponder: o_video_view];
1341 [o_fullscreen_window makeKeyWindow];
1342 [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
1344 /* tell the fspanel to move itself to front next time it's triggered */
1345 [o_fspanel setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
1346 [o_fspanel setActive: nil];
1348 if([self isVisible])
1349 [super orderOut: self];
1351 [o_fspanel setActive: nil];
1354 [self unlockFullscreenAnimation];
1357 - (void)leaveFullscreen
1359 [self leaveFullscreenAndFadeOut: NO];
1362 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
1364 NSMutableDictionary *dict1, *dict2;
1366 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
1368 [self lockFullscreenAnimation];
1371 [o_fullscreen_btn setState: NO];
1373 /* We always try to do so */
1374 if (!(OSX_LION && b_nativeFullscreenMode))
1375 [NSScreen unblackoutScreens];
1376 vout_thread_t *p_vout = getVout();
1379 if( var_GetBool( p_vout, "video-on-top" ) )
1380 [[o_video_view window] setLevel: NSStatusWindowLevel];
1382 [[o_video_view window] setLevel: NSNormalWindowLevel];
1383 vlc_object_release( p_vout );
1385 [[o_video_view window] makeKeyAndOrderFront: nil];
1387 /* Don't do anything if o_fullscreen_window is already closed */
1388 if (!o_fullscreen_window)
1390 [self unlockFullscreenAnimation];
1396 /* We don't animate if we are not visible, instead we
1397 * simply fade the display */
1398 CGDisplayFadeReservationToken token;
1400 if( blackout_other_displays )
1402 CGAcquireDisplayFadeReservation( kCGMaxDisplayReservationInterval, &token );
1403 CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1406 [o_fspanel setNonActive: nil];
1408 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
1410 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
1412 /* Will release the lock */
1413 [self hasEndedFullscreen];
1415 /* Our window is hidden, and might be faded. We need to workaround that, so note it
1417 b_window_is_invisible = YES;
1419 if( blackout_other_displays )
1421 CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1422 CGReleaseDisplayFadeReservation( token );
1428 [self setAlphaValue: 0.0];
1429 [self orderFront: self];
1430 [[o_video_view window] orderFront: self];
1432 [o_fspanel setNonActive: nil];
1434 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
1436 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
1438 if (o_fullscreen_anim1)
1440 [o_fullscreen_anim1 stopAnimation];
1441 [o_fullscreen_anim1 release];
1443 if (o_fullscreen_anim2)
1445 [o_fullscreen_anim2 stopAnimation];
1446 [o_fullscreen_anim2 release];
1449 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
1450 frame.origin.x += [self frame].origin.x;
1451 frame.origin.y += [self frame].origin.y;
1453 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
1454 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
1455 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1457 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
1460 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1461 [o_fullscreen_anim2 setDuration: 0.3];
1462 [o_fullscreen_anim2 setFrameRate: 30];
1464 [o_fullscreen_anim2 setDelegate: self];
1466 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
1468 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1469 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1470 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
1472 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
1475 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1476 [o_fullscreen_anim1 setDuration: 0.2];
1477 [o_fullscreen_anim1 setFrameRate: 30];
1478 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
1480 /* Make sure o_fullscreen_window is the frontmost window */
1481 [o_fullscreen_window orderFront: self];
1483 [o_fullscreen_anim1 startAnimation];
1484 /* fullscreenAnimation will be unlocked when animation ends */
1487 - (void)hasEndedFullscreen
1489 /* This function is private and should be only triggered at the end of the fullscreen change animation */
1490 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1491 NSDisableScreenUpdates();
1492 [o_video_view retain];
1493 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1494 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
1495 [o_video_view release];
1496 [o_video_view setFrame:[o_temp_view frame]];
1497 [self makeFirstResponder: o_video_view];
1498 if ([self isVisible])
1499 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
1500 [o_fullscreen_window orderOut: self];
1501 NSEnableScreenUpdates();
1503 [o_fullscreen_window release];
1504 o_fullscreen_window = nil;
1505 [self setLevel:i_originalLevel];
1507 [self unlockFullscreenAnimation];
1510 - (void)animationDidEnd:(NSAnimation*)animation
1512 NSArray *viewAnimations;
1513 if( o_makekey_anim == animation )
1515 [o_makekey_anim release];
1518 if ([animation currentValue] < 1.0)
1521 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
1522 viewAnimations = [o_fullscreen_anim2 viewAnimations];
1523 if ([viewAnimations count] >=1 &&
1524 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
1526 /* Fullscreen ended */
1527 [self hasEndedFullscreen];
1531 /* Fullscreen started */
1532 [self hasBecomeFullscreen];
1536 - (void)orderOut: (id)sender
1538 /* Make sure we leave fullscreen */
1539 if (!(OSX_LION && b_nativeFullscreenMode))
1540 [self leaveFullscreenAndFadeOut: YES];
1542 [super orderOut: sender];
1545 - (void)makeKeyAndOrderFront: (id)sender
1548 * when we exit fullscreen and fade out, we may endup in
1549 * having a window that is faded. We can't have it fade in unless we
1552 if(!b_window_is_invisible)
1554 /* Make sure we don't do it too much */
1555 [super makeKeyAndOrderFront: sender];
1559 [super setAlphaValue:0.0f];
1560 [super makeKeyAndOrderFront: sender];
1562 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
1563 [dict setObject:self forKey:NSViewAnimationTargetKey];
1564 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1566 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
1569 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
1570 [o_makekey_anim setDuration: 0.1];
1571 [o_makekey_anim setFrameRate: 30];
1572 [o_makekey_anim setDelegate: self];
1574 [o_makekey_anim startAnimation];
1575 b_window_is_invisible = NO;
1577 /* fullscreenAnimation will be unlocked when animation ends */
1580 /* Make sure setFrame gets executed on main thread especially if we are animating.
1581 * (Thus we won't block the video output thread) */
1582 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
1584 struct { NSRect frame; BOOL display; BOOL animate;} args;
1588 args.display = display;
1589 args.animate = animate;
1591 packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
1593 [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
1594 withObject: packedargs waitUntilDone: YES];
1597 - (void)setFrameOnMainThread:(NSData*)packedargs
1599 struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
1603 /* Make sure we don't block too long and set up a non blocking animation */
1604 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
1605 self, NSViewAnimationTargetKey,
1606 [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
1607 [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
1609 NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
1611 [anim setAnimationBlockingMode: NSAnimationNonblocking];
1612 [anim setDuration: 0.4];
1613 [anim setFrameRate: 30];
1614 [anim startAnimation];
1619 [super setFrame:args->frame display:args->display animate:args->animate];
1624 #pragma mark Lion's native fullscreen handling
1625 - (void)windowWillEnterFullScreen:(NSNotification *)notification
1627 [o_video_view setFrame: [[self contentView] frame]];
1628 [NSCursor setHiddenUntilMouseMoves: YES];
1630 [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
1632 if (b_dark_interface)
1634 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
1637 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1638 winrect = [self frame];
1640 winrect.size.height = winrect.size.height - f_titleBarHeight;
1641 [self setFrame: winrect display:NO animate:NO];
1642 winrect = [o_split_view frame];
1643 winrect.size.height = winrect.size.height + f_titleBarHeight;
1644 [o_split_view setFrame: winrect];
1648 - (void)windowWillExitFullScreen:(NSNotification *)notification
1650 [o_video_view setFrame: [o_split_view frame]];
1651 [NSCursor setHiddenUntilMouseMoves: NO];
1652 [o_fspanel setNonActive: nil];
1655 if (b_dark_interface)
1658 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1659 winrect = [self frame];
1661 [o_titlebar_view setFrame: NSMakeRect( 0, winrect.size.height - f_titleBarHeight,
1662 winrect.size.width, f_titleBarHeight )];
1663 [[self contentView] addSubview: o_titlebar_view];
1665 winrect.size.height = winrect.size.height + f_titleBarHeight;
1666 [self setFrame: winrect display:NO animate:NO];
1667 winrect = [o_split_view frame];
1668 winrect.size.height = winrect.size.height - f_titleBarHeight;
1669 [o_split_view setFrame: winrect];
1670 [o_video_view setFrame: winrect];
1675 #pragma mark split view delegate
1676 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
1678 if (dividerIndex == 0)
1684 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
1686 if (dividerIndex == 0)
1687 return ([self frame].size.width - 300.0);
1693 #pragma mark Side Bar Data handling
1694 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1695 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
1697 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1699 return [o_sidebaritems count];
1702 return [[item children] count];
1707 - (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
1709 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1711 return [o_sidebaritems objectAtIndex:index];
1714 return [[item children] objectAtIndex:index];
1719 - (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
1721 return [item title];
1724 - (void)sourceList:(PXSourceList*)aSourceList setObjectValue:(id)object forItem:(id)item
1726 [item setTitle:object];
1729 - (BOOL)sourceList:(PXSourceList*)aSourceList isItemExpandable:(id)item
1731 return [item hasChildren];
1735 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasBadge:(id)item
1737 if ([[item identifier] isEqualToString: @"playlist"])
1740 return [item hasBadge];
1744 - (NSInteger)sourceList:(PXSourceList*)aSourceList badgeValueForItem:(id)item
1746 if ([[item identifier] isEqualToString: @"playlist"]) {
1747 playlist_t * p_playlist = pl_Get( VLCIntf );
1748 NSInteger i_playlist_size;
1751 i_playlist_size = playlist_CurrentSize( p_playlist );
1754 return i_playlist_size;
1756 return [item badgeValue];
1760 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasIcon:(id)item
1762 return [item hasIcon];
1766 - (NSImage*)sourceList:(PXSourceList*)aSourceList iconForItem:(id)item
1771 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
1773 if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
1774 NSMenu * m = [[NSMenu alloc] init];
1776 [m addItemWithTitle:[item title] action:nil keyEquivalent:@""];
1777 return [m autorelease];
1783 #pragma mark Side Bar Delegate Methods
1784 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1785 - (BOOL)sourceList:(PXSourceList*)aSourceList isGroupAlwaysExpanded:(id)group
1787 if([[group identifier] isEqualToString:@"library"])
1793 - (void)sourceListSelectionDidChange:(NSNotification *)notification
1795 NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
1797 //Set the label text to represent the new selection
1798 if([selectedIndexes count]==1) {
1799 NSString *title = [[o_sidebar_view itemAtRow:[selectedIndexes firstIndex]] title];
1801 [o_chosen_category_lbl setStringValue:title];
1804 [o_chosen_category_lbl setStringValue:@"(none)"];