X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/29c93cc57d2f7715c58b4e577440bc580a47bd8a..d2e33e78a1d8deef4043b44802adc3ab51977698:/src/uibuilder.c diff --git a/src/uibuilder.c b/src/uibuilder.c index 9eec9b31..20c5d20e 100644 --- a/src/uibuilder.c +++ b/src/uibuilder.c @@ -29,6 +29,9 @@ #include "vikfileentry.h" #include "vikfilelist.h" +VikLayerParamData vik_lpd_true_default ( void ) { return VIK_LPD_BOOLEAN ( TRUE ); } +VikLayerParamData vik_lpd_false_default ( void ) { return VIK_LPD_BOOLEAN ( FALSE ); } + GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data ) { GtkWidget *rv = NULL; @@ -48,19 +51,21 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data } break; case VIK_LAYER_WIDGET_COMBOBOX: -#ifndef GTK_2_2 if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data ) { + /* Build a simple combobox */ gchar **pstr = param->widget_data; - rv = gtk_combo_box_new_text (); + rv = vik_combo_box_text_new (); while ( *pstr ) - gtk_combo_box_append_text ( GTK_COMBO_BOX ( rv ), *(pstr++) ); + vik_combo_box_text_append ( rv, *(pstr++) ); if ( param->extra_widget_data ) /* map of alternate uint values for options */ { + /* Set the effective default value */ int i; for ( i = 0; ((const char **)param->widget_data)[i]; i++ ) if ( ((guint *)param->extra_widget_data)[i] == data.u ) { + /* Match default value */ gtk_combo_box_set_active ( GTK_COMBO_BOX(rv), i ); break; } @@ -68,19 +73,47 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data else gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), data.u ); } - else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data ) + else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data && !param->extra_widget_data ) { + /* Build a combobox with editable text */ gchar **pstr = param->widget_data; - rv = GTK_WIDGET ( gtk_combo_box_entry_new_text () ); +#if GTK_CHECK_VERSION (2, 24, 0) + rv = gtk_combo_box_text_new_with_entry (); +#else + rv = gtk_combo_box_entry_new_text (); +#endif + if ( data.s ) + vik_combo_box_text_append ( rv, data.s ); + while ( *pstr ) + vik_combo_box_text_append ( rv, *(pstr++) ); if ( data.s ) - gtk_combo_box_append_text ( GTK_COMBO_BOX ( rv ), data.s ); + gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 ); + } + else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data && param->extra_widget_data) + { + /* Build a combobox with fixed selections without editable text */ + gchar **pstr = param->widget_data; + rv = GTK_WIDGET ( vik_combo_box_text_new () ); while ( *pstr ) - gtk_combo_box_append_text ( GTK_COMBO_BOX ( rv ), *(pstr++) ); + vik_combo_box_text_append ( rv, *(pstr++) ); if ( data.s ) + { + /* Set the effective default value */ + /* In case of value does not exist, set the first value */ + gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 ); + int i; + for ( i = 0; ((const char **)param->widget_data)[i]; i++ ) + if ( strcmp(((const char **)param->extra_widget_data)[i], data.s) == 0 ) + { + /* Match default value */ + gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), i ); + break; + } + } + else gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 ); } break; -#endif case VIK_LAYER_WIDGET_RADIOGROUP: /* widget_data and extra_widget_data are GList */ if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data ) @@ -151,14 +184,16 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data if ( param->type == VIK_LAYER_PARAM_STRING ) { rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN); - vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), data.s ); + if ( data.s ) + vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), data.s ); } break; case VIK_LAYER_WIDGET_FOLDERENTRY: if ( param->type == VIK_LAYER_PARAM_STRING ) { rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); - vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), data.s ); + if ( data.s ) + vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), data.s ); } break; @@ -199,7 +234,6 @@ VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerPara rv.b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); break; case VIK_LAYER_WIDGET_COMBOBOX: -#ifndef GTK_2_2 if ( param->type == VIK_LAYER_PARAM_UINT ) { rv.i = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) ); @@ -210,11 +244,24 @@ VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerPara } if ( param->type == VIK_LAYER_PARAM_STRING) { - rv.s = gtk_combo_box_get_active_text ( GTK_COMBO_BOX(widget) ); + if ( param->extra_widget_data ) + { + /* Combobox displays labels and we want values from extra */ + int pos = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) ); + rv.s = ((const char **)param->extra_widget_data)[pos]; + } + else + { + /* Return raw value */ +#if GTK_CHECK_VERSION (2, 24, 0) + rv.s = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget)))); +#else + rv.s = gtk_combo_box_get_active_text ( GTK_COMBO_BOX(widget) ); +#endif + } g_debug("%s: %s", __FUNCTION__, rv.s); } break; -#endif case VIK_LAYER_WIDGET_RADIOGROUP: case VIK_LAYER_WIDGET_RADIOGROUP_STATIC: rv.u = vik_radio_group_get_selected(VIK_RADIO_GROUP(widget)); @@ -252,7 +299,6 @@ VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerPara return rv; } - gint a_uibuilder_properties_factory ( const gchar *dialog_name, GtkWindow *parent, VikLayerParam *params, guint16 params_count, gchar **groups, guint8 groups_count, gboolean (*setparam) (gpointer,guint16,VikLayerParamData,gpointer,gboolean), @@ -299,7 +345,10 @@ gint a_uibuilder_properties_factory ( const gchar *dialog_name, GtkWindow *paren guint8 current_group; guint16 tab_widget_count; notebook = gtk_notebook_new (); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, FALSE, FALSE, 0); + // Switch to vertical notebook mode when many groups + if ( groups_count > 4 ) + gtk_notebook_set_tab_pos ( GTK_NOTEBOOK(notebook), GTK_POS_LEFT ); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), notebook, FALSE, FALSE, 0); tables = g_malloc ( sizeof(GtkWidget *) * groups_count ); for ( current_group = 0; current_group < groups_count; current_group++ ) { @@ -318,7 +367,7 @@ gint a_uibuilder_properties_factory ( const gchar *dialog_name, GtkWindow *paren else { table = gtk_table_new( widget_count, 1, FALSE ); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), table, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, FALSE, FALSE, 0); } for ( i = 0, j = 0; i < params_count; i++ ) @@ -330,10 +379,10 @@ gint a_uibuilder_properties_factory ( const gchar *dialog_name, GtkWindow *paren widgets[j] = a_uibuilder_new_widget ( &(params[i]), getparam ( pass_along_getparam, i, FALSE ) ); - g_assert ( widgets[j] != NULL ); - - gtk_table_attach ( GTK_TABLE(table), gtk_label_new(_(params[i].title)), 0, 1, j, j+1, 0, 0, 0, 0 ); - gtk_table_attach ( GTK_TABLE(table), widgets[j], 1, 2, j, j+1, GTK_EXPAND | GTK_FILL, 0, 2, 2 ); + if ( widgets[j] ) { + gtk_table_attach ( GTK_TABLE(table), gtk_label_new(_(params[i].title)), 0, 1, j, j+1, 0, 0, 0, 0 ); + gtk_table_attach ( GTK_TABLE(table), widgets[j], 1, 2, j, j+1, GTK_EXPAND | GTK_FILL, 0, 2, 2 ); + } j++; } } @@ -437,6 +486,8 @@ void a_uibuilder_free_paramdatas ( VikLayerParamData *paramdatas, VikLayerParam } g_list_free ( paramdatas[i].sl ); break; + default: + break; } } }