]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/prefs_widgets.m
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / macosx / prefs_widgets.m
index bdf4a74407139e5679cc3dfdb1ef079ca70927e3..62c2ab1e5fea74ce13567b1e21885272f8a992fb 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * prefs_widgets.m: Preferences controls
  *****************************************************************************
- * Copyright (C) 2002-2003 the VideoLAN team
+ * Copyright (C) 2002-2007 the VideoLAN team
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan.org>
@@ -11,7 +11,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -38,7 +38,7 @@
 #define OFFSET_RIGHT 20
 #define OFFSET_BETWEEN 2
 
-#define UPWARDS_WHITE_ARROW                 "\xE2\x87\xA7" 
+#define UPWARDS_WHITE_ARROW                 "\xE2\x87\xA7"
 #define OPTION_KEY                          "\xE2\x8C\xA5"
 #define UP_ARROWHEAD                        "\xE2\x8C\x83"
 #define PLACE_OF_INTEREST_SIGN              "\xE2\x8C\x98"
         action:nil keyEquivalent:@""];                                      \
     [o_mi setKeyEquivalentModifierMask:                                     \
         0];                                                                 \
-if( MACOS_VERSION >= 10.3 )                                                 \
     [o_mi setAlternate: NO];                                                \
     [o_mi setTag:                                                           \
         ( value )];                                                         \
     [o_menu addItem: o_mi];                                                 \
-if( MACOS_VERSION >= 10.3 )                                                 \
-{                                                                           \
 /*  Ctrl */                                                                 \
     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
         [[NSString stringWithUTF8String:                                    \
@@ -245,7 +242,6 @@ if( MACOS_VERSION >= 10.3 )                                                 \
     [o_mi setTag:                                                           \
         KEY_MODIFIER_COMMAND | ( value )];                                  \
     [o_menu addItem: o_mi];                                                 \
-}                                                                           \
 }
 
 #define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label )      \
@@ -413,6 +409,16 @@ if( MACOS_VERSION >= 10.3 )                                                 \
     [self setFrame:frame];
 }
 
+#if GC_ENABLED
+- (void)finalize
+{
+    /* since dealloc isn't called on 10.5 if GC is enabled and since GC is
+     * Obj-C only, we need to do this: */
+    if( psz_name ) free( psz_name );
+    [super finalize];
+}
+#endif
+
 - (void)dealloc
 {
     if( o_label ) [o_label release];
@@ -890,18 +896,9 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         }
         break;
     case CONFIG_ITEM_KEY:
-        if( MACOS_VERSION < 10.3 )
-        {
-            p_control = [[KeyConfigControlBefore103 alloc]
+        p_control = [[KeyConfigControl alloc]
                         initWithItem: _p_item
                         withView: o_parent_view];
-        }
-        else
-        {
-            p_control = [[KeyConfigControlAfter103 alloc]
-                        initWithItem: _p_item
-                        withView: o_parent_view];
-        }
         break;
     case CONFIG_ITEM_MODULE_LIST:
     case CONFIG_ITEM_MODULE_LIST_CAT:
@@ -1189,8 +1186,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
             [[VLCMain sharedInstance]
                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
         if( p_item->value.psz )
-            o_textfieldString = [[VLCMain sharedInstance]
-                                    localizedString: (char *)p_item->value.psz];
+            o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
         else
             o_textfieldString = [NSString stringWithString: @""];
         ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
@@ -1229,7 +1225,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         types:nil
         modalForWindow:[sender window]
         modalDelegate: self
-        didEndSelector: @selector(pathChosenInPanel: 
+        didEndSelector: @selector(pathChosenInPanel:
                         withReturn:
                         contextInfo:)
         contextInfo: nil];
@@ -1270,7 +1266,6 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         int i_index;
         vlc_list_t *p_list;
         module_t *p_parser;
-        module_config_t *p_end;
         i_view_type = CONFIG_ITEM_MODULE;
 
         /* add the label */
@@ -1299,7 +1294,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         for( i_index = 0; i_index < p_list->i_count; i_index++ )
         {
             p_parser = (module_t *)p_list->p_values[i_index].p_object;
-            p_end = p_item + p_parser->confsize;
+
             if( p_item->i_type == CONFIG_ITEM_MODULE )
             {
                 if( !strcmp( p_parser->psz_capability,
@@ -1316,13 +1311,14 @@ if( MACOS_VERSION >= 10.3 )                                                 \
             }
             else
             {
-                module_config_t *p_config;
+                int i;
+
                 if( !strcmp( p_parser->psz_object_name, "main" ) )
-                      continue;
+                    continue;
 
-                p_config = p_parser->p_config;
-                if( p_config ) do
+                for ( i = 0; i < p_parser->confsize; i++ )
                 {
+                    module_config_t *p_config = p_parser->p_config + i;
                     /* Hack: required subcategory is stored in i_min */
                     if( p_config->i_type == CONFIG_SUBCATEGORY &&
                         p_config->value.i == p_item->min.i )
@@ -1335,7 +1331,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
                                                 p_parser->psz_object_name) )
                             [o_popup selectItem:[o_popup lastItem]];
                     }
-                } while( p_item < p_end && p_config++ );
+                }
             }
         }
         vlc_list_release( p_list );
@@ -1368,16 +1364,15 @@ if( MACOS_VERSION >= 10.3 )                                                 \
 {
     NSString *newval = [o_popup titleOfSelectedItem];
     char *returnval = NULL;
-    int i_index;
+    int i_module_index;
     vlc_list_t *p_list;
     module_t *p_parser;
-    module_config_t *p_end;
 
     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
-    for( i_index = 0; i_index < p_list->i_count; i_index++ )
+    for( i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ )
     {
-        p_parser = (module_t *)p_list->p_values[i_index].p_object;
-         p_end = p_item + p_parser->confsize;
+        p_parser = (module_t *)p_list->p_values[i_module_index].p_object;
+
         if( p_item->i_type == CONFIG_ITEM_MODULE )
         {
             if( !strcmp( p_parser->psz_capability,
@@ -1394,13 +1389,14 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         }
         else
         {
-            module_config_t *p_config;
+            int i;
+
             if( !strcmp( p_parser->psz_object_name, "main" ) )
-                  continue;
+                continue;
 
-            p_config = p_parser->p_config;
-            if( p_config ) do
+            for ( i = 0; i < p_parser->confsize; i++ )
             {
+                module_config_t *p_config = p_parser->p_config + i;
                 /* Hack: required subcategory is stored in i_min */
                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
                     p_config->value.i == p_item->min.i )
@@ -1413,7 +1409,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
                         break;
                     }
                 }
-            } while( p_item < p_end && p_config++ );
+            }
         }
     }
     vlc_list_release( p_list );
@@ -1426,7 +1422,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
            withView: (NSView *)o_parent_view
 {
     NSRect mainFrame = [o_parent_view frame];
-    NSString *o_labelString, *o_tooltip, *o_textfieldString;
+    NSString *o_labelString, *o_tooltip;
     mainFrame.size.height = 23;
     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
     mainFrame.origin.x = LEFTMARGIN;
@@ -1457,12 +1453,6 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
         [self addSubview: o_stepper];
 
-        /* build the textfield */
-        if( p_item->value.psz )
-            o_textfieldString = [[VLCMain sharedInstance]
-                                    localizedString: (char *)p_item->value.psz];
-        else
-            o_textfieldString = [NSString stringWithString: @""];
         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
             1, 49, o_tooltip, @"" )
         [o_textfield setIntValue: p_item->value.i];
@@ -1723,7 +1713,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
            withView: (NSView *)o_parent_view
 {
     NSRect mainFrame = [o_parent_view frame];
-    NSString *o_labelString, *o_tooltip, *o_textfieldString;
+    NSString *o_labelString, *o_tooltip;
     mainFrame.size.height = 23;
     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
     mainFrame.origin.x = LEFTMARGIN;
@@ -1755,11 +1745,6 @@ if( MACOS_VERSION >= 10.3 )                                                 \
         [self addSubview: o_stepper];
 
         /* build the textfield */
-        if( p_item->value.psz )
-            o_textfieldString = [[VLCMain sharedInstance]
-                                    localizedString: (char *)p_item->value.psz];
-        else
-            o_textfieldString = [NSString stringWithString: @""];
         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
             1, 49, o_tooltip, @"" )
         [o_textfield setFloatValue: p_item->value.f];
@@ -1974,155 +1959,7 @@ if( MACOS_VERSION >= 10.3 )                                                 \
 
 @end
 
-@implementation KeyConfigControlBefore103
-
-- (id) initWithItem: (module_config_t *)_p_item
-           withView: (NSView *)o_parent_view
-{
-    NSRect mainFrame = [o_parent_view frame];
-    NSString *o_labelString, *o_tooltip;
-    mainFrame.size.height = 37;
-    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
-    mainFrame.origin.x = LEFTMARGIN;
-    mainFrame.origin.y = 0;
-
-    if( [super initWithFrame: mainFrame item: _p_item] != nil )
-    {
-        i_view_type = CONFIG_ITEM_KEY_BEFORE_10_3;
-
-        /* add the label */
-        if( p_item->psz_text )
-            o_labelString = [[VLCMain sharedInstance]
-                                localizedString: (char *)p_item->psz_text];
-        else
-            o_labelString = [NSString stringWithString:@""];
-        ADD_LABEL( o_label, mainFrame, 0, -10, o_labelString )
-        [o_label setAutoresizingMask:NSViewNotSizable ];
-        [self addSubview: o_label];
-
-        /* add the checkboxes */
-        o_tooltip = [[VLCMain sharedInstance] wrapString:
-            [[VLCMain sharedInstance]
-                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
-        ADD_CHECKBOX( o_cmd_checkbox, mainFrame,
-            [o_label frame].size.width + 2, 0,
-            [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN], o_tooltip,
-            ((((unsigned int)p_item->value.i) & KEY_MODIFIER_COMMAND)?YES:NO),
-            NSImageLeft )
-        [o_cmd_checkbox setState: p_item->value.i & KEY_MODIFIER_COMMAND];
-        ADD_CHECKBOX( o_ctrl_checkbox, mainFrame,
-            [o_cmd_checkbox frame].size.width +
-            [o_cmd_checkbox frame].origin.x + 6, 0,
-            [NSString stringWithUTF8String:UP_ARROWHEAD], o_tooltip,
-            ((((unsigned int)p_item->value.i) & KEY_MODIFIER_CTRL)?YES:NO),
-            NSImageLeft )
-        [o_ctrl_checkbox setState: p_item->value.i & KEY_MODIFIER_CTRL];
-        ADD_CHECKBOX( o_alt_checkbox, mainFrame, [o_label frame].size.width +
-            2, -2 - [o_cmd_checkbox frame].size.height,
-            [NSString stringWithUTF8String:OPTION_KEY], o_tooltip,
-            ((((unsigned int)p_item->value.i) & KEY_MODIFIER_ALT)?YES:NO),
-            NSImageLeft )
-        [o_alt_checkbox setState: p_item->value.i & KEY_MODIFIER_ALT];
-        ADD_CHECKBOX( o_shift_checkbox, mainFrame,
-            [o_cmd_checkbox frame].size.width +
-            [o_cmd_checkbox frame].origin.x + 6, -2 -
-            [o_cmd_checkbox frame].size.height,
-            [NSString stringWithUTF8String:UPWARDS_WHITE_ARROW], o_tooltip,
-            ((((unsigned int)p_item->value.i) & KEY_MODIFIER_SHIFT)?YES:NO),
-            NSImageLeft )
-        [o_shift_checkbox setState: p_item->value.i & KEY_MODIFIER_SHIFT];
-        [self addSubview: o_cmd_checkbox];
-        [self addSubview: o_ctrl_checkbox];
-        [self addSubview: o_alt_checkbox];
-        [self addSubview: o_shift_checkbox];
-
-        /* build the popup */
-        ADD_POPUP( o_popup, mainFrame, [o_shift_checkbox frame].origin.x +
-            [o_shift_checkbox frame].size.width + 4,
-            4, 0, o_tooltip )
-        [o_popup setAutoresizingMask:NSViewWidthSizable ];
-
-        if( o_keys_menu == nil )
-        {
-            unsigned int i;
-            o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
-            for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
-                if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
-                    POPULATE_A_KEY( o_keys_menu,
-                        [NSString stringWithCString:vlc_keys[i].psz_key_string]
-                        , vlc_keys[i].i_key_code)
-        }
-        [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
-        [o_popup selectItemWithTitle: [[VLCMain sharedInstance]
-            localizedString:(char *)KeyToString(
-            (((unsigned int)p_item->value.i) & ~KEY_MODIFIER ))]];
-        [self addSubview: o_popup];
-    }
-    return self;
-}
-
-- (void) alignWithXPosition:(int)i_xPos
-{
-    NSRect frame;
-    NSRect superFrame = [self frame];
-    frame = [o_label frame];
-    frame.origin.x = i_xPos - frame.size.width - 3;
-    [o_label setFrame:frame];
-
-    frame = [o_cmd_checkbox frame];
-    frame.origin.x = i_xPos;
-    [o_cmd_checkbox setFrame:frame];
-
-    frame = [o_ctrl_checkbox frame];
-    frame.origin.x = [o_cmd_checkbox frame].size.width +
-                        [o_cmd_checkbox frame].origin.x + 4;
-    [o_ctrl_checkbox setFrame:frame];
-
-    frame = [o_alt_checkbox frame];
-    frame.origin.x = i_xPos;
-    [o_alt_checkbox setFrame:frame];
-
-    frame = [o_shift_checkbox frame];
-    frame.origin.x = [o_cmd_checkbox frame].size.width +
-                        [o_cmd_checkbox frame].origin.x + 4;
-    [o_shift_checkbox setFrame:frame];
-
-    frame = [o_popup frame];
-    frame.origin.x = [o_shift_checkbox frame].origin.x +
-                        [o_shift_checkbox frame].size.width + 3;
-    frame.size.width = superFrame.size.width - frame.origin.x + 2;
-    [o_popup setFrame:frame];
-}
-
-- (void)dealloc
-{
-    [o_cmd_checkbox release];
-    [o_ctrl_checkbox release];
-    [o_alt_checkbox release];
-    [o_shift_checkbox release];
-    [o_popup release];
-    [super dealloc];
-}
-
-- (int)intValue
-{
-    unsigned int i_new_key = 0;
-
-    i_new_key |= ([o_cmd_checkbox state] == NSOnState) ?
-        KEY_MODIFIER_COMMAND : 0;
-    i_new_key |= ([o_ctrl_checkbox state] == NSOnState) ?
-        KEY_MODIFIER_CTRL : 0;
-    i_new_key |= ([o_alt_checkbox state] == NSOnState) ?
-        KEY_MODIFIER_ALT : 0;
-    i_new_key |= ([o_shift_checkbox state] == NSOnState) ?
-        KEY_MODIFIER_SHIFT : 0;
-
-    i_new_key |= StringToKey((char *)[[[o_popup selectedItem] title] cString]);
-    return i_new_key;
-}
-@end
-
-@implementation KeyConfigControlAfter103
+@implementation KeyConfigControl
 - (id) initWithItem: (module_config_t *)_p_item
            withView: (NSView *)o_parent_view
 {
@@ -2211,27 +2048,27 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
 //Fill our array to know how may items we have...
     vlc_list_t *p_list;
     module_t *p_parser;
-    module_config_t *p_end;
-    int i_index;
+    int i_module_index;
     NSRect mainFrame = [o_parent_view frame];
     NSString *o_labelString, *o_textfieldString, *o_tooltip;
 
     o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
     /* build a list of available modules */
     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
-    for( i_index = 0; i_index < p_list->i_count; i_index++ )
+    for( i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ )
     {
-        p_parser = (module_t *)p_list->p_values[i_index].p_object;
-        p_end = p_item + p_parser->confsize;
+        int i;
+        p_parser = (module_t *)p_list->p_values[i_module_index].p_object;
 
         if( !strcmp( p_parser->psz_object_name, "main" ) )
             continue;
 
-        module_config_t *p_config = p_parser->p_config;
-        if( p_config ) do
+        for ( i = 0; i < p_parser->confsize; i++ )
         {
+            module_config_t *p_config = p_parser->p_config + i;
             NSString *o_modulelongname, *o_modulename;
             NSNumber *o_moduleenabled = nil;
+
             /* Hack: required subcategory is stored in i_min */
             if( p_config->i_type == CONFIG_SUBCATEGORY &&
                 p_config->value.i == _p_item->min.i )
@@ -2251,7 +2088,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
                     arrayWithObjects: o_modulename, o_modulelongname,
                     o_moduleenabled, nil]];
             }
-        } while( p_item < p_end && p_config++ );
+        }
     }
     vlc_list_release( p_list );
 
@@ -2298,13 +2135,11 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
     o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
     [o_scrollview setDrawsBackground: NO];
     [o_scrollview setBorderType: NSBezelBorder];
-    if( MACOS_VERSION >= 10.3 )
-        [o_scrollview setAutohidesScrollers:YES];
+    [o_scrollview setAutohidesScrollers:YES];
 
     NSTableView *o_tableview;
     o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
-    if( MACOS_VERSION >= 10.3 )
-        [o_tableview setUsesAlternatingRowBackgroundColors:YES];
+    [o_tableview setUsesAlternatingRowBackgroundColors:YES];
     [o_tableview setHeaderView:nil];
 /* TODO: find a good way to fix the row height and text size*/
 /* FIXME: support for multiple selection... */
@@ -2380,7 +2215,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
 
 - (char *)stringValue
 {
-    return strdup( [[o_textfield stringValue] cString] );
+    return strdup( [[o_textfield stringValue] UTF8String] );
 }
 
 @end