Commit 4eadbaec authored by David Fuhrmann's avatar 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.
parent def5284a
...@@ -72,9 +72,9 @@ static NSMenu *o_keys_menu = nil; ...@@ -72,9 +72,9 @@ static NSMenu *o_keys_menu = nil;
@end @end
@interface StringListConfigControl : VLCConfigControl <NSComboBoxDataSource> @interface StringListConfigControl : VLCConfigControl
{ {
NSComboBox *o_combo; NSPopUpButton *o_popup;
} }
- (id) initWithItem: (module_config_t *)_p_item - (id) initWithItem: (module_config_t *)_p_item
...@@ -120,9 +120,9 @@ static NSMenu *o_keys_menu = nil; ...@@ -120,9 +120,9 @@ static NSMenu *o_keys_menu = nil;
@end @end
@interface IntegerListConfigControl : VLCConfigControl <NSComboBoxDataSource> @interface IntegerListConfigControl : VLCConfigControl
{ {
NSComboBox *o_combo; NSPopUpButton *o_popup;
} }
- (id) initWithItem: (module_config_t *)_p_item - (id) initWithItem: (module_config_t *)_p_item
......
...@@ -1025,17 +1025,28 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \ ...@@ -1025,17 +1025,28 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
[self addSubview: o_label]; [self addSubview: o_label];
/* build the textfield */ /* 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) -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++) { 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]) 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] && else if (p_item->value.psz && p_item->list.psz[i_index] &&
!strcmp(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]; [o_popup selectItemAtIndex: i_index];
} }
[self addSubview: o_combo];
[self addSubview: o_popup];
} }
return self; return self;
} }
...@@ -1048,41 +1059,40 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \ ...@@ -1048,41 +1059,40 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
frame.origin.x = i_xPos - frame.size.width - 3; frame.origin.x = i_xPos - frame.size.width - 3;
[o_label setFrame:frame]; [o_label setFrame:frame];
frame = [o_combo frame]; frame = [o_popup frame];
frame.origin.x = i_xPos + 2; frame.origin.x = i_xPos + 2;
frame.size.width = superFrame.size.width - frame.origin.x + 2; frame.size.width = superFrame.size.width - frame.origin.x + 2;
[o_combo setFrame:frame]; [o_popup setFrame:frame];
} }
- (void)dealloc - (void)dealloc
{ {
[o_combo release]; [o_popup release];
[super dealloc]; [super dealloc];
} }
- (char *)stringValue - (char *)stringValue
{ {
if ([o_combo indexOfSelectedItem] >= 0) { if ([o_popup indexOfSelectedItem] >= 0) {
if (p_item->list.psz[[o_combo indexOfSelectedItem]] != NULL) if (p_item->list.psz[[o_popup indexOfSelectedItem]] != NULL)
return strdup(p_item->list.psz[[o_combo indexOfSelectedItem]]); return strdup(p_item->list.psz[[o_popup indexOfSelectedItem]]);
} else { } else {
if ([[VLCStringUtility sharedInstance] delocalizeString: [o_combo stringValue]] != NULL) if ([[VLCStringUtility sharedInstance] delocalizeString: [o_popup stringValue]] != NULL)
return strdup([[VLCStringUtility sharedInstance] delocalizeString: [o_combo stringValue]]); return strdup([[VLCStringUtility sharedInstance] delocalizeString: [o_popup stringValue]]);
} }
return NULL; return NULL;
} }
- (void)resetValues - (void)resetValues
{ {
[o_combo reloadData];
char *psz_value = config_GetPsz(VLCIntf, p_item->psz_name); char *psz_value = config_GetPsz(VLCIntf, p_item->psz_name);
for (int i_index = 0; i_index < p_item->list_count; i_index++) { for (int i_index = 0; i_index < p_item->list_count; i_index++) {
if (!psz_value && !p_item->list.psz[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] && else if (psz_value && p_item->list.psz[i_index] &&
!strcmp(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); free(psz_value);
...@@ -1090,21 +1100,6 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \ ...@@ -1090,21 +1100,6 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
} }
@end @end
@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]);
}
@end
@implementation FileConfigControl @implementation FileConfigControl
- (id) initWithItem: (module_config_t *)_p_item - (id) initWithItem: (module_config_t *)_p_item
withView: (NSView *)o_parent_view withView: (NSView *)o_parent_view
...@@ -1478,14 +1473,24 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \ ...@@ -1478,14 +1473,24 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
[self addSubview: o_label]; [self addSubview: o_label];
/* build the textfield */ /* 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) -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++) { 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]) 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; return self;
} }
...@@ -1498,52 +1503,36 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \ ...@@ -1498,52 +1503,36 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
frame.origin.x = i_xPos - frame.size.width - 3; frame.origin.x = i_xPos - frame.size.width - 3;
[o_label setFrame:frame]; [o_label setFrame:frame];
frame = [o_combo frame]; frame = [o_popup frame];
frame.origin.x = i_xPos + 2; frame.origin.x = i_xPos + 2;
frame.size.width = superFrame.size.width - frame.origin.x + 2; frame.size.width = superFrame.size.width - frame.origin.x + 2;
[o_combo setFrame:frame]; [o_popup setFrame:frame];
} }
- (void)dealloc - (void)dealloc
{ {
[o_combo release]; [o_popup release];
[super dealloc]; [super dealloc];
} }
- (int)intValue - (int)intValue
{ {
if ([o_combo indexOfSelectedItem] >= 0) if ([o_popup indexOfSelectedItem] >= 0)
return p_item->list.i[[o_combo indexOfSelectedItem]]; return p_item->list.i[[o_popup indexOfSelectedItem]];
else else
return [o_combo intValue]; return [o_popup intValue];
} }
-(void)resetValues -(void)resetValues
{ {
[o_combo reloadData];
for (int i_index = 0; i_index < p_item->list_count; i_index++) { 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]) 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 @end
@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]];
}
@end
@implementation RangedIntegerConfigControl @implementation RangedIntegerConfigControl
- (id) initWithItem: (module_config_t *)_p_item - (id) initWithItem: (module_config_t *)_p_item
withView: (NSView *)o_parent_view withView: (NSView *)o_parent_view
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment