prefs_widgets.m
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:88k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * prefs_widgets.m: Preferences controls
  3.  *****************************************************************************
  4.  * Copyright (C) 2002-2007 the VideoLAN team
  5.  * $Id: e3b83d4283670eb7d31c4c7c40eb4933ae2baefc $
  6.  *
  7.  * Authors: Derk-Jan Hartman <hartman at videolan.org>
  8.  *          Jérôme Decoodt <djc at videolan.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.  * Preamble
  26.  *****************************************************************************/
  27. #include <stdlib.h>                                      /* malloc(), free() */
  28. #include <string.h>
  29. #ifdef HAVE_CONFIG_H
  30. # include "config.h"
  31. #endif
  32. #include <vlc_common.h>
  33. #include "vlc_keys.h"
  34. #include "intf.h"
  35. #include "prefs_widgets.h"
  36. #define PREFS_WRAP 300
  37. #define OFFSET_RIGHT 20
  38. #define OFFSET_BETWEEN 2
  39. #define UPWARDS_WHITE_ARROW                 "xE2x87xA7"
  40. #define OPTION_KEY                          "xE2x8CxA5"
  41. #define UP_ARROWHEAD                        "xE2x8Cx83"
  42. #define PLACE_OF_INTEREST_SIGN              "xE2x8Cx98"
  43. #define POPULATE_A_KEY( o_menu, string, value )                             
  44. {                                                                           
  45.     NSMenuItem *o_mi;                                                       
  46. /*  Normal */                                                               
  47.     o_mi = [[NSMenuItem alloc] initWithTitle:string                         
  48.         action:nil keyEquivalent:@""];                                      
  49.     [o_mi setKeyEquivalentModifierMask:                                     
  50.         0];                                                                 
  51.     [o_mi setAlternate: NO];                                                
  52.     [o_mi setTag:                                                           
  53.         ( value )];                                                         
  54.     [o_menu addItem: o_mi];                                                 
  55. /*  Ctrl */                                                                 
  56.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  57.         [[NSString stringWithUTF8String:                                    
  58.             UP_ARROWHEAD                                                    
  59.         ] stringByAppendingString: string]                                  
  60.         action:nil keyEquivalent:@""];                                      
  61.     [o_mi setKeyEquivalentModifierMask:                                     
  62.         NSControlKeyMask];                                                  
  63.     [o_mi setAlternate: YES];                                               
  64.     [o_mi setTag:                                                           
  65.         KEY_MODIFIER_CTRL | ( value )];                                     
  66.     [o_menu addItem: o_mi];                                                 
  67. /* Ctrl+Alt */                                                              
  68.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  69.         [[NSString stringWithUTF8String:                                    
  70.             UP_ARROWHEAD OPTION_KEY                                         
  71.         ] stringByAppendingString: string]                                  
  72.         action:nil keyEquivalent:@""];                                      
  73.     [o_mi setKeyEquivalentModifierMask:                                     
  74.         NSControlKeyMask | NSAlternateKeyMask];                             
  75.     [o_mi setAlternate: YES];                                               
  76.     [o_mi setTag:                                                           
  77.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT) | ( value )];                
  78.     [o_menu addItem: o_mi];                                                 
  79. /* Ctrl+Shift */                                                            
  80.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  81.         [[NSString stringWithUTF8String:                                    
  82.             UP_ARROWHEAD UPWARDS_WHITE_ARROW                                
  83.         ] stringByAppendingString: string]                                  
  84.         action:nil keyEquivalent:@""];                                      
  85.     [o_mi setKeyEquivalentModifierMask:                                     
  86.        NSControlKeyMask | NSShiftKeyMask];                                  
  87.     [o_mi setAlternate: YES];                                               
  88.     [o_mi setTag:                                                           
  89.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT) | ( value )];              
  90.     [o_menu addItem: o_mi];                                                 
  91. /* Ctrl+Apple */                                                            
  92.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  93.         [[NSString stringWithUTF8String:                                    
  94.             UP_ARROWHEAD PLACE_OF_INTEREST_SIGN                             
  95.         ] stringByAppendingString: string]                                  
  96.         action:nil keyEquivalent:@""];                                      
  97.     [o_mi setKeyEquivalentModifierMask:                                     
  98.         NSControlKeyMask | NSCommandKeyMask];                               
  99.     [o_mi setAlternate: YES];                                               
  100.     [o_mi setTag:                                                           
  101.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_COMMAND) | ( value )];            
  102.     [o_menu addItem: o_mi];                                                 
  103. /* Ctrl+Alt+Shift */                                                        
  104.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  105.         [[NSString stringWithUTF8String:                                    
  106.             UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW                     
  107.         ] stringByAppendingString: string]                                  
  108.         action:nil keyEquivalent:@""];                                      
  109.     [o_mi setKeyEquivalentModifierMask:                                     
  110.         NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask];            
  111.     [o_mi setAlternate: YES];                                               
  112.     [o_mi setTag:                                                           
  113.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) |       
  114.              ( value )];                                                    
  115.     [o_menu addItem: o_mi];                                                 
  116. /* Ctrl+Alt+Apple */                                                        
  117.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  118.         [[NSString stringWithUTF8String:                                    
  119.             UP_ARROWHEAD OPTION_KEY PLACE_OF_INTEREST_SIGN                  
  120.         ] stringByAppendingString: string]                                  
  121.         action:nil keyEquivalent:@""];                                      
  122.     [o_mi setKeyEquivalentModifierMask:                                     
  123.         NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask];          
  124.     [o_mi setAlternate: YES];                                               
  125.     [o_mi setTag:                                                           
  126.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) |     
  127.             ( value )];                                                     
  128.     [o_menu addItem: o_mi];                                                 
  129. /* Ctrl+Shift+Apple */                                                      
  130.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  131.         [[NSString stringWithUTF8String:                                    
  132.             UP_ARROWHEAD UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN         
  133.         ] stringByAppendingString: string]                                  
  134.         action:nil keyEquivalent:@""];                                      
  135.     [o_mi setKeyEquivalentModifierMask:                                     
  136.         NSControlKeyMask | NSShiftKeyMask | NSCommandKeyMask];              
  137.     [o_mi setAlternate: YES];                                               
  138.     [o_mi setTag:                                                           
  139.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) |   
  140.             ( value )];                                                     
  141.     [o_menu addItem: o_mi];                                                 
  142. /* Ctrl+Alt+Shift+Apple */                                                  
  143.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  144.         [[NSString stringWithUTF8String:                                    
  145.             UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW                     
  146.                 PLACE_OF_INTEREST_SIGN                                      
  147.         ] stringByAppendingString: string]                                  
  148.         action:nil keyEquivalent:@""];                                      
  149.     [o_mi setKeyEquivalentModifierMask:                                     
  150.         NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask |            
  151.             NSCommandKeyMask];                                              
  152.     [o_mi setAlternate: YES];                                               
  153.     [o_mi setTag:                                                           
  154.         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT |        
  155.             KEY_MODIFIER_COMMAND) | ( value )];                             
  156.     [o_menu addItem: o_mi];                                                 
  157. /* Alt */                                                                   
  158.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  159.         [[NSString stringWithUTF8String:                                    
  160.             OPTION_KEY                                                      
  161.         ] stringByAppendingString: string]                                  
  162.         action:nil keyEquivalent:@""];                                      
  163.     [o_mi setKeyEquivalentModifierMask:                                     
  164.         NSAlternateKeyMask];                                                
  165.     [o_mi setAlternate: YES];                                               
  166.     [o_mi setTag:                                                           
  167.         KEY_MODIFIER_ALT | ( value )];                                      
  168.     [o_menu addItem: o_mi];                                                 
  169. /* Alt+Shift */                                                             
  170.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  171.         [[NSString stringWithUTF8String:                                    
  172.             OPTION_KEY UPWARDS_WHITE_ARROW                                  
  173.         ] stringByAppendingString: string]                                  
  174.         action:nil keyEquivalent:@""];                                      
  175.     [o_mi setKeyEquivalentModifierMask:                                     
  176.         NSAlternateKeyMask | NSShiftKeyMask];                               
  177.     [o_mi setAlternate: YES];                                               
  178.     [o_mi setTag:                                                           
  179.         (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | ( value )];               
  180.     [o_menu addItem: o_mi];                                                 
  181. /* Alt+Apple */                                                             
  182.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  183.         [[NSString stringWithUTF8String:                                    
  184.             OPTION_KEY PLACE_OF_INTEREST_SIGN                               
  185.         ] stringByAppendingString: string]                                  
  186.         action:nil keyEquivalent:@""];                                      
  187.     [o_mi setKeyEquivalentModifierMask:                                     
  188.         NSAlternateKeyMask | NSCommandKeyMask];                             
  189.     [o_mi setAlternate: YES];                                               
  190.     [o_mi setTag:                                                           
  191.         (KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | ( value )];             
  192.     [o_menu addItem: o_mi];                                                 
  193. /* Alt+Shift+Apple */                                                       
  194.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  195.         [[NSString stringWithUTF8String:                                    
  196.             OPTION_KEY UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN           
  197.         ] stringByAppendingString: string]                                  
  198.         action:nil keyEquivalent:@""];                                      
  199.     [o_mi setKeyEquivalentModifierMask:                                     
  200.         NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask];            
  201.     [o_mi setAlternate: YES];                                               
  202.     [o_mi setTag:                                                           
  203.         (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) |    
  204.             ( value )];                                                     
  205.     [o_menu addItem: o_mi];                                                 
  206. /* Shift */                                                                 
  207.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  208.         [[NSString stringWithUTF8String:                                    
  209.             UPWARDS_WHITE_ARROW                                             
  210.         ] stringByAppendingString: string]                                  
  211.         action:nil keyEquivalent:@""];                                      
  212.     [o_mi setKeyEquivalentModifierMask:                                     
  213.         NSShiftKeyMask];                                                    
  214.     [o_mi setAlternate: YES];                                               
  215.     [o_mi setTag:                                                           
  216.         KEY_MODIFIER_SHIFT | ( value )];                                    
  217.     [o_menu addItem: o_mi];                                                 
  218. /* Shift+Apple */                                                           
  219.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  220.         [[NSString stringWithUTF8String:                                    
  221.             UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN                      
  222.         ] stringByAppendingString: string]                                  
  223.         action:nil keyEquivalent:@""];                                      
  224.     [o_mi setKeyEquivalentModifierMask:                                     
  225.         NSShiftKeyMask | NSCommandKeyMask];                                 
  226.     [o_mi setAlternate: YES];                                               
  227.     [o_mi setTag:                                                           
  228.         (KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | ( value )];           
  229.     [o_menu addItem: o_mi];                                                 
  230. /* Apple */                                                                 
  231.     o_mi = [[NSMenuItem alloc] initWithTitle:                               
  232.         [[NSString stringWithUTF8String:                                    
  233.         PLACE_OF_INTEREST_SIGN                                              
  234.         ] stringByAppendingString: string]                                  
  235.         action:nil keyEquivalent:@""];                                      
  236.     [o_mi setKeyEquivalentModifierMask:                                     
  237.         NSCommandKeyMask];                                                  
  238.     [o_mi setAlternate: YES];                                               
  239.     [o_mi setTag:                                                           
  240.         KEY_MODIFIER_COMMAND | ( value )];                                  
  241.     [o_menu addItem: o_mi];                                                 
  242. }
  243. #define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label,       
  244.     tooltip )                                                               
  245. {                                                                           
  246.     NSRect s_rc = superFrame;                                               
  247.     s_rc.size.height = 17;                                                  
  248.     s_rc.origin.x = x_offset - 3;                                           
  249.     s_rc.origin.y = superFrame.size.height - 17 + my_y_offset;              
  250.     o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];           
  251.     [o_label setDrawsBackground: NO];                                       
  252.     [o_label setBordered: NO];                                              
  253.     [o_label setEditable: NO];                                              
  254.     [o_label setSelectable: NO];                                            
  255.     [o_label setStringValue: label];                                        
  256.     [o_label setToolTip: tooltip];                                          
  257.     [o_label setFont:[NSFont systemFontOfSize:0]];                          
  258.     [o_label sizeToFit];                                                    
  259. }
  260. #define ADD_TEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset,      
  261.     my_width, tooltip, init_value )                                         
  262. {                                                                           
  263.     NSRect s_rc = superFrame;                                               
  264.     s_rc.origin.x = x_offset;                                               
  265.     s_rc.origin.y = my_y_offset;                                            
  266.     s_rc.size.height = 22;                                                  
  267.     s_rc.size.width = my_width;                                             
  268.     o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];       
  269.     [o_textfield setFont:[NSFont systemFontOfSize:0]];                      
  270.     [o_textfield setToolTip: tooltip];                                      
  271.     [o_textfield setStringValue: init_value];                               
  272. }
  273. #define ADD_SECURETEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset,      
  274. my_width, tooltip, init_value )                                         
  275. {                                                                           
  276. NSRect s_rc = superFrame;                                               
  277. s_rc.origin.x = x_offset;                                               
  278. s_rc.origin.y = my_y_offset;                                            
  279. s_rc.size.height = 22;                                                  
  280. s_rc.size.width = my_width;                                             
  281. o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       
  282. [o_textfield setFont:[NSFont systemFontOfSize:0]];                      
  283. [o_textfield setToolTip: tooltip];                                      
  284. [o_textfield setStringValue: init_value];                               
  285. }
  286. #define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset,   
  287.     tooltip )                                                               
  288. {                                                                           
  289.     NSRect s_rc = superFrame;                                               
  290.     s_rc.origin.x = x_offset + 2;                                           
  291.     s_rc.origin.y = my_y_offset;                                            
  292.     s_rc.size.height = 26;                                                  
  293.     s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x -           
  294.         (x2_offset);                                                        
  295.     o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain];            
  296.     [o_combo setFont:[NSFont systemFontOfSize:0]];                          
  297.     [o_combo setToolTip: tooltip];                                          
  298.     [o_combo setUsesDataSource:TRUE];                                       
  299.     [o_combo setDataSource:self];                                           
  300.     [o_combo setNumberOfVisibleItems:10];                                   
  301.     [o_combo setCompletes:YES];                                             
  302. }
  303. #define ADD_RIGHT_BUTTON( o_button, superFrame, x_offset, my_y_offset,      
  304.     tooltip, title )                                                        
  305. {                                                                           
  306.     NSRect s_rc = superFrame;                                               
  307.     o_button = [[[NSButton alloc] initWithFrame: s_rc] retain];             
  308.     [o_button setButtonType: NSMomentaryPushInButton];                      
  309.     [o_button setBezelStyle: NSRoundedBezelStyle];                          
  310.     [o_button setTitle: title];                                             
  311.     [o_button setFont:[NSFont systemFontOfSize:0]];                         
  312.     [o_button sizeToFit];                                                   
  313.     s_rc = [o_button frame];                                                
  314.     s_rc.origin.x = superFrame.size.width - [o_button frame].size.width - 6;
  315.     s_rc.origin.y = my_y_offset - 6;                                        
  316.     s_rc.size.width += 12;                                                  
  317.     [o_button setFrame: s_rc];                                              
  318.     [o_button setToolTip: tooltip];                                         
  319.     [o_button setTarget: self];                                             
  320.     [o_button setAction: @selector(openFileDialog:)];                       
  321. }
  322. #define ADD_POPUP( o_popup, superFrame, x_offset, my_y_offset, x2_offset,   
  323.     tooltip )                                                               
  324. {                                                                           
  325.     NSRect s_rc = superFrame;                                               
  326.     s_rc.origin.x = x_offset - 1;                                           
  327.     s_rc.origin.y = my_y_offset;                                            
  328.     s_rc.size.height = 26;                                                  
  329.     s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x -           
  330.         (x2_offset);                                                        
  331.     o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain];         
  332.     [o_popup setFont:[NSFont systemFontOfSize:0]];                          
  333.     [o_popup setToolTip: tooltip];                                          
  334. }
  335. #define ADD_STEPPER( o_stepper, superFrame, x_offset, my_y_offset, tooltip, 
  336.     lower, higher )                                                         
  337. {                                                                           
  338.     NSRect s_rc = superFrame;                                               
  339.     s_rc.origin.x = x_offset;                                               
  340.     s_rc.origin.y = my_y_offset;                                            
  341.     s_rc.size.height = 23;                                                  
  342.     s_rc.size.width = 23;                                                   
  343.     o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain];           
  344.     [o_stepper setFont:[NSFont systemFontOfSize:0]];                        
  345.     [o_stepper setToolTip: tooltip];                                        
  346.     [o_stepper setMaxValue: higher];                                        
  347.     [o_stepper setMinValue: lower];                                         
  348.     [o_stepper setTarget: self];                                            
  349.     [o_stepper setAction: @selector(stepperChanged:)];                      
  350.     [o_stepper sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |       
  351.         NSLeftMouseDraggedMask];                                            
  352. }
  353. #define ADD_SLIDER( o_slider, superFrame, x_offset, my_y_offset, my_width,  
  354.     tooltip, lower, higher )                                                
  355. {                                                                           
  356.     NSRect s_rc = superFrame;                                               
  357.     s_rc.origin.x = x_offset;                                               
  358.     s_rc.origin.y = my_y_offset;                                            
  359.     s_rc.size.height = 21;                                                  
  360.     s_rc.size.width = my_width;                                             
  361.     o_slider = [[[NSSlider alloc] initWithFrame: s_rc] retain];             
  362.     [o_slider setFont:[NSFont systemFontOfSize:0]];                         
  363.     [o_slider setToolTip: tooltip];                                         
  364.     [o_slider setMaxValue: higher];                                         
  365.     [o_slider setMinValue: lower];                                          
  366. }
  367. #define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, 
  368.     tooltip, init_value, position )                                         
  369. {                                                                           
  370.     NSRect s_rc = superFrame;                                               
  371.     s_rc.size.height = 18;                                                  
  372.     s_rc.origin.x = x_offset - 2;                                           
  373.     s_rc.origin.y = superFrame.size.height - 18 + my_y_offset;              
  374.     o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain];           
  375.     [o_checkbox setFont:[NSFont systemFontOfSize:0]];                       
  376.     [o_checkbox setButtonType: NSSwitchButton];                             
  377.     [o_checkbox setImagePosition: position];                                
  378.     [o_checkbox setIntValue: init_value];                                   
  379.     [o_checkbox setTitle: label];                                           
  380.     [o_checkbox setToolTip: tooltip];                                       
  381.     [o_checkbox sizeToFit];                                                 
  382. }
  383. @implementation VLCConfigControl
  384. - (id)initWithFrame: (NSRect)frame
  385. {
  386.     return [self initWithFrame: frame
  387.                     item: nil];
  388. }
  389. - (id)initWithFrame: (NSRect)frame
  390.         item: (module_config_t *)_p_item
  391. {
  392.     self = [super initWithFrame: frame];
  393.     if( self != nil )
  394.     {
  395.         p_item = _p_item;
  396.         psz_name = p_item->psz_name;
  397.         o_label = NULL;
  398.         i_type = p_item->i_type;
  399.         i_view_type = 0;
  400.         b_advanced = p_item->b_advanced;
  401.         [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
  402.     }
  403.     return (self);
  404. }
  405. - (void)setYPos:(int)i_yPos
  406. {
  407.     NSRect frame = [self frame];
  408.     frame.origin.y = i_yPos;
  409.     [self setFrame:frame];
  410. }
  411. - (void)dealloc
  412. {
  413.     if( o_label ) [o_label release];
  414.     free( psz_name );
  415.     [super dealloc];
  416. }
  417. + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
  418. {
  419.     int i_margin;
  420.     switch( i_curItem )
  421.     {
  422.     case CONFIG_ITEM_STRING:
  423.     case CONFIG_ITEM_PASSWORD:
  424.         switch( i_lastItem )
  425.         {
  426.         case CONFIG_ITEM_STRING:
  427.         case CONFIG_ITEM_PASSWORD:
  428.             i_margin = 8;
  429.             break;
  430.         case CONFIG_ITEM_STRING_LIST:
  431.             i_margin = 7;
  432.             break;
  433.         case CONFIG_ITEM_FILE:
  434.             i_margin = 8;
  435.             break;
  436.         case CONFIG_ITEM_MODULE:
  437.             i_margin = 4;
  438.             break;
  439.         case CONFIG_ITEM_INTEGER:
  440.             i_margin = 7;
  441.             break;
  442.         case CONFIG_ITEM_RANGED_INTEGER:
  443.             i_margin = 5;
  444.             break;
  445.         case CONFIG_ITEM_BOOL:
  446.             i_margin = 7;
  447.             break;
  448.         case CONFIG_ITEM_KEY_AFTER_10_3:
  449.             i_margin = 6;
  450.             break;
  451.         case CONFIG_ITEM_MODULE_LIST:
  452.             i_margin = 8;
  453.             break;
  454.         default:
  455.             i_margin = 20;
  456.             break;
  457.         }
  458.         break;
  459.     case CONFIG_ITEM_STRING_LIST:
  460.         switch( i_lastItem )
  461.         {
  462.         case CONFIG_ITEM_STRING:
  463.         case CONFIG_ITEM_PASSWORD:
  464.             i_margin = 8;
  465.             break;
  466.         case CONFIG_ITEM_STRING_LIST:
  467.             i_margin = 7;
  468.             break;
  469.         case CONFIG_ITEM_FILE:
  470.             i_margin = 6;
  471.             break;
  472.         case CONFIG_ITEM_MODULE:
  473.             i_margin = 4;
  474.             break;
  475.         case CONFIG_ITEM_INTEGER:
  476.             i_margin = 7;
  477.             break;
  478.         case CONFIG_ITEM_RANGED_INTEGER:
  479.             i_margin = 5;
  480.             break;
  481.         case CONFIG_ITEM_BOOL:
  482.             i_margin = 7;
  483.             break;
  484.         case CONFIG_ITEM_KEY_AFTER_10_3:
  485.             i_margin = 6;
  486.             break;
  487.         case CONFIG_ITEM_MODULE_LIST:
  488.             i_margin = 8;
  489.             break;
  490.         default:
  491.             i_margin = 20;
  492.             break;
  493.         }
  494.         break;
  495.     case CONFIG_ITEM_FILE:
  496.         switch( i_lastItem )
  497.         {
  498.         case CONFIG_ITEM_STRING:
  499.         case CONFIG_ITEM_PASSWORD:
  500.             i_margin = 13;
  501.             break;
  502.         case CONFIG_ITEM_STRING_LIST:
  503.             i_margin = 10;
  504.             break;
  505.         case CONFIG_ITEM_FILE:
  506.             i_margin = 9;
  507.             break;
  508.         case CONFIG_ITEM_MODULE:
  509.             i_margin = 9;
  510.             break;
  511.         case CONFIG_ITEM_INTEGER:
  512.             i_margin = 10;
  513.             break;
  514.         case CONFIG_ITEM_RANGED_INTEGER:
  515.             i_margin = 8;
  516.             break;
  517.         case CONFIG_ITEM_BOOL:
  518.             i_margin = 10;
  519.             break;
  520.         case CONFIG_ITEM_KEY_AFTER_10_3:
  521.             i_margin = 9;
  522.             break;
  523.         case CONFIG_ITEM_MODULE_LIST:
  524.             i_margin = 11;
  525.             break;
  526.         default:
  527.             i_margin = 23;
  528.             break;
  529.         }
  530.         break;
  531.     case CONFIG_ITEM_MODULE:
  532.         switch( i_lastItem )
  533.         {
  534.         case CONFIG_ITEM_STRING:
  535.         case CONFIG_ITEM_PASSWORD:
  536.             i_margin = 8;
  537.             break;
  538.         case CONFIG_ITEM_STRING_LIST:
  539.             i_margin = 7;
  540.             break;
  541.         case CONFIG_ITEM_FILE:
  542.             i_margin = 6;
  543.             break;
  544.         case CONFIG_ITEM_MODULE:
  545.             i_margin = 5;
  546.             break;
  547.         case CONFIG_ITEM_INTEGER:
  548.             i_margin = 7;
  549.             break;
  550.         case CONFIG_ITEM_RANGED_INTEGER:
  551.             i_margin = 6;
  552.             break;
  553.         case CONFIG_ITEM_BOOL:
  554.             i_margin = 8;
  555.             break;
  556.         case CONFIG_ITEM_KEY_AFTER_10_3:
  557.             i_margin = 7;
  558.             break;
  559.         case CONFIG_ITEM_MODULE_LIST:
  560.             i_margin = 9;
  561.             break;
  562.         default:
  563.             i_margin = 20;
  564.             break;
  565.         }
  566.         break;
  567.     case CONFIG_ITEM_INTEGER:
  568.         switch( i_lastItem )
  569.         {
  570.         case CONFIG_ITEM_STRING:
  571.         case CONFIG_ITEM_PASSWORD:
  572.             i_margin = 8;
  573.             break;
  574.         case CONFIG_ITEM_STRING_LIST:
  575.             i_margin = 7;
  576.             break;
  577.         case CONFIG_ITEM_FILE:
  578.             i_margin = 6;
  579.             break;
  580.         case CONFIG_ITEM_MODULE:
  581.             i_margin = 4;
  582.             break;
  583.         case CONFIG_ITEM_INTEGER:
  584.             i_margin = 7;
  585.             break;
  586.         case CONFIG_ITEM_RANGED_INTEGER:
  587.             i_margin = 5;
  588.             break;
  589.         case CONFIG_ITEM_BOOL:
  590.             i_margin = 7;
  591.             break;
  592.         case CONFIG_ITEM_KEY_AFTER_10_3:
  593.             i_margin = 6;
  594.             break;
  595.         case CONFIG_ITEM_MODULE_LIST:
  596.             i_margin = 8;
  597.             break;
  598.         default:
  599.             i_margin = 20;
  600.             break;
  601.         }
  602.         break;
  603.     case CONFIG_ITEM_RANGED_INTEGER:
  604.         switch( i_lastItem )
  605.         {
  606.         case CONFIG_ITEM_STRING:
  607.         case CONFIG_ITEM_PASSWORD:
  608.             i_margin = 8;
  609.             break;
  610.         case CONFIG_ITEM_STRING_LIST:
  611.             i_margin = 7;
  612.             break;
  613.         case CONFIG_ITEM_FILE:
  614.             i_margin = 8;
  615.             break;
  616.         case CONFIG_ITEM_MODULE:
  617.             i_margin = 4;
  618.             break;
  619.         case CONFIG_ITEM_INTEGER:
  620.             i_margin = 7;
  621.             break;
  622.         case CONFIG_ITEM_RANGED_INTEGER:
  623.             i_margin = 5;
  624.             break;
  625.         case CONFIG_ITEM_BOOL:
  626.             i_margin = 7;
  627.             break;
  628.         case CONFIG_ITEM_KEY_AFTER_10_3:
  629.             i_margin = 6;
  630.             break;
  631.         case CONFIG_ITEM_MODULE_LIST:
  632.             i_margin = 8;
  633.             break;
  634.         default:
  635.             i_margin = 20;
  636.             break;
  637.         }
  638.         break;
  639.     case CONFIG_ITEM_BOOL:
  640.         switch( i_lastItem )
  641.         {
  642.         case CONFIG_ITEM_STRING:
  643.         case CONFIG_ITEM_PASSWORD:
  644.             i_margin = 10;
  645.             break;
  646.         case CONFIG_ITEM_STRING_LIST:
  647.             i_margin = 9;
  648.             break;
  649.         case CONFIG_ITEM_FILE:
  650.             i_margin = 8;
  651.             break;
  652.         case CONFIG_ITEM_MODULE:
  653.             i_margin = 6;
  654.             break;
  655.         case CONFIG_ITEM_INTEGER:
  656.             i_margin = 9;
  657.             break;
  658.         case CONFIG_ITEM_RANGED_INTEGER:
  659.             i_margin = 7;
  660.             break;
  661.         case CONFIG_ITEM_BOOL:
  662.             i_margin = 7;
  663.             break;
  664.         case CONFIG_ITEM_KEY_AFTER_10_3:
  665.             i_margin = 5;
  666.             break;
  667.         case CONFIG_ITEM_MODULE_LIST:
  668.             i_margin = 10;
  669.             break;
  670.         default:
  671.             i_margin = 20;
  672.             break;
  673.         }
  674.         break;
  675.     case CONFIG_ITEM_KEY_AFTER_10_3:
  676.         switch( i_lastItem )
  677.         {
  678.         case CONFIG_ITEM_STRING:
  679.         case CONFIG_ITEM_PASSWORD:
  680.             i_margin = 8;
  681.             break;
  682.         case CONFIG_ITEM_STRING_LIST:
  683.             i_margin = 7;
  684.             break;
  685.         case CONFIG_ITEM_FILE:
  686.             i_margin = 6;
  687.             break;
  688.         case CONFIG_ITEM_MODULE:
  689.             i_margin = 6;
  690.             break;
  691.         case CONFIG_ITEM_INTEGER:
  692.             i_margin = 7;
  693.             break;
  694.         case CONFIG_ITEM_RANGED_INTEGER:
  695.             i_margin = 5;
  696.             break;
  697.         case CONFIG_ITEM_BOOL:
  698.             i_margin = 7;
  699.             break;
  700.         case CONFIG_ITEM_KEY_AFTER_10_3:
  701.             i_margin = 8;
  702.             break;
  703.         case CONFIG_ITEM_MODULE_LIST:
  704.             i_margin = 10;
  705.             break;
  706.         default:
  707.             i_margin = 20;
  708.             break;
  709.         }
  710.         break;
  711.     case CONFIG_ITEM_MODULE_LIST:
  712.         switch( i_lastItem )
  713.         {
  714.         case CONFIG_ITEM_STRING:
  715.         case CONFIG_ITEM_PASSWORD:
  716.             i_margin = 10;
  717.             break;
  718.         case CONFIG_ITEM_STRING_LIST:
  719.             i_margin = 7;
  720.             break;
  721.         case CONFIG_ITEM_FILE:
  722.             i_margin = 6;
  723.             break;
  724.         case CONFIG_ITEM_MODULE:
  725.             i_margin = 6;
  726.             break;
  727.         case CONFIG_ITEM_INTEGER:
  728.             i_margin = 9;
  729.             break;
  730.         case CONFIG_ITEM_RANGED_INTEGER:
  731.             i_margin = 5;
  732.             break;
  733.         case CONFIG_ITEM_BOOL:
  734.             i_margin = 7;
  735.             break;
  736.         case CONFIG_ITEM_KEY_AFTER_10_3:
  737.             i_margin = 5;
  738.             break;
  739.         case CONFIG_ITEM_MODULE_LIST:
  740.             i_margin = 8;
  741.             break;
  742.         default:
  743.             i_margin = 20;
  744.             break;
  745.         }
  746.         break;
  747.     default:
  748.         i_margin = 20;
  749.         break;
  750.     }
  751.     return i_margin;
  752. }
  753. + (VLCConfigControl *)newControl: (module_config_t *)_p_item
  754.                       withView: (NSView *)o_parent_view
  755. {
  756.     VLCConfigControl *p_control = NULL;
  757.     switch( _p_item->i_type )
  758.     {
  759.     case CONFIG_ITEM_STRING:
  760.     case CONFIG_ITEM_PASSWORD:
  761.         if( !_p_item->i_list )
  762.         {
  763.             p_control = [[StringConfigControl alloc]
  764.                     initWithItem: _p_item
  765.                     withView: o_parent_view];
  766.         }
  767.         else
  768.         {
  769.             p_control = [[StringListConfigControl alloc]
  770.                     initWithItem: _p_item
  771.                     withView: o_parent_view];
  772.         }
  773.         break;
  774.     case CONFIG_ITEM_FILE:
  775.     case CONFIG_ITEM_DIRECTORY:
  776.         p_control = [[FileConfigControl alloc]
  777.                     initWithItem: _p_item
  778.                     withView: o_parent_view];
  779.         break;
  780.     case CONFIG_ITEM_MODULE:
  781.     case CONFIG_ITEM_MODULE_CAT:
  782.         p_control = [[ModuleConfigControl alloc]
  783.                     initWithItem: _p_item
  784.                     withView: o_parent_view];
  785.         break;
  786.     case CONFIG_ITEM_INTEGER:
  787.         if( _p_item->i_list )
  788.         {
  789.             p_control = [[IntegerListConfigControl alloc]
  790.                         initWithItem: _p_item
  791.                         withView: o_parent_view];
  792.         }
  793.         else if( _p_item->min.i != 0 || _p_item->max.i != 0 )
  794.         {
  795.             p_control = [[RangedIntegerConfigControl alloc]
  796.                         initWithItem: _p_item
  797.                         withView: o_parent_view];
  798.         }
  799.         else
  800.         {
  801.             p_control = [[IntegerConfigControl alloc]
  802.                         initWithItem: _p_item
  803.                         withView: o_parent_view];
  804.         }
  805.         break;
  806.     case CONFIG_ITEM_BOOL:
  807.         p_control = [[BoolConfigControl alloc]
  808.                     initWithItem: _p_item
  809.                     withView: o_parent_view];
  810.         break;
  811.     case CONFIG_ITEM_FLOAT:
  812.         if( _p_item->min.f != 0 || _p_item->max.f != 0 )
  813.         {
  814.             p_control = [[RangedFloatConfigControl alloc]
  815.                         initWithItem: _p_item
  816.                         withView: o_parent_view];
  817.         }
  818.         else
  819.         {
  820.             p_control = [[FloatConfigControl alloc]
  821.                         initWithItem: _p_item
  822.                         withView: o_parent_view];
  823.         }
  824.         break;
  825.     case CONFIG_ITEM_KEY:
  826.         p_control = [[KeyConfigControl alloc]
  827.                         initWithItem: _p_item
  828.                         withView: o_parent_view];
  829.         break;
  830.     case CONFIG_ITEM_MODULE_LIST:
  831.     case CONFIG_ITEM_MODULE_LIST_CAT:
  832.         p_control = [[ModuleListConfigControl alloc]
  833.                     initWithItem: _p_item
  834.                     withView: o_parent_view];
  835.         break;
  836.     default:
  837.         break;
  838.     }
  839.     return p_control;
  840. }
  841. - (NSString *)name
  842. {
  843.     return [[VLCMain sharedInstance] localizedString: psz_name];
  844. }
  845. - (int)type
  846. {
  847.     return i_type;
  848. }
  849. - (int)viewType
  850. {
  851.     return i_view_type;
  852. }
  853. - (BOOL)isAdvanced
  854. {
  855.     return b_advanced;
  856. }
  857. - (int)intValue
  858. {
  859.     return 0;
  860. }
  861. - (float)floatValue
  862. {
  863.     return 0;
  864. }
  865. - (char *)stringValue
  866. {
  867.     return NULL;
  868. }
  869. - (void)applyChanges
  870. {
  871.     vlc_value_t val;
  872.     switch( p_item->i_type )
  873.     {
  874.     case CONFIG_ITEM_STRING:
  875.     case CONFIG_ITEM_PASSWORD:
  876.     case CONFIG_ITEM_FILE:
  877.     case CONFIG_ITEM_DIRECTORY:
  878.     case CONFIG_ITEM_MODULE:
  879.     case CONFIG_ITEM_MODULE_LIST:
  880.     case CONFIG_ITEM_MODULE_LIST_CAT:
  881.         config_PutPsz( VLCIntf, psz_name, [self stringValue] );
  882.         break;
  883.     case CONFIG_ITEM_KEY:
  884.         /* So you don't need to restart to have the changes take effect */
  885.         val.i_int = [self intValue];
  886.         var_Set( VLCIntf->p_libvlc, psz_name, val );
  887.     case CONFIG_ITEM_INTEGER:
  888.     case CONFIG_ITEM_BOOL:
  889.         config_PutInt( VLCIntf, psz_name, [self intValue] );
  890.         break;
  891.     case CONFIG_ITEM_FLOAT:
  892.         config_PutFloat( VLCIntf, psz_name, [self floatValue] );
  893.         break;
  894.     }
  895. }
  896. - (void)resetValues
  897. {
  898. }
  899. - (int)labelSize
  900. {
  901.     return [o_label frame].size.width;
  902. }
  903. - (void) alignWithXPosition:(int)i_xPos;
  904. {
  905.     /* FIXME: not implemented atm, but created to shut up the warning
  906.      * about "method definition not found" -- FK @ 7/24/05 */
  907. }
  908. @end
  909. @implementation StringConfigControl
  910. - (id) initWithItem: (module_config_t *)_p_item
  911.            withView: (NSView *)o_parent_view
  912. {
  913.     NSRect mainFrame = [o_parent_view frame];
  914.     NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
  915.     mainFrame.size.height = 22;
  916.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
  917.     mainFrame.origin.x = LEFTMARGIN;
  918.     mainFrame.origin.y = 0;
  919.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  920.     {
  921.         if( p_item->i_type == CONFIG_ITEM_PASSWORD )
  922.             i_view_type = CONFIG_ITEM_PASSWORD;
  923.         else
  924.             i_view_type = CONFIG_ITEM_STRING;
  925.         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
  926.                               [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext]
  927.                                                           toWidth: PREFS_WRAP];
  928.         /* add the label */
  929.         if( p_item->psz_text )
  930.             o_labelString = [[VLCMain sharedInstance]
  931.                                 localizedString: (char *)p_item->psz_text];
  932.         else
  933.             o_labelString = [NSString stringWithString:@""];
  934.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
  935.         [o_label setAutoresizingMask:NSViewNotSizable ];
  936.         [self addSubview: o_label];
  937.         /* build the textfield */
  938.         if( p_item->value.psz )
  939.             o_textfieldString = [[VLCMain sharedInstance]
  940.                                     localizedString: (char *)p_item->value.psz];
  941.         else
  942.             o_textfieldString = [NSString stringWithString: @""];
  943.         if( p_item->i_type == CONFIG_ITEM_PASSWORD )
  944.         {
  945.             ADD_SECURETEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
  946.                           0, mainFrame.size.width - [o_label frame].size.width -
  947.                           2, o_textfieldTooltip, o_textfieldString )
  948.         }
  949.         else
  950.         {
  951.             ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
  952.                             0, mainFrame.size.width - [o_label frame].size.width -
  953.                             2, o_textfieldTooltip, o_textfieldString )
  954.         }
  955.         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
  956.         [self addSubview: o_textfield];
  957.     }
  958.     return self;
  959. }
  960. - (void) alignWithXPosition:(int)i_xPos
  961. {
  962.     NSRect frame;
  963.     NSRect superFrame = [self frame];
  964.     frame = [o_label frame];
  965.     frame.origin.x = i_xPos - frame.size.width - 3;
  966.     [o_label setFrame:frame];
  967.     frame = [o_textfield frame];
  968.     frame.origin.x = i_xPos + 2;
  969.     frame.size.width = superFrame.size.width - frame.origin.x - 1;
  970.     [o_textfield setFrame:frame];
  971. }
  972. - (void)dealloc
  973. {
  974.     [o_textfield release];
  975.     [super dealloc];
  976. }
  977. - (char *)stringValue
  978. {
  979.     return [[VLCMain sharedInstance] delocalizeString:
  980.                         [o_textfield stringValue]];
  981. }
  982. - (void)resetValues
  983. {
  984.     NSString *o_textfieldString;
  985.     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
  986.     if( psz_value )
  987.         o_textfieldString = [[VLCMain sharedInstance]
  988.                                 localizedString: psz_value];
  989.     else
  990.         o_textfieldString = [NSString stringWithString: @""];
  991.     free( psz_value );
  992.     [super resetValues];
  993. }
  994. @end
  995. @implementation StringListConfigControl
  996. - (id) initWithItem: (module_config_t *)_p_item
  997.            withView: (NSView *)o_parent_view
  998. {
  999.     NSRect mainFrame = [o_parent_view frame];
  1000.     NSString *o_labelString, *o_textfieldTooltip;
  1001.     mainFrame.size.height = 22;
  1002.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
  1003.     mainFrame.origin.x = LEFTMARGIN;
  1004.     mainFrame.origin.y = 0;
  1005.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1006.     {
  1007.         int i_index;
  1008.         i_view_type = CONFIG_ITEM_STRING_LIST;
  1009.         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
  1010.                               [[VLCMain sharedInstance]
  1011.                                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1012.         /* add the label */
  1013.         if( p_item->psz_text )
  1014.             o_labelString = [[VLCMain sharedInstance]
  1015.                                 localizedString: (char *)p_item->psz_text];
  1016.         else
  1017.             o_labelString = [NSString stringWithString:@""];
  1018.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
  1019.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1020.         [self addSubview: o_label];
  1021.         /* build the textfield */
  1022.         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
  1023.             -2, 0, o_textfieldTooltip )
  1024.         [o_combo setAutoresizingMask:NSViewWidthSizable ];
  1025.         for( i_index = 0; i_index < p_item->i_list; i_index++ )
  1026.             if( p_item->value.psz &&
  1027.                 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
  1028.                 [o_combo selectItemAtIndex: i_index];
  1029.         [self addSubview: o_combo];
  1030.     }
  1031.     return self;
  1032. }
  1033. - (void) alignWithXPosition:(int)i_xPos
  1034. {
  1035.     NSRect frame;
  1036.     NSRect superFrame = [self frame];
  1037.     frame = [o_label frame];
  1038.     frame.origin.x = i_xPos - frame.size.width - 3;
  1039.     [o_label setFrame:frame];
  1040.     frame = [o_combo frame];
  1041.     frame.origin.x = i_xPos + 2;
  1042.     frame.size.width = superFrame.size.width - frame.origin.x + 2;
  1043.     [o_combo setFrame:frame];
  1044. }
  1045. - (void)dealloc
  1046. {
  1047.     [o_combo release];
  1048.     [super dealloc];
  1049. }
  1050. - (char *)stringValue
  1051. {
  1052.     if( [o_combo indexOfSelectedItem] >= 0 )
  1053.         return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
  1054.     else
  1055.         return strdup( [[VLCMain sharedInstance]
  1056.                             delocalizeString: [o_combo stringValue]] );
  1057. }
  1058. - (void)resetValues
  1059. {
  1060.     int i_index;
  1061.     [o_combo reloadData];
  1062.     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
  1063.     for( i_index = 0; i_index < p_item->i_list; i_index++ )
  1064.         if( psz_value &&
  1065.             !strcmp( psz_value, p_item->ppsz_list[i_index] ) )
  1066.             [o_combo selectItemAtIndex: i_index];
  1067.     free( psz_value );
  1068.     [super resetValues];
  1069. }
  1070. @end
  1071. @implementation StringListConfigControl (NSComboBoxDataSource)
  1072. - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
  1073. {
  1074.         return p_item->i_list;
  1075. }
  1076. - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
  1077. {
  1078.     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
  1079.     {
  1080.         return [[VLCMain sharedInstance]
  1081.                     localizedString: (char *)p_item->ppsz_list_text[i_index]];
  1082.     } else return [[VLCMain sharedInstance]
  1083.                     localizedString: (char *)p_item->ppsz_list[i_index]];
  1084. }
  1085. @end
  1086. @implementation FileConfigControl
  1087. - (id) initWithItem: (module_config_t *)_p_item
  1088.            withView: (NSView *)o_parent_view
  1089. {
  1090.     NSRect mainFrame = [o_parent_view frame];
  1091.     NSString *o_labelString, *o_itemTooltip, *o_textfieldString;
  1092.     mainFrame.size.height = 46;
  1093.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
  1094.     mainFrame.origin.x = LEFTMARGIN;
  1095.     mainFrame.origin.y = 0;
  1096.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1097.     {
  1098.         i_view_type = CONFIG_ITEM_FILE;
  1099.         o_itemTooltip = [[VLCMain sharedInstance]
  1100.                            wrapString: [[VLCMain sharedInstance]
  1101.                                         localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1102.         /* is it a directory */
  1103.         b_directory = ( [self type] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
  1104.         /* add the label */
  1105.         if( p_item->psz_text )
  1106.             o_labelString = [[VLCMain sharedInstance]
  1107.                                 localizedString: (char *)p_item->psz_text];
  1108.         else
  1109.             o_labelString = [NSString stringWithString:@""];
  1110.         ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString, o_itemTooltip )
  1111.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1112.         [self addSubview: o_label];
  1113.         /* build the button */
  1114.         ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_itemTooltip,
  1115.                             _NS("Browse...") )
  1116.         [o_button setAutoresizingMask:NSViewMinXMargin ];
  1117.         [self addSubview: o_button];
  1118.         /* build the textfield */
  1119.         if( p_item->value.psz )
  1120.             o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
  1121.         else
  1122.             o_textfieldString = [NSString stringWithString: @""];
  1123.         ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
  1124.                         8 - [o_button frame].size.width,
  1125.                         o_itemTooltip, o_textfieldString )
  1126.         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
  1127.         [self addSubview: o_textfield];
  1128.     }
  1129.     return self;
  1130. }
  1131. - (void) alignWithXPosition:(int)i_xPos
  1132. {
  1133.     ;
  1134. }
  1135. - (void)dealloc
  1136. {
  1137.     [o_textfield release];
  1138.     [o_button release];
  1139.     [super dealloc];
  1140. }
  1141. - (IBAction)openFileDialog: (id)sender
  1142. {
  1143.     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
  1144.     [o_open_panel setTitle: (b_directory)?
  1145.         _NS("Select a directory"):_NS("Select a file")];
  1146.     [o_open_panel setPrompt: _NS("Select")];
  1147.     [o_open_panel setAllowsMultipleSelection: NO];
  1148.     [o_open_panel setCanChooseFiles: !b_directory];
  1149.     [o_open_panel setCanChooseDirectories: b_directory];
  1150.     [o_open_panel beginSheetForDirectory:nil
  1151.         file:nil
  1152.         types:nil
  1153.         modalForWindow:[sender window]
  1154.         modalDelegate: self
  1155.         didEndSelector: @selector(pathChosenInPanel:
  1156.                         withReturn:
  1157.                         contextInfo:)
  1158.         contextInfo: nil];
  1159. }
  1160. - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
  1161.     withReturn:(int)i_return_code contextInfo:(void  *)o_context_info
  1162. {
  1163.     if( i_return_code == NSOKButton )
  1164.     {
  1165.         NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
  1166.         [o_textfield setStringValue: o_path];
  1167.     }
  1168. }
  1169. - (char *)stringValue
  1170. {
  1171.     if( [[o_textfield stringValue] length] != 0)
  1172.         return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
  1173.     else
  1174.         return NULL;
  1175. }
  1176. -(void)resetValues
  1177. {
  1178.     NSString *o_textfieldString;
  1179.     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
  1180.     if( psz_value )
  1181.         o_textfieldString = [NSString stringWithFormat: @"%s", psz_value];
  1182.     else
  1183.         o_textfieldString = [NSString stringWithString: @""];
  1184.     free(psz_value);
  1185.     [super resetValues];
  1186. }
  1187. @end
  1188. @implementation ModuleConfigControl
  1189. - (id) initWithItem: (module_config_t *)_p_item
  1190.            withView: (NSView *)o_parent_view
  1191. {
  1192.     NSRect mainFrame = [o_parent_view frame];
  1193.     NSString *o_labelString, *o_popupTooltip;
  1194.     mainFrame.size.height = 22;
  1195.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
  1196.     mainFrame.origin.x = LEFTMARGIN;
  1197.     mainFrame.origin.y = 0;
  1198.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1199.     {
  1200.         i_view_type = CONFIG_ITEM_MODULE;
  1201.         o_popupTooltip = [[VLCMain sharedInstance] wrapString:
  1202.                           [[VLCMain sharedInstance]
  1203.                            localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1204.         /* add the label */
  1205.         if( p_item->psz_text )
  1206.             o_labelString = [[VLCMain sharedInstance]
  1207.                                 localizedString: (char *)p_item->psz_text];
  1208.         else
  1209.             o_labelString = [NSString stringWithString:@""];
  1210.         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_popupTooltip )
  1211.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1212.         [self addSubview: o_label];
  1213.         /* build the popup */
  1214.         ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
  1215.             -2, 0, o_popupTooltip )
  1216.         [o_popup setAutoresizingMask:NSViewWidthSizable ];
  1217.         [o_popup addItemWithTitle: _NS("Default")];
  1218.         [[o_popup lastItem] setTag: -1];
  1219.         [o_popup selectItem: [o_popup lastItem]];
  1220.         [self resetValues];
  1221.         [self addSubview: o_popup];
  1222.     }
  1223.     return self;
  1224. }
  1225. - (void) alignWithXPosition:(int)i_xPos
  1226. {
  1227.     NSRect frame;
  1228.     NSRect superFrame = [self frame];
  1229.     frame = [o_label frame];
  1230.     frame.origin.x = i_xPos - frame.size.width - 3;
  1231.     [o_label setFrame:frame];
  1232.     frame = [o_popup frame];
  1233.     frame.origin.x = i_xPos - 1;
  1234.     frame.size.width = superFrame.size.width - frame.origin.x + 2;
  1235.     [o_popup setFrame:frame];
  1236. }
  1237. - (void)dealloc
  1238. {
  1239.     [o_popup release];
  1240.     [super dealloc];
  1241. }
  1242. - (char *)stringValue
  1243. {
  1244.     NSString *newval = [o_popup titleOfSelectedItem];
  1245.     char *returnval = NULL;
  1246.     size_t i_module_index;
  1247.     module_t *p_parser, **p_list;
  1248.     p_list = module_list_get( NULL );
  1249.     for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
  1250.     {
  1251.         p_parser = p_list[i_module_index];
  1252.         if( p_item->i_type == CONFIG_ITEM_MODULE )
  1253.         {
  1254.             if( module_provides( p_parser, p_item->psz_type ) )
  1255.             {
  1256.                 NSString *o_description = [[VLCMain sharedInstance]
  1257.                     localizedString: module_GetLongName( p_parser )];
  1258.                 if( [newval isEqualToString: o_description] )
  1259.                 {
  1260.                     returnval = strdup( module_get_object( p_parser ));
  1261.                     break;
  1262.                 }
  1263.             }
  1264.         }
  1265.         else
  1266.         {
  1267.             int i;
  1268.             if( module_is_main( p_parser) )
  1269.                 continue;
  1270.             unsigned int confsize, unused;
  1271.             module_config_get( p_parser, &confsize );
  1272.             for ( i = 0; i < confsize; i++ )
  1273.             {
  1274.                 module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
  1275.                 /* Hack: required subcategory is stored in i_min */
  1276.                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
  1277.                     p_config->value.i == p_item->min.i )
  1278.                 {
  1279.                     NSString *o_description = [[VLCMain sharedInstance]
  1280.                         localizedString: module_GetLongName( p_parser )];
  1281.                     if( [newval isEqualToString: o_description] )
  1282.                     {
  1283.                         returnval = strdup(module_get_object( p_parser ));
  1284.                         break;
  1285.                     }
  1286.                 }
  1287.             }
  1288.         }
  1289.     }
  1290.     module_list_free( p_list );
  1291.     return returnval;
  1292. }
  1293. -(void)resetValues
  1294. {
  1295.     /* build a list of available modules */
  1296.     size_t i_index;
  1297.     module_t *p_parser, **p_list;
  1298.     p_list = module_list_get( NULL );
  1299.     for( i_index = 0; p_list[i_index]; i_index++ )
  1300.     {
  1301.         p_parser = p_list[i_index];
  1302.         if( p_item->i_type == CONFIG_ITEM_MODULE )
  1303.         {
  1304.             if( module_provides( p_parser, p_item->psz_type ) )
  1305.             {
  1306.                 NSString *o_description = [[VLCMain sharedInstance]
  1307.                     localizedString: module_GetLongName( p_parser )];
  1308.                 [o_popup addItemWithTitle: o_description];
  1309.                 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
  1310.                 if( psz_value &&
  1311.                     !strcmp( psz_value, module_get_object( p_parser ) ) )
  1312.                     [o_popup selectItem:[o_popup lastItem]];
  1313.                 free(psz_value);
  1314.             }
  1315.         }
  1316.         else
  1317.         {
  1318.             int i;
  1319.             if( module_is_main( p_parser ) )
  1320.                 continue;
  1321.             unsigned int confsize;
  1322.             unsigned int unused;
  1323.             module_config_t *p_configlist = module_config_get( p_parser, &confsize );
  1324.             for ( i = 0; i < confsize; i++ )
  1325.             {
  1326.                 module_config_t *p_config = &p_configlist[i];
  1327.                 /* Hack: required subcategory is stored in i_min */
  1328.                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
  1329.                     config_GetInt( VLCIntf, p_item->psz_name) == p_item->min.i )
  1330.                 {
  1331.                     NSString *o_description = [[VLCMain sharedInstance]
  1332.                         localizedString: module_GetLongName( p_parser )];
  1333.                     [o_popup addItemWithTitle: o_description];
  1334.                     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
  1335.                     if( psz_value && !strcmp(psz_value,
  1336.                                             module_get_object( p_parser )) )
  1337.                         [o_popup selectItem:[o_popup lastItem]];
  1338.                     free( psz_value );
  1339.                 }
  1340.             }
  1341.             module_config_free( p_configlist );
  1342.         }
  1343.     }
  1344.     module_list_free( p_list );
  1345.     [super resetValues];
  1346. }
  1347. @end
  1348. @implementation IntegerConfigControl
  1349. - (id) initWithItem: (module_config_t *)_p_item
  1350.            withView: (NSView *)o_parent_view
  1351. {
  1352.     NSRect mainFrame = [o_parent_view frame];
  1353.     NSString *o_labelString, *o_tooltip;
  1354.     mainFrame.size.height = 23;
  1355.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
  1356.     mainFrame.origin.x = LEFTMARGIN;
  1357.     mainFrame.origin.y = 0;
  1358.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1359.     {
  1360.         i_view_type = CONFIG_ITEM_INTEGER;
  1361.         o_tooltip = [[VLCMain sharedInstance] wrapString:
  1362.             [[VLCMain sharedInstance]
  1363.                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1364.         /* add the label */
  1365.         if( p_item->psz_text )
  1366.             o_labelString = [[VLCMain sharedInstance]
  1367.                                 localizedString: (char *)p_item->psz_text];
  1368.         else
  1369.             o_labelString = [NSString stringWithString:@""];
  1370.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
  1371.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1372.         [self addSubview: o_label];
  1373.         /* build the stepper */
  1374.         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
  1375.             0, o_tooltip, -100000, 100000)
  1376.         [o_stepper setIntValue: p_item->value.i];
  1377.         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
  1378.         [self addSubview: o_stepper];
  1379.         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
  1380.             1, 49, o_tooltip, @"" )
  1381.         [o_textfield setIntValue: p_item->value.i];
  1382.         [o_textfield setDelegate: self];
  1383.         [[NSNotificationCenter defaultCenter] addObserver: self
  1384.             selector: @selector(textfieldChanged:)
  1385.             name: NSControlTextDidChangeNotification
  1386.             object: o_textfield];
  1387.         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
  1388.         [self addSubview: o_textfield];
  1389.     }
  1390.     return self;
  1391. }
  1392. - (void) alignWithXPosition:(int)i_xPos
  1393. {
  1394.     NSRect frame;
  1395.     frame = [o_label frame];
  1396.     frame.origin.x = i_xPos - frame.size.width - 3;
  1397.     [o_label setFrame:frame];
  1398.     frame = [o_textfield frame];
  1399.     frame.origin.x = i_xPos + 2;
  1400.     [o_textfield setFrame:frame];
  1401.     frame = [o_stepper frame];
  1402.     frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
  1403.     [o_stepper setFrame:frame];
  1404. }
  1405. - (void)dealloc
  1406. {
  1407.     [o_stepper release];
  1408.     [o_textfield release];
  1409.     [super dealloc];
  1410. }
  1411. - (IBAction)stepperChanged:(id)sender
  1412. {
  1413.     [o_textfield setIntValue: [o_stepper intValue]];
  1414. }
  1415. - (void)textfieldChanged:(NSNotification *)o_notification
  1416. {
  1417.     [o_stepper setIntValue: [o_textfield intValue]];
  1418. }
  1419. - (int)intValue
  1420. {
  1421.     return [o_textfield intValue];
  1422. }
  1423. -(void)resetValues
  1424. {
  1425.     [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)];
  1426.     [super resetValues];
  1427. }
  1428. @end
  1429. @implementation IntegerListConfigControl
  1430. - (id) initWithItem: (module_config_t *)_p_item
  1431.            withView: (NSView *)o_parent_view
  1432. {
  1433.     NSRect mainFrame = [o_parent_view frame];
  1434.     NSString *o_labelString, *o_textfieldTooltip;
  1435.     mainFrame.size.height = 22;
  1436.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
  1437.     mainFrame.origin.x = LEFTMARGIN;
  1438.     mainFrame.origin.y = 0;
  1439.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1440.     {
  1441.         int i_index;
  1442.         i_view_type = CONFIG_ITEM_STRING_LIST;
  1443.         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
  1444.                               [[VLCMain sharedInstance]
  1445.                                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];        
  1446.         /* add the label */
  1447.         if( p_item->psz_text )
  1448.             o_labelString = [[VLCMain sharedInstance]
  1449.                 localizedString: (char *)p_item->psz_text];
  1450.         else
  1451.             o_labelString = [NSString stringWithString:@""];
  1452.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
  1453.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1454.         [self addSubview: o_label];
  1455.         /* build the textfield */
  1456.         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
  1457.             -2, 0, o_textfieldTooltip )
  1458.         [o_combo setAutoresizingMask:NSViewWidthSizable ];
  1459.         for( i_index = 0; i_index < p_item->i_list; i_index++ )
  1460.         {
  1461.             if( p_item->value.i == p_item->pi_list[i_index] )
  1462.             {
  1463.                 [o_combo selectItemAtIndex: i_index];
  1464.             }
  1465.         }
  1466.         [self addSubview: o_combo];
  1467.     }
  1468.     return self;
  1469. }
  1470. - (void) alignWithXPosition:(int)i_xPos
  1471. {
  1472.     NSRect frame;
  1473.     NSRect superFrame = [self frame];
  1474.     frame = [o_label frame];
  1475.     frame.origin.x = i_xPos - frame.size.width - 3;
  1476.     [o_label setFrame:frame];
  1477.     frame = [o_combo frame];
  1478.     frame.origin.x = i_xPos + 2;
  1479.     frame.size.width = superFrame.size.width - frame.origin.x + 2;
  1480.     [o_combo setFrame:frame];
  1481. }
  1482. - (void)dealloc
  1483. {
  1484.     [o_combo release];
  1485.     [super dealloc];
  1486. }
  1487. - (int)intValue
  1488. {
  1489.     if( [o_combo indexOfSelectedItem] >= 0 )
  1490.         return p_item->pi_list[[o_combo indexOfSelectedItem]];
  1491.     else
  1492.         return [o_combo intValue];
  1493. }
  1494. -(void)resetValues
  1495. {
  1496.     int i_index;
  1497.     [o_combo reloadData];
  1498.     for( i_index = 0; i_index < p_item->i_list; i_index++ )
  1499.     {
  1500.         if( config_GetInt( VLCIntf, p_item->psz_name) == p_item->pi_list[i_index] )
  1501.         {
  1502.             [o_combo selectItemAtIndex: i_index];
  1503.         }
  1504.     }
  1505. }
  1506. @end
  1507. @implementation IntegerListConfigControl (NSComboBoxDataSource)
  1508. - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
  1509. {
  1510.     return p_item->i_list;
  1511. }
  1512. - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
  1513. {
  1514.     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
  1515.         return [[VLCMain sharedInstance]
  1516.                     localizedString: (char *)p_item->ppsz_list_text[i_index]];
  1517.     else
  1518.         return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
  1519. }
  1520. @end
  1521. @implementation RangedIntegerConfigControl
  1522. - (id) initWithItem: (module_config_t *)_p_item
  1523.            withView: (NSView *)o_parent_view
  1524. {
  1525.     NSRect mainFrame = [o_parent_view frame];
  1526.     NSString *o_labelString, *o_tooltip;
  1527.     mainFrame.size.height = 50;
  1528.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
  1529.     mainFrame.origin.x = LEFTMARGIN;
  1530.     mainFrame.origin.y = 0;
  1531.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1532.     {
  1533.         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
  1534.         o_tooltip = [[VLCMain sharedInstance] wrapString:
  1535.                      [[VLCMain sharedInstance]
  1536.                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1537.         /* add the label */
  1538.         if( p_item->psz_text )
  1539.             o_labelString = [[VLCMain sharedInstance]
  1540.                                 localizedString: (char *)p_item->psz_text];
  1541.         else
  1542.             o_labelString = [NSString stringWithString:@""];
  1543.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
  1544.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1545.         [self addSubview: o_label];
  1546.         /* build the textfield */
  1547.         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
  1548.             28, 49, o_tooltip, @"" )
  1549.         [o_textfield setIntValue: p_item->value.i];
  1550.         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
  1551.         [o_textfield setDelegate: self];
  1552.         [[NSNotificationCenter defaultCenter] addObserver: self
  1553.             selector: @selector(textfieldChanged:)
  1554.             name: NSControlTextDidChangeNotification
  1555.             object: o_textfield];
  1556.         [self addSubview: o_textfield];
  1557.         /* build the mintextfield */
  1558.         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
  1559.         [o_textfield_min setIntValue: p_item->min.i];
  1560.         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
  1561.         [o_textfield_min setAlignment:NSRightTextAlignment];
  1562.         [self addSubview: o_textfield_min];
  1563.         /* build the maxtextfield */
  1564.         ADD_LABEL( o_textfield_max, mainFrame,
  1565.                     mainFrame.size.width - 31, -30, @"8888", @"" )
  1566.         [o_textfield_max setIntValue: p_item->max.i];
  1567.         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
  1568.         [self addSubview: o_textfield_max];
  1569.         /* build the slider */
  1570.         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
  1571.             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
  1572.             [o_textfield_max frame].size.width -
  1573.             [o_textfield_max frame].size.width - 14 -
  1574.             [o_textfield_min frame].origin.x, o_tooltip,
  1575.             p_item->min.i, p_item->max.i )
  1576.         [o_slider setIntValue: p_item->value.i];
  1577.         [o_slider setAutoresizingMask:NSViewWidthSizable ];
  1578.         [o_slider setTarget: self];
  1579.         [o_slider setAction: @selector(sliderChanged:)];
  1580.         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
  1581.             NSLeftMouseDraggedMask];
  1582.         [self addSubview: o_slider];
  1583.     }
  1584.     return self;
  1585. }
  1586. - (void) alignWithXPosition:(int)i_xPos
  1587. {
  1588.     NSRect frame;
  1589.     frame = [o_label frame];
  1590.     frame.origin.x = i_xPos - frame.size.width - 3;
  1591.     [o_label setFrame:frame];
  1592.     frame = [o_textfield frame];
  1593.     frame.origin.x = i_xPos + 2;
  1594.     [o_textfield setFrame:frame];
  1595. }
  1596. - (void)dealloc
  1597. {
  1598.     [o_textfield release];
  1599.     [o_textfield_min release];
  1600.     [o_textfield_max release];
  1601.     [o_slider release];
  1602.     [super dealloc];
  1603. }
  1604. - (IBAction)sliderChanged:(id)sender
  1605. {
  1606.     [o_textfield setIntValue: [o_slider intValue]];
  1607. }
  1608. - (void)textfieldChanged:(NSNotification *)o_notification
  1609. {
  1610.     [o_slider setIntValue: [o_textfield intValue]];
  1611. }
  1612. - (int)intValue
  1613. {
  1614.     return [o_slider intValue];
  1615. }
  1616. - (void)resetValues
  1617. {
  1618.     int value = config_GetInt( VLCIntf, p_item->psz_name );
  1619.     [o_textfield setIntValue:value];
  1620.     [o_slider setIntValue:value];
  1621.     [super resetValues];
  1622. }
  1623. @end
  1624. @implementation FloatConfigControl
  1625. - (id) initWithItem: (module_config_t *)_p_item
  1626.            withView: (NSView *)o_parent_view
  1627. {
  1628.     NSRect mainFrame = [o_parent_view frame];
  1629.     NSString *o_labelString, *o_tooltip;
  1630.     mainFrame.size.height = 23;
  1631.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
  1632.     mainFrame.origin.x = LEFTMARGIN;
  1633.     mainFrame.origin.y = 0;
  1634.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1635.     {
  1636.         i_view_type = CONFIG_ITEM_INTEGER;
  1637.         o_tooltip = [[VLCMain sharedInstance] wrapString:
  1638.             [[VLCMain sharedInstance]
  1639.                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1640.         /* add the label */
  1641.         if( p_item->psz_text )
  1642.             o_labelString = [[VLCMain sharedInstance]
  1643.                                 localizedString: (char *)p_item->psz_text];
  1644.         else
  1645.             o_labelString = [NSString stringWithString:@""];
  1646.         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString, o_tooltip )
  1647.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1648.         [self addSubview: o_label];
  1649.         /* build the stepper */
  1650.         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
  1651.             0, o_tooltip, -100000, 100000)
  1652.         [o_stepper setFloatValue: p_item->value.f];
  1653.         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
  1654.         [self addSubview: o_stepper];
  1655.         /* build the textfield */
  1656.         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
  1657.             1, 49, o_tooltip, @"" )
  1658.         [o_textfield setFloatValue: p_item->value.f];
  1659.         [o_textfield setDelegate: self];
  1660.         [[NSNotificationCenter defaultCenter] addObserver: self
  1661.             selector: @selector(textfieldChanged:)
  1662.             name: NSControlTextDidChangeNotification
  1663.             object: o_textfield];
  1664.         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
  1665.         [self addSubview: o_textfield];
  1666.     }
  1667.     return self;
  1668. }
  1669. - (void) alignWithXPosition:(int)i_xPos
  1670. {
  1671.     NSRect frame;
  1672.     frame = [o_label frame];
  1673.     frame.origin.x = i_xPos - frame.size.width - 3;
  1674.     [o_label setFrame:frame];
  1675.     frame = [o_textfield frame];
  1676.     frame.origin.x = i_xPos + 2;
  1677.     [o_textfield setFrame:frame];
  1678.     frame = [o_stepper frame];
  1679.     frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
  1680.     [o_stepper setFrame:frame];
  1681. }
  1682. - (void)dealloc
  1683. {
  1684.     [o_stepper release];
  1685.     [o_textfield release];
  1686.     [super dealloc];
  1687. }
  1688. - (IBAction)stepperChanged:(id)sender
  1689. {
  1690.     [o_textfield setFloatValue: [o_stepper floatValue]];
  1691. }
  1692. - (void)textfieldChanged:(NSNotification *)o_notification
  1693. {
  1694.     [o_stepper setFloatValue: [o_textfield floatValue]];
  1695. }
  1696. - (float)floatValue
  1697. {
  1698.     return [o_stepper floatValue];
  1699. }
  1700. - (void)resetValues
  1701. {
  1702.     [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)];
  1703.     [super resetValues];
  1704. }
  1705. @end
  1706. @implementation RangedFloatConfigControl
  1707. - (id) initWithItem: (module_config_t *)_p_item
  1708.            withView: (NSView *)o_parent_view
  1709. {
  1710.     NSRect mainFrame = [o_parent_view frame];
  1711.     NSString *o_labelString, *o_tooltip;
  1712.     mainFrame.size.height = 50;
  1713.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
  1714.     mainFrame.origin.x = LEFTMARGIN;
  1715.     mainFrame.origin.y = 0;
  1716.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1717.     {
  1718.         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
  1719.         o_tooltip = [[VLCMain sharedInstance] wrapString:
  1720.                      [[VLCMain sharedInstance]
  1721.                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];        
  1722.         /* add the label */
  1723.         if( p_item->psz_text )
  1724.             o_labelString = [[VLCMain sharedInstance]
  1725.                                 localizedString: (char *)p_item->psz_text];
  1726.         else
  1727.             o_labelString = [NSString stringWithString:@""];
  1728.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
  1729.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1730.         [self addSubview: o_label];
  1731.         /* build the textfield */
  1732.         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
  1733.             28, 49, o_tooltip, @"" )
  1734.         [o_textfield setFloatValue: p_item->value.f];
  1735.         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
  1736.         [o_textfield setDelegate: self];
  1737.         [[NSNotificationCenter defaultCenter] addObserver: self
  1738.             selector: @selector(textfieldChanged:)
  1739.             name: NSControlTextDidChangeNotification
  1740.             object: o_textfield];
  1741.         [self addSubview: o_textfield];
  1742.         /* build the mintextfield */
  1743.         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
  1744.         [o_textfield_min setFloatValue: p_item->min.f];
  1745.         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
  1746.         [o_textfield_min setAlignment:NSRightTextAlignment];
  1747.         [self addSubview: o_textfield_min];
  1748.         /* build the maxtextfield */
  1749.         ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
  1750.             -30, @"8888", @"" )
  1751.         [o_textfield_max setFloatValue: p_item->max.f];
  1752.         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
  1753.         [self addSubview: o_textfield_max];
  1754.         /* build the slider */
  1755.         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
  1756.             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
  1757.             [o_textfield_max frame].size.width -
  1758.             [o_textfield_max frame].size.width - 14 -
  1759.             [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
  1760.             p_item->max.f )
  1761.         [o_slider setFloatValue: p_item->value.f];
  1762.         [o_slider setAutoresizingMask:NSViewWidthSizable ];
  1763.         [o_slider setTarget: self];
  1764.         [o_slider setAction: @selector(sliderChanged:)];
  1765.         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
  1766.             NSLeftMouseDraggedMask];
  1767.         [self addSubview: o_slider];
  1768.     }
  1769.     return self;
  1770. }
  1771. - (void) alignWithXPosition:(int)i_xPos
  1772. {
  1773.     NSRect frame;
  1774.     frame = [o_label frame];
  1775.     frame.origin.x = i_xPos - frame.size.width - 3;
  1776.     [o_label setFrame:frame];
  1777.     frame = [o_textfield frame];
  1778.     frame.origin.x = i_xPos + 2;
  1779.     [o_textfield setFrame:frame];
  1780. }
  1781. - (void)dealloc
  1782. {
  1783.     [o_textfield release];
  1784.     [o_textfield_min release];
  1785.     [o_textfield_max release];
  1786.     [o_slider release];
  1787.     [super dealloc];
  1788. }
  1789. - (IBAction)sliderChanged:(id)sender
  1790. {
  1791.     [o_textfield setFloatValue: [o_slider floatValue]];
  1792. }
  1793. - (void)textfieldChanged:(NSNotification *)o_notification
  1794. {
  1795.     [o_slider setFloatValue: [o_textfield floatValue]];
  1796. }
  1797. - (float)floatValue
  1798. {
  1799.     return [o_slider floatValue];
  1800. }
  1801. - (void)resetValues
  1802. {
  1803.     [o_textfield setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
  1804.     [o_slider setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
  1805.     [super resetValues];
  1806. }
  1807. @end
  1808. @implementation BoolConfigControl
  1809. - (id) initWithItem: (module_config_t *)_p_item
  1810.            withView: (NSView *)o_parent_view
  1811. {
  1812.     NSRect mainFrame = [o_parent_view frame];
  1813.     NSString *o_labelString, *o_tooltip;
  1814.     mainFrame.size.height = 17;
  1815.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
  1816.     mainFrame.origin.x = LEFTMARGIN;
  1817.     mainFrame.origin.y = 0;
  1818.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1819.     {
  1820.         i_view_type = CONFIG_ITEM_BOOL;
  1821.         /* add the checkbox */
  1822.         o_tooltip = [[VLCMain sharedInstance]
  1823.             wrapString: [[VLCMain sharedInstance]
  1824.             localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1825.         ADD_CHECKBOX( o_checkbox, mainFrame, 0,
  1826.                         0, @"", o_tooltip, p_item->value.i, NSImageLeft)
  1827.         [o_checkbox setAutoresizingMask:NSViewNotSizable ];
  1828.         [self addSubview: o_checkbox];
  1829.         /* add the label */
  1830.         if( p_item->psz_text )
  1831.             o_labelString = [[VLCMain sharedInstance]
  1832.                                 localizedString: (char *)p_item->psz_text];
  1833.         else
  1834.             o_labelString = [NSString stringWithString:@""];
  1835.         ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString, o_tooltip )
  1836.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1837.         [self addSubview: o_label];
  1838.     }
  1839.     return self;
  1840. }
  1841. - (void)dealloc
  1842. {
  1843.     [o_checkbox release];
  1844.     [super dealloc];
  1845. }
  1846. - (int)intValue
  1847. {
  1848.     return [o_checkbox intValue];
  1849. }
  1850. - (void)resetValues
  1851. {
  1852.     [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)];
  1853.     [super resetValues];
  1854. }
  1855. @end
  1856. @implementation KeyConfigControl
  1857. - (id) initWithItem: (module_config_t *)_p_item
  1858.            withView: (NSView *)o_parent_view
  1859. {
  1860.     NSRect mainFrame = [o_parent_view frame];
  1861.     NSString *o_labelString, *o_tooltip;
  1862.     mainFrame.size.height = 22;
  1863.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
  1864.     mainFrame.origin.x = LEFTMARGIN;
  1865.     mainFrame.origin.y = 0;
  1866.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1867.     {
  1868.         i_view_type = CONFIG_ITEM_KEY_AFTER_10_3;
  1869.         o_tooltip = [[VLCMain sharedInstance] wrapString:
  1870.                      [[VLCMain sharedInstance]
  1871.                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1872.         /* add the label */
  1873.         if( p_item->psz_text )
  1874.             o_labelString = [[VLCMain sharedInstance]
  1875.                 localizedString: (char *)p_item->psz_text];
  1876.         else
  1877.             o_labelString = [NSString stringWithString:@""];
  1878.         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_tooltip )
  1879.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1880.         [self addSubview: o_label];
  1881.         /* build the popup */
  1882.         ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
  1883.             [o_label frame].size.width + 3,
  1884.             -2, 0, o_tooltip )
  1885.         [o_popup setAutoresizingMask:NSViewWidthSizable ];
  1886.         if( o_keys_menu == nil )
  1887.         {
  1888.             unsigned int i;
  1889.             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
  1890.             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
  1891.                 if( vlc_keys[i].psz_key_string )
  1892.                     POPULATE_A_KEY( o_keys_menu,
  1893.                         [NSString stringWithUTF8String:vlc_keys[i].psz_key_string]
  1894.                         , vlc_keys[i].i_key_code)
  1895.         }
  1896.         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
  1897.         [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
  1898.         [self addSubview: o_popup];
  1899.     }
  1900.     return self;
  1901. }
  1902. - (void) alignWithXPosition:(int)i_xPos
  1903. {
  1904.     NSRect frame;
  1905.     NSRect superFrame = [self frame];
  1906.     frame = [o_label frame];
  1907.     frame.origin.x = i_xPos - frame.size.width - 3;
  1908.     [o_label setFrame:frame];
  1909.     frame = [o_popup frame];
  1910.     frame.origin.x = i_xPos - 1;
  1911.     frame.size.width = superFrame.size.width - frame.origin.x + 2;
  1912.     [o_popup setFrame:frame];
  1913. }
  1914. - (void)dealloc
  1915. {
  1916.     [o_popup release];
  1917.     [super dealloc];
  1918. }
  1919. - (int)intValue
  1920. {
  1921.     return [o_popup selectedTag];
  1922. }
  1923. - (void)resetValues
  1924. {
  1925.     [o_popup selectItem:[[o_popup menu] itemWithTag:config_GetInt( VLCIntf, p_item->psz_name )]];
  1926.     [super resetValues];
  1927. }
  1928. @end
  1929. @implementation ModuleListConfigControl
  1930. - (id) initWithItem: (module_config_t *)_p_item
  1931.            withView: (NSView *)o_parent_view
  1932. {
  1933.     if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
  1934. //TODO....
  1935.         return nil;
  1936. //Fill our array to know how may items we have...
  1937.     module_t *p_parser, **p_list;
  1938.     size_t i_module_index;
  1939.     NSRect mainFrame = [o_parent_view frame];
  1940.     NSString *o_labelString, *o_textfieldString, *o_tooltip;
  1941.     o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
  1942.     /* build a list of available modules */
  1943.     p_list = module_list_get( NULL );
  1944.     for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
  1945.     {
  1946.         int i;
  1947.         p_parser = p_list[i_module_index];
  1948.         if( module_is_main( p_parser ) )
  1949.             continue;
  1950.         unsigned int confsize;
  1951.         module_config_t *p_configlist = module_config_get( p_parser, &confsize );
  1952.         for ( i = 0; i < confsize; i++ )
  1953.         {
  1954.             unsigned int unused;
  1955.             module_config_t *p_config = &p_configlist[i];
  1956.             NSString *o_modulelongname, *o_modulename;
  1957.             NSNumber *o_moduleenabled = nil;
  1958.             /* Hack: required subcategory is stored in i_min */
  1959.             if( p_config->i_type == CONFIG_SUBCATEGORY &&
  1960.                 p_config->value.i == _p_item->min.i )
  1961.             {
  1962.                 o_modulelongname = [NSString stringWithUTF8String:
  1963.                                         module_GetLongName( p_parser )];
  1964.                 o_modulename = [NSString stringWithUTF8String:
  1965.                                         module_get_object( p_parser )];
  1966.                 if( _p_item->value.psz &&
  1967.                     strstr( _p_item->value.psz, module_get_object( p_parser ) ) )
  1968.                     o_moduleenabled = [NSNumber numberWithBool:YES];
  1969.                 else
  1970.                     o_moduleenabled = [NSNumber numberWithBool:NO];
  1971.                 [o_modulearray addObject:[NSMutableArray
  1972.                     arrayWithObjects: o_modulename, o_modulelongname,
  1973.                     o_moduleenabled, nil]];
  1974.             }
  1975.         }
  1976.         module_config_free( p_configlist );
  1977.     }
  1978.     module_list_free( p_list );
  1979.     mainFrame.size.height = 30 + 18 * [o_modulearray count];
  1980.     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
  1981.     mainFrame.origin.x = LEFTMARGIN;
  1982.     mainFrame.origin.y = 0;
  1983.     if( [super initWithFrame: mainFrame item: _p_item] != nil )
  1984.     {
  1985.         i_view_type = CONFIG_ITEM_MODULE_LIST;
  1986.         o_tooltip = [[VLCMain sharedInstance] wrapString:
  1987.                      [[VLCMain sharedInstance]
  1988.                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
  1989.         /* add the label */
  1990.         if( p_item->psz_text )
  1991.             o_labelString = [[VLCMain sharedInstance]
  1992.                                 localizedString: (char *)p_item->psz_text];
  1993.         else
  1994.             o_labelString = [NSString stringWithString:@""];
  1995.         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
  1996.         [o_label setAutoresizingMask:NSViewNotSizable ];
  1997.         [self addSubview: o_label];
  1998.         /* build the textfield */
  1999.         if( p_item->value.psz )
  2000.             o_textfieldString = [[VLCMain sharedInstance]
  2001.                 localizedString: (char *)p_item->value.psz];
  2002.         else
  2003.             o_textfieldString = [NSString stringWithString: @""];
  2004.         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
  2005.             mainFrame.size.height - 22, mainFrame.size.width -
  2006.             [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
  2007.         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
  2008.         [self addSubview: o_textfield];
  2009. {
  2010.     NSRect s_rc = mainFrame;
  2011.     s_rc.size.height = mainFrame.size.height - 30;
  2012.     s_rc.size.width = mainFrame.size.width - 12;
  2013.     s_rc.origin.x = 12;
  2014.     s_rc.origin.y = 0;
  2015.     o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
  2016.     [o_scrollview setDrawsBackground: NO];
  2017.     [o_scrollview setBorderType: NSBezelBorder];
  2018.     [o_scrollview setAutohidesScrollers:YES];
  2019.     NSTableView *o_tableview;
  2020.     o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
  2021.     [o_tableview setUsesAlternatingRowBackgroundColors:YES];
  2022.     [o_tableview setHeaderView:nil];
  2023. /* TODO: find a good way to fix the row height and text size*/
  2024. /* FIXME: support for multiple selection... */
  2025. //    [o_tableview setAllowsMultipleSelection:YES];
  2026.     NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
  2027.     NSCell *o_dataCell = [[NSButtonCell alloc] init];
  2028.     [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
  2029.     [o_dataCell setTitle:@""];
  2030.     [o_dataCell setFont:[NSFont systemFontOfSize:0]];
  2031.     NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
  2032.         initWithIdentifier:@"Enabled"];
  2033.     [o_tableColumn setHeaderCell: o_headerCell];
  2034.     [o_tableColumn setDataCell: o_dataCell];
  2035.     [o_tableColumn setWidth:17];
  2036.     [o_tableview addTableColumn: o_tableColumn];
  2037.     o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
  2038.     o_dataCell = [[NSTextFieldCell alloc] init];
  2039.     [o_dataCell setFont:[NSFont systemFontOfSize:12]];
  2040.     o_tableColumn = [[NSTableColumn alloc]
  2041.         initWithIdentifier:@"Module"];
  2042.     [o_tableColumn setHeaderCell: o_headerCell];
  2043.     [o_tableColumn setDataCell: o_dataCell];
  2044.     [o_tableColumn setWidth:388 - 17];
  2045.     [o_tableview addTableColumn: o_tableColumn];
  2046.     [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
  2047.             @"VLC media player module", nil]];
  2048.     [o_tableview setDataSource:self];
  2049.     [o_tableview setTarget: self];
  2050.     [o_tableview setAction: @selector(tableChanged:)];
  2051.     [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
  2052.         NSLeftMouseDraggedMask];
  2053.     [o_scrollview setDocumentView: o_tableview];
  2054. }
  2055.     [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
  2056.     [self addSubview: o_scrollview];
  2057.     }
  2058.     return self;
  2059. }
  2060. - (void) alignWithXPosition:(int)i_xPos
  2061. {
  2062.     ;
  2063. }
  2064. - (IBAction)tableChanged:(id)sender
  2065. {
  2066.     NSString *o_newstring = @"";
  2067.     unsigned int i;
  2068.     for( i = 0 ; i < [o_modulearray count] ; i++ )
  2069.         if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
  2070.             boolValue] != NO )
  2071.         {
  2072.             o_newstring = [o_newstring stringByAppendingString:
  2073.                 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
  2074.             o_newstring = [o_newstring stringByAppendingString:@":"];
  2075.         }
  2076.     [o_textfield setStringValue: [o_newstring
  2077.         substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
  2078. }
  2079. - (void)dealloc
  2080. {
  2081.     [o_scrollview release];
  2082.     [super dealloc];
  2083. }
  2084. - (char *)stringValue
  2085. {
  2086.     return strdup( [[o_textfield stringValue] UTF8String] );
  2087. }
  2088. -(void)resetValues
  2089. {
  2090. #warning Reset prefs of the module selector is broken atm. 
  2091.     NSLog( @"don't forget about modulelistconfig" );
  2092.     [super resetValues];
  2093. }
  2094. @end
  2095. @implementation ModuleListConfigControl (NSTableDataSource)
  2096. - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
  2097.     toPasteboard:(NSPasteboard*)pb
  2098. {
  2099.     // We only want to allow dragging of selected rows.
  2100.     NSEnumerator    *iter = [rows objectEnumerator];
  2101.     NSNumber        *row;
  2102.     while ((row = [iter nextObject]) != nil)
  2103.     {
  2104.         if (![table isRowSelected:[row intValue]])
  2105.             return NO;
  2106.     }
  2107.     [pb declareTypes:[NSArray
  2108.         arrayWithObject:@"VLC media player module"] owner:nil];
  2109.     [pb setPropertyList:rows forType:@"VLC media player module"];
  2110.     return YES;
  2111. }
  2112. - (NSDragOperation)tableView:(NSTableView*)table
  2113.     validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
  2114.     proposedDropOperation:(NSTableViewDropOperation)op
  2115. {
  2116.     // Make drops at the end of the table go to the end.
  2117.     if (row == -1)
  2118.     {
  2119.         row = [table numberOfRows];
  2120.         op = NSTableViewDropAbove;
  2121.         [table setDropRow:row dropOperation:op];
  2122.     }
  2123.     // We don't ever want to drop onto a row, only between rows.
  2124.     if (op == NSTableViewDropOn)
  2125.         [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
  2126.     return NSTableViewDropAbove;
  2127. }
  2128. - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
  2129.     row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
  2130. {
  2131.     NSPasteboard    *pb = [info draggingPasteboard];
  2132.     NSDragOperation srcMask = [info draggingSourceOperationMask];
  2133.     BOOL accepted = NO;
  2134.     NS_DURING
  2135.         NSArray *array;
  2136.         // Intra-table drag - data is the array of rows.
  2137.         if (!accepted && (array =
  2138.             [pb propertyListForType:@"VLC media player module"]) != NULL)
  2139.         {
  2140.             NSEnumerator *iter = nil;
  2141.             id val;
  2142.             BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
  2143.             // Move the modules
  2144.             iter = [array objectEnumerator];
  2145.             while ((val = [iter nextObject]) != NULL)
  2146.             {
  2147.                 NSArray *o_tmp = [[o_modulearray objectAtIndex:
  2148.                     [val intValue]] mutableCopyWithZone:nil];
  2149.                 [o_modulearray removeObject:o_tmp];
  2150.                 [o_modulearray insertObject:o_tmp
  2151.                     atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
  2152.                 dropRow++;
  2153.             }
  2154.             // Select the newly-dragged items.
  2155.             iter = [array objectEnumerator];
  2156. //TODO...
  2157.             [table deselectAll:self];
  2158.             [self tableChanged:self];
  2159.             [table setNeedsDisplay:YES];
  2160.             // Indicate that we finished the drag.
  2161.             accepted = YES;
  2162.         }
  2163.         [table reloadData];
  2164.         [table setNeedsDisplay:YES];
  2165.         NS_HANDLER
  2166.             // An exception occurred. Uh-oh. Update the track table so that
  2167.             // it stays consistent, and re-raise the exception.
  2168.             [table reloadData];
  2169.             [localException raise];
  2170.             [table setNeedsDisplay:YES];
  2171.     NS_ENDHANDLER
  2172.     return accepted;
  2173. }
  2174. - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
  2175. {
  2176.     return [o_modulearray count];
  2177. }
  2178. - (id)tableView:(NSTableView *)aTableView
  2179.     objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
  2180. {
  2181.     if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
  2182.         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
  2183.     if( [[aTableColumn identifier] isEqualToString: @"Module"] )
  2184.         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
  2185.     return nil;
  2186. }
  2187. - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
  2188.     forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
  2189. {
  2190.     [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
  2191.         withObject: anObject];
  2192. }
  2193. @end