]> git.sesse.net Git - vlc/blob - modules/gui/macosx/prefs.m
Implement the full/basic switch correctly and completely. Additionally, fixed a rare...
[vlc] / modules / gui / macosx / prefs.m
1 /*****************************************************************************
2  * prefs.m: MacOS X module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *          Derk-Jan Hartman <hartman at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /* VLCPrefs manages the main preferences dialog
26    the class is related to wxwindows intf, PrefsPanel */
27 /* VLCTreeItem should contain:
28    - the children of the treeitem
29    - the associated prefs widgets
30    - the documentview with all the prefs widgets in it
31    - a saveChanges action
32    - a revertChanges action
33    - an advanced action (to hide/show advanced options)
34    - a redraw view action
35    - the children action should generate a list of the treeitems children (to be used by VLCPrefs datasource)
36
37    The class is sort of a mix of wxwindows intfs, PrefsTreeCtrl and ConfigTreeData
38 */
39 /* VLCConfigControl are subclassed NSView's containing and managing individual config items
40    the classes are VERY closely related to wxwindows ConfigControls */
41
42 /*****************************************************************************
43  * Preamble
44  *****************************************************************************/
45 #include <stdlib.h>                                      /* malloc(), free() */
46 #include <sys/param.h>                                    /* for MAXPATHLEN */
47 #include <string.h>
48
49 #ifdef HAVE_CONFIG_H
50 # include "config.h"
51 #endif
52
53 #include <vlc_common.h>
54 #include <vlc_config_cat.h>
55
56 #import "intf.h"
57 #import "prefs.h"
58 #import "simple_prefs.h"
59 #import "prefs_widgets.h"
60 #import "vlc_keys.h"
61
62 /*****************************************************************************
63  * VLCPrefs implementation
64  *****************************************************************************/
65 @implementation VLCPrefs
66
67 static VLCPrefs *_o_sharedMainInstance = nil;
68
69 + (VLCPrefs *)sharedInstance
70 {
71     return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
72 }
73
74 - (id)init
75 {
76     if( _o_sharedMainInstance ) {
77         [self dealloc];
78     }
79     else
80     {
81         _o_sharedMainInstance = [super init];
82         p_intf = VLCIntf;
83         o_empty_view = [[NSView alloc] init];
84     }
85
86     return _o_sharedMainInstance;
87 }
88
89 - (void)dealloc
90 {
91     [o_empty_view release];
92     [super dealloc];
93 }
94
95 - (void)awakeFromNib
96 {
97     p_intf = VLCIntf;
98     b_advanced = config_GetInt( p_intf, "advanced" );
99
100     [self initStrings];
101     [o_advanced_ckb setState: b_advanced];
102     [o_prefs_view setBorderType: NSGrooveBorder];
103     [o_prefs_view setHasVerticalScroller: YES];
104     [o_prefs_view setDrawsBackground: NO];
105     [o_prefs_view setDocumentView: o_empty_view];
106     [o_tree selectRow:0 byExtendingSelection:NO];
107 }
108
109 - (void)setTitle: (NSString *) o_title_name
110 {
111     [o_title setStringValue: o_title_name];
112 }
113
114 - (void)showPrefs
115 {
116     [[o_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
117     [[o_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
118     
119     [o_prefs_window center];
120     [o_prefs_window makeKeyAndOrderFront:self];
121 }
122
123 - (void)initStrings
124 {
125     [o_prefs_window setTitle: _NS("Preferences")];
126     [o_save_btn setTitle: _NS("Save")];
127     [o_cancel_btn setTitle: _NS("Cancel")];
128     [o_reset_btn setTitle: _NS("Reset All")];
129     [o_advanced_ckb setTitle: _NS("Advanced")];
130     [[o_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
131     [[o_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
132 }
133
134 - (IBAction)savePrefs: (id)sender
135 {
136     /* TODO: call savePrefs on Root item */
137     [[VLCTreeItem rootItem] applyChanges];
138     config_SaveConfigFile( p_intf, NULL );
139     [o_prefs_window orderOut:self];
140 }
141
142 - (IBAction)closePrefs: (id)sender
143 {
144     [o_prefs_window orderOut:self];
145 }
146
147 - (IBAction)resetAll: (id)sender
148 {
149     NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"),
150         _NS("Continue"), nil, o_prefs_window, self,
151         @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
152         _NS("Beware this will reset the VLC media player preferences.\n"
153             "Are you sure you want to continue?") );
154 }
155
156 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return
157     contextInfo:(void *)o_context
158 {
159     if( i_return == NSAlertAlternateReturn )
160     {
161         [o_prefs_view setDocumentView: o_empty_view];
162         config_ResetAll( p_intf );
163         [[VLCTreeItem rootItem] resetView];
164         [[o_tree itemAtRow:[o_tree selectedRow]]
165             showView:o_prefs_view advancedView:
166             ( [o_advanced_ckb state] == NSOnState ) ? true : false];
167     }
168 }
169
170 - (IBAction)advancedToggle: (id)sender
171 {
172     b_advanced = !b_advanced;
173     [o_advanced_ckb setState: b_advanced];
174     /* refresh the view of the current treeitem */
175     [[o_tree itemAtRow:[o_tree selectedRow]] showView:o_prefs_view advancedView:
176         ( [o_advanced_ckb state] == NSOnState ) ? true : false];
177 }
178
179 - (IBAction)buttonAction: (id)sender
180 {
181     [o_prefs_window orderOut: self];
182     [[o_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
183     [[o_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
184     [[[VLCMain sharedInstance] getSimplePreferences] showSimplePrefs];
185 }
186
187 - (void)loadConfigTree
188 {
189 }
190
191 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
192 {
193 }
194
195 /* update the document view to the view of the selected tree item */
196 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
197 {
198     [[o_tree itemAtRow:[o_tree selectedRow]] showView: o_prefs_view
199         advancedView:( [o_advanced_ckb state] == NSOnState ) ?
200         true : false];
201 }
202
203 @end
204
205 @implementation VLCPrefs (NSTableDataSource)
206
207 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
208     return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] :
209                             [item numberOfChildren];
210 }
211
212 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
213 {
214     return (item == nil) ? YES : ( ([item numberOfChildren] != -1) &&
215                                    ([item numberOfChildren] != 0));
216 }
217
218 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
219     return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] :
220                             (id)[item childAtIndex:index];
221 }
222
223 - (id)outlineView:(NSOutlineView *)outlineView
224     objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
225 {
226     return (item == nil) ? @"" : (id)[item getName];
227 }
228
229 @end
230
231 @implementation VLCTreeItem
232
233 static VLCTreeItem *o_root_item = nil;
234
235 #define IsALeafNode ((id)-1)
236
237 - (id)initWithName: (NSString *)o_item_name
238     withTitle: (NSString *)o_item_title
239     withHelp: (NSString *)o_item_help
240     ID: (int)i_id
241     parent:(VLCTreeItem *)o_parent_item
242     children:(NSMutableArray *)o_children_array
243     whithCategory: (int) i_category
244 {
245     self = [super init];
246
247     if( self != nil )
248     {
249         o_name = [o_item_name copy];
250         o_title= [o_item_title copy];
251         o_help= [o_item_help copy];
252         i_object_id = i_id;
253         o_parent = o_parent_item;
254         o_children = o_children_array;
255         i_object_category = i_category;
256         o_subviews = nil;
257     }
258     return( self );
259 }
260
261 + (VLCTreeItem *)rootItem
262 {
263    if (o_root_item == nil)
264         o_root_item = [[VLCTreeItem alloc] initWithName:@"main" withTitle:@"main" withHelp:@"" ID:0
265             parent:nil children:[[NSMutableArray alloc] initWithCapacity:10]
266             whithCategory: -1];
267    return o_root_item;
268 }
269
270 - (void)dealloc
271 {
272     if (o_children != IsALeafNode) [o_children release];
273     [o_name release];
274     [o_title release];
275     [o_help release];
276     [super dealloc];
277 }
278
279 /* Creates and returns the array of children
280  * Loads children incrementally */
281 - (NSArray *)children
282 {
283     if( o_children == IsALeafNode )
284         return o_children;
285     if( [ o_children count] == 0 )
286     {
287         intf_thread_t   *p_intf = VLCIntf;
288         vlc_list_t      *p_list;
289         module_t        *p_module = NULL;
290         module_t        *p_parser;
291         module_config_t *p_item,
292                         *p_end;
293         int             i_index = 0;
294
295         /* List the modules */
296         p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
297         if( !p_list ) return nil;
298
299         /* get parser */
300         p_parser = (module_t *)p_list->p_values[i_index].p_object;
301
302         if( [[self getName] isEqualToString: @"main"] )
303         {
304             /*
305             * Find the main module
306             */
307             for( i_index = 0; i_index < p_list->i_count; i_index++ )
308             {
309                 p_module = (module_t *)p_list->p_values[i_index].p_object;
310                 if( !strcmp( module_GetObjName( p_module ), "main" ) )
311                     break;
312             }
313             if( p_module == NULL )
314             {
315                 msg_Err( p_intf,
316                     "could not load the preferences" );
317                 return nil;
318             }
319             if( i_index < p_list->i_count )
320             {
321                 /* We found the main module */
322                 /* Enumerate config categories and store a reference so we can
323                  * generate their config panel them when it is asked by the user. */
324                 VLCTreeItem *p_last_category = NULL;
325                 unsigned int i_confsize;
326                 p_item = module_GetConfig( p_parser, &i_confsize );
327                 p_end = p_item + i_confsize;
328                 o_children = [[NSMutableArray alloc] initWithCapacity:10];
329                 if( p_item ) do
330                 {
331                     NSString *o_child_name;
332                     NSString *o_child_title;
333                     NSString *o_child_help;
334                     switch( p_item->i_type )
335                     {
336                     case CONFIG_CATEGORY:
337                         if( p_item->value.i == -1 ) break;
338
339                         o_child_name = [[VLCMain sharedInstance]
340                             localizedString: config_CategoryNameGet( p_item->value.i )];
341                         o_child_title = o_child_name;
342                         o_child_help = [[VLCMain sharedInstance]
343                             localizedString: config_CategoryHelpGet( p_item->value.i )];
344                         p_last_category = [VLCTreeItem alloc];
345                         [o_children addObject:[p_last_category
346                             initWithName: o_child_name
347                             withTitle: o_child_title
348                             withHelp: o_child_help
349                             ID: p_item->value.i
350                             parent:self
351                             children:[[NSMutableArray alloc]
352                                 initWithCapacity:10]
353                             whithCategory: p_item - module_GetConfig( p_module, &i_confsize )]];
354                         break;
355                     case CONFIG_SUBCATEGORY:
356                         if( p_item->value.i == -1 ) break;
357
358                         if( p_item->value.i != SUBCAT_PLAYLIST_GENERAL &&
359                             p_item->value.i != SUBCAT_VIDEO_GENERAL &&
360                             p_item->value.i != SUBCAT_INPUT_GENERAL &&
361                             p_item->value.i != SUBCAT_INTERFACE_GENERAL &&
362                             p_item->value.i != SUBCAT_SOUT_GENERAL &&
363                             p_item->value.i != SUBCAT_ADVANCED_MISC &&
364                             p_item->value.i != SUBCAT_AUDIO_GENERAL )
365                         {
366                             o_child_name = [[VLCMain sharedInstance]
367                                 localizedString: config_CategoryNameGet( p_item->value.i ) ];
368                             o_child_title = o_child_name;
369                             o_child_help = [[VLCMain sharedInstance]
370                                 localizedString: config_CategoryHelpGet( p_item->value.i ) ];
371
372                             [p_last_category->o_children
373                                 addObject:[[VLCTreeItem alloc]
374                                 initWithName: o_child_name
375                                 withTitle: o_child_title
376                                 withHelp: o_child_help
377                                 ID: p_item->value.i
378                                 parent:p_last_category
379                                 children:[[NSMutableArray alloc]
380                                     initWithCapacity:10]
381                                 whithCategory: p_item - module_GetConfig( p_parser, &i_confsize )]];
382                         }
383  
384                         break;
385                     default:
386                         break;
387                     }
388                 } while( p_item < p_end && p_item++ );
389             }
390
391             /* Build a tree of the plugins */
392             /* Add the capabilities */
393             for( i_index = 0; i_index < p_list->i_count; i_index++ )
394             {
395                 unsigned int confsize;
396                 p_module = (module_t *)p_list->p_values[i_index].p_object;
397
398                 /* Exclude the main module */
399                 if( !strcmp( module_GetObjName( p_module ), "main" ) )
400                     continue;
401
402                 /* Exclude empty plugins (submodules don't have config */
403                 /* options, they are stored in the parent module) */
404 // Does not work
405 //                if( modules_IsSubModule( p_module ) )
406 //                    continue;
407                 p_item = module_GetConfig( p_module, &confsize );
408
409                 if( !p_item ) continue;
410                 if( !p_item->i_type ) break;
411                 int i_category = -1;
412                 int i_subcategory = -1;
413                 int i_options = 0;
414                 do
415                 {
416                     if( p_item->i_type == CONFIG_CATEGORY )
417                         i_category = p_item->value.i;
418                     else if( p_item->i_type == CONFIG_SUBCATEGORY )
419                         i_subcategory = p_item->value.i;
420
421                     if( p_item->i_type & CONFIG_ITEM )
422                         i_options ++;
423                     if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
424                         break;
425                 } while( p_item < p_end && p_item++ );
426                 if( !i_options ) continue;
427
428                 /* Find the right category item */
429
430                 long cookie;
431                 bool b_found = false;
432                 unsigned int i;
433                 VLCTreeItem* p_category_item, * p_subcategory_item;
434                 for (i = 0 ; i < [o_children count] ; i++)
435                 {
436                     p_category_item = [o_children objectAtIndex: i];
437                     if( p_category_item->i_object_id == i_category )
438                     {
439                         b_found = true;
440                         break;
441                     }
442                 }
443                 if( !b_found ) continue;
444
445                 /* Find subcategory item */
446                 b_found = false;
447                 cookie = -1;
448                 for (i = 0 ; i < [p_category_item->o_children count] ; i++)
449                 {
450                     p_subcategory_item = [p_category_item->o_children
451                                             objectAtIndex: i];
452                     if( p_subcategory_item->i_object_id == i_subcategory )
453                     {
454                         b_found = true;
455                         break;
456                     }
457                 }
458                 if( !b_found )
459                     p_subcategory_item = p_category_item;
460
461                 [p_subcategory_item->o_children addObject:[[VLCTreeItem alloc]
462                     initWithName:[[VLCMain sharedInstance]
463                         localizedString: module_GetName( p_module, false ) ]
464                     withTitle:[[VLCMain sharedInstance]
465                         localizedString:  module_GetLongName( p_module ) ]
466                     withHelp: @""
467                     ID: ((vlc_object_t*)p_module)->i_object_id
468                     parent:p_subcategory_item
469                     children:IsALeafNode
470                     whithCategory: -1]];
471                 }
472         }
473         vlc_list_release( p_list );
474     }
475     return o_children;
476 }
477
478 - (int)getObjectID
479 {
480     return i_object_id;
481 }
482
483 - (NSString *)getName
484 {
485     return o_name;
486 }
487
488 - (NSString *)getTitle
489 {
490     return o_title;
491 }
492
493 - (NSString *)getHelp
494 {
495     return o_help;
496 }
497
498 - (VLCTreeItem *)childAtIndex:(int)i_index
499 {
500     return [[self children] objectAtIndex:i_index];
501 }
502
503 - (int)numberOfChildren {
504     id i_tmp = [self children];
505     return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
506 }
507
508 - (BOOL)hasPrefs:(NSString *)o_module_name
509 {
510     intf_thread_t *p_intf = VLCIntf;
511     module_t *p_parser;
512     vlc_list_t *p_list;
513     char *psz_module_name;
514     int i_index;
515
516     psz_module_name = (char *)[o_module_name UTF8String];
517
518     /* look for module */
519     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
520
521     for( i_index = 0; i_index < p_list->i_count; i_index++ )
522     {
523         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
524
525         if( !strcmp( module_GetObjName( p_parser ), psz_module_name ) )
526         {
527             unsigned int confsize;
528             module_GetConfig( p_parser, &confsize );
529             BOOL b_has_prefs = confsize != 0;
530             vlc_list_release( p_list );
531             return( b_has_prefs );
532         }
533     }
534
535     vlc_list_release( p_list );
536
537     return( NO );
538 }
539
540 - (NSView *)showView:(NSScrollView *)o_prefs_view
541     advancedView:(bool) b_advanced
542 {
543     NSRect          s_vrc;
544     NSView          *o_view;
545
546     [[VLCPrefs sharedInstance] setTitle: [self getTitle]];
547     /* NSLog( [self getHelp] ); */
548     s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
549     o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
550     [o_view setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin |
551                                     NSViewMaxYMargin];
552
553 /* Create all subviews if it isn't already done because we cannot use */
554 /* setHiden for MacOS < 10.3*/
555     if( o_subviews == nil )
556     {
557         intf_thread_t   *p_intf = VLCIntf;
558         vlc_list_t      *p_list;
559         module_t        *p_parser = NULL;
560         module_config_t *p_item,
561                         *p_end;
562         unsigned int confsize;
563
564         o_subviews = [[NSMutableArray alloc] initWithCapacity:10];
565         /* Get a pointer to the module */
566         if( i_object_category == -1 )
567         {
568             p_parser = (module_t *) vlc_object_get( i_object_id );
569             if( !p_parser )
570             {
571                 /* 0OOoo something went really bad */
572                 return nil;
573             }
574             p_item = module_GetConfig( p_parser, &confsize );
575             p_end = p_item + confsize;
576
577             do
578             {
579                 if( !p_item )
580                 {
581                     msg_Err( p_intf, "invalid preference item found" );
582                     break;
583                 }
584                 if( p_item > p_end )
585                     break;
586                 switch(p_item->i_type)
587                 {
588                 case CONFIG_SUBCATEGORY:
589                     break;
590                 case CONFIG_CATEGORY:
591                     break;
592                 case CONFIG_SECTION:
593                     break;
594                 case CONFIG_HINT_USAGE:
595                     break;
596                 default:
597                 {
598                     VLCConfigControl *o_control = nil;
599                     o_control = [VLCConfigControl newControl:p_item
600                                                   withView:o_view];
601                     if( o_control != nil )
602                     {
603                         [o_control setAutoresizingMask: NSViewMaxYMargin |
604                             NSViewWidthSizable];
605                         [o_subviews addObject: o_control];
606                     }
607                 }
608                     break;
609                 }
610             } while( p_item < p_end && p_item++ );
611
612             vlc_object_release( (vlc_object_t*)p_parser );
613         }
614         else
615         {
616             int i_index;
617             p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
618             if( !p_list ) return o_view;
619
620             /*
621             * Find the main module
622             */
623             for( i_index = 0; i_index < p_list->i_count; i_index++ )
624             {
625                 p_parser = (module_t *)p_list->p_values[i_index].p_object;
626                 if( !strcmp( module_GetObjName( p_parser ), "main" ) )
627                     break;
628             }
629             if( p_parser == NULL )
630             {
631                 msg_Err( p_intf, "could not load preferences" );
632                 return o_view;
633             }
634             unsigned int confsize;
635             p_item = module_GetConfig( p_parser, &confsize );
636             p_end = p_item + confsize;
637             p_item += i_object_category;
638
639             if( ( p_item->i_type == CONFIG_CATEGORY ) &&
640               ( ( p_item->value.i == CAT_PLAYLIST )  ||
641                 ( p_item->value.i == CAT_AUDIO )  ||
642                 ( p_item->value.i == CAT_VIDEO ) ||
643                 ( p_item->value.i == CAT_INTERFACE ) ||
644                 ( p_item->value.i == CAT_INPUT ) ||
645                 ( p_item->value.i == CAT_SOUT ) ) )
646                 p_item++;
647
648             do
649             {
650                 p_item++;
651                 if( !p_item || !p_item->i_type )
652                 {
653                     msg_Err( p_intf, "invalid preference item found" );
654                     break;
655                 }
656                 if( p_item > p_end )
657                     break;
658                 switch( p_item->i_type )
659                 {
660                 case CONFIG_SUBCATEGORY:
661                     break;
662                 case CONFIG_CATEGORY:
663                     break;
664                 case CONFIG_SECTION:
665                     break;
666                 case CONFIG_HINT_USAGE:
667                     break;
668                 default:
669                 {
670                     VLCConfigControl *o_control = nil;
671                     o_control = [VLCConfigControl newControl:p_item
672                                                   withView:o_view];
673                     if( o_control != nil )
674                     {
675                         [o_control setAutoresizingMask: NSViewMaxYMargin |
676                                                         NSViewWidthSizable];
677                         [o_subviews addObject: o_control];
678                     }
679                     break;
680                 }
681                 }
682             } while ( ( p_item < p_end ) &&
683                       ( p_item->i_type != CONFIG_SUBCATEGORY ) );
684
685             vlc_list_release( p_list );
686         }
687     }
688
689     if( o_view != nil )
690     {
691         int i_lastItem = 0;
692         int i_yPos = -2;
693         int i_max_label = 0;
694         int i_show_advanced = 0;
695
696         NSEnumerator *enumerator = [o_subviews objectEnumerator];
697         VLCConfigControl *o_widget;
698         NSRect o_frame;
699  
700         while( ( o_widget = [enumerator nextObject] ) )
701             if( ( [o_widget isAdvanced] ) && (! b_advanced) )
702                 continue;
703             else if( i_max_label < [o_widget getLabelSize] )
704                 i_max_label = [o_widget getLabelSize];
705
706         enumerator = [o_subviews objectEnumerator];
707         while( ( o_widget = [enumerator nextObject] ) )
708         {
709             int i_widget;
710             if( ( [o_widget isAdvanced] ) && (! b_advanced) )
711             {
712                 i_show_advanced++;
713                 continue;
714             }
715
716             i_widget = [o_widget getViewType];
717             i_yPos += [VLCConfigControl calcVerticalMargin:i_widget
718                 lastItem:i_lastItem];
719             [o_widget setYPos:i_yPos];
720             o_frame = [o_widget frame];
721             o_frame.size.width = [o_view frame].size.width -
722                                     LEFTMARGIN - RIGHTMARGIN;
723             [o_widget setFrame:o_frame];
724             [o_widget alignWithXPosition: i_max_label];
725             i_yPos += [o_widget frame].size.height;
726             i_lastItem = i_widget;
727             [o_view addSubview:o_widget];
728          }
729         if( i_show_advanced != 0 )
730         {
731             /* We add the advanced notice... */
732             NSRect s_rc = [o_view frame];
733             NSTextField *o_label;
734             s_rc.size.height = 17;
735             s_rc.origin.x = LEFTMARGIN;
736             s_rc.origin.y = i_yPos += [VLCConfigControl
737                                         calcVerticalMargin:CONFIG_ITEM_STRING
738                                         lastItem:i_lastItem];
739             o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
740             [o_label setDrawsBackground: NO];
741             [o_label setBordered: NO];
742             [o_label setEditable: NO];
743             [o_label setSelectable: NO];
744             [o_label setStringValue: _NS("Some options are hidden. " \
745                                 "Check \"Advanced\" to display them.")];
746             [o_label setFont:[NSFont systemFontOfSize:10]];
747             [o_label sizeToFit];
748             [o_view addSubview:o_label];
749             i_yPos += [o_label frame].size.height;
750         }
751         o_frame = [o_view frame];
752         o_frame.size.height = i_yPos;
753         [o_view setFrame:o_frame];
754         [o_prefs_view setDocumentView:o_view];
755
756     }
757     return o_view;
758 }
759
760 - (void)applyChanges
761 {
762     unsigned int i;
763     if( o_subviews != nil )
764         //Item has been shown
765         for( i = 0 ; i < [o_subviews count] ; i++ )
766             [[o_subviews objectAtIndex:i] applyChanges];
767
768     if( o_children != IsALeafNode )
769         for( i = 0 ; i < [o_children count] ; i++ )
770             [[o_children objectAtIndex:i] applyChanges];
771 }
772
773 - (void)resetView
774 {
775     unsigned int i;
776     if( o_subviews != nil )
777     {
778         //Item has been shown
779         [o_subviews release];
780         o_subviews = nil;
781     }
782
783     if( o_children != IsALeafNode )
784         for( i = 0 ; i < [o_children count] ; i++ )
785             [[o_children objectAtIndex:i] resetView];
786 }
787
788 @end
789
790
791 @implementation VLCFlippedView
792
793 - (BOOL)isFlipped
794 {
795     return( YES );
796 }
797
798 @end