[vlc-commits] macosx: prefs: implement string list config and integer list config with popup box

David Fuhrmann git at videolan.org
Sat Mar 2 23:11:51 CET 2013


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sat Mar  2 13:10:07 2013 +0100| [4eadbaec8662fd330f91fbacc4849858ec177157] | committer: David Fuhrmann

macosx: prefs: implement string list config and integer list config with popup box

There should be no reason why the user should be able to freely changes strings here.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4eadbaec8662fd330f91fbacc4849858ec177157
---

 modules/gui/macosx/prefs_widgets.h |    8 +--
 modules/gui/macosx/prefs_widgets.m |  109 ++++++++++++++++--------------------
 2 files changed, 53 insertions(+), 64 deletions(-)

diff --git a/modules/gui/macosx/prefs_widgets.h b/modules/gui/macosx/prefs_widgets.h
index d3e00db..ab5be7c 100644
--- a/modules/gui/macosx/prefs_widgets.h
+++ b/modules/gui/macosx/prefs_widgets.h
@@ -72,9 +72,9 @@ static NSMenu   *o_keys_menu = nil;
 
 @end
 
- at interface StringListConfigControl : VLCConfigControl <NSComboBoxDataSource>
+ at interface StringListConfigControl : VLCConfigControl
 {
-    NSComboBox      *o_combo;
+    NSPopUpButton      *o_popup;
 }
 
 - (id) initWithItem: (module_config_t *)_p_item
@@ -120,9 +120,9 @@ static NSMenu   *o_keys_menu = nil;
 
 @end
 
- at interface IntegerListConfigControl : VLCConfigControl <NSComboBoxDataSource>
+ at interface IntegerListConfigControl : VLCConfigControl
 {
-    NSComboBox      *o_combo;
+    NSPopUpButton      *o_popup;
 }
 
 - (id) initWithItem: (module_config_t *)_p_item
diff --git a/modules/gui/macosx/prefs_widgets.m b/modules/gui/macosx/prefs_widgets.m
index af296f1..0820f86 100644
--- a/modules/gui/macosx/prefs_widgets.m
+++ b/modules/gui/macosx/prefs_widgets.m
@@ -1025,17 +1025,28 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];     \
         [self addSubview: o_label];
 
         /* build the textfield */
-        ADD_COMBO(o_combo, mainFrame, [o_label frame].size.width,
+        ADD_POPUP(o_popup, mainFrame, [o_label frame].size.width,
             -2, 0, o_textfieldTooltip)
-        [o_combo setAutoresizingMask:NSViewWidthSizable ];
+        [o_popup setAutoresizingMask:NSViewWidthSizable];
+
+        /* add items */
         for (int i_index = 0; i_index < p_item->list_count; i_index++) {
+            NSString *o_text;
+            if (p_item->list_text && p_item->list_text[i_index])
+                o_text = _NS((char *)p_item->list_text[i_index]);
+            else
+                o_text = _NS((char *)p_item->list.psz[i_index]);
+            [o_popup addItemWithTitle: o_text];
+
+            /* select default item */
             if (!p_item->value.psz && !p_item->list.psz[i_index])
-                [o_combo selectItemAtIndex: i_index];
+                [o_popup selectItemAtIndex: i_index];
             else if (p_item->value.psz && p_item->list.psz[i_index] &&
-                !strcmp(p_item->value.psz, p_item->list.psz[i_index]))
-                [o_combo selectItemAtIndex: i_index];
-       }
-        [self addSubview: o_combo];
+                     !strcmp(p_item->value.psz, p_item->list.psz[i_index]))
+                [o_popup selectItemAtIndex: i_index];
+        }
+
+        [self addSubview: o_popup];
     }
     return self;
 }
@@ -1048,41 +1059,40 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];     \
     frame.origin.x = i_xPos - frame.size.width - 3;
     [o_label setFrame:frame];
 
-    frame = [o_combo frame];
+    frame = [o_popup frame];
     frame.origin.x = i_xPos + 2;
     frame.size.width = superFrame.size.width - frame.origin.x + 2;
-    [o_combo setFrame:frame];
+    [o_popup setFrame:frame];
 }
 
 - (void)dealloc
 {
-    [o_combo release];
+    [o_popup release];
     [super dealloc];
 }
 
 - (char *)stringValue
 {
-    if ([o_combo indexOfSelectedItem] >= 0) {
-        if (p_item->list.psz[[o_combo indexOfSelectedItem]] != NULL)
-            return strdup(p_item->list.psz[[o_combo indexOfSelectedItem]]);
+    if ([o_popup indexOfSelectedItem] >= 0) {
+        if (p_item->list.psz[[o_popup indexOfSelectedItem]] != NULL)
+            return strdup(p_item->list.psz[[o_popup indexOfSelectedItem]]);
     } else {
-        if ([[VLCStringUtility sharedInstance] delocalizeString: [o_combo stringValue]] != NULL)
-            return strdup([[VLCStringUtility sharedInstance] delocalizeString: [o_combo stringValue]]);
+        if ([[VLCStringUtility sharedInstance] delocalizeString: [o_popup stringValue]] != NULL)
+            return strdup([[VLCStringUtility sharedInstance] delocalizeString: [o_popup stringValue]]);
     }
     return NULL;
 }
 
 - (void)resetValues
 {
-    [o_combo reloadData];
     char *psz_value = config_GetPsz(VLCIntf, p_item->psz_name);
 
     for (int i_index = 0; i_index < p_item->list_count; i_index++) {
         if (!psz_value && !p_item->list.psz[i_index])
-            [o_combo selectItemAtIndex: i_index];
+            [o_popup selectItemAtIndex: i_index];
         else if (psz_value && p_item->list.psz[i_index] &&
             !strcmp(psz_value, p_item->list.psz[i_index]))
-            [o_combo selectItemAtIndex: i_index];
+            [o_popup selectItemAtIndex: i_index];
     }
 
     free(psz_value);
@@ -1090,21 +1100,6 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];     \
 }
 @end
 
- at implementation StringListConfigControl (NSComboBoxDataSource)
-- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
-{
-        return p_item->list_count;
-}
-
-- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
-{
-    if (p_item->list_text && p_item->list_text[i_index]) {
-        return _NS((char *)p_item->list_text[i_index]);
-    } else
-        return _NS((char *)p_item->list.psz[i_index]);
-}
- at end
-
 @implementation FileConfigControl
 - (id) initWithItem: (module_config_t *)_p_item
            withView: (NSView *)o_parent_view
@@ -1478,14 +1473,24 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];     \
         [self addSubview: o_label];
 
         /* build the textfield */
-        ADD_COMBO(o_combo, mainFrame, [o_label frame].size.width,
+        ADD_POPUP(o_popup, mainFrame, [o_label frame].size.width,
             -2, 0, o_textfieldTooltip)
-        [o_combo setAutoresizingMask:NSViewWidthSizable ];
+        [o_popup setAutoresizingMask:NSViewWidthSizable ];
+
+        /* add items */
         for (int i_index = 0; i_index < p_item->list_count; i_index++) {
+            NSString *o_text;
+            if (p_item->list_text && p_item->list_text[i_index])
+                o_text = _NS((char *)p_item->list_text[i_index]);
+            else
+                o_text = [NSString stringWithFormat: @"%i", p_item->list.i[i_index]];
+            [o_popup addItemWithTitle: o_text];
+
             if (p_item->value.i == p_item->list.i[i_index])
-                [o_combo selectItemAtIndex: i_index];
+                [o_popup selectItemAtIndex: i_index];
         }
-        [self addSubview: o_combo];
+        
+        [self addSubview: o_popup];
     }
     return self;
 }
@@ -1498,52 +1503,36 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];     \
     frame.origin.x = i_xPos - frame.size.width - 3;
     [o_label setFrame:frame];
 
-    frame = [o_combo frame];
+    frame = [o_popup frame];
     frame.origin.x = i_xPos + 2;
     frame.size.width = superFrame.size.width - frame.origin.x + 2;
-    [o_combo setFrame:frame];
+    [o_popup setFrame:frame];
 }
 
 - (void)dealloc
 {
-    [o_combo release];
+    [o_popup release];
     [super dealloc];
 }
 
 - (int)intValue
 {
-    if ([o_combo indexOfSelectedItem] >= 0)
-        return p_item->list.i[[o_combo indexOfSelectedItem]];
+    if ([o_popup indexOfSelectedItem] >= 0)
+        return p_item->list.i[[o_popup indexOfSelectedItem]];
     else
-        return [o_combo intValue];
+        return [o_popup intValue];
 }
 
 -(void)resetValues
 {
-    [o_combo reloadData];
     for (int i_index = 0; i_index < p_item->list_count; i_index++) {
         if (config_GetInt(VLCIntf, p_item->psz_name) == p_item->list.i[i_index])
-            [o_combo selectItemAtIndex: i_index];
+            [o_popup selectItemAtIndex: i_index];
     }
 
 }
 @end
 
- at implementation IntegerListConfigControl (NSComboBoxDataSource)
-- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
-{
-    return p_item->list_count;
-}
-
-- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
-{
-    if (p_item->list_text && p_item->list_text[i_index])
-        return _NS((char *)p_item->list_text[i_index]);
-    else
-        return [NSString stringWithFormat: @"%i", p_item->list.i[i_index]];
-}
- at end
-
 @implementation RangedIntegerConfigControl
 - (id) initWithItem: (module_config_t *)_p_item
            withView: (NSView *)o_parent_view



More information about the vlc-commits mailing list