Previously used GtkOptionMenu is deprecated since GTK 2.4. Also eliminated TYPE_ERASE, unchanged line type is now communicated using a separate column in GtkTreeModel. --- gschem/src/x_dialog.c | 212 ++++++++++++++++++++++++++++++------------------- 1 files changed, 129 insertions(+), 83 deletions(-)
diff --git a/gschem/src/x_dialog.c b/gschem/src/x_dialog.c index 507919c..0828d06 100644 --- a/gschem/src/x_dialog.c +++ b/gschem/src/x_dialog.c @@ -39,7 +39,7 @@ g_object_set_data_full (G_OBJECT (component), name, \ gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) -static GtkWidget* create_menu_linetype (GSCHEM_TOPLEVEL *w_current); +static GtkWidget* create_line_type_combo (void); static gint line_type_dialog_linetype_change (GtkWidget *w, gpointer data); static void line_type_dialog_ok (GtkWidget *w, gpointer data); @@ -51,7 +51,7 @@ static void fill_type_dialog_ok(GtkWidget *w, gpointer data); struct line_type_data { GtkWidget *dialog; GtkWidget *width_entry; - GtkWidget *line_type; + GtkComboBox *line_type; GtkWidget *length_entry; GtkWidget *space_entry; @@ -573,40 +573,58 @@ void text_edit_dialog (GSCHEM_TOPLEVEL *w_current, const char *string, int text_ /***************** Start of Line Type/width dialog box ****************/ -/*! \brief Create a line type menu for the line type dialog +enum line_type_columns { + LT_COLUMN_STRING, /*!< Text displayed in the choice box */ + LT_COLUMN_VALUE, /*!< Corresponding value (line type/end type) */ + LT_COLUMN_VALID, /*!< Is the value valid */ + LT_NUM_COLUMNS, /*!< Total number of columns in the model */ +}; + +/*! \brief Create a GtkComboBox for line type selection * \par Function Description - * This function creates a GtkMenu with the different linetypes. + * This function creates a GtkComboBox based on list of line types. */ -static GtkWidget *create_menu_linetype (GSCHEM_TOPLEVEL *w_current) +static GtkWidget *create_line_type_combo (void) { - GtkWidget *menu; - GSList *group; - struct line_type { - gchar *str; - OBJECT_TYPE type; - } types[] = { { N_("Solid"), TYPE_SOLID }, - { N_("Dotted"), TYPE_DOTTED }, - { N_("Dashed"), TYPE_DASHED }, - { N_("Center"), TYPE_CENTER }, - { N_("Phantom"), TYPE_PHANTOM }, - { N_("*unchanged*"), TYPE_ERASE } }; - gint i; + const struct { + gchar *str; + OBJECT_TYPE type; + gboolean valid; + } types[] = { { N_("Solid"), TYPE_SOLID, TRUE }, + { N_("Dotted"), TYPE_DOTTED, TRUE }, + { N_("Dashed"), TYPE_DASHED, TRUE }, + { N_("Center"), TYPE_CENTER, TRUE }, + { N_("Phantom"), TYPE_PHANTOM, TRUE }, + { N_("*unchanged*"), 0, FALSE } }; - menu = gtk_menu_new (); - group = NULL; - - for (i = 0; i < sizeof (types) / sizeof (struct line_type); i++) { - GtkWidget *menuitem; - - menuitem = gtk_radio_menu_item_new_with_label (group, _(types[i].str)); - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_object_set_data (GTK_OBJECT(menuitem), "linetype", - GINT_TO_POINTER (types[i].type)); - gtk_widget_show (menuitem); + gint i; + GtkListStore *list_store; + GtkCellRenderer *cell; + GtkWidget *combo; + + list_store = gtk_list_store_new (LT_NUM_COLUMNS, + G_TYPE_STRING, + G_TYPE_INT, + G_TYPE_BOOLEAN); + + for (i = 0; i < sizeof (types) / sizeof (*types); i++) { + GtkTreeIter iter; + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + LT_COLUMN_STRING, types[i].str, + LT_COLUMN_VALUE, types[i].type, + LT_COLUMN_VALID, types[i].valid, + -1); } - return(menu); + combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (list_store)); + g_object_unref (G_OBJECT (list_store)); + cell = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell, + "text", LT_COLUMN_STRING, NULL); + + return combo; } /*! \brief get the linetype data from selected objects @@ -676,14 +694,30 @@ static void line_type_dialog_set_values(struct line_type_data *line_type_data, gint width, gint length, gint space) { gchar *text; - GtkWidget *menu, *menuitem; + GtkTreeIter iter; + GtkTreeModel *model; - if (type == -2) - type = TYPE_ERASE; - gtk_option_menu_set_history(GTK_OPTION_MENU(line_type_data->line_type), type); - menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(line_type_data->line_type)); - menuitem = gtk_menu_get_active(GTK_MENU(menu)); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE); + model = gtk_combo_box_get_model (line_type_data->line_type); + g_assert (gtk_tree_model_get_iter_first (model, &iter)); + do { + if (type == -2) { + gboolean valid; + gtk_tree_model_get (model, &iter, + LT_COLUMN_VALID, &valid, + -1); + if (! valid) + break; + } else { + gint value; + gtk_tree_model_get (model, &iter, + LT_COLUMN_VALUE, &value, + -1); + if (type == value) + break; + } + } while (gtk_tree_model_iter_next (model, &iter)); + gtk_combo_box_set_active_iter (line_type_data->line_type, + &iter); if (width == -2) text = g_strdup(_("*unchanged*")); @@ -722,34 +756,42 @@ static void line_type_dialog_set_values(struct line_type_data *line_type_data, static gint line_type_dialog_linetype_change(GtkWidget *w, gpointer data) { struct line_type_data *line_type_data = (struct line_type_data*) data; - GtkWidget *menuitem; - gboolean activate_length_entry, activate_space_entry; - gint type; - - menuitem = gtk_menu_get_active ( - GTK_MENU (gtk_option_menu_get_menu ( - GTK_OPTION_MENU (line_type_data->line_type)))); - - type = GPOINTER_TO_INT( - gtk_object_get_data (GTK_OBJECT (menuitem), "linetype")); - switch(type) { - case(TYPE_SOLID): - activate_length_entry = FALSE; - activate_space_entry = FALSE; - break; - case(TYPE_DOTTED): - activate_length_entry = FALSE; - activate_space_entry = TRUE; - break; - case(TYPE_DASHED): - case(TYPE_CENTER): - case(TYPE_PHANTOM): - activate_length_entry = TRUE; - activate_space_entry = TRUE; - break; - default: - activate_length_entry = TRUE; - activate_space_entry = TRUE; + gboolean activate_length_entry = TRUE; + gboolean activate_space_entry = TRUE; + GtkTreeIter iter; + GtkTreeModel *model = gtk_combo_box_get_model (line_type_data->line_type); + + g_assert (model); + if (gtk_combo_box_get_active_iter (line_type_data->line_type, &iter)) { + gint type; + gboolean valid; + gtk_tree_model_get (model, &iter, + LT_COLUMN_VALUE, &type, + LT_COLUMN_VALID, &valid, + -1); + if (valid) + switch(type) { + case (TYPE_SOLID): + activate_length_entry = FALSE; + activate_space_entry = FALSE; + break; + + case (TYPE_DOTTED): + activate_length_entry = FALSE; + activate_space_entry = TRUE; + break; + + case (TYPE_DASHED): + case (TYPE_CENTER): + case (TYPE_PHANTOM): + activate_length_entry = TRUE; + activate_space_entry = TRUE; + break; + + default: + activate_length_entry = TRUE; + activate_space_entry = TRUE; + } } gtk_widget_set_sensitive (line_type_data->space_entry, @@ -757,7 +799,7 @@ static gint line_type_dialog_linetype_change(GtkWidget *w, gpointer data) gtk_widget_set_sensitive (line_type_data->length_entry, activate_length_entry); - return(0); + return 0; } @@ -793,15 +835,21 @@ static void line_type_dialog_ok(GtkWidget *w, gpointer data) line_type_data->length_entry)); space_str = gtk_entry_get_text (GTK_ENTRY ( line_type_data->space_entry)); - type = GPOINTER_TO_INT( - gtk_object_get_data ( - GTK_OBJECT ( - gtk_menu_get_active ( - GTK_MENU (gtk_option_menu_get_menu ( - GTK_OPTION_MENU ( - line_type_data->line_type))))), "linetype")); - if (type == TYPE_ERASE) - type = -1; + { + GtkTreeModel *model = + gtk_combo_box_get_model (line_type_data->line_type); + GtkTreeIter iter; + gboolean type_valid; + gint type_value; + + g_assert (model); + gtk_combo_box_get_active_iter (line_type_data->line_type, &iter); + gtk_tree_model_get (model, &iter, + LT_COLUMN_VALUE, &type_value, + LT_COLUMN_VALID, &type_valid, + -1); + type = type_valid ? type_value : -1; + } /* convert the options to integers (-1 means unchanged) */ width = g_strcasecmp (width_str, @@ -888,7 +936,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current) { GtkWidget *dialog; GtkWidget *vbox; - GtkWidget *optionmenu = NULL; + GtkWidget *type_combo = NULL; GtkWidget *length_entry = NULL; GtkWidget *space_entry = NULL; GtkWidget *width_entry = NULL; @@ -968,10 +1016,8 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current) gtk_misc_set_alignment(GTK_MISC(label), 0, 0); gtk_table_attach(GTK_TABLE(table), label, 0,1,3,4, GTK_FILL,0,0,0); - optionmenu = gtk_option_menu_new (); - gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu), - create_menu_linetype (w_current)); - gtk_table_attach_defaults(GTK_TABLE(table), optionmenu, + type_combo = create_line_type_combo(); + gtk_table_attach_defaults(GTK_TABLE(table), type_combo, 1,2,0,1); width_entry = gtk_entry_new(); @@ -980,7 +1026,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current) gtk_table_attach_defaults(GTK_TABLE(table), width_entry, 1,2,1,2); - gtk_signal_connect(GTK_OBJECT (optionmenu), "changed", + gtk_signal_connect(GTK_OBJECT (type_combo), "changed", (GtkSignalFunc) line_type_dialog_linetype_change, line_type_data); @@ -999,7 +1045,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current) /* populate the data structure */ line_type_data->dialog = dialog; line_type_data->width_entry = width_entry; - line_type_data->line_type = optionmenu; + line_type_data->line_type = GTK_COMBO_BOX (type_combo); line_type_data->length_entry = length_entry; line_type_data->space_entry = space_entry; @@ -1010,7 +1056,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current) width, length, space); /* calling it once will set the dash space/length activity */ - line_type_dialog_linetype_change(optionmenu, line_type_data); + line_type_dialog_linetype_change(type_combo, line_type_data); gtk_widget_grab_focus(width_entry); gtk_widget_show_all (dialog); -- 1.6.2 -- Krzysztof Kościuszkiewicz "Simplicity is the ultimate sophistication" -- Leonardo da Vinci _______________________________________________ geda-user mailing list geda-user@moria.seul.org http://www.seul.org/cgi-bin/mailman/listinfo/geda-user