macosx: reimplement 'fullscreen video device' (fixes #5831)
[vlc.git] / modules / gui / macosx / MainMenu.m
1 /*****************************************************************************
2  * MainMenu.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "MainMenu.h"
25 #import <vlc_common.h>
26 #import <vlc_playlist.h>
27
28 #import "intf.h"
29 #import "open.h"
30 #import "wizard.h"
31 #import "about.h"
32 #import "AudioEffects.h"
33 #import "TrackSynchronization.h"
34 #import "VideoEffects.h"
35 #import "bookmarks.h"
36 #import "simple_prefs.h"
37 #import "coredialogs.h"
38 #import "controls.h"
39 #import "playlistinfo.h"
40 #import "VideoView.h"
41 #import "CoreInteraction.h"
42 #import "MainWindow.h"
43
44 @implementation VLCMainMenu
45 static VLCMainMenu *_o_sharedInstance = nil;
46
47 + (VLCMainMenu *)sharedInstance
48 {
49     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
50 }
51
52 #pragma mark -
53 #pragma mark Initialization
54
55 - (id)init
56 {
57     if( _o_sharedInstance)
58     {
59         [self dealloc];
60         return _o_sharedInstance;
61     }
62     else
63     {
64         _o_sharedInstance = [super init];
65     }
66
67     return _o_sharedInstance;
68 }
69
70 - (void)dealloc
71 {
72     [[NSNotificationCenter defaultCenter] removeObserver: self];
73     
74     if (b_nib_about_loaded)
75         [o_about release];
76
77     if (b_nib_videoeffects_loaded)
78         [o_videoeffects release];
79
80     if (b_nib_audioeffects_loaded)
81         [o_audioeffects release];
82
83     if (b_nib_tracksynchro_loaded)
84         [o_trackSynchronization release];
85
86     [super dealloc];
87 }
88
89 - (void)awakeFromNib
90 {
91     [[NSNotificationCenter defaultCenter] addObserver: self 
92                                              selector: @selector(applicationWillFinishLaunching:)
93                                                  name: NSApplicationWillFinishLaunchingNotification
94                                                object: nil];
95 }
96
97 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
98 {
99     p_intf = VLCIntf;
100
101     NSString* o_key;
102     playlist_t *p_playlist;
103     vlc_value_t val;
104     id o_vlcmain = [VLCMain sharedInstance];
105     char * key;
106
107     /* Check if we already did this once. Opening the other nibs calls it too,
108      because VLCMain is the owner */
109     if( b_mainMenu_setup ) return;
110
111     [self initStrings];
112
113     key = config_GetPsz( p_intf, "key-quit" );
114     o_key = [NSString stringWithFormat:@"%s", key];
115     [o_mi_quit setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
116     [o_mi_quit setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
117     FREENULL( key );
118
119     key = config_GetPsz( p_intf, "key-play-pause" );
120     o_key = [NSString stringWithFormat:@"%s", key];
121     [o_mi_play setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
122     [o_mi_play setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
123     FREENULL( key );
124
125     key = config_GetPsz( p_intf, "key-stop" );
126     o_key = [NSString stringWithFormat:@"%s", key];
127     [o_mi_stop setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
128     [o_mi_stop setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
129     FREENULL( key );
130
131     key = config_GetPsz( p_intf, "key-prev" );
132     o_key = [NSString stringWithFormat:@"%s", key];
133     [o_mi_previous setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
134     [o_mi_previous setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
135     FREENULL( key );
136
137     key = config_GetPsz( p_intf, "key-next" );
138     o_key = [NSString stringWithFormat:@"%s", key];
139     [o_mi_next setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
140     [o_mi_next setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
141     FREENULL( key );
142
143     key = config_GetPsz( p_intf, "key-jump+short" );
144     o_key = [NSString stringWithFormat:@"%s", key];
145     [o_mi_fwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
146     [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
147     FREENULL( key );
148
149     key = config_GetPsz( p_intf, "key-jump-short" );
150     o_key = [NSString stringWithFormat:@"%s", key];
151     [o_mi_bwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
152     [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
153     FREENULL( key );
154
155     key = config_GetPsz( p_intf, "key-vol-up" );
156     o_key = [NSString stringWithFormat:@"%s", key];
157     [o_mi_vol_up setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
158     [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
159     FREENULL( key );
160
161     key = config_GetPsz( p_intf, "key-vol-down" );
162     o_key = [NSString stringWithFormat:@"%s", key];
163     [o_mi_vol_down setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
164     [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
165     FREENULL( key );
166
167     key = config_GetPsz( p_intf, "key-vol-mute" );
168     o_key = [NSString stringWithFormat:@"%s", key];
169     [o_mi_mute setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
170     [o_mi_mute setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
171     FREENULL( key );
172
173     key = config_GetPsz( p_intf, "key-toggle-fullscreen" );
174     o_key = [NSString stringWithFormat:@"%s", key];
175     [o_mi_fullscreen setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
176     [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
177     FREENULL( key );
178
179     key = config_GetPsz( p_intf, "key-snapshot" );
180     o_key = [NSString stringWithFormat:@"%s", key];
181     [o_mi_snapshot setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
182     [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
183     FREENULL( key );
184
185     key = config_GetPsz( p_intf, "key-random" );
186     o_key = [NSString stringWithFormat:@"%s", key];
187     [o_mi_random setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
188     [o_mi_random setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
189     FREENULL( key );
190
191     key = config_GetPsz( p_intf, "key-zoom-half" );
192     o_key = [NSString stringWithFormat:@"%s", key];
193     [o_mi_half_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
194     [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
195     FREENULL( key );
196
197     key = config_GetPsz( p_intf, "key-zoom-original" );
198     o_key = [NSString stringWithFormat:@"%s", key];
199     [o_mi_normal_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
200     [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
201     FREENULL( key );
202
203     key = config_GetPsz( p_intf, "key-zoom-double" );
204     o_key = [NSString stringWithFormat:@"%s", key];
205     [o_mi_double_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
206     [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
207     FREENULL( key );
208
209     [self setSubmenusEnabled: FALSE];
210
211     [[NSNotificationCenter defaultCenter] addObserver: self
212                                              selector: @selector(refreshVoutDeviceMenu:)
213                                                  name: NSApplicationDidChangeScreenParametersNotification
214                                                object: nil];
215
216     /* we're done */
217     b_mainMenu_setup = YES;
218
219     [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
220                              var: "intf-add" selector: @selector(toggleVar:)];
221 }
222
223 - (void)initStrings
224 {
225     /* main menu */
226     [o_mi_about setTitle: [_NS("About VLC media player") \
227                            stringByAppendingString: @"..."]];
228     [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
229     [o_mi_prefs setTitle: _NS("Preferences...")];
230     [o_mi_add_intf setTitle: _NS("Add Interface")];
231     [o_mu_add_intf setTitle: _NS("Add Interface")];
232     [o_mi_services setTitle: _NS("Services")];
233     [o_mi_hide setTitle: _NS("Hide VLC")];
234     [o_mi_hide_others setTitle: _NS("Hide Others")];
235     [o_mi_show_all setTitle: _NS("Show All")];
236     [o_mi_quit setTitle: _NS("Quit VLC")];
237
238     [o_mu_file setTitle: _ANS("1:File")];
239     [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
240     [o_mi_open_file setTitle: _NS("Open File...")];
241     [o_mi_open_disc setTitle: _NS("Open Disc...")];
242     [o_mi_open_net setTitle: _NS("Open Network...")];
243     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
244     [o_mi_open_recent setTitle: _NS("Open Recent")];
245     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
246
247     [o_mu_edit setTitle: _NS("Edit")];
248     [o_mi_cut setTitle: _NS("Cut")];
249     [o_mi_copy setTitle: _NS("Copy")];
250     [o_mi_paste setTitle: _NS("Paste")];
251     [o_mi_clear setTitle: _NS("Clear")];
252     [o_mi_select_all setTitle: _NS("Select All")];
253
254     [o_mu_controls setTitle: _NS("Playback")];
255     [o_mi_play setTitle: _NS("Play")];
256     [o_mi_stop setTitle: _NS("Stop")];
257     [o_mi_record setTitle: _NS("Record")];
258     [o_mi_rate setView: o_mi_rate_view];
259     [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
260     [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
261     [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
262     [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
263     [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
264     [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
265     [o_mi_previous setTitle: _NS("Previous")];
266     [o_mi_next setTitle: _NS("Next")];
267     [o_mi_random setTitle: _NS("Random")];
268     [o_mi_repeat setTitle: _NS("Repeat One")];
269     [o_mi_loop setTitle: _NS("Repeat All")];
270     [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
271     [o_mi_fwd setTitle: _NS("Step Forward")];
272     [o_mi_bwd setTitle: _NS("Step Backward")];
273
274     [o_mi_program setTitle: _NS("Program")];
275     [o_mu_program setTitle: _NS("Program")];
276     [o_mi_title setTitle: _NS("Title")];
277     [o_mu_title setTitle: _NS("Title")];
278     [o_mi_chapter setTitle: _NS("Chapter")];
279     [o_mu_chapter setTitle: _NS("Chapter")];
280
281     [o_mu_audio setTitle: _NS("Audio")];
282     [o_mi_vol_up setTitle: _NS("Increase Volume")];
283     [o_mi_vol_down setTitle: _NS("Decrease Volume")];
284     [o_mi_mute setTitle: _NS("Mute")];
285     [o_mi_audiotrack setTitle: _NS("Audio Track")];
286     [o_mu_audiotrack setTitle: _NS("Audio Track")];
287     [o_mi_channels setTitle: _NS("Audio Channels")];
288     [o_mu_channels setTitle: _NS("Audio Channels")];
289     [o_mi_device setTitle: _NS("Audio Device")];
290     [o_mu_device setTitle: _NS("Audio Device")];
291     [o_mi_visual setTitle: _NS("Visualizations")];
292     [o_mu_visual setTitle: _NS("Visualizations")];
293
294     [o_mu_video setTitle: _NS("Video")];
295     [o_mi_half_window setTitle: _NS("Half Size")];
296     [o_mi_normal_window setTitle: _NS("Normal Size")];
297     [o_mi_double_window setTitle: _NS("Double Size")];
298     [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
299     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
300     [o_mi_floatontop setTitle: _NS("Float on Top")];
301     [o_mi_snapshot setTitle: _NS("Snapshot")];
302     [o_mi_videotrack setTitle: _NS("Video Track")];
303     [o_mu_videotrack setTitle: _NS("Video Track")];
304     [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
305     [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
306     [o_mi_crop setTitle: _NS("Crop")];
307     [o_mu_crop setTitle: _NS("Crop")];
308     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
309     [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
310     [o_mi_subtitle setTitle: _NS("Subtitles Track")];
311     [o_mu_subtitle setTitle: _NS("Subtitles Track")];
312     [o_mi_addSub setTitle: _NS("Open File...")];
313     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
314     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
315     [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
316     [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
317     [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
318     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
319     [o_mi_teletext setTitle: _NS("Teletext")];
320     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
321     [o_mi_teletext_index setTitle: _NS("Index")];
322     [o_mi_teletext_red setTitle: _NS("Red")];
323     [o_mi_teletext_green setTitle: _NS("Green")];
324     [o_mi_teletext_yellow setTitle: _NS("Yellow")];
325     [o_mi_teletext_blue setTitle: _NS("Blue")];
326
327     [o_mu_window setTitle: _NS("Window")];
328     [o_mi_minimize setTitle: _NS("Minimize Window")];
329     [o_mi_close_window setTitle: _NS("Close Window")];
330     [o_mi_player setTitle: _NS("Player...")];
331     [o_mi_controller setTitle: _NS("Main Window...")];
332     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
333     [o_mi_videoeffects setTitle: _NS("Video Filters...")];
334     [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
335     [o_mi_playlist setTitle: _NS("Playlist...")];
336     [o_mi_info setTitle: _NS("Media Information...")];
337     [o_mi_messages setTitle: _NS("Messages...")];
338     [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
339
340     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
341
342     [o_mu_help setTitle: _NS("Help")];
343     [o_mi_help setTitle: _NS("VLC media player Help...")];
344     [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
345     [o_mi_license setTitle: _NS("License")];
346     [o_mi_documentation setTitle: _NS("Online Documentation...")];
347     [o_mi_website setTitle: _NS("VideoLAN Website...")];
348     [o_mi_donation setTitle: _NS("Make a donation...")];
349     [o_mi_forum setTitle: _NS("Online Forum...")];
350
351     /* dock menu */
352     [o_dmi_play setTitle: _NS("Play")];
353     [o_dmi_stop setTitle: _NS("Stop")];
354     [o_dmi_next setTitle: _NS("Next")];
355     [o_dmi_previous setTitle: _NS("Previous")];
356     [o_dmi_mute setTitle: _NS("Mute")];
357
358     /* vout menu */
359     [o_vmi_play setTitle: _NS("Play")];
360     [o_vmi_stop setTitle: _NS("Stop")];
361     [o_vmi_prev setTitle: _NS("Previous")];
362     [o_vmi_next setTitle: _NS("Next")];
363     [o_vmi_volup setTitle: _NS("Volume Up")];
364     [o_vmi_voldown setTitle: _NS("Volume Down")];
365     [o_vmi_mute setTitle: _NS("Mute")];
366     [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
367     [o_vmi_snapshot setTitle: _NS("Snapshot")];
368 }
369
370 #pragma mark -
371 #pragma mark Termination
372
373 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
374 {
375     if( !p_intf ) return;
376     
377     NSArray *menuitems_array = [the_menu itemArray];
378     NSUInteger menuItemCount = [menuitems_array count];
379     for( NSUInteger i=0; i < menuItemCount; i++ )
380     {
381         NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
382         if( [one_item hasSubmenu] )
383             [self releaseRepresentedObjects: [one_item submenu]];
384
385         [one_item setRepresentedObject:NULL];
386     }
387 }
388
389 #pragma mark -
390 #pragma mark Interface update
391
392 - (void)setupMenus
393 {
394     playlist_t * p_playlist = pl_Get( p_intf );
395     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
396     if( p_input != NULL )
397     {
398         [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
399
400         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
401                                  var: "program" selector: @selector(toggleVar:)];
402
403         [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
404                                  var: "title" selector: @selector(toggleVar:)];
405
406         [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
407                                  var: "chapter" selector: @selector(toggleVar:)];
408
409         [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
410                                  var: "audio-es" selector: @selector(toggleVar:)];
411
412         [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
413                                  var: "video-es" selector: @selector(toggleVar:)];
414
415         [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
416                                  var: "spu-es" selector: @selector(toggleVar:)];
417
418         /* special case for "Open File" inside the subtitles menu item */
419         if( [o_mi_videotrack isEnabled] == YES )
420             [o_mi_subtitle setEnabled: YES];
421
422         audio_output_t * p_aout = input_GetAout( p_input );
423         if( p_aout != NULL )
424         {
425             [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
426                                      var: "audio-channels" selector: @selector(toggleVar:)];
427
428             [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
429                                      var: "audio-device" selector: @selector(toggleVar:)];
430
431             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
432                                      var: "visual" selector: @selector(toggleVar:)];
433             vlc_object_release( (vlc_object_t *)p_aout );
434         }
435
436         vout_thread_t * p_vout = input_GetVout( p_input );
437
438         if( p_vout != NULL )
439         {
440             vlc_object_t * p_dec_obj;
441
442             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
443                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
444
445             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
446                                      var: "crop" selector: @selector(toggleVar:)];
447
448             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
449                                      var: "deinterlace" selector: @selector(toggleVar:)];
450
451             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
452                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
453
454 #if 1
455             [self setupVarMenuItem: o_mi_ffmpeg_pp target:
456              (vlc_object_t *)p_vout var:"postprocess" selector:
457              @selector(toggleVar:)];
458 #endif
459             vlc_object_release( (vlc_object_t *)p_vout );
460
461             [self refreshVoutDeviceMenu:nil];
462             [self setSubmenusEnabled: YES];
463         }
464         vlc_object_release( p_input );
465     }
466     else
467     {
468         [o_mi_record setEnabled: NO];
469     }
470 }
471
472 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
473 {
474     NSUInteger count = [o_mu_screen numberOfItems];
475     NSMenu * o_submenu = o_mu_screen;
476     if (count > 0)
477     {
478         if (OSX_LEOPARD)
479         {
480             NSUInteger count = [o_submenu numberOfItems];
481             for( NSUInteger i = 0; i < count; i++ )
482                 [o_submenu removeItemAtIndex: 0];
483         }
484         else
485             [o_submenu removeAllItems];
486     }
487
488     NSArray * o_screens = [NSScreen screens];
489     count = [o_screens count];
490     [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
491     [[o_submenu itemAtIndex: 0] setTag: 0];
492     [[o_submenu itemAtIndex: 0] setEnabled: YES];
493     [[o_submenu itemAtIndex: 0] setTarget: self];
494     NSRect s_rect;
495     for (NSUInteger i = 0; i < count; i++)
496     {
497         s_rect = [[o_screens objectAtIndex: i] frame];
498         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
499                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
500         [[o_submenu itemAtIndex:i+1] setTag: (int)[[o_screens objectAtIndex: i] displayID]];
501         [[o_submenu itemAtIndex:i+1] setEnabled: YES];
502         [[o_submenu itemAtIndex:i+1] setTarget: self];
503     }
504     [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
505 }
506
507 - (void)setSubmenusEnabled:(BOOL)b_enabled
508 {
509     [o_mi_program setEnabled: b_enabled];
510     [o_mi_title setEnabled: b_enabled];
511     [o_mi_chapter setEnabled: b_enabled];
512     [o_mi_audiotrack setEnabled: b_enabled];
513     [o_mi_visual setEnabled: b_enabled];
514     [o_mi_videotrack setEnabled: b_enabled];
515     [o_mi_subtitle setEnabled: b_enabled];
516     [o_mi_channels setEnabled: b_enabled];
517     [o_mi_deinterlace setEnabled: b_enabled];
518     [o_mi_deinterlace_mode setEnabled: b_enabled];
519     [o_mi_ffmpeg_pp setEnabled: b_enabled];
520     [o_mi_device setEnabled: b_enabled];
521     [o_mi_screen setEnabled: b_enabled];
522     [o_mi_aspect_ratio setEnabled: b_enabled];
523     [o_mi_crop setEnabled: b_enabled];
524     [o_mi_teletext setEnabled: b_enabled];
525 }
526
527 - (void)setRateControlsEnabled:(BOOL)b_enabled
528 {
529     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
530     [o_mi_rate_sld setEnabled: b_enabled];
531     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
532     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
533     if (i == 0)
534         i = 1;
535     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
536     if (b_enabled) {
537         [o_mi_rate_lbl setHidden: NO];
538         [o_mi_rate_lbl_gray setHidden: YES];
539     }
540     else
541     {
542         [o_mi_rate_lbl setHidden: YES];
543         [o_mi_rate_lbl_gray setHidden: NO];
544     }
545     [o_pool release];
546 }
547
548 #pragma mark -
549 #pragma mark Playback
550 - (IBAction)toggleRecord:(id)sender
551 {
552     [[VLCCoreInteraction sharedInstance] toggleRecord];
553 }
554
555 - (void)updateRecordState:(BOOL)b_value
556 {
557     [o_mi_record setState:b_value];
558 }
559
560 - (IBAction)setPlaybackRate:(id)sender
561 {
562     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
563     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
564     if (i == 0)
565         i = 1;
566     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
567 }
568
569 - (void)updatePlaybackRate
570 {
571     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
572     if (i == 0)
573         i = 1;
574     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
575     [o_mi_rate_sld setIntValue: i];
576 }
577
578 #pragma mark -
579 #pragma video menu
580 - (IBAction)toggleFullscreen:(id)sender
581 {
582     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
583 }
584
585 - (IBAction)resizeVideoWindow:(id)sender
586 {
587     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
588     if (p_input)
589     {
590         vout_thread_t *p_vout = getVout();
591         if (p_vout)
592         {
593             if (sender == o_mi_half_window)
594                 var_SetFloat( p_vout, "zoom", 0.5 );
595             else if (sender == o_mi_normal_window)
596                 var_SetFloat( p_vout, "zoom", 1.0 );
597             else if (sender == o_mi_double_window)
598                 var_SetFloat( p_vout, "zoom", 2.0 );
599             else
600             {
601                 var_ToggleBool( p_vout, "autoscale" );
602             }
603             vlc_object_release( p_vout );
604         }
605         vlc_object_release( p_input );
606     }
607 }
608
609 - (IBAction)floatOnTop:(id)sender
610 {
611     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
612     if (p_input)
613     {
614         vout_thread_t *p_vout = getVout();
615         if (p_vout)
616         {
617             var_ToggleBool( p_vout, "video-on-top" );
618             vlc_object_release( p_vout );
619         }
620         vlc_object_release( p_input );
621     }
622 }
623
624 - (IBAction)createVideoSnapshot:(id)sender
625 {
626     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
627     if (p_input)
628     {
629         vout_thread_t *p_vout = getVout();
630         if (p_vout)
631         {
632             var_TriggerCallback( p_vout, "video-snapshot" );
633             vlc_object_release( p_vout );
634         }
635         vlc_object_release( p_input );
636     }
637 }
638
639 - (IBAction)toggleFullscreenDevice:(id)sender
640 {
641     config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
642     [self refreshVoutDeviceMenu: nil];
643 }
644
645 - (id)voutMenu
646 {
647     return o_vout_menu;
648 }
649
650 #pragma mark -
651 #pragma mark Panels
652
653 - (IBAction)intfOpenFile:(id)sender
654 {
655     [[[VLCMain sharedInstance] open] openFile];
656 }
657
658 - (IBAction)intfOpenFileGeneric:(id)sender
659 {
660     [[[VLCMain sharedInstance] open] openFileGeneric];
661 }
662
663 - (IBAction)intfOpenDisc:(id)sender
664 {
665     [[[VLCMain sharedInstance] open] openDisc];
666 }
667
668 - (IBAction)intfOpenNet:(id)sender
669 {
670     [[[VLCMain sharedInstance] open] openNet];
671 }
672
673 - (IBAction)intfOpenCapture:(id)sender
674 {
675     [[[VLCMain sharedInstance] open] openCapture];
676 }
677
678 - (IBAction)showWizard:(id)sender
679 {
680     [[[VLCMain sharedInstance] wizard] resetWizard];
681     [[[VLCMain sharedInstance] wizard] showWizard];
682 }
683
684 - (IBAction)showVideoEffects:(id)sender
685 {
686     if( o_videoeffects == nil )
687         o_videoeffects = [[VLCVideoEffects alloc] init];
688
689     if( !b_nib_videoeffects_loaded )
690         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
691
692     [o_videoeffects toggleWindow:sender];
693 }
694
695 - (IBAction)showTrackSynchronization:(id)sender
696 {
697     if (!o_trackSynchronization)
698         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
699
700     if (!b_nib_tracksynchro_loaded)
701         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
702
703     [o_trackSynchronization toggleWindow:sender];
704 }
705
706 - (IBAction)showAudioEffects:(id)sender
707 {
708     if (!o_audioeffects)
709         o_audioeffects = [[VLCAudioEffects alloc] init];
710
711     if (!b_nib_audioeffects_loaded)
712         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
713
714     [o_audioeffects toggleWindow:sender];
715 }
716
717 - (IBAction)showBookmarks:(id)sender
718 {
719     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
720 }
721
722 - (IBAction)viewPreferences:(id)sender
723 {
724     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
725 }
726
727 #pragma mark -
728 #pragma mark Help and Docs
729
730 - (void)initAbout
731 {
732     if(! o_about )
733         o_about = [[VLAboutBox alloc] init];
734
735     if( !b_nib_about_loaded )
736         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
737 }
738
739 - (IBAction)viewAbout:(id)sender
740 {
741     [self initAbout];
742     [o_about showAbout];
743 }
744
745 - (IBAction)showLicense:(id)sender
746 {
747     [self initAbout];
748     [o_about showGPL: sender];
749 }
750
751 - (IBAction)viewHelp:(id)sender
752 {
753     [self initAbout];
754     [o_about showHelp];
755 }
756
757 - (IBAction)openReadMe:(id)sender
758 {
759     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
760
761     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
762 }
763
764 - (IBAction)openDocumentation:(id)sender
765 {
766     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
767
768     [[NSWorkspace sharedWorkspace] openURL: o_url];
769 }
770
771 - (IBAction)openWebsite:(id)sender
772 {
773     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
774
775     [[NSWorkspace sharedWorkspace] openURL: o_url];
776 }
777
778 - (IBAction)openForum:(id)sender
779 {
780     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
781
782     [[NSWorkspace sharedWorkspace] openURL: o_url];
783 }
784
785 - (IBAction)openDonate:(id)sender
786 {
787     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
788
789     [[NSWorkspace sharedWorkspace] openURL: o_url];
790 }
791
792 #pragma mark -
793 #pragma mark Errors, warnings and messages
794
795 - (IBAction)viewErrorsAndWarnings:(id)sender
796 {
797     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
798 }
799
800 - (IBAction)showInformationPanel:(id)sender
801 {
802     [[[VLCMain sharedInstance] info] initPanel];
803 }
804
805 #pragma mark -
806 #pragma mark convinience stuff for other objects
807 - (void)setPlay
808 {
809     [o_mi_play setTitle: _NS("Play")];
810     [o_dmi_play setTitle: _NS("Play")];
811     [o_vmi_play setTitle: _NS("Play")];
812 }
813
814 - (void)setPause
815 {
816     [o_mi_play setTitle: _NS("Pause")];
817     [o_dmi_play setTitle: _NS("Pause")];
818     [o_vmi_play setTitle: _NS("Pause")];
819 }
820
821 - (void)setRepeatOne
822 {
823     [o_mi_repeat setState: NSOnState];
824     [o_mi_loop setState: NSOffState];
825 }
826
827 - (void)setRepeatAll
828 {
829     [o_mi_repeat setState: NSOffState];
830     [o_mi_loop setState: NSOnState];
831 }
832
833 - (void)setRepeatOff
834 {
835     [o_mi_repeat setState: NSOffState];
836     [o_mi_loop setState: NSOffState];
837 }
838
839 - (void)setShuffle
840 {
841     bool b_value;
842     playlist_t *p_playlist = pl_Get( VLCIntf );
843     b_value = var_GetBool( p_playlist, "random" );
844         [o_mi_random setState: b_value];
845 }
846
847 #pragma mark -
848 #pragma mark Dynamic menu creation and validation
849
850 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
851                   target:(vlc_object_t *)p_object
852                      var:(const char *)psz_variable
853                 selector:(SEL)pf_callback
854 {
855     vlc_value_t val, text;
856     int i_type = var_Type( p_object, psz_variable );
857
858     switch( i_type & VLC_VAR_TYPE )
859     {
860         case VLC_VAR_VOID:
861         case VLC_VAR_BOOL:
862         case VLC_VAR_VARIABLE:
863         case VLC_VAR_STRING:
864         case VLC_VAR_INTEGER:
865             break;
866         default:
867             /* Variable doesn't exist or isn't handled */
868             return;
869     }
870
871     /* Make sure we want to display the variable */
872     if( i_type & VLC_VAR_HASCHOICE )
873     {
874         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
875         if( val.i_int == 0 ) return;
876         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
877             return;
878     }
879
880     /* Get the descriptive name of the variable */
881     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
882     [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
883                      text.psz_string : psz_variable ]];
884
885     if( i_type & VLC_VAR_HASCHOICE )
886     {
887         NSMenu *o_menu = [o_mi submenu];
888         
889         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
890                        var:psz_variable selector:pf_callback];
891         
892         free( text.psz_string );
893         return;
894     }
895     if( var_Get( p_object, psz_variable, &val ) < 0 )
896     {
897         return;
898     }
899
900     VLCAutoGeneratedMenuContent *o_data;
901     switch( i_type & VLC_VAR_TYPE )
902     {
903         case VLC_VAR_VOID:
904             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
905                                                                       andValue: val ofType: i_type];
906             [o_mi setRepresentedObject: [o_data autorelease]];
907             break;
908
909         case VLC_VAR_BOOL:
910             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
911                                                                       andValue: val ofType: i_type];
912             [o_mi setRepresentedObject: [o_data autorelease]];
913             if( !( i_type & VLC_VAR_ISCOMMAND ) )
914                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
915             break;
916
917         default:
918             break;
919     }
920
921     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
922     free( text.psz_string );
923 }
924
925
926 - (void)setupVarMenu:(NSMenu *)o_menu
927          forMenuItem: (NSMenuItem *)o_parent
928               target:(vlc_object_t *)p_object
929                  var:(const char *)psz_variable
930             selector:(SEL)pf_callback
931 {
932     vlc_value_t val, val_list, text_list;
933     int i_type, i;
934
935     /* remove previous items */
936     if (OSX_LEOPARD)
937     {
938         int i_nb_items;
939         i_nb_items = [o_menu numberOfItems];
940         for( i = 0; i < i_nb_items; i++ )
941             [o_menu removeItemAtIndex: 0];
942     }
943     else
944     {
945         /* this is more efficient then the legacy code, but 10.6+ only */
946         [o_menu removeAllItems];
947     }
948
949     /* Check the type of the object variable */
950     i_type = var_Type( p_object, psz_variable );
951
952     /* Make sure we want to display the variable */
953     if( i_type & VLC_VAR_HASCHOICE )
954     {
955         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
956         if( val.i_int == 0 ) return;
957         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
958             return;
959     }
960     else
961         return;
962
963     switch( i_type & VLC_VAR_TYPE )
964     {
965         case VLC_VAR_VOID:
966         case VLC_VAR_BOOL:
967         case VLC_VAR_VARIABLE:
968         case VLC_VAR_STRING:
969         case VLC_VAR_INTEGER:
970             break;
971         default:
972             /* Variable doesn't exist or isn't handled */
973             return;
974     }
975
976     if( var_Get( p_object, psz_variable, &val ) < 0 )
977     {
978         return;
979     }
980
981     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
982                    &val_list, &text_list ) < 0 )
983     {
984         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
985         return;
986     }
987
988     /* make (un)sensitive */
989     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
990
991     /* Aspect Ratio */
992     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
993     {
994         NSMenuItem *o_lmi_tmp2;
995         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
996         [o_lmi_tmp2 setTarget: self];
997         [o_lmi_tmp2 setEnabled: YES];
998         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
999         [o_parent setEnabled: YES];
1000         [o_menu addItem: [NSMenuItem separatorItem]];
1001     }
1002
1003     /* special case for the subtitles items */
1004     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1005     {
1006         NSMenuItem * o_lmi_tmp;
1007         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1008         [o_lmi_tmp setTarget: self];
1009         [o_lmi_tmp setEnabled: YES];
1010         [o_parent setEnabled: YES];
1011         [o_menu addItem: [NSMenuItem separatorItem]];
1012     }
1013
1014     for( i = 0; i < val_list.p_list->i_count; i++ )
1015     {
1016         NSMenuItem * o_lmi;
1017         NSString *o_title = @"";
1018         VLCAutoGeneratedMenuContent *o_data;
1019
1020         switch( i_type & VLC_VAR_TYPE )
1021         {
1022             case VLC_VAR_STRING:
1023
1024                 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
1025                            text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
1026
1027                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1028                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1029                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1030                 [o_lmi setRepresentedObject: [o_data autorelease]];
1031                 [o_lmi setTarget: self];
1032
1033                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1034                     [o_lmi setState: TRUE ];
1035
1036                 break;
1037
1038             case VLC_VAR_INTEGER:
1039
1040                 o_title = text_list.p_list->p_values[i].psz_string ?
1041                 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
1042                 [NSString stringWithFormat: @"%"PRId64,
1043                  val_list.p_list->p_values[i].i_int];
1044
1045                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1046                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1047                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1048                 [o_lmi setRepresentedObject: [o_data autorelease]];
1049                 [o_lmi setTarget: self];
1050
1051                 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1052                     [o_lmi setState: TRUE ];
1053                 break;
1054
1055             default:
1056                 break;
1057         }
1058     }
1059
1060     /* special case for the subtitles sub-menu
1061      * In case that we don't have any subs, we don't want a separator item at the end */
1062     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1063     {
1064         if( [o_menu numberOfItems] == 2 )
1065             [o_menu removeItemAtIndex: 1];
1066     }
1067
1068     /* clean up everything */
1069     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1070     var_FreeList( &val_list, &text_list );
1071 }
1072
1073 - (IBAction)toggleVar:(id)sender
1074 {
1075     NSMenuItem *o_mi = (NSMenuItem *)sender;
1076     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1077     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1078                              toTarget: self withObject: o_data];
1079
1080     return;
1081 }
1082
1083 - (int)toggleVarThread: (id)data
1084 {
1085     vlc_object_t *p_object;
1086     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1087
1088     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1089     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1090
1091     p_object = [menuContent vlcObject];
1092
1093     if( p_object != NULL )
1094     {
1095         var_Set( p_object, [menuContent name], [menuContent value] );
1096         vlc_object_release( p_object );
1097         [o_pool release];
1098         return true;
1099     }
1100     [o_pool release];
1101     return VLC_EGENERIC;
1102 }
1103
1104 @end
1105
1106 @implementation VLCMainMenu (NSMenuValidation)
1107
1108 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1109 {
1110     NSString *o_title = [o_mi title];
1111     BOOL bEnabled = TRUE;
1112     vlc_value_t val;
1113     playlist_t * p_playlist = pl_Get( p_intf );
1114     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1115
1116     if( [o_title isEqualToString: _NS("Stop")] )
1117     {
1118         if( p_input == NULL )
1119         {
1120             bEnabled = FALSE;
1121         }
1122         [self setupMenus]; /* Make sure input menu is up to date */
1123     }
1124     else if( [o_title isEqualToString: _NS("Previous")] ||
1125             [o_title isEqualToString: _NS("Next")] )
1126     {
1127         PL_LOCK;
1128         bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1129         PL_UNLOCK;
1130     }
1131     else if( [o_title isEqualToString: _NS("Random")] )
1132     {
1133         int i_state;
1134         var_Get( p_playlist, "random", &val );
1135         i_state = val.b_bool ? NSOnState : NSOffState;
1136         [o_mi setState: i_state];
1137     }
1138     else if( [o_title isEqualToString: _NS("Repeat One")] )
1139     {
1140         int i_state;
1141         var_Get( p_playlist, "repeat", &val );
1142         i_state = val.b_bool ? NSOnState : NSOffState;
1143         [o_mi setState: i_state];
1144     }
1145     else if( [o_title isEqualToString: _NS("Repeat All")] )
1146     {
1147         int i_state;
1148         var_Get( p_playlist, "loop", &val );
1149         i_state = val.b_bool ? NSOnState : NSOffState;
1150         [o_mi setState: i_state];
1151     }
1152     else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1153     {
1154         int i_state;
1155         var_Get( p_playlist, "play-and-exit", &val );
1156         i_state = val.b_bool ? NSOnState : NSOffState;
1157         [o_mi setState: i_state];
1158     }
1159     else if( [o_title isEqualToString: _NS("Step Forward")] ||
1160             [o_title isEqualToString: _NS("Step Backward")] ||
1161             [o_title isEqualToString: _NS("Jump To Time")])
1162     {
1163         if( p_input != NULL )
1164         {
1165             var_Get( p_input, "can-seek", &val);
1166             bEnabled = val.b_bool;
1167         }
1168         else bEnabled = FALSE;
1169     }
1170     else if( [o_title isEqualToString: _NS("Mute")] )
1171     {
1172         //FIXME [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1173         [self setupMenus]; /* Make sure audio menu is up to date */
1174     }
1175     else if( [o_title isEqualToString: _NS("Half Size")] ||
1176             [o_title isEqualToString: _NS("Normal Size")] ||
1177             [o_title isEqualToString: _NS("Double Size")] ||
1178             [o_title isEqualToString: _NS("Fit to Screen")] ||
1179             [o_title isEqualToString: _NS("Snapshot")] ||
1180             [o_title isEqualToString: _NS("Fullscreen")] ||
1181             [o_title isEqualToString: _NS("Float on Top")] )
1182     {
1183         bEnabled = FALSE;
1184
1185         if( p_input != NULL )
1186         {
1187             vout_thread_t *p_vout = input_GetVout( p_input );
1188             if( p_vout != NULL )
1189             {
1190                 if( [o_title isEqualToString: _NS("Float on Top")] )
1191                 {
1192                     [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1193                 }
1194
1195                 bEnabled = TRUE;
1196
1197                 vlc_object_release( (vlc_object_t *)p_vout );
1198             }
1199         }
1200         if( [o_title isEqualToString: _NS("Fullscreen")] )
1201         {
1202         [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1203             bEnabled = TRUE;
1204         }
1205         [self setupMenus]; /* Make sure video menu is up to date */
1206     }
1207
1208     /* Special case for telx menu */
1209     if( [o_title isEqualToString: _NS("Normal Size")] )
1210     {
1211         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1212                 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1213
1214         [[item submenu] setAutoenablesItems:NO];
1215         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1216         {
1217             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1218         }
1219     }
1220
1221     if( p_input ) vlc_object_release( p_input );
1222
1223     return( bEnabled );
1224 }
1225
1226 @end
1227
1228
1229 /*****************************************************************************
1230  * VLCAutoGeneratedMenuContent implementation
1231  *****************************************************************************
1232  * Object connected to a playlistitem which remembers the data belonging to
1233  * the variable of the autogenerated menu
1234  *****************************************************************************/
1235 @implementation VLCAutoGeneratedMenuContent
1236
1237 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1238                   andValue:(vlc_value_t)val ofType:(int)type
1239 {
1240     self = [super init];
1241
1242     if( self != nil )
1243     {
1244         _vlc_object = vlc_object_hold( object );
1245         psz_name = strdup( name );
1246         i_type = type;
1247         value = val;
1248         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1249             value.psz_string = strdup( val.psz_string );
1250     }
1251
1252     return( self );
1253 }
1254
1255 - (void)dealloc
1256 {
1257     vlc_object_release( _vlc_object );
1258     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1259         free( value.psz_string );
1260     free( psz_name );
1261     [super dealloc];
1262 }
1263
1264 - (const char *)name
1265 {
1266     return psz_name;
1267 }
1268
1269 - (vlc_value_t)value
1270 {
1271     return value;
1272 }
1273
1274 - (vlc_object_t *)vlcObject
1275 {
1276     return vlc_object_hold( _vlc_object );
1277 }
1278
1279
1280 - (int)type
1281 {
1282     return i_type;
1283 }
1284
1285 @end