delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2012/02/08/09:29:04

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Message-ID: <4F32865F.9090200@x-eike.de>
Date: Wed, 08 Feb 2012 15:27:43 +0100
From: Eike Krumbacher <eike DOT krumbacher AT x-eike DOT de>
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0
MIME-Version: 1.0
To: geda-user AT delorie DOT com
Subject: [geda-user] Patch: change GtkOptionMenu, GtkCombo to GtkComboBoxText (part two)
X-bounce-key: webpack.hosteurope.de;eike DOT krumbacher AT x-eike DOT de;1328711268;c2654749;
Reply-To: geda-user AT delorie DOT com

This is a multi-part message in MIME format.
--------------040705070308080806010007
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Folks!

GtkCombo and GtkOptionMenu are deprecated. I ported both to 
GtkComboBoxText in gschem/.../x_multiattrib.{h,c}.

The diff is against my local HEAD and made with
$ git format-patch -1
and help from Peter S.

I hope it is OK to send this format-patch as an attachment. Sending from 
the command line does not work for me.

Please tell me, if something is wrong, I try to correct it then.

Best regards

Eike


--------------040705070308080806010007
Content-Type: text/x-diff;
 name="0001-GtkCombo-and-GtkOptionMenu-are-deprecated-since-vers.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-GtkCombo-and-GtkOptionMenu-are-deprecated-since-vers.pa";
 filename*1="tch"

From 836c0e4172d0ad929db6bcfdedf80a2c26da5ec8 Mon Sep 17 00:00:00 2001
From: eikekrumbacher <eike DOT krumbacher AT x-eike DOT de>
Date: Wed, 8 Feb 2012 14:54:08 +0100
Subject: [PATCH] GtkCombo and GtkOptionMenu are deprecated since version 2.4
 of GTK+. I replaced both in x_multiattrib{h,c} with
 GtkComboBoxText. I tested the changes by creating new
 attributes, saving and loading a file.

---
 gschem/include/x_multiattrib.h |    5 +-
 gschem/src/x_multiattrib.c     |  100 ++++++++++++---------------------------
 2 files changed, 34 insertions(+), 71 deletions(-)

diff --git a/gschem/include/x_multiattrib.h b/gschem/include/x_multiattrib.h
index a451afd..867e984 100644
--- a/gschem/include/x_multiattrib.h
+++ b/gschem/include/x_multiattrib.h
@@ -49,10 +49,11 @@ struct _Multiattrib {
   GtkTreeView    *treeview;
 
   GtkWidget      *show_inherited;
-  GtkCombo       *combo_name;
   GtkTextView    *textview_value;
   GtkCheckButton *button_visible;
-  GtkOptionMenu  *optionmenu_shownv;
+  GtkComboBoxText *cmbtext_name;        /* attributes name, editable */
+  GtkComboBoxText *cmbtext_shownv;      /* visibility */
+  
   GtkWidget      *frame_attributes;
   GtkWidget      *frame_add;
 
diff --git a/gschem/src/x_multiattrib.c b/gschem/src/x_multiattrib.c
index 792ea9c..07d22ae 100644
--- a/gschem/src/x_multiattrib.c
+++ b/gschem/src/x_multiattrib.c
@@ -35,27 +35,6 @@
 #endif
 
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Documentation
- *
- */
-static gint option_menu_get_history (GtkOptionMenu *option_menu) 
-{ 
-  GtkWidget *active_widget; 
-         
-  g_return_val_if_fail (GTK_IS_OPTION_MENU (option_menu), -1); 
-         
-  active_widget = gtk_menu_get_active (GTK_MENU (option_menu->menu)); 
-
-  if (active_widget) 
-    return g_list_index (GTK_MENU_SHELL (option_menu->menu)->children, 
-			 active_widget); 
-  else 
-    return -1; 
-} 
-
-
 /*! \brief Update the multiattrib editor dialog when the page's
  *         selection changes.
  *  \par Function Description
@@ -1472,8 +1451,8 @@ static void multiattrib_callback_button_add(GtkButton *button,
   
   /* retrieve information from the Add/Edit frame */
   /*   - attribute's name */
-  name = gtk_entry_get_text (
-    GTK_ENTRY (GTK_COMBO (multiattrib->combo_name)->entry));
+  name = gtk_combo_box_text_get_active_text (
+    GTK_COMBO_BOX_TEXT (multiattrib->cmbtext_name));
   /*   - attribute's value */
   gtk_text_buffer_get_bounds (buffer, &start, &end);
   value = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
@@ -1481,7 +1460,8 @@ static void multiattrib_callback_button_add(GtkButton *button,
   visible = gtk_toggle_button_get_active (
     (GtkToggleButton*)multiattrib->button_visible);
   /*   - visibility type */
-  shownv = (gint)gtk_option_menu_get_history (multiattrib->optionmenu_shownv);
+  shownv = gtk_combo_box_get_active (
+    GTK_COMBO_BOX (multiattrib->cmbtext_shownv));
 
   if (name[0] == '\0' || name[0] == ' ') {
     /* name not allowed for an attribute */
@@ -1502,43 +1482,16 @@ static void multiattrib_callback_button_add(GtkButton *button,
  *  \par Function Description
  *
  */
-static void multiattrib_init_attrib_names(GtkCombo *combo)
+static void multiattrib_init_attrib_names(GtkComboBoxText *combobox_text)
 {
-  GList *items = NULL;
   const gchar *string;
-  gint i;
-  
-  for (i = 0, string = s_attrib_get (i);
-       string != NULL;
-       i++, string = s_attrib_get (i)) {
-    items = g_list_append (items, (gpointer)string);
-  }
-
-  gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);
-
-  g_list_free (items);
-  
-}
-
-/*! \todo Finish function documentation
- *  \brief
- *  \par Function Description
- *
- */
-static void multiattrib_init_visible_types(GtkOptionMenu *optionmenu)
-{
-  GtkWidget *menu, *item;
+  gint i = 0;
 
-  menu = gtk_menu_new ();
-  item = gtk_menu_item_new_with_label (_("Show Name & Value"));
-  gtk_menu_append (menu, item);
-  item = gtk_menu_item_new_with_label (_("Show Value only"));
-  gtk_menu_append (menu, item);
-  item = gtk_menu_item_new_with_label (_("Show Name only"));
-  gtk_menu_append (menu, item);
-
-  gtk_option_menu_set_menu (optionmenu, menu);
-  
+  string = s_attrib_get (i);
+  while (string != NULL) {
+    gtk_combo_box_text_append_text (combobox_text, string);
+    string = s_attrib_get (++i);
+  }
 }
 
 
@@ -1770,7 +1723,7 @@ static void multiattrib_show_inherited_toggled (GtkToggleButton *button,
 static void multiattrib_init(Multiattrib *multiattrib)
 {
   GtkWidget *frame, *label, *scrolled_win, *treeview;
-  GtkWidget *table, *textview, *combo, *optionm, *button;
+  GtkWidget *table, *textview, *cmbtext, *cmbvisibility, *button;
   GtkWidget *attrib_vbox, *show_inherited;
   GtkTreeModel *store;
   GtkCellRenderer *renderer;
@@ -1993,15 +1946,16 @@ static void multiattrib_init(Multiattrib *multiattrib)
 				    /* GtkLabel */
 				    "label",  _("Name:"),
 				    NULL));
-  combo = GTK_WIDGET (g_object_new (GTK_TYPE_COMBO,
-				    /* GtkCombo */
-				    "value-in-list", FALSE,
+  cmbtext = GTK_WIDGET (g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
+				    /* GtkComboBoxText */
+				    "has-entry", TRUE,
+				    "entry-text-column", 0,
 				    NULL));
-  multiattrib_init_attrib_names (GTK_COMBO (combo));
-  multiattrib->combo_name = GTK_COMBO (combo);
+  multiattrib_init_attrib_names (GTK_COMBO_BOX_TEXT (cmbtext));
+  multiattrib->cmbtext_name = GTK_COMBO_BOX_TEXT (cmbtext);
   gtk_table_attach (GTK_TABLE (table), label,
 		    0, 1, 0, 1, 0, 0, 0, 0);
-  gtk_table_attach (GTK_TABLE (table), combo,
+  gtk_table_attach (GTK_TABLE (table), cmbtext,
 		    1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 6, 3);
   
   /*   - the value entry: a GtkEntry */
@@ -2064,11 +2018,19 @@ static void multiattrib_init(Multiattrib *multiattrib)
 		    0, 1, 2, 3, GTK_FILL, 0, 3, 0);
   
   /*   - the visibility type */
-  optionm = GTK_WIDGET (g_object_new (GTK_TYPE_OPTION_MENU,
+  cmbvisibility = GTK_WIDGET (g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
 				      NULL));
-  multiattrib_init_visible_types (GTK_OPTION_MENU (optionm));
-  multiattrib->optionmenu_shownv = GTK_OPTION_MENU (optionm);
-  gtk_table_attach (GTK_TABLE (table), optionm,
+
+  /* Be careful, the order reflects the numbered order of SHOW_NAME_VALUE and
+    friends in libgeda/include/libgeda/defines.h */
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cmbvisibility), _("Show Name & Value"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cmbvisibility), _("Show Value Only"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cmbvisibility), _("Show Name Only"));
+  gtk_combo_box_set_active (GTK_COMBO_BOX (cmbvisibility), SHOW_VALUE);
+
+  multiattrib->cmbtext_shownv = GTK_COMBO_BOX_TEXT (cmbvisibility);
+  
+  gtk_table_attach (GTK_TABLE (table), cmbvisibility,
 		    1, 2, 2, 3, GTK_EXPAND | GTK_FILL, 0, 6, 3);
   gtk_widget_show_all (table);
   
-- 
1.7.5.4


--------------040705070308080806010007--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019