1 /*****************************************************************************
2 * MainWindow.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 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
36 #import "SideBarItem.h"
38 #import <vlc_playlist.h>
39 #import <vlc_aout_intf.h>
41 #import <vlc_strings.h>
42 #import <vlc_services_discovery.h>
43 #import <vlc_aout_intf.h>
45 @interface VLCMainWindow ()
46 - (void)addJumpButtons:(BOOL)b_fast;
47 - (void)removeJumpButtons:(BOOL)b_fast;
48 - (void)addPlaymodeButtons:(BOOL)b_fast;
49 - (void)removePlaymodeButtons:(BOOL)b_fast;
51 - (void)resetPreviousButton;
52 - (void)resetBackwardSkip;
53 - (void)resetNextButton;
54 - (void)resetForwardSkip;
55 - (void)resizePlaylistAfterCollapse;
56 - (void)makeSplitViewVisible;
57 - (void)makeSplitViewHidden;
61 @implementation VLCMainWindow
62 static const float f_min_video_height = 70.0;
64 static VLCMainWindow *_o_sharedInstance = nil;
66 + (VLCMainWindow *)sharedInstance
68 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
72 #pragma mark Initialization
76 if (_o_sharedInstance) {
78 return _o_sharedInstance;
80 _o_sharedInstance = [super init];
82 return _o_sharedInstance;
85 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
86 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
88 self = [super initWithContentRect:contentRect styleMask:styleMask
89 backing:backingType defer:flag];
90 _o_sharedInstance = self;
92 [[VLCMain sharedInstance] updateTogglePlaylistState];
97 - (BOOL)isEvent:(NSEvent *)o_event forKey:(const char *)keyString
102 key = config_GetPsz(VLCIntf, keyString);
103 o_key = [NSString stringWithFormat:@"%s", key];
106 unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa:o_key];
108 NSString * characters = [o_event charactersIgnoringModifiers];
109 if ([characters length] > 0) {
110 return [[characters lowercaseString] isEqualToString: [[VLCStringUtility sharedInstance] VLCKeyToString: o_key]] &&
111 (i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) &&
112 (i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) &&
113 (i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
114 (i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask);
119 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
122 // these are key events which should be handled by vlc core, but are attached to a main menu item
123 if (![self isEvent: o_event forKey: "key-vol-up"] &&
124 ![self isEvent: o_event forKey: "key-vol-down"] &&
125 ![self isEvent: o_event forKey: "key-vol-mute"]) {
126 /* We indeed want to prioritize some Cocoa key equivalent against libvlc,
127 so we perform the menu equivalent now. */
128 if ([[NSApp mainMenu] performKeyEquivalent:o_event])
134 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event force:b_force] ||
135 [(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event];
140 if (b_dark_interface)
141 [o_color_backdrop release];
143 [[NSNotificationCenter defaultCenter] removeObserver: self];
144 [o_sidebaritems release];
146 if (o_extra_video_window) {
147 [o_extra_video_window release];
148 o_extra_video_window = nil;
156 BOOL b_splitviewShouldBeHidden = NO;
158 /* setup the styled interface */
159 b_nativeFullscreenMode = NO;
160 #ifdef MAC_OS_X_VERSION_10_7
161 if (!OSX_SNOW_LEOPARD)
162 b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
164 t_hide_mouse_timer = nil;
165 [o_detached_video_window setDelegate: self];
166 [self useOptimizedDrawing: YES];
168 [o_play_btn setToolTip: _NS("Play/Pause")];
169 [[o_play_btn cell] accessibilitySetOverrideValue:_NS("Click to play or pause the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
170 [o_detached_play_btn setToolTip: [o_play_btn toolTip]];
171 [[o_play_btn cell] accessibilitySetOverrideValue:[o_play_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
172 [[o_detached_play_btn cell] accessibilitySetOverrideValue:[o_play_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
173 [[o_detached_play_btn cell] accessibilitySetOverrideValue:_NS("Click to play or pause the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
174 [o_bwd_btn setToolTip: _NS("Backward")];
175 [[o_bwd_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the previous playlist item. Hold to skip backward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
176 [o_detached_bwd_btn setToolTip: [o_bwd_btn toolTip]];
177 [[o_bwd_btn cell] accessibilitySetOverrideValue:[o_bwd_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
178 [[o_detached_bwd_btn cell] accessibilitySetOverrideValue:[o_bwd_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
179 [[o_detached_bwd_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the previous playlist item. Hold to skip backward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
180 [o_fwd_btn setToolTip: _NS("Forward")];
181 [[o_fwd_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the next playlist item. Hold to skip forward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
182 [o_detached_fwd_btn setToolTip: [o_fwd_btn toolTip]];
183 [[o_detached_fwd_btn cell] accessibilitySetOverrideValue:[o_fwd_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
184 [[o_detached_fwd_btn cell] accessibilitySetOverrideValue:[o_fwd_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
185 [[o_detached_fwd_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the next playlist item. Hold to skip forward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
186 [o_stop_btn setToolTip: _NS("Stop")];
187 [[o_stop_btn cell] accessibilitySetOverrideValue:_NS("Click to stop playback.") forAttribute:NSAccessibilityDescriptionAttribute];
188 [[o_stop_btn cell] accessibilitySetOverrideValue:[o_stop_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
189 [o_playlist_btn setToolTip: _NS("Show/Hide Playlist")];
190 [[o_playlist_btn cell] accessibilitySetOverrideValue:_NS("Click to switch between video output and playlist. If no video is shown in the main window, this allows you to hide the playlist.") forAttribute:NSAccessibilityDescriptionAttribute];
191 [[o_playlist_btn cell] accessibilitySetOverrideValue:[o_playlist_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
192 [o_repeat_btn setToolTip: _NS("Repeat")];
193 [[o_repeat_btn cell] accessibilitySetOverrideValue:_NS("Click to change repeat mode. There are 3 states: repeat one, repeat all and off.") forAttribute:NSAccessibilityDescriptionAttribute];
194 [[o_repeat_btn cell] accessibilitySetOverrideValue:[o_repeat_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
195 [o_shuffle_btn setToolTip: _NS("Shuffle")];
196 [[o_shuffle_btn cell] accessibilitySetOverrideValue:[o_shuffle_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
197 [[o_shuffle_btn cell] accessibilitySetOverrideValue:_NS("Click to enable or disable random playback.") forAttribute:NSAccessibilityDescriptionAttribute];
198 [o_effects_btn setToolTip: _NS("Effects")];
199 [[o_effects_btn cell] accessibilitySetOverrideValue:_NS("Click to show an Audio Effects panel featuring an equalizer and further filters.") forAttribute:NSAccessibilityDescriptionAttribute];
200 [[o_effects_btn cell] accessibilitySetOverrideValue:[o_effects_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
201 [o_fullscreen_btn setToolTip: _NS("Toggle Fullscreen mode")];
202 [[o_fullscreen_btn cell] accessibilitySetOverrideValue:_NS("Click to enable fullscreen video playback.") forAttribute:NSAccessibilityDescriptionAttribute];
203 [o_detached_fullscreen_btn setToolTip: [o_fullscreen_btn toolTip]];
204 [[o_fullscreen_btn cell] accessibilitySetOverrideValue:[o_fullscreen_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
205 [[o_detached_fullscreen_btn cell] accessibilitySetOverrideValue:[o_fullscreen_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
206 [[o_detached_fullscreen_btn cell] accessibilitySetOverrideValue:_NS("Click to enable fullscreen video playback.") forAttribute:NSAccessibilityDescriptionAttribute];
207 [[o_search_fld cell] setPlaceholderString: _NS("Search")];
208 [[o_search_fld cell] accessibilitySetOverrideValue:_NS("Enter a term to search the playlist. Results will be selected in the table.") forAttribute:NSAccessibilityDescriptionAttribute];
209 [o_volume_sld setToolTip: _NS("Volume")];
210 [[o_volume_sld cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change the volume.") forAttribute:NSAccessibilityDescriptionAttribute];
211 [[o_volume_sld cell] accessibilitySetOverrideValue:[o_volume_sld toolTip] forAttribute:NSAccessibilityTitleAttribute];
212 [o_volume_down_btn setToolTip: _NS("Mute")];
213 [[o_volume_down_btn cell] accessibilitySetOverrideValue:_NS("Click to mute or unmute the audio.") forAttribute:NSAccessibilityDescriptionAttribute];
214 [[o_volume_down_btn cell] accessibilitySetOverrideValue:[o_volume_down_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
215 [o_volume_up_btn setToolTip: _NS("Full Volume")];
216 [[o_volume_up_btn cell] accessibilitySetOverrideValue:_NS("Click to play the audio at maximum volume.") forAttribute:NSAccessibilityDescriptionAttribute];
217 [[o_volume_up_btn cell] accessibilitySetOverrideValue:[o_volume_up_btn toolTip] forAttribute:NSAccessibilityTitleAttribute];
218 [o_time_sld setToolTip: _NS("Position")];
219 [[o_time_sld cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change current playback position.") forAttribute:NSAccessibilityDescriptionAttribute];
220 [[o_time_sld cell] accessibilitySetOverrideValue:[o_time_sld toolTip] forAttribute:NSAccessibilityTitleAttribute];
221 [o_detached_time_sld setToolTip: [o_time_sld toolTip]];
222 [[o_detached_time_sld cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change current playback position.") forAttribute:NSAccessibilityDescriptionAttribute];
223 [[o_detached_time_sld cell] accessibilitySetOverrideValue:[o_time_sld toolTip] forAttribute:NSAccessibilityTitleAttribute];
224 [o_dropzone_btn setTitle: _NS("Open media...")];
225 [[o_dropzone_btn cell] accessibilitySetOverrideValue:_NS("Click to open an advanced dialog to select the media to play. You can also drop files here to play.") forAttribute:NSAccessibilityDescriptionAttribute];
226 [o_dropzone_lbl setStringValue: _NS("Drop media here")];
228 [o_podcast_add_btn setTitle: _NS("Subscribe")];
229 [o_podcast_remove_btn setTitle: _NS("Unsubscribe")];
230 [o_podcast_subscribe_title_lbl setStringValue: _NS("Subscribe to a podcast")];
231 [o_podcast_subscribe_subtitle_lbl setStringValue: _NS("Enter URL of the podcast to subscribe to:")];
232 [o_podcast_subscribe_cancel_btn setTitle: _NS("Cancel")];
233 [o_podcast_subscribe_ok_btn setTitle: _NS("Subscribe")];
234 [o_podcast_unsubscribe_title_lbl setStringValue: _NS("Unsubscribe from a podcast")];
235 [o_podcast_unsubscribe_subtitle_lbl setStringValue: _NS("Select the podcast you would like to unsubscribe from:")];
236 [o_podcast_unsubscribe_ok_btn setTitle: _NS("Unsubscribe")];
237 [o_podcast_unsubscribe_cancel_btn setTitle: _NS("Cancel")];
239 if (!b_dark_interface) {
240 [o_bottombar_view setImagesLeft: [NSImage imageNamed:@"bottom-background"] middle: [NSImage imageNamed:@"bottom-background"] right: [NSImage imageNamed:@"bottom-background"]];
241 [o_detached_bottombar_view setImagesLeft: [NSImage imageNamed:@"bottom-background"] middle: [NSImage imageNamed:@"bottom-background"] right: [NSImage imageNamed:@"bottom-background"]];
242 [o_bwd_btn setImage: [NSImage imageNamed:@"backward-3btns"]];
243 [o_bwd_btn setAlternateImage: [NSImage imageNamed:@"backward-3btns-pressed"]];
244 [o_detached_bwd_btn setImage: [NSImage imageNamed:@"backward-3btns"]];
245 [o_detached_bwd_btn setAlternateImage: [NSImage imageNamed:@"backward-3btns-pressed"]];
246 o_play_img = [[NSImage imageNamed:@"play"] retain];
247 o_play_pressed_img = [[NSImage imageNamed:@"play-pressed"] retain];
248 o_pause_img = [[NSImage imageNamed:@"pause"] retain];
249 o_pause_pressed_img = [[NSImage imageNamed:@"pause-pressed"] retain];
250 [o_fwd_btn setImage: [NSImage imageNamed:@"forward-3btns"]];
251 [o_fwd_btn setAlternateImage: [NSImage imageNamed:@"forward-3btns-pressed"]];
252 [o_detached_fwd_btn setImage: [NSImage imageNamed:@"forward-3btns"]];
253 [o_detached_fwd_btn setAlternateImage: [NSImage imageNamed:@"forward-3btns-pressed"]];
254 [o_stop_btn setImage: [NSImage imageNamed:@"stop"]];
255 [o_stop_btn setAlternateImage: [NSImage imageNamed:@"stop-pressed"]];
256 [o_playlist_btn setImage: [NSImage imageNamed:@"playlist-btn"]];
257 [o_playlist_btn setAlternateImage: [NSImage imageNamed:@"playlist-btn-pressed"]];
258 o_repeat_img = [[NSImage imageNamed:@"repeat"] retain];
259 o_repeat_pressed_img = [[NSImage imageNamed:@"repeat-pressed"] retain];
260 o_repeat_all_img = [[NSImage imageNamed:@"repeat-all"] retain];
261 o_repeat_all_pressed_img = [[NSImage imageNamed:@"repeat-all-pressed"] retain];
262 o_repeat_one_img = [[NSImage imageNamed:@"repeat-one"] retain];
263 o_repeat_one_pressed_img = [[NSImage imageNamed:@"repeat-one-pressed"] retain];
264 o_shuffle_img = [[NSImage imageNamed:@"shuffle"] retain];
265 o_shuffle_pressed_img = [[NSImage imageNamed:@"shuffle-pressed"] retain];
266 o_shuffle_on_img = [[NSImage imageNamed:@"shuffle-blue"] retain];
267 o_shuffle_on_pressed_img = [[NSImage imageNamed:@"shuffle-blue-pressed"] retain];
268 [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"]];
269 [o_detached_time_sld_background setImagesLeft: [NSImage imageNamed:@"progression-track-wrapper-left"] middle: [NSImage imageNamed:@"progression-track-wrapper-middle"] right: [NSImage imageNamed:@"progression-track-wrapper-right"]];
270 [o_volume_down_btn setImage: [NSImage imageNamed:@"volume-low"]];
271 [o_volume_track_view setImage: [NSImage imageNamed:@"volume-slider-track"]];
272 [o_volume_up_btn setImage: [NSImage imageNamed:@"volume-high"]];
273 if (b_nativeFullscreenMode) {
274 [o_effects_btn setImage: [NSImage imageNamed:@"effects-one-button"]];
275 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-one-button-blue"]];
277 [o_effects_btn setImage: [NSImage imageNamed:@"effects-double-buttons"]];
278 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-double-buttons-pressed"]];
280 [o_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-double-buttons"]];
281 [o_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-double-buttons-pressed"]];
282 [o_detached_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-one-button"]];
283 [o_detached_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-one-button-pressed"]];
284 [o_time_sld_fancygradient_view setImagesLeft:[NSImage imageNamed:@"progression-fill-left"] middle:[NSImage imageNamed:@"progression-fill-middle"] right:[NSImage imageNamed:@"progression-fill-right"]];
285 [o_detached_time_sld_fancygradient_view setImagesLeft:[NSImage imageNamed:@"progression-fill-left"] middle:[NSImage imageNamed:@"progression-fill-middle"] right:[NSImage imageNamed:@"progression-fill-right"]];
287 [o_bottombar_view setImagesLeft: [NSImage imageNamed:@"bottomdark-left"] middle: [NSImage imageNamed:@"bottom-background_dark"] right: [NSImage imageNamed:@"bottomdark-right"]];
288 [o_detached_bottombar_view setImagesLeft: [NSImage imageNamed:@"bottomdark-left"] middle: [NSImage imageNamed:@"bottom-background_dark"] right: [NSImage imageNamed:@"bottomdark-right"]];
289 [o_bwd_btn setImage: [NSImage imageNamed:@"backward-3btns-dark"]];
290 [o_bwd_btn setAlternateImage: [NSImage imageNamed:@"backward-3btns-dark-pressed"]];
291 [o_detached_bwd_btn setImage: [NSImage imageNamed:@"backward-3btns-dark"]];
292 [o_detached_bwd_btn setAlternateImage: [NSImage imageNamed:@"backward-3btns-dark-pressed"]];
293 o_play_img = [[NSImage imageNamed:@"play_dark"] retain];
294 o_play_pressed_img = [[NSImage imageNamed:@"play-pressed_dark"] retain];
295 o_pause_img = [[NSImage imageNamed:@"pause_dark"] retain];
296 o_pause_pressed_img = [[NSImage imageNamed:@"pause-pressed_dark"] retain];
297 [o_fwd_btn setImage: [NSImage imageNamed:@"forward-3btns-dark"]];
298 [o_fwd_btn setAlternateImage: [NSImage imageNamed:@"forward-3btns-dark-pressed"]];
299 [o_detached_fwd_btn setImage: [NSImage imageNamed:@"forward-3btns-dark"]];
300 [o_detached_fwd_btn setAlternateImage: [NSImage imageNamed:@"forward-3btns-dark-pressed"]];
301 [o_stop_btn setImage: [NSImage imageNamed:@"stop_dark"]];
302 [o_stop_btn setAlternateImage: [NSImage imageNamed:@"stop-pressed_dark"]];
303 [o_playlist_btn setImage: [NSImage imageNamed:@"playlist_dark"]];
304 [o_playlist_btn setAlternateImage: [NSImage imageNamed:@"playlist-pressed_dark"]];
305 o_repeat_img = [[NSImage imageNamed:@"repeat_dark"] retain];
306 o_repeat_pressed_img = [[NSImage imageNamed:@"repeat-pressed_dark"] retain];
307 o_repeat_all_img = [[NSImage imageNamed:@"repeat-all-blue_dark"] retain];
308 o_repeat_all_pressed_img = [[NSImage imageNamed:@"repeat-all-blue-pressed_dark"] retain];
309 o_repeat_one_img = [[NSImage imageNamed:@"repeat-one-blue_dark"] retain];
310 o_repeat_one_pressed_img = [[NSImage imageNamed:@"repeat-one-blue-pressed_dark"] retain];
311 o_shuffle_img = [[NSImage imageNamed:@"shuffle_dark"] retain];
312 o_shuffle_pressed_img = [[NSImage imageNamed:@"shuffle-pressed_dark"] retain];
313 o_shuffle_on_img = [[NSImage imageNamed:@"shuffle-blue_dark"] retain];
314 o_shuffle_on_pressed_img = [[NSImage imageNamed:@"shuffle-blue-pressed_dark"] retain];
315 [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"]];
316 [o_detached_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"]];
317 [o_volume_down_btn setImage: [NSImage imageNamed:@"volume-low_dark"]];
318 [o_volume_track_view setImage: [NSImage imageNamed:@"volume-slider-track_dark"]];
319 [o_volume_up_btn setImage: [NSImage imageNamed:@"volume-high_dark"]];
320 if (b_nativeFullscreenMode) {
321 [o_effects_btn setImage: [NSImage imageNamed:@"effects-one-button_dark"]];
322 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-one-button-blue_dark"]];
324 [o_effects_btn setImage: [NSImage imageNamed:@"effects-double-buttons_dark"]];
325 [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-double-buttons-pressed_dark"]];
327 [o_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-double-buttons_dark"]];
328 [o_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-double-buttons-pressed_dark"]];
329 [o_detached_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-one-button_dark"]];
330 [o_detached_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-one-button-pressed_dark"]];
331 [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"]];
332 [o_detached_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"]];
334 [o_repeat_btn setImage: o_repeat_img];
335 [o_repeat_btn setAlternateImage: o_repeat_pressed_img];
336 [o_shuffle_btn setImage: o_shuffle_img];
337 [o_shuffle_btn setAlternateImage: o_shuffle_pressed_img];
338 [o_play_btn setImage: o_play_img];
339 [o_play_btn setAlternateImage: o_play_pressed_img];
340 [o_detached_play_btn setImage: o_play_img];
341 [o_detached_play_btn setAlternateImage: o_play_pressed_img];
342 BOOL b_mute = ![[VLCCoreInteraction sharedInstance] mute];
343 [o_volume_sld setEnabled: b_mute];
344 [o_volume_up_btn setEnabled: b_mute];
346 b_show_jump_buttons = config_GetInt(VLCIntf, "macosx-show-playback-buttons");
347 if (b_show_jump_buttons)
348 [self addJumpButtons:YES];
350 b_show_playmode_buttons = config_GetInt(VLCIntf, "macosx-show-playmode-buttons");
351 if (!b_show_playmode_buttons)
352 [self removePlaymodeButtons:YES];
354 /* interface builder action */
355 float f_threshold_height = f_min_video_height + [o_bottombar_view frame].size.height;
356 if (b_dark_interface)
357 f_threshold_height += [o_titlebar_view frame].size.height;
358 if ([[self contentView] frame].size.height < f_threshold_height)
359 b_splitviewShouldBeHidden = YES;
361 [self setDelegate: self];
362 [self setExcludedFromWindowsMenu: YES];
363 [self setAcceptsMouseMovedEvents: YES];
364 // Set that here as IB seems to be buggy
365 if (b_dark_interface) {
366 [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
367 [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [o_detached_bottombar_view frame].size.height + [o_titlebar_view frame].size.height)];
369 [self setContentMinSize:NSMakeSize(604., 288.)];
370 [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [o_detached_bottombar_view frame].size.height)];
373 [self setTitle: _NS("VLC media player")];
374 [o_time_fld setAlignment: NSCenterTextAlignment];
375 [o_time_fld setNeedsDisplay:YES];
376 b_dropzone_active = YES;
377 o_temp_view = [[NSView alloc] init];
378 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
379 [o_dropzone_view setFrame: [o_playlist_table frame]];
380 [o_left_split_view setFrame: [o_sidebar_view frame]];
381 if (b_nativeFullscreenMode) {
383 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
384 float f_width = [o_fullscreen_btn frame].size.width;
386 #define moveItem(item) \
387 frame = [item frame]; \
388 frame.origin.x = f_width + frame.origin.x; \
389 [item setFrame: frame]
391 moveItem(o_effects_btn);
392 moveItem(o_volume_up_btn);
393 moveItem(o_volume_sld);
394 moveItem(o_volume_track_view);
395 moveItem(o_volume_down_btn);
396 moveItem(o_time_fld);
399 #define enlargeItem(item) \
400 frame = [item frame]; \
401 frame.size.width = f_width + frame.size.width; \
402 [item setFrame: frame]
404 enlargeItem(o_time_sld);
405 enlargeItem(o_progress_bar);
406 enlargeItem(o_time_sld_background);
407 enlargeItem(o_time_sld_fancygradient_view);
410 [o_fullscreen_btn removeFromSuperviewWithoutNeedingDisplay];
412 [o_titlebar_view setFullscreenButtonHidden: YES];
415 if (!OSX_SNOW_LEOPARD) {
416 /* the default small size of the search field is slightly different on Lion, let's work-around that */
418 frame = [o_search_fld frame];
419 frame.origin.y = frame.origin.y + 2.0;
420 frame.size.height = frame.size.height - 1.0;
421 [o_search_fld setFrame: frame];
424 /* create the sidebar */
425 o_sidebaritems = [[NSMutableArray alloc] init];
426 SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
427 SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
428 [playlistItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
429 SideBarItem *medialibraryItem = [SideBarItem itemWithTitle:_NS("Media Library") identifier:@"medialibrary"];
430 [medialibraryItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
431 SideBarItem *mycompItem = [SideBarItem itemWithTitle:_NS("MY COMPUTER") identifier:@"mycomputer"];
432 SideBarItem *devicesItem = [SideBarItem itemWithTitle:_NS("DEVICES") identifier:@"devices"];
433 SideBarItem *lanItem = [SideBarItem itemWithTitle:_NS("LOCAL NETWORK") identifier:@"localnetwork"];
434 SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
436 /* SD subnodes, inspired by the Qt4 intf */
437 char **ppsz_longnames;
439 char **ppsz_names = vlc_sd_GetNames(pl_Get(VLCIntf), &ppsz_longnames, &p_categories);
441 msg_Err(VLCIntf, "no sd item found"); //TODO
442 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
443 int *p_category = p_categories;
444 NSMutableArray *internetItems = [[NSMutableArray alloc] init];
445 NSMutableArray *devicesItems = [[NSMutableArray alloc] init];
446 NSMutableArray *lanItems = [[NSMutableArray alloc] init];
447 NSMutableArray *mycompItems = [[NSMutableArray alloc] init];
448 NSString *o_identifier;
449 for (; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++) {
450 o_identifier = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
451 switch (*p_category) {
452 case SD_CAT_INTERNET:
453 [internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
454 if (!strncmp(*ppsz_name, "podcast", 7))
455 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
457 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
458 [[internetItems lastObject] setSdtype: SD_CAT_INTERNET];
459 [[internetItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
462 [devicesItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
463 [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
464 [[devicesItems lastObject] setSdtype: SD_CAT_DEVICES];
465 [[devicesItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
468 [lanItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
469 [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
470 [[lanItems lastObject] setSdtype: SD_CAT_LAN];
471 [[lanItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
473 case SD_CAT_MYCOMPUTER:
474 [mycompItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
475 if (!strncmp(*ppsz_name, "video_dir", 9))
476 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
477 else if (!strncmp(*ppsz_name, "audio_dir", 9))
478 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
479 else if (!strncmp(*ppsz_name, "picture_dir", 11))
480 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
482 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
483 [[mycompItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
484 [[mycompItems lastObject] setSdtype: SD_CAT_MYCOMPUTER];
487 msg_Warn(VLCIntf, "unknown SD type found, skipping (%s)", *ppsz_name);
492 free(*ppsz_longname);
494 [mycompItem setChildren: [NSArray arrayWithArray: mycompItems]];
495 [devicesItem setChildren: [NSArray arrayWithArray: devicesItems]];
496 [lanItem setChildren: [NSArray arrayWithArray: lanItems]];
497 [internetItem setChildren: [NSArray arrayWithArray: internetItems]];
498 [mycompItems release];
499 [devicesItems release];
501 [internetItems release];
503 free(ppsz_longnames);
506 [libraryItem setChildren: [NSArray arrayWithObjects: playlistItem, medialibraryItem, nil]];
507 [o_sidebaritems addObject: libraryItem];
508 if ([mycompItem hasChildren])
509 [o_sidebaritems addObject: mycompItem];
510 if ([devicesItem hasChildren])
511 [o_sidebaritems addObject: devicesItem];
512 if ([lanItem hasChildren])
513 [o_sidebaritems addObject: lanItem];
514 if ([internetItem hasChildren])
515 [o_sidebaritems addObject: internetItem];
517 [o_sidebar_view reloadData];
518 [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
519 [o_sidebar_view setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
520 [o_sidebar_view registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
522 [o_sidebar_view setAutosaveName:@"mainwindow-sidebar"];
523 [(PXSourceList *)o_sidebar_view setDataSource:self];
524 [o_sidebar_view setDelegate:self];
525 [o_sidebar_view setAutosaveExpandedItems:YES];
527 [o_sidebar_view expandItem: libraryItem expandChildren: YES];
529 /* make sure we display the desired default appearance when VLC launches for the first time */
530 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
531 if (![defaults objectForKey:@"VLCFirstRun"]) {
532 [defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
534 NSUInteger i_sidebaritem_count = [o_sidebaritems count];
535 for (NSUInteger x = 0; x < i_sidebaritem_count; x++)
536 [o_sidebar_view expandItem: [o_sidebaritems objectAtIndex: x] expandChildren: YES];
539 if (b_dark_interface) {
540 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
541 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
543 [self setBackgroundColor: [NSColor clearColor]];
544 [self setOpaque: NO];
546 [self setHasShadow:NO];
547 [self setHasShadow:YES];
549 NSRect winrect = [self frame];
550 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
552 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
553 winrect.size.width, f_titleBarHeight)];
554 [[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: o_split_view];
556 if (winrect.size.height > 100) {
557 [self setFrame: winrect display:YES animate:YES];
558 previousSavedFrame = winrect;
561 winrect = [o_split_view frame];
562 winrect.size.height = winrect.size.height - f_titleBarHeight;
563 [o_split_view setFrame: winrect];
564 [o_video_view setFrame: winrect];
566 o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_split_view frame]];
567 [[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_split_view];
568 [o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
571 frame = [o_time_sld_fancygradient_view frame];
572 frame.size.height = frame.size.height - 1;
573 frame.origin.y = frame.origin.y + 1;
574 [o_time_sld_fancygradient_view setFrame: frame];
576 frame = [o_detached_time_sld_fancygradient_view frame];
577 frame.size.height = frame.size.height - 1;
578 frame.origin.y = frame.origin.y + 1;
579 [o_detached_time_sld_fancygradient_view setFrame: frame];
581 [o_video_view setFrame: [o_split_view frame]];
582 [o_playlist_table setBorderType: NSNoBorder];
583 [o_sidebar_scrollview setBorderType: NSNoBorder];
587 frame = [o_time_sld_fancygradient_view frame];
588 frame.size.width = 0;
589 [o_time_sld_fancygradient_view setFrame: frame];
591 frame = [o_detached_time_sld_fancygradient_view frame];
592 frame.size.width = 0;
593 [o_detached_time_sld_fancygradient_view setFrame: frame];
595 if (!OSX_SNOW_LEOPARD) {
596 [o_resize_view setImage: NULL];
597 [o_detached_resize_view setImage: NULL];
600 if ([self styleMask] & NSResizableWindowMask) {
601 [o_resize_view removeFromSuperviewWithoutNeedingDisplay];
602 [o_detached_resize_view removeFromSuperviewWithoutNeedingDisplay];
605 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
606 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
607 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
608 [[VLCMain sharedInstance] playbackModeUpdated];
610 [o_split_view setAutosaveName:@"10thanniversary-splitview"];
611 if (b_splitviewShouldBeHidden) {
612 [self hideSplitView];
613 i_lastSplitViewHeight = 300;
616 /* sanity check for the window size */
617 frame = [self frame];
618 NSSize screenSize = [[self screen] frame].size;
619 if (screenSize.width <= frame.size.width || screenSize.height <= frame.size.height) {
620 nativeVideoSize = screenSize;
626 #pragma mark interface customization
627 - (void)toggleJumpButtons
629 b_show_jump_buttons = config_GetInt(VLCIntf, "macosx-show-playback-buttons");
631 if (b_show_jump_buttons)
632 [self addJumpButtons:NO];
634 [self removeJumpButtons:NO];
637 - (void)addJumpButtons:(BOOL)b_fast
639 NSRect preliminaryFrame = [o_bwd_btn frame];
640 BOOL b_enabled = [o_bwd_btn isEnabled];
641 preliminaryFrame.size.width = 29.;
642 o_prev_btn = [[NSButton alloc] initWithFrame:preliminaryFrame];
643 [o_prev_btn setButtonType: NSMomentaryChangeButton];
644 [o_prev_btn setBezelStyle:NSRegularSquareBezelStyle];
645 [o_prev_btn setBordered:NO];
646 [o_prev_btn setTarget:self];
647 [o_prev_btn setAction:@selector(prev:)];
648 [o_prev_btn setToolTip: _NS("Previous")];
649 [[o_prev_btn cell] accessibilitySetOverrideValue:_NS("Previous") forAttribute:NSAccessibilityTitleAttribute];
650 [[o_prev_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the previous playlist item.") forAttribute:NSAccessibilityDescriptionAttribute];
651 [o_prev_btn setEnabled: b_enabled];
653 o_next_btn = [[NSButton alloc] initWithFrame:preliminaryFrame];
654 [o_next_btn setButtonType: NSMomentaryChangeButton];
655 [o_next_btn setBezelStyle:NSRegularSquareBezelStyle];
656 [o_next_btn setBordered:NO];
657 [o_next_btn setTarget:self];
658 [o_next_btn setAction:@selector(next:)];
659 [o_next_btn setToolTip: _NS("Next")];
660 [[o_next_btn cell] accessibilitySetOverrideValue:_NS("Next") forAttribute:NSAccessibilityTitleAttribute];
661 [[o_next_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the next playlist item.") forAttribute:NSAccessibilityDescriptionAttribute];
662 [o_next_btn setEnabled: b_enabled];
664 if (b_dark_interface) {
665 [o_prev_btn setImage: [NSImage imageNamed:@"previous-6btns-dark"]];
666 [o_prev_btn setAlternateImage: [NSImage imageNamed:@"previous-6btns-dark-pressed"]];
667 [o_next_btn setImage: [NSImage imageNamed:@"next-6btns-dark"]];
668 [o_next_btn setAlternateImage: [NSImage imageNamed:@"next-6btns-dark-pressed"]];
670 [o_prev_btn setImage: [NSImage imageNamed:@"previous-6btns"]];
671 [o_prev_btn setAlternateImage: [NSImage imageNamed:@"previous-6btns-pressed"]];
672 [o_next_btn setImage: [NSImage imageNamed:@"next-6btns"]];
673 [o_next_btn setAlternateImage: [NSImage imageNamed:@"next-6btns-pressed"]];
676 /* change the accessibility help for the backward/forward buttons accordingly */
677 [[o_bwd_btn cell] accessibilitySetOverrideValue:_NS("Click and hold to skip backward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
678 [[o_fwd_btn cell] accessibilitySetOverrideValue:_NS("Click and hold to skip forward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
681 frame = [o_bwd_btn frame];
683 [o_bwd_btn setFrame:frame];
684 frame = [o_fwd_btn frame];
686 [o_fwd_btn setFrame:frame];
689 #define moveItem(item) \
690 frame = [item frame]; \
691 frame.origin.x = frame.origin.x + f_space; \
693 [item setFrame: frame]; \
695 [[item animator] setFrame: frame]
698 moveItem(o_play_btn);
702 moveItem(o_stop_btn);
703 moveItem(o_playlist_btn);
704 moveItem(o_repeat_btn);
705 moveItem(o_shuffle_btn);
708 #define resizeItem(item) \
709 frame = [item frame]; \
710 frame.size.width = frame.size.width - f_space; \
711 frame.origin.x = frame.origin.x + f_space; \
713 [item setFrame: frame]; \
715 [[item animator] setFrame: frame]
717 resizeItem(o_time_sld);
718 resizeItem(o_progress_bar);
719 resizeItem(o_time_sld_background);
720 resizeItem(o_time_sld_fancygradient_view);
723 if (b_dark_interface) {
724 [[o_fwd_btn animator] setImage:[NSImage imageNamed:@"forward-6btns-dark"]];
725 [[o_fwd_btn animator] setAlternateImage:[NSImage imageNamed:@"forward-6btns-dark-pressed"]];
726 [[o_bwd_btn animator] setImage:[NSImage imageNamed:@"backward-6btns-dark"]];
727 [[o_bwd_btn animator] setAlternateImage:[NSImage imageNamed:@"backward-6btns-dark-pressed"]];
729 [[o_fwd_btn animator] setImage:[NSImage imageNamed:@"forward-6btns"]];
730 [[o_fwd_btn animator] setAlternateImage:[NSImage imageNamed:@"forward-6btns-pressed"]];
731 [[o_bwd_btn animator] setImage:[NSImage imageNamed:@"backward-6btns"]];
732 [[o_bwd_btn animator] setAlternateImage:[NSImage imageNamed:@"backward-6btns-pressed"]];
735 preliminaryFrame.origin.x = [o_next_btn frame].origin.x + 82. + [o_fwd_btn frame].size.width;
736 [o_next_btn setFrame: preliminaryFrame];
738 // wait until the animation is done, if displayed
740 [[self contentView] addSubview:o_prev_btn];
741 [[self contentView] addSubview:o_next_btn];
743 [[self contentView] performSelector:@selector(addSubview:) withObject:o_prev_btn afterDelay:.2];
744 [[self contentView] performSelector:@selector(addSubview:) withObject:o_next_btn afterDelay:.2];
747 [o_fwd_btn setAction:@selector(forward:)];
748 [o_bwd_btn setAction:@selector(backward:)];
751 - (void)removeJumpButtons:(BOOL)b_fast
753 if (!o_prev_btn || !o_next_btn)
757 [o_prev_btn setHidden: YES];
758 [o_next_btn setHidden: YES];
760 [[o_prev_btn animator] setHidden: YES];
761 [[o_next_btn animator] setHidden: YES];
763 [o_prev_btn removeFromSuperviewWithoutNeedingDisplay];
764 [o_next_btn removeFromSuperviewWithoutNeedingDisplay];
765 [o_prev_btn release];
766 [o_next_btn release];
768 /* change the accessibility help for the backward/forward buttons accordingly */
769 [[o_bwd_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the previous playlist item. Hold to skip backward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
770 [[o_fwd_btn cell] accessibilitySetOverrideValue:_NS("Click to go to the next playlist item. Hold to skip forward through the current media.") forAttribute:NSAccessibilityDescriptionAttribute];
773 frame = [o_bwd_btn frame];
775 [o_bwd_btn setFrame:frame];
776 frame = [o_fwd_btn frame];
778 [o_fwd_btn setFrame:frame];
781 #define moveItem(item) \
782 frame = [item frame]; \
783 frame.origin.x = frame.origin.x - f_space; \
785 [item setFrame: frame]; \
787 [[item animator] setFrame: frame]
790 moveItem(o_play_btn);
794 moveItem(o_stop_btn);
795 moveItem(o_playlist_btn);
796 moveItem(o_repeat_btn);
797 moveItem(o_shuffle_btn);
800 #define resizeItem(item) \
801 frame = [item frame]; \
802 frame.size.width = frame.size.width + f_space; \
803 frame.origin.x = frame.origin.x - f_space; \
805 [item setFrame: frame]; \
807 [[item animator] setFrame: frame]
809 resizeItem(o_time_sld);
810 resizeItem(o_progress_bar);
811 resizeItem(o_time_sld_background);
812 resizeItem(o_time_sld_fancygradient_view);
815 if (b_dark_interface) {
816 [[o_fwd_btn animator] setImage:[NSImage imageNamed:@"forward-3btns-dark"]];
817 [[o_fwd_btn animator] setAlternateImage:[NSImage imageNamed:@"forward-3btns-dark-pressed"]];
818 [[o_bwd_btn animator] setImage:[NSImage imageNamed:@"backward-3btns-dark"]];
819 [[o_bwd_btn animator] setAlternateImage:[NSImage imageNamed:@"backward-3btns-dark-pressed"]];
821 [[o_fwd_btn animator] setImage:[NSImage imageNamed:@"forward-3btns"]];
822 [[o_fwd_btn animator] setAlternateImage:[NSImage imageNamed:@"forward-3btns-pressed"]];
823 [[o_bwd_btn animator] setImage:[NSImage imageNamed:@"backward-3btns"]];
824 [[o_bwd_btn animator] setAlternateImage:[NSImage imageNamed:@"backward-3btns-pressed"]];
827 [o_bottombar_view setNeedsDisplay:YES];
829 [o_fwd_btn setAction:@selector(fwd:)];
830 [o_bwd_btn setAction:@selector(bwd:)];
833 - (void)togglePlaymodeButtons
835 b_show_playmode_buttons = config_GetInt(VLCIntf, "macosx-show-playmode-buttons");
837 if (b_show_playmode_buttons)
838 [self addPlaymodeButtons:NO];
840 [self removePlaymodeButtons:NO];
843 - (void)addPlaymodeButtons:(BOOL)b_fast
846 float f_space = [o_repeat_btn frame].size.width + [o_shuffle_btn frame].size.width - 6.;
848 if (b_dark_interface) {
849 [[o_playlist_btn animator] setImage:[NSImage imageNamed:@"playlist_dark"]];
850 [[o_playlist_btn animator] setAlternateImage:[NSImage imageNamed:@"playlist-pressed_dark"]];
852 [[o_playlist_btn animator] setImage:[NSImage imageNamed:@"playlist-btn"]];
853 [[o_playlist_btn animator] setAlternateImage:[NSImage imageNamed:@"playlist-btn-pressed"]];
855 frame = [o_playlist_btn frame];
857 [o_playlist_btn setFrame:frame];
860 [o_repeat_btn setHidden: NO];
861 [o_shuffle_btn setHidden: NO];
863 [[o_repeat_btn animator] setHidden: NO];
864 [[o_shuffle_btn animator] setHidden: NO];
867 #define resizeItem(item) \
868 frame = [item frame]; \
869 frame.size.width = frame.size.width - f_space; \
870 frame.origin.x = frame.origin.x + f_space; \
872 [item setFrame: frame]; \
874 [[item animator] setFrame: frame]
876 resizeItem(o_time_sld);
877 resizeItem(o_progress_bar);
878 resizeItem(o_time_sld_background);
879 resizeItem(o_time_sld_fancygradient_view);
883 - (void)removePlaymodeButtons:(BOOL)b_fast
886 float f_space = [o_repeat_btn frame].size.width + [o_shuffle_btn frame].size.width - 6.;
887 [o_repeat_btn setHidden: YES];
888 [o_shuffle_btn setHidden: YES];
890 if (b_dark_interface) {
891 [[o_playlist_btn animator] setImage:[NSImage imageNamed:@"playlist-1btn-dark"]];
892 [[o_playlist_btn animator] setAlternateImage:[NSImage imageNamed:@"playlist-1btn-dark-pressed"]];
894 [[o_playlist_btn animator] setImage:[NSImage imageNamed:@"playlist-1btn"]];
895 [[o_playlist_btn animator] setAlternateImage:[NSImage imageNamed:@"playlist-1btn-pressed"]];
897 frame = [o_playlist_btn frame];
899 [o_playlist_btn setFrame:frame];
901 #define resizeItem(item) \
902 frame = [item frame]; \
903 frame.size.width = frame.size.width + f_space; \
904 frame.origin.x = frame.origin.x - f_space; \
906 [item setFrame: frame]; \
908 [[item animator] setFrame: frame]
910 resizeItem(o_time_sld);
911 resizeItem(o_progress_bar);
912 resizeItem(o_time_sld_background);
913 resizeItem(o_time_sld_fancygradient_view);
918 #pragma mark Button Actions
920 - (IBAction)play:(id)sender
922 [[VLCCoreInteraction sharedInstance] play];
925 - (void)resetPreviousButton
927 if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35) {
928 // seems like no further event occurred, so let's switch the playback item
929 [[VLCCoreInteraction sharedInstance] previous];
930 just_triggered_previous = NO;
934 - (void)resetBackwardSkip
936 // the user stopped skipping, so let's allow him to change the item
937 if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35)
938 just_triggered_previous = NO;
941 - (IBAction)prev:(id)sender
943 [[VLCCoreInteraction sharedInstance] previous];
946 - (IBAction)bwd:(id)sender
948 if (!just_triggered_previous) {
949 just_triggered_previous = YES;
950 [self performSelector:@selector(resetPreviousButton)
954 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16) {
955 // we just skipped 4 "continous" events, otherwise we are too fast
956 [[VLCCoreInteraction sharedInstance] backwardExtraShort];
957 last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
958 [self performSelector:@selector(resetBackwardSkip)
965 - (IBAction)backward:(id)sender
967 [[VLCCoreInteraction sharedInstance] backwardShort];
970 - (void)resetNextButton
972 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35) {
973 // seems like no further event occurred, so let's switch the playback item
974 [[VLCCoreInteraction sharedInstance] next];
975 just_triggered_next = NO;
979 - (void)resetForwardSkip
981 // the user stopped skipping, so let's allow him to change the item
982 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35)
983 just_triggered_next = NO;
986 - (IBAction)next:(id)sender
988 [[VLCCoreInteraction sharedInstance] next];
991 - (IBAction)forward:(id)sender
993 [[VLCCoreInteraction sharedInstance] forwardShort];
996 - (IBAction)fwd:(id)sender
998 if (!just_triggered_next) {
999 just_triggered_next = YES;
1000 [self performSelector:@selector(resetNextButton)
1004 if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16) {
1005 // we just skipped 4 "continous" events, otherwise we are too fast
1006 [[VLCCoreInteraction sharedInstance] forwardExtraShort];
1007 last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
1008 [self performSelector:@selector(resetForwardSkip)
1015 - (IBAction)stop:(id)sender
1017 [[VLCCoreInteraction sharedInstance] stop];
1020 - (void)resizePlaylistAfterCollapse
1023 plrect = [o_playlist_table frame];
1024 plrect.size.height = i_lastSplitViewHeight - 20.0; // actual pl top bar height, which differs from its frame
1025 [[o_playlist_table animator] setFrame: plrect];
1027 NSRect rightSplitRect;
1028 rightSplitRect = [o_right_split_view frame];
1029 plrect = [o_dropzone_box frame];
1030 plrect.origin.x = (rightSplitRect.size.width - plrect.size.width) / 2;
1031 plrect.origin.y = (rightSplitRect.size.height - plrect.size.height) / 2;
1032 [[o_dropzone_box animator] setFrame: plrect];
1035 - (void)makeSplitViewVisible
1037 if (b_dark_interface)
1038 [self setContentMinSize: NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
1040 [self setContentMinSize: NSMakeSize(604., 288.)];
1042 NSRect old_frame = [self frame];
1043 float newHeight = [self minSize].height;
1044 if (old_frame.size.height < newHeight) {
1045 NSRect new_frame = old_frame;
1046 new_frame.origin.y = old_frame.origin.y + old_frame.size.height - newHeight;
1047 new_frame.size.height = newHeight;
1049 [[self animator] setFrame: new_frame display: YES animate: YES];
1052 [o_video_view setHidden: YES];
1053 [o_split_view setHidden: NO];
1054 [self makeFirstResponder: nil];
1058 - (void)makeSplitViewHidden
1060 if (b_dark_interface)
1061 [self setContentMinSize: NSMakeSize(604., f_min_video_height + [o_titlebar_view frame].size.height)];
1063 [self setContentMinSize: NSMakeSize(604., f_min_video_height)];
1065 [o_split_view setHidden: YES];
1066 [o_video_view setHidden: NO];
1068 if ([[o_video_view subviews] count] > 0)
1069 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
1072 - (IBAction)togglePlaylist:(id)sender
1074 if (![self isVisible] && sender != nil) {
1075 [self makeKeyAndOrderFront: sender];
1079 BOOL b_activeVideo = [[VLCMain sharedInstance] activeVideoPlayback];
1080 BOOL b_restored = NO;
1082 // TODO: implement toggle playlist in this situation (triggerd via menu item).
1083 // but for now we block this case, to avoid displaying only the half
1084 if (b_nativeFullscreenMode && b_fullscreen && b_activeVideo && sender != nil)
1087 if (b_dropzone_active && ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) {
1088 [self hideDropZone];
1092 if (!(b_nativeFullscreenMode && b_fullscreen) && !b_splitview_removed && ((([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0 && b_activeVideo)
1093 || (b_nonembedded && sender != nil)
1094 || (!b_activeVideo && sender != nil)
1095 || b_minimized_view))
1096 [self hideSplitView];
1098 if (b_splitview_removed) {
1099 if (!b_nonembedded || (sender != nil && b_nonembedded))
1100 [self showSplitView];
1103 b_minimized_view = YES;
1105 b_minimized_view = NO;
1111 if (!b_nonembedded) {
1112 if (([o_video_view isHidden] && b_activeVideo) || b_restored || (b_activeVideo && sender == nil))
1113 [self makeSplitViewHidden];
1115 [self makeSplitViewVisible];
1117 [o_split_view setHidden: NO];
1118 [o_playlist_table setHidden: NO];
1119 [o_video_view setHidden: !b_activeVideo];
1120 if (b_activeVideo && [[o_video_view subviews] count] > 0)
1121 [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
1126 - (void)setRepeatOne
1128 [o_repeat_btn setImage: o_repeat_one_img];
1129 [o_repeat_btn setAlternateImage: o_repeat_one_pressed_img];
1132 - (void)setRepeatAll
1134 [o_repeat_btn setImage: o_repeat_all_img];
1135 [o_repeat_btn setAlternateImage: o_repeat_all_pressed_img];
1138 - (void)setRepeatOff
1140 [o_repeat_btn setImage: o_repeat_img];
1141 [o_repeat_btn setAlternateImage: o_repeat_pressed_img];
1144 - (IBAction)repeat:(id)sender
1146 vlc_value_t looping,repeating;
1147 intf_thread_t * p_intf = VLCIntf;
1148 playlist_t * p_playlist = pl_Get(p_intf);
1150 var_Get(p_playlist, "repeat", &repeating);
1151 var_Get(p_playlist, "loop", &looping);
1153 if (!repeating.b_bool && !looping.b_bool) {
1154 /* was: no repeating at all, switching to Repeat One */
1155 [[VLCCoreInteraction sharedInstance] repeatOne];
1156 [self setRepeatOne];
1158 else if (repeating.b_bool && !looping.b_bool) {
1159 /* was: Repeat One, switching to Repeat All */
1160 [[VLCCoreInteraction sharedInstance] repeatAll];
1161 [self setRepeatAll];
1163 /* was: Repeat All or bug in VLC, switching to Repeat Off */
1164 [[VLCCoreInteraction sharedInstance] repeatOff];
1165 [self setRepeatOff];
1172 playlist_t *p_playlist = pl_Get(VLCIntf);
1173 b_value = var_GetBool(p_playlist, "random");
1176 [o_shuffle_btn setImage: o_shuffle_on_img];
1177 [o_shuffle_btn setAlternateImage: o_shuffle_on_pressed_img];
1179 [o_shuffle_btn setImage: o_shuffle_img];
1180 [o_shuffle_btn setAlternateImage: o_shuffle_pressed_img];
1184 - (IBAction)shuffle:(id)sender
1186 [[VLCCoreInteraction sharedInstance] shuffle];
1190 - (IBAction)timeSliderAction:(id)sender
1193 input_thread_t * p_input;
1195 switch([[NSApp currentEvent] type]) {
1197 case NSLeftMouseDown:
1198 case NSLeftMouseDragged:
1199 f_updated = [sender floatValue];
1205 p_input = pl_CurrentInput(VLCIntf);
1206 if (p_input != NULL) {
1210 pos.f_float = f_updated / 10000.;
1211 var_Set(p_input, "position", pos);
1212 [o_time_sld setFloatValue: f_updated];
1214 o_time = [[VLCStringUtility sharedInstance] getCurrentTimeAsString: p_input negative:[o_time_fld timeRemaining]];
1215 [o_time_fld setStringValue: o_time];
1216 [o_fspanel setStreamPos: f_updated andTime: o_time];
1217 vlc_object_release(p_input);
1221 - (IBAction)volumeAction:(id)sender
1223 if (sender == o_volume_sld)
1224 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
1225 else if (sender == o_volume_down_btn)
1226 [[VLCCoreInteraction sharedInstance] toggleMute];
1228 [[VLCCoreInteraction sharedInstance] setVolume: AOUT_VOLUME_MAX];
1231 - (IBAction)effects:(id)sender
1233 [[VLCMainMenu sharedInstance] showAudioEffects: sender];
1236 - (IBAction)fullscreen:(id)sender
1238 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1241 - (IBAction)dropzoneButtonAction:(id)sender
1243 [[[VLCMain sharedInstance] open] openFileGeneric];
1247 #pragma mark overwritten default functionality
1248 - (BOOL)canBecomeKeyWindow
1253 - (void)windowResizedOrMoved:(NSNotification *)notification
1255 [self saveFrameUsingName: [self frameAutosaveName]];
1258 - (void)applicationWillTerminate:(NSNotification *)notification
1260 [self saveFrameUsingName: [self frameAutosaveName]];
1264 - (void)someWindowWillClose:(NSNotification *)notification
1266 id obj = [notification object];
1267 if (obj == o_detached_video_window || obj == o_extra_video_window || (obj == self && !b_nonembedded)) {
1268 if ([[VLCMain sharedInstance] activeVideoPlayback])
1269 [[VLCCoreInteraction sharedInstance] stop];
1273 - (void)someWindowWillMiniaturize:(NSNotification *)notification
1275 if (config_GetInt(VLCIntf, "macosx-pause-minimized")) {
1276 id obj = [notification object];
1277 if (obj == o_detached_video_window || obj == o_extra_video_window || (obj == self && !b_nonembedded)) {
1278 if ([[VLCMain sharedInstance] activeVideoPlayback])
1279 [[VLCCoreInteraction sharedInstance] pause];
1284 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
1286 id videoWindow = [o_video_view window];
1287 if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != videoWindow)
1288 return proposedFrameSize;
1290 // needed when entering lion fullscreen mode
1292 return proposedFrameSize;
1294 if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
1295 NSRect videoWindowFrame = [videoWindow frame];
1296 NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
1297 NSRect contentRect = [videoWindow contentRectForFrameRect:videoWindowFrame];
1298 float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
1299 float marginx = contentRect.size.width - viewRect.size.width;
1300 if (b_dark_interface)// && b_video_deco)
1301 marginy += [o_titlebar_view frame].size.height;
1303 proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
1306 return proposedFrameSize;
1310 #pragma mark Update interface and respond to foreign events
1311 - (void)showDropZone
1313 b_dropzone_active = YES;
1314 [o_right_split_view addSubview: o_dropzone_view positioned:NSWindowAbove relativeTo:o_playlist_table];
1315 [o_dropzone_view setFrame: [o_playlist_table frame]];
1316 [[o_playlist_table animator] setHidden:YES];
1319 - (void)hideDropZone
1321 b_dropzone_active = NO;
1322 [o_dropzone_view removeFromSuperview];
1323 [[o_playlist_table animator] setHidden: NO];
1326 - (void)hideSplitView
1328 NSRect winrect = [self frame];
1329 i_lastSplitViewHeight = [o_split_view frame].size.height;
1330 winrect.size.height = winrect.size.height - i_lastSplitViewHeight;
1331 winrect.origin.y = winrect.origin.y + i_lastSplitViewHeight;
1332 [self setFrame: winrect display: YES animate: YES];
1333 [self performSelector:@selector(hideDropZone) withObject:nil afterDelay:0.1];
1334 if (b_dark_interface) {
1335 [self setContentMinSize: NSMakeSize(604., [o_bottombar_view frame].size.height + [o_titlebar_view frame].size.height)];
1336 [self setContentMaxSize: NSMakeSize(FLT_MAX, [o_bottombar_view frame].size.height + [o_titlebar_view frame].size.height)];
1338 [self setContentMinSize: NSMakeSize(604., [o_bottombar_view frame].size.height)];
1339 [self setContentMaxSize: NSMakeSize(FLT_MAX, [o_bottombar_view frame].size.height)];
1342 b_splitview_removed = YES;
1345 - (void)showSplitView
1347 [self updateWindow];
1348 if (b_dark_interface)
1349 [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
1351 [self setContentMinSize:NSMakeSize(604., 288.)];
1352 [self setContentMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
1355 winrect = [self frame];
1356 winrect.size.height = winrect.size.height + i_lastSplitViewHeight;
1357 winrect.origin.y = winrect.origin.y - i_lastSplitViewHeight;
1358 [self setFrame: winrect display: YES animate: YES];
1360 [self performSelector:@selector(resizePlaylistAfterCollapse) withObject: nil afterDelay:0.75];
1362 b_splitview_removed = NO;
1365 - (void)updateTimeSlider
1367 input_thread_t * p_input;
1368 p_input = pl_CurrentInput(VLCIntf);
1374 var_Get(p_input, "position", &pos);
1375 f_updated = 10000. * pos.f_float;
1376 [o_time_sld setFloatValue: f_updated];
1378 o_time = [[VLCStringUtility sharedInstance] getCurrentTimeAsString: p_input negative:[o_time_fld timeRemaining]];
1380 mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
1382 [o_time_sld setEnabled: NO];
1383 [o_time_sld setHidden: YES];
1384 [o_time_sld_fancygradient_view setHidden: YES];
1386 [o_time_sld setEnabled: YES];
1387 [o_time_sld setHidden: NO];
1388 [o_time_sld_fancygradient_view setHidden: NO];
1391 [o_time_fld setStringValue: o_time];
1392 [o_time_fld setNeedsDisplay:YES];
1393 [o_fspanel setStreamPos: f_updated andTime: o_time];
1394 vlc_object_release(p_input);
1396 [o_time_sld setFloatValue: 0.0];
1397 [o_time_fld setStringValue: @"00:00"];
1398 [o_time_sld setEnabled: NO];
1399 [o_time_sld setHidden: YES];
1400 [o_time_sld_fancygradient_view setHidden: YES];
1401 [o_detached_time_sld_fancygradient_view setHidden: YES];
1404 [o_detached_time_sld setFloatValue: [o_time_sld floatValue]];
1405 [o_detached_time_sld setEnabled: [o_time_sld isEnabled]];
1406 [o_detached_time_fld setStringValue: [o_time_fld stringValue]];
1407 [o_detached_time_sld setHidden: [o_time_sld isHidden]];
1410 - (void)updateVolumeSlider
1412 int i_volume = [[VLCCoreInteraction sharedInstance] volume];
1413 BOOL b_muted = [[VLCCoreInteraction sharedInstance] mute];
1416 [o_volume_sld setIntValue: i_volume];
1417 [o_fspanel setVolumeLevel: i_volume];
1419 [o_volume_sld setIntValue: 0];
1421 [o_volume_sld setEnabled: !b_muted];
1422 [o_volume_up_btn setEnabled: !b_muted];
1427 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1428 input_thread_t * p_input;
1429 p_input = pl_CurrentInput(VLCIntf);
1432 char *format = var_InheritString(VLCIntf, "input-title-format");
1433 char *formated = str_format_meta(pl_Get(VLCIntf), format);
1435 aString = [NSString stringWithUTF8String:formated];
1438 char *uri = input_item_GetURI(input_GetItem(p_input));
1440 NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
1441 if ([o_url isFileURL]) {
1442 [self setRepresentedURL: o_url];
1443 [o_detached_video_window setRepresentedURL: o_url];
1445 [self setRepresentedURL: nil];
1446 [o_detached_video_window setRepresentedURL: nil];
1450 if ([aString isEqualToString:@""]) {
1451 if ([o_url isFileURL])
1452 aString = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
1454 aString = [o_url absoluteString];
1457 [self setTitle: aString];
1458 if (b_nonembedded && [[VLCMain sharedInstance] activeVideoPlayback])
1459 [o_detached_video_window setTitle: aString];
1461 [o_fspanel setStreamTitle: aString];
1462 vlc_object_release(p_input);
1464 [self setTitle: _NS("VLC media player")];
1465 [self setRepresentedURL: nil];
1471 - (void)updateWindow
1473 bool b_input = false;
1474 bool b_plmul = false;
1475 bool b_control = false;
1476 bool b_seekable = false;
1477 bool b_chapters = false;
1479 playlist_t * p_playlist = pl_Get(VLCIntf);
1482 b_plmul = playlist_CurrentSize(p_playlist) > 1;
1485 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
1487 bool b_buffering = NO;
1489 if ((b_input = (p_input != NULL))) {
1490 /* seekable streams */
1491 cachedInputState = input_GetState(p_input);
1492 if (cachedInputState == INIT_S || cachedInputState == OPENING_S)
1495 /* seekable streams */
1496 b_seekable = var_GetBool(p_input, "can-seek");
1498 /* check whether slow/fast motion is possible */
1499 b_control = var_GetBool(p_input, "can-rate");
1501 /* chapters & titles */
1502 //FIXME! b_chapters = p_input->stream.i_area_nb > 1;
1504 vlc_object_release(p_input);
1508 [o_progress_bar startAnimation:self];
1509 [o_progress_bar setIndeterminate:YES];
1510 [o_progress_bar setHidden:NO];
1512 [o_progress_bar stopAnimation:self];
1513 [o_progress_bar setHidden:YES];
1516 [o_stop_btn setEnabled: b_input];
1517 [o_fwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
1518 [o_bwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
1519 if (b_show_jump_buttons) {
1520 [o_prev_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
1521 [o_next_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
1523 [o_detached_fwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
1524 [o_detached_bwd_btn setEnabled: (b_seekable || b_plmul || b_chapters)];
1525 [[VLCMainMenu sharedInstance] setRateControlsEnabled: b_control];
1527 [o_time_sld setEnabled: b_seekable];
1528 [self updateTimeSlider];
1529 [o_fspanel setSeekable: b_seekable];
1532 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
1533 [self hideDropZone];
1535 [self showDropZone];
1537 [o_sidebar_view setNeedsDisplay:YES];
1542 [o_play_btn setImage: o_pause_img];
1543 [o_play_btn setAlternateImage: o_pause_pressed_img];
1544 [o_play_btn setToolTip: _NS("Pause")];
1545 [o_detached_play_btn setImage: o_pause_img];
1546 [o_detached_play_btn setAlternateImage: o_pause_pressed_img];
1547 [o_detached_play_btn setToolTip: _NS("Pause")];
1548 [o_fspanel setPause];
1553 [o_play_btn setImage: o_play_img];
1554 [o_play_btn setAlternateImage: o_play_pressed_img];
1555 [o_play_btn setToolTip: _NS("Play")];
1556 [o_detached_play_btn setImage: o_play_img];
1557 [o_detached_play_btn setAlternateImage: o_play_pressed_img];
1558 [o_detached_play_btn setToolTip: _NS("Play")];
1559 [o_fspanel setPlay];
1562 - (void)drawFancyGradientEffectForTimeSlider
1564 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1565 CGFloat f_value = [o_time_sld knobPosition];
1566 if (f_value > 7.5) {
1567 NSRect oldFrame = [o_time_sld_fancygradient_view frame];
1568 if (f_value != oldFrame.size.width) {
1569 if ([o_time_sld_fancygradient_view isHidden])
1570 [o_time_sld_fancygradient_view setHidden: NO];
1571 [o_time_sld_fancygradient_view setFrame: NSMakeRect(oldFrame.origin.x, oldFrame.origin.y, f_value, oldFrame.size.height)];
1574 if (b_nonembedded) {
1575 f_value = [o_detached_time_sld knobPosition];
1576 oldFrame = [o_detached_time_sld_fancygradient_view frame];
1577 if (f_value != oldFrame.size.width)
1579 if ([o_detached_time_sld_fancygradient_view isHidden])
1580 [o_detached_time_sld_fancygradient_view setHidden: NO];
1581 [o_detached_time_sld_fancygradient_view setFrame: NSMakeRect(oldFrame.origin.x, oldFrame.origin.y, f_value, oldFrame.size.height)];
1586 frame = [o_time_sld_fancygradient_view frame];
1587 if (frame.size.width > 0) {
1588 frame.size.width = 0;
1589 [o_time_sld_fancygradient_view setFrame: frame];
1591 frame = [o_detached_time_sld_fancygradient_view frame];
1592 frame.size.width = 0;
1593 [o_detached_time_sld_fancygradient_view setFrame: frame];
1595 [o_time_sld_fancygradient_view setHidden: YES];
1596 [o_detached_time_sld_fancygradient_view setHidden: YES];
1602 #pragma mark Video Output handling
1605 return o_video_view;
1608 - (void)setupVideoView
1610 BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
1611 BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
1613 // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
1614 if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
1615 // b_video_wallpaper is priorized over !b_video_deco
1617 msg_Dbg(VLCIntf, "Creating background / blank window");
1618 NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
1620 screen = [self screen];
1623 if (b_video_wallpaper)
1624 window_rect = [screen frame];
1626 window_rect = NSMakeRect(50, 50, 200, 200); // TODO: find something more sensible here
1628 if (o_extra_video_window)
1629 [o_extra_video_window release];
1631 NSUInteger mask = NSBorderlessWindowMask;
1632 if (!OSX_SNOW_LEOPARD && !b_video_deco)
1633 mask |= NSResizableWindowMask;
1635 BOOL b_no_video_deco_only = !b_video_wallpaper;
1636 o_extra_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
1637 [o_extra_video_window setDelegate:self];
1639 if (b_video_wallpaper)
1640 [o_extra_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
1642 [o_extra_video_window setBackgroundColor: [NSColor blackColor]];
1643 [o_extra_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
1644 [o_extra_video_window setCanBecomeMainWindow: !b_video_wallpaper];
1645 [o_extra_video_window setAcceptsMouseMovedEvents:!b_video_wallpaper];
1646 [o_extra_video_window setMovableByWindowBackground: !b_video_wallpaper];
1647 [o_extra_video_window useOptimizedDrawing: YES];
1649 [o_video_view retain];
1650 if ([o_video_view superview] != NULL)
1651 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1652 window_rect.origin.x = window_rect.origin.y = 0;
1653 [o_video_view setFrame: window_rect];
1654 [[o_extra_video_window contentView] addSubview: o_video_view positioned:NSWindowAbove relativeTo:nil];
1655 [o_video_view release];
1657 if (b_video_wallpaper)
1658 [o_extra_video_window orderBack:nil];
1660 [o_extra_video_window setFrameAutosaveName:@"extra-videowindow"];
1661 [o_detached_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
1664 b_nonembedded = YES;
1666 if (var_InheritBool(VLCIntf, "embedded-video") || b_nativeFullscreenMode) {
1667 if ([o_video_view window] != self) {
1668 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1669 [o_video_view setFrame: [o_split_view frame]];
1670 [[self contentView] addSubview:o_video_view positioned:NSWindowAbove relativeTo:nil];
1674 if ([o_video_view superview] != NULL)
1675 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1678 videoFrame.size = [[o_detached_video_window contentView] frame].size;
1679 videoFrame.size.height -= [o_detached_bottombar_view frame].size.height;
1680 if (b_dark_interface)
1681 videoFrame.size.height -= [o_titlebar_view frame].size.height;
1683 videoFrame.origin.x = .0;
1684 videoFrame.origin.y = [o_detached_bottombar_view frame].size.height;
1686 [o_video_view setFrame: videoFrame];
1687 [[o_detached_video_window contentView] addSubview: o_video_view positioned:NSWindowAbove relativeTo:nil];
1688 [o_detached_video_window setLevel:NSNormalWindowLevel];
1689 [o_detached_video_window useOptimizedDrawing: YES];
1690 b_nonembedded = YES;
1694 if (!b_video_wallpaper) {
1695 [[o_video_view window] makeKeyAndOrderFront: self];
1697 vout_thread_t *p_vout = getVout();
1699 if (var_GetBool(p_vout, "video-on-top"))
1700 [[o_video_view window] setLevel: NSStatusWindowLevel];
1702 [[o_video_view window] setLevel: NSNormalWindowLevel];
1703 vlc_object_release(p_vout);
1707 [[o_video_view window] setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
1710 - (void)setVideoplayEnabled
1712 BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
1714 if (b_videoPlayback) {
1715 frameBeforePlayback = [self frame];
1717 // look for 'start at fullscreen'
1718 [[VLCMain sharedInstance] fullscreenChanged];
1720 [[self animator] setFrame:frameBeforePlayback display:YES];
1722 [self makeFirstResponder: nil];
1723 [o_detached_video_window orderOut: nil];
1724 if (o_extra_video_window)
1725 [o_extra_video_window orderOut: nil];
1727 if ([self level] != NSNormalWindowLevel)
1728 [self setLevel: NSNormalWindowLevel];
1729 if ([o_detached_video_window level] != NSNormalWindowLevel)
1730 [o_detached_video_window setLevel: NSNormalWindowLevel];
1732 // restore alpha value to 1 for the case that macosx-opaqueness is set to < 1
1733 [self setAlphaValue:1.0];
1736 if (b_nativeFullscreenMode) {
1737 if ([NSApp presentationOptions] & NSApplicationPresentationFullScreen)
1738 [o_bottombar_view setHidden: b_videoPlayback];
1740 [o_bottombar_view setHidden: NO];
1741 if (b_videoPlayback && b_fullscreen)
1742 [o_fspanel setActive: nil];
1743 if (!b_videoPlayback)
1744 [o_fspanel setNonActive: nil];
1747 if (!b_videoPlayback && b_fullscreen) {
1748 if (!b_nativeFullscreenMode)
1749 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1753 - (void)resizeWindow
1755 if (b_fullscreen || (b_nativeFullscreenMode && [NSApp presentationOptions] & NSApplicationPresentationFullScreen))
1758 id o_videoWindow = [o_video_view window];
1759 NSSize windowMinSize = [o_videoWindow minSize];
1760 NSRect screenFrame = [[o_videoWindow screen] visibleFrame];
1762 NSPoint topleftbase = NSMakePoint(0, [o_videoWindow frame].size.height);
1763 NSPoint topleftscreen = [o_videoWindow convertBaseToScreen: topleftbase];
1765 unsigned int i_width = nativeVideoSize.width;
1766 unsigned int i_height = nativeVideoSize.height;
1767 if (i_width < windowMinSize.width)
1768 i_width = windowMinSize.width;
1769 if (i_height < f_min_video_height)
1770 i_height = f_min_video_height;
1772 /* Calculate the window's new size */
1774 new_frame.size.width = [o_videoWindow frame].size.width - [o_video_view frame].size.width + i_width;
1775 new_frame.size.height = [o_videoWindow frame].size.height - [o_video_view frame].size.height + i_height;
1776 new_frame.origin.x = topleftscreen.x;
1777 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
1779 /* make sure the window doesn't exceed the screen size the window is on */
1780 if (new_frame.size.width > screenFrame.size.width) {
1781 new_frame.size.width = screenFrame.size.width;
1782 new_frame.origin.x = screenFrame.origin.x;
1784 if (new_frame.size.height > screenFrame.size.height) {
1785 new_frame.size.height = screenFrame.size.height;
1786 new_frame.origin.y = screenFrame.origin.y;
1788 if (new_frame.origin.y < screenFrame.origin.y)
1789 new_frame.origin.y = screenFrame.origin.y;
1791 CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
1792 CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
1793 if (right_window_point > right_screen_point)
1794 new_frame.origin.x -= (right_window_point - right_screen_point);
1796 [[o_videoWindow animator] setFrame:new_frame display:YES];
1799 - (void)setNativeVideoSize:(NSSize)size
1801 nativeVideoSize = size;
1803 if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !b_fullscreen && !var_InheritBool(VLCIntf, "video-wallpaper"))
1804 [self performSelectorOnMainThread:@selector(resizeWindow) withObject:nil waitUntilDone:NO];
1807 // Called automatically if window's acceptsMouseMovedEvents property is true
1808 - (void)mouseMoved:(NSEvent *)theEvent
1811 [self recreateHideMouseTimer];
1813 [super mouseMoved: theEvent];
1816 - (void)recreateHideMouseTimer
1818 if (t_hide_mouse_timer != nil) {
1819 [t_hide_mouse_timer invalidate];
1820 [t_hide_mouse_timer release];
1823 t_hide_mouse_timer = [NSTimer scheduledTimerWithTimeInterval:2
1825 selector:@selector(hideMouseCursor:)
1828 [t_hide_mouse_timer retain];
1831 // NSTimer selectors require this function signature as per Apple's docs
1832 - (void)hideMouseCursor:(NSTimer *)timer
1834 [NSCursor setHiddenUntilMouseMoves: YES];
1838 #pragma mark Fullscreen support
1839 - (void)showFullscreenController
1841 if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback])
1847 return b_fullscreen;
1850 - (void)lockFullscreenAnimation
1852 [o_animation_lock lock];
1855 - (void)unlockFullscreenAnimation
1857 [o_animation_lock unlock];
1860 - (void)enterFullscreen
1862 NSMutableDictionary *dict1, *dict2;
1866 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
1867 o_current_video_window = [o_video_view window];
1869 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
1870 [self lockFullscreenAnimation];
1873 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
1874 screen = [o_current_video_window screen];
1877 msg_Dbg(VLCIntf, "Using deepest screen");
1878 screen = [NSScreen deepestScreen];
1881 screen_rect = [screen frame];
1883 [o_fullscreen_btn setState: YES];
1884 [o_detached_fullscreen_btn setState: YES];
1886 [self recreateHideMouseTimer];
1888 if (blackout_other_displays)
1889 [screen blackoutOtherScreens];
1891 /* Make sure we don't see the window flashes in float-on-top mode */
1892 i_originalLevel = [o_current_video_window level];
1893 [o_current_video_window setLevel:NSNormalWindowLevel];
1895 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
1896 if (!o_fullscreen_window) {
1897 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
1899 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
1900 rect.origin.x += [o_current_video_window frame].origin.x;
1901 rect.origin.y += [o_current_video_window frame].origin.y;
1902 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
1903 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
1904 [o_fullscreen_window setCanBecomeKeyWindow: YES];
1905 [o_fullscreen_window setCanBecomeMainWindow: YES];
1907 if (![o_current_video_window isVisible] || [o_current_video_window alphaValue] == 0.0) {
1908 /* We don't animate if we are not visible, instead we
1909 * simply fade the display */
1910 CGDisplayFadeReservationToken token;
1912 if (blackout_other_displays) {
1913 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1914 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
1917 if ([screen mainScreen])
1918 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1920 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1921 [o_temp_view setFrame:[o_video_view frame]];
1922 [o_fullscreen_window setContentView:o_video_view];
1924 [o_fullscreen_window makeKeyAndOrderFront:self];
1925 [o_fullscreen_window orderFront:self animate:YES];
1927 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
1928 [o_fullscreen_window setLevel:NSNormalWindowLevel];
1930 if (blackout_other_displays) {
1931 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
1932 CGReleaseDisplayFadeReservation(token);
1935 /* Will release the lock */
1936 [self hasBecomeFullscreen];
1941 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1942 NSDisableScreenUpdates();
1943 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1944 [o_temp_view setFrame:[o_video_view frame]];
1945 [o_fullscreen_window setContentView:o_video_view];
1946 [o_fullscreen_window makeKeyAndOrderFront:self];
1947 NSEnableScreenUpdates();
1950 /* We are in fullscreen (and no animation is running) */
1952 /* Make sure we are hidden */
1953 [o_current_video_window orderOut: self];
1955 [self unlockFullscreenAnimation];
1959 if (o_fullscreen_anim1) {
1960 [o_fullscreen_anim1 stopAnimation];
1961 [o_fullscreen_anim1 release];
1963 if (o_fullscreen_anim2) {
1964 [o_fullscreen_anim2 stopAnimation];
1965 [o_fullscreen_anim2 release];
1968 if ([screen mainScreen])
1969 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1971 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
1972 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
1974 [dict1 setObject:o_current_video_window forKey:NSViewAnimationTargetKey];
1975 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
1977 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1978 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1979 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
1981 /* Strategy with NSAnimation allocation:
1982 - Keep at most 2 animation at a time
1983 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
1985 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
1986 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
1991 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1992 [o_fullscreen_anim1 setDuration: 0.3];
1993 [o_fullscreen_anim1 setFrameRate: 30];
1994 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1995 [o_fullscreen_anim2 setDuration: 0.2];
1996 [o_fullscreen_anim2 setFrameRate: 30];
1998 [o_fullscreen_anim2 setDelegate: self];
1999 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
2001 [o_fullscreen_anim1 startAnimation];
2002 /* fullscreenAnimation will be unlocked when animation ends */
2005 - (void)hasBecomeFullscreen
2007 if ([[o_video_view subviews] count] > 0)
2008 [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
2010 [o_fullscreen_window makeKeyWindow];
2011 [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
2013 /* tell the fspanel to move itself to front next time it's triggered */
2014 [o_fspanel setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
2015 [o_fspanel setActive: nil];
2017 if ([o_current_video_window isVisible])
2018 [o_current_video_window orderOut: self];
2021 [self unlockFullscreenAnimation];
2024 - (void)leaveFullscreen
2026 [self leaveFullscreenAndFadeOut: NO];
2029 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
2031 NSMutableDictionary *dict1, *dict2;
2033 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
2035 if (!o_current_video_window)
2038 [self lockFullscreenAnimation];
2040 [o_fullscreen_btn setState: NO];
2041 [o_detached_fullscreen_btn setState: NO];
2043 /* We always try to do so */
2044 [NSScreen unblackoutScreens];
2046 vout_thread_t *p_vout = getVout();
2048 if (var_GetBool(p_vout, "video-on-top"))
2049 [[o_video_view window] setLevel: NSStatusWindowLevel];
2051 [[o_video_view window] setLevel: NSNormalWindowLevel];
2052 vlc_object_release(p_vout);
2054 [[o_video_view window] makeKeyAndOrderFront: nil];
2056 /* Don't do anything if o_fullscreen_window is already closed */
2057 if (!o_fullscreen_window) {
2058 [self unlockFullscreenAnimation];
2063 /* We don't animate if we are not visible, instead we
2064 * simply fade the display */
2065 CGDisplayFadeReservationToken token;
2067 if (blackout_other_displays) {
2068 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
2069 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
2072 [o_fspanel setNonActive: nil];
2073 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
2075 /* Will release the lock */
2076 [self hasEndedFullscreen];
2078 /* Our window is hidden, and might be faded. We need to workaround that, so note it
2080 b_window_is_invisible = YES;
2082 if (blackout_other_displays) {
2083 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
2084 CGReleaseDisplayFadeReservation(token);
2090 [o_current_video_window setAlphaValue: 0.0];
2091 [o_current_video_window orderFront: self];
2092 [[o_video_view window] orderFront: self];
2094 [o_fspanel setNonActive: nil];
2095 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
2097 if (o_fullscreen_anim1) {
2098 [o_fullscreen_anim1 stopAnimation];
2099 [o_fullscreen_anim1 release];
2101 if (o_fullscreen_anim2) {
2102 [o_fullscreen_anim2 stopAnimation];
2103 [o_fullscreen_anim2 release];
2106 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
2107 frame.origin.x += [o_current_video_window frame].origin.x;
2108 frame.origin.y += [o_current_video_window frame].origin.y;
2110 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
2111 [dict2 setObject:o_current_video_window forKey:NSViewAnimationTargetKey];
2112 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
2114 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
2117 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
2118 [o_fullscreen_anim2 setDuration: 0.3];
2119 [o_fullscreen_anim2 setFrameRate: 30];
2121 [o_fullscreen_anim2 setDelegate: self];
2123 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
2125 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
2126 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
2127 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
2129 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
2132 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
2133 [o_fullscreen_anim1 setDuration: 0.2];
2134 [o_fullscreen_anim1 setFrameRate: 30];
2135 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
2137 /* Make sure o_fullscreen_window is the frontmost window */
2138 [o_fullscreen_window orderFront: self];
2140 [o_fullscreen_anim1 startAnimation];
2141 /* fullscreenAnimation will be unlocked when animation ends */
2144 - (void)hasEndedFullscreen
2148 /* This function is private and should be only triggered at the end of the fullscreen change animation */
2149 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
2150 NSDisableScreenUpdates();
2151 [o_video_view retain];
2152 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
2153 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
2154 [o_video_view release];
2155 [o_video_view setFrame:[o_temp_view frame]];
2156 if ([[o_video_view subviews] count] > 0)
2157 [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
2159 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
2161 [[o_video_view window] makeKeyAndOrderFront: self];
2162 [o_fullscreen_window orderOut: self];
2163 NSEnableScreenUpdates();
2165 [o_fullscreen_window release];
2166 o_fullscreen_window = nil;
2167 [[o_video_view window] setLevel:i_originalLevel];
2168 [[o_video_view window] setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
2170 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
2171 if (![[VLCMain sharedInstance] activeVideoPlayback] && b_nonembedded)
2172 [o_current_video_window orderOut: self];
2174 o_current_video_window = nil;
2175 [self unlockFullscreenAnimation];
2178 - (void)animationDidEnd:(NSAnimation*)animation
2180 NSArray *viewAnimations;
2181 if (o_makekey_anim == animation) {
2182 [o_makekey_anim release];
2185 if ([animation currentValue] < 1.0)
2188 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
2189 viewAnimations = [o_fullscreen_anim2 viewAnimations];
2190 if ([viewAnimations count] >=1 &&
2191 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
2192 /* Fullscreen ended */
2193 [self hasEndedFullscreen];
2195 /* Fullscreen started */
2196 [self hasBecomeFullscreen];
2199 - (void)makeKeyAndOrderFront: (id)sender
2202 * when we exit fullscreen and fade out, we may endup in
2203 * having a window that is faded. We can't have it fade in unless we
2206 if (!b_window_is_invisible) {
2207 /* Make sure we don't do it too much */
2208 [super makeKeyAndOrderFront: sender];
2212 [super setAlphaValue:0.0f];
2213 [super makeKeyAndOrderFront: sender];
2215 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
2216 [dict setObject:self forKey:NSViewAnimationTargetKey];
2217 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
2219 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
2222 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
2223 [o_makekey_anim setDuration: 0.1];
2224 [o_makekey_anim setFrameRate: 30];
2225 [o_makekey_anim setDelegate: self];
2227 [o_makekey_anim startAnimation];
2228 b_window_is_invisible = NO;
2230 /* fullscreenAnimation will be unlocked when animation ends */
2234 #pragma mark Lion native fullscreen handling
2235 - (void)windowWillEnterFullScreen:(NSNotification *)notification
2237 // workaround, see #6668
2238 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
2240 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
2242 vout_thread_t *p_vout = getVout();
2244 var_SetBool(p_vout, "fullscreen", true);
2245 vlc_object_release(p_vout);
2248 [o_video_view setFrame: [[self contentView] frame]];
2251 [self recreateHideMouseTimer];
2252 i_originalLevel = [self level];
2253 [self setLevel:NSNormalWindowLevel];
2255 if (b_dark_interface) {
2256 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
2259 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
2260 winrect = [self frame];
2262 winrect.size.height = winrect.size.height - f_titleBarHeight;
2263 [self setFrame: winrect display:NO animate:NO];
2264 winrect = [o_split_view frame];
2265 winrect.size.height = winrect.size.height + f_titleBarHeight;
2266 [o_split_view setFrame: winrect];
2269 if ([[VLCMain sharedInstance] activeVideoPlayback])
2270 [o_bottombar_view setHidden: YES];
2272 [self setMovableByWindowBackground: NO];
2275 - (void)windowDidEnterFullScreen:(NSNotification *)notification
2277 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
2278 // But this creates some problems when leaving fs over remote intfs, so activate app here.
2279 [NSApp activateIgnoringOtherApps:YES];
2281 [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
2282 [o_fspanel setActive: nil];
2285 - (void)windowWillExitFullScreen:(NSNotification *)notification
2288 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
2290 vout_thread_t *p_vout = getVout();
2292 var_SetBool(p_vout, "fullscreen", false);
2293 vlc_object_release(p_vout);
2296 [o_video_view setFrame: [o_split_view frame]];
2297 [NSCursor setHiddenUntilMouseMoves: NO];
2298 [o_fspanel setNonActive: nil];
2299 [self setLevel:i_originalLevel];
2302 if (b_dark_interface) {
2304 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
2305 winrect = [self frame];
2307 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
2308 winrect.size.width, f_titleBarHeight)];
2309 [[self contentView] addSubview: o_titlebar_view];
2311 winrect.size.height = winrect.size.height + f_titleBarHeight;
2312 [self setFrame: winrect display:NO animate:NO];
2313 winrect = [o_split_view frame];
2314 winrect.size.height = winrect.size.height - f_titleBarHeight;
2315 [o_split_view setFrame: winrect];
2316 [o_video_view setFrame: winrect];
2319 if ([[VLCMain sharedInstance] activeVideoPlayback])
2320 [o_bottombar_view setHidden: NO];
2322 [self setMovableByWindowBackground: YES];
2326 #pragma mark split view delegate
2327 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
2329 if (dividerIndex == 0)
2335 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
2337 if (dividerIndex == 0)
2343 - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview
2345 return ([subview isEqual:o_left_split_view]);
2348 - (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)subview
2350 if ([subview isEqual:o_left_split_view])
2356 #pragma mark Side Bar Data handling
2357 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
2358 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
2360 //Works the same way as the NSOutlineView data source: `nil` means a parent item
2362 return [o_sidebaritems count];
2364 return [[item children] count];
2368 - (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
2370 //Works the same way as the NSOutlineView data source: `nil` means a parent item
2372 return [o_sidebaritems objectAtIndex:index];
2374 return [[item children] objectAtIndex:index];
2378 - (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
2380 return [item title];
2383 - (void)sourceList:(PXSourceList*)aSourceList setObjectValue:(id)object forItem:(id)item
2385 [item setTitle:object];
2388 - (BOOL)sourceList:(PXSourceList*)aSourceList isItemExpandable:(id)item
2390 return [item hasChildren];
2394 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasBadge:(id)item
2396 if ([[item identifier] isEqualToString: @"playlist"] || [[item identifier] isEqualToString: @"medialibrary"])
2399 return [item hasBadge];
2403 - (NSInteger)sourceList:(PXSourceList*)aSourceList badgeValueForItem:(id)item
2405 playlist_t * p_playlist = pl_Get(VLCIntf);
2406 NSInteger i_playlist_size;
2408 if ([[item identifier] isEqualToString: @"playlist"]) {
2410 i_playlist_size = p_playlist->p_local_category->i_children;
2413 return i_playlist_size;
2415 if ([[item identifier] isEqualToString: @"medialibrary"]) {
2417 i_playlist_size = p_playlist->p_ml_category->i_children;
2420 return i_playlist_size;
2423 return [item badgeValue];
2427 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasIcon:(id)item
2429 return [item hasIcon];
2433 - (NSImage*)sourceList:(PXSourceList*)aSourceList iconForItem:(id)item
2438 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
2440 if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
2443 if ([item sdtype] > 0)
2445 m = [[NSMenu alloc] init];
2446 playlist_t * p_playlist = pl_Get(VLCIntf);
2447 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
2449 [m addItemWithTitle:_NS("Enable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
2451 [m addItemWithTitle:_NS("Disable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
2452 [[m itemAtIndex:0] setRepresentedObject: [item identifier]];
2454 return [m autorelease];
2461 - (IBAction)sdmenuhandler:(id)sender
2463 NSString * identifier = [sender representedObject];
2464 if ([identifier length] > 0 && ![identifier isEqualToString:@"lua{sd='freebox',longname='Freebox TV'}"]) {
2465 playlist_t * p_playlist = pl_Get(VLCIntf);
2466 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [identifier UTF8String]);
2469 playlist_ServicesDiscoveryAdd(p_playlist, [identifier UTF8String]);
2471 playlist_ServicesDiscoveryRemove(p_playlist, [identifier UTF8String]);
2476 #pragma mark Side Bar Delegate Methods
2477 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
2478 - (BOOL)sourceList:(PXSourceList*)aSourceList isGroupAlwaysExpanded:(id)group
2480 if ([[group identifier] isEqualToString:@"library"])
2486 - (void)sourceListSelectionDidChange:(NSNotification *)notification
2488 playlist_t * p_playlist = pl_Get(VLCIntf);
2490 NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
2491 id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
2494 //Set the label text to represent the new selection
2495 if ([item sdtype] > -1 && [[item identifier] length] > 0) {
2496 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
2498 playlist_ServicesDiscoveryAdd(p_playlist, [[item identifier] UTF8String]);
2501 [o_chosen_category_lbl setStringValue:[item title]];
2503 if ([[item identifier] isEqualToString:@"playlist"]) {
2504 [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_local_category];
2505 } else if ([[item identifier] isEqualToString:@"medialibrary"]) {
2506 [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_ml_category];
2508 playlist_item_t * pl_item;
2510 pl_item = playlist_ChildSearchName(p_playlist->p_root, [[item untranslatedTitle] UTF8String]);
2512 [[[VLCMain sharedInstance] playlist] setPlaylistRoot: pl_item];
2516 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
2517 [self hideDropZone];
2519 [self showDropZone];
2522 if ([[item identifier] isEqualToString:@"podcast{longname=\"Podcasts\"}"])
2523 [self showPodcastControls];
2525 [self hidePodcastControls];
2528 - (NSDragOperation)sourceList:(PXSourceList *)aSourceList validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
2530 if ([[item identifier] isEqualToString:@"playlist"] || [[item identifier] isEqualToString:@"medialibrary"]) {
2531 NSPasteboard *o_pasteboard = [info draggingPasteboard];
2532 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] || [[o_pasteboard types] containsObject: NSFilenamesPboardType])
2533 return NSDragOperationGeneric;
2535 return NSDragOperationNone;
2538 - (BOOL)sourceList:(PXSourceList *)aSourceList acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
2540 NSPasteboard *o_pasteboard = [info draggingPasteboard];
2542 playlist_t * p_playlist = pl_Get(VLCIntf);
2543 playlist_item_t *p_node;
2545 if ([[item identifier] isEqualToString:@"playlist"])
2546 p_node = p_playlist->p_local_category;
2548 p_node = p_playlist->p_ml_category;
2550 if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
2551 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
2552 NSUInteger count = [o_values count];
2553 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
2555 for(NSUInteger i = 0; i < count; i++) {
2556 NSDictionary *o_dic;
2557 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
2561 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
2565 [o_array addObject: o_dic];
2568 [[[VLCMain sharedInstance] playlist] appendNodeArray:o_array inNode: p_node atPos:-1 enqueue:YES];
2571 else if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
2572 NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
2574 NSUInteger count = [array count];
2575 playlist_item_t * p_item = NULL;
2578 for(NSUInteger i = 0; i < count; i++) {
2579 p_item = [[array objectAtIndex:i] pointerValue];
2580 if (!p_item) continue;
2581 playlist_NodeAddCopy(p_playlist, p_item, p_node, PLAYLIST_END);
2590 - (id)sourceList:(PXSourceList *)aSourceList persistentObjectForItem:(id)item
2592 return [item identifier];
2595 - (id)sourceList:(PXSourceList *)aSourceList itemForPersistentObject:(id)object
2597 /* the following code assumes for sakes of simplicity that only the top level
2598 * items are allowed to have children */
2600 NSArray * array = [NSArray arrayWithArray: o_sidebaritems]; // read-only arrays are noticebly faster
2601 NSUInteger count = [array count];
2605 for (NSUInteger x = 0; x < count; x++) {
2606 id item = [array objectAtIndex: x]; // save one objc selector call
2607 if ([[item identifier] isEqualToString:object])
2615 #pragma mark Podcast
2617 - (IBAction)addPodcast:(id)sender
2619 [NSApp beginSheet:o_podcast_subscribe_window modalForWindow:self modalDelegate:self didEndSelector:NULL contextInfo:nil];
2622 - (IBAction)addPodcastWindowAction:(id)sender
2624 [o_podcast_subscribe_window orderOut:sender];
2625 [NSApp endSheet: o_podcast_subscribe_window];
2627 if (sender == o_podcast_subscribe_ok_btn && [[o_podcast_subscribe_url_fld stringValue] length] > 0) {
2628 NSMutableString * podcastConf = [[NSMutableString alloc] init];
2629 if (config_GetPsz(VLCIntf, "podcast-urls") != NULL)
2630 [podcastConf appendFormat:@"%s|", config_GetPsz(VLCIntf, "podcast-urls")];
2632 [podcastConf appendString: [o_podcast_subscribe_url_fld stringValue]];
2633 config_PutPsz(VLCIntf, "podcast-urls", [podcastConf UTF8String]);
2635 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name(VLCIntf->p_libvlc, "podcast");
2637 var_SetString(p_obj, "podcast-urls", [podcastConf UTF8String]);
2638 vlc_object_release(p_obj);
2640 [podcastConf release];
2644 - (IBAction)removePodcast:(id)sender
2646 if (config_GetPsz(VLCIntf, "podcast-urls") != NULL) {
2647 [o_podcast_unsubscribe_pop removeAllItems];
2648 [o_podcast_unsubscribe_pop addItemsWithTitles:[[NSString stringWithUTF8String:config_GetPsz(VLCIntf, "podcast-urls")] componentsSeparatedByString:@"|"]];
2649 [NSApp beginSheet:o_podcast_unsubscribe_window modalForWindow:self modalDelegate:self didEndSelector:NULL contextInfo:nil];
2653 - (IBAction)removePodcastWindowAction:(id)sender
2655 [o_podcast_unsubscribe_window orderOut:sender];
2656 [NSApp endSheet: o_podcast_unsubscribe_window];
2658 if (sender == o_podcast_unsubscribe_ok_btn) {
2659 NSMutableArray * urls = [[NSMutableArray alloc] initWithArray:[[NSString stringWithUTF8String:config_GetPsz(VLCIntf, "podcast-urls")] componentsSeparatedByString:@"|"]];
2660 [urls removeObjectAtIndex: [o_podcast_unsubscribe_pop indexOfSelectedItem]];
2661 config_PutPsz(VLCIntf, "podcast-urls", [[urls componentsJoinedByString:@"|"] UTF8String]);
2664 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name(VLCIntf->p_libvlc, "podcast");
2666 var_SetString(p_obj, "podcast-urls", config_GetPsz(VLCIntf, "podcast-urls"));
2667 vlc_object_release(p_obj);
2670 /* reload the podcast module, since it won't update its list when removing podcasts */
2671 playlist_t * p_playlist = pl_Get(VLCIntf);
2672 if (playlist_IsServicesDiscoveryLoaded(p_playlist, "podcast{longname=\"Podcasts\"}")) {
2673 playlist_ServicesDiscoveryRemove(p_playlist, "podcast{longname=\"Podcasts\"}");
2674 playlist_ServicesDiscoveryAdd(p_playlist, "podcast{longname=\"Podcasts\"}");
2675 [o_playlist_table reloadData];
2681 - (void)showPodcastControls
2683 NSRect podcastViewDimensions = [o_podcast_view frame];
2684 NSRect rightSplitRect = [o_right_split_view frame];
2685 NSRect playlistTableRect = [o_playlist_table frame];
2687 podcastViewDimensions.size.width = rightSplitRect.size.width;
2688 podcastViewDimensions.origin.x = podcastViewDimensions.origin.y = .0;
2689 [o_podcast_view setFrame:podcastViewDimensions];
2691 playlistTableRect.origin.y = playlistTableRect.origin.y + podcastViewDimensions.size.height;
2692 playlistTableRect.size.height = playlistTableRect.size.height - podcastViewDimensions.size.height;
2693 [o_playlist_table setFrame:playlistTableRect];
2694 [o_playlist_table setNeedsDisplay:YES];
2696 [o_right_split_view addSubview: o_podcast_view positioned: NSWindowAbove relativeTo: o_right_split_view];
2697 b_podcastView_displayed = YES;
2700 - (void)hidePodcastControls
2702 if (b_podcastView_displayed) {
2703 NSRect podcastViewDimensions = [o_podcast_view frame];
2704 NSRect playlistTableRect = [o_playlist_table frame];
2706 playlistTableRect.origin.y = playlistTableRect.origin.y - podcastViewDimensions.size.height;
2707 playlistTableRect.size.height = playlistTableRect.size.height + podcastViewDimensions.size.height;
2709 [o_podcast_view removeFromSuperviewWithoutNeedingDisplay];
2710 [o_playlist_table setFrame: playlistTableRect];
2711 b_podcastView_displayed = NO;
2717 @implementation VLCDetachedVideoWindow
2719 - (void)awakeFromNib
2721 [self setAcceptsMouseMovedEvents: YES];
2723 if (b_dark_interface) {
2724 [self setBackgroundColor: [NSColor clearColor]];
2725 [self setOpaque: NO];
2727 [self setHasShadow:NO];
2728 [self setHasShadow:YES];
2730 NSRect winrect = [self frame];
2731 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
2733 [self setTitle: _NS("VLC media player")];
2734 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight, winrect.size.width, f_titleBarHeight)];
2735 [[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: nil];
2737 // native fs not supported with detached view yet
2738 [o_titlebar_view setFullscreenButtonHidden: YES];
2743 - (IBAction)fullscreen:(id)sender
2745 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
2748 - (BOOL)canBecomeKeyWindow