Help newbie with gtk+ patch



Hi all.

I'm trying to fix the long-standing data-loss bug at:
http://bugzilla.gnome.org/show_bug.cgi?id=156017

The problem is that I'm only learning C. In fact this is my first C code
at all; I'm a Perl programmer.

The bug:
If a user types data into a GtkComboBoxEntry's entry instead of using
the ComboBox with their mouse, the Combo doesn't record a 'match' in
it's model. It instead assumes that the user typed something that isn't
in the model.

Anyway, here is my attempt at fixing
gtk_combo_box_entry_contents_changed in gtkcomboboxentry.c ( below ).

It compiles, but when I test typing into a GtkComboBoxEntry, I get:

GLib-GObject-WARNING **: gvalue.c:89: cannot initialize GValue with type
`gchararray', the value has already been initialized as `(null)'
at .posting/posting.pl line 364.
GLib-GObject-CRITICAL **: g_value_set_string: assertion
`G_VALUE_HOLDS_STRING (value)' failed at .posting/posting.pl line 364.
Segmentation fault

I'm testing with a Gtk2-Perl app.

Can someone please tell me all the mistakes I've made? :)

Dan

--

static void
gtk_combo_box_entry_contents_changed (GtkEntry *entry,
                                      gpointer  user_data)
{
  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
  
  GtkTreeModel *model;
  GtkTreeIter iter;
  GValue *str;
  GValue *this_str;
  gboolean have_iter;
  gboolean found_match;
  gint text_column;
  
  str = gtk_entry_get_text (entry);
  g_signal_handlers_block_by_func (combo_box,
                                   gtk_combo_box_entry_active_changed,
                                   NULL);
  
  text_column = gtk_combo_box_entry_get_text_column (combo_box);
  model = gtk_combo_box_get_model(combo_box);
  have_iter = gtk_tree_model_get_iter_first(model, &iter);
  
  while (have_iter)
  {
    gtk_tree_model_get_value (model, &iter, text_column, &this_str);
    if (!strcmp (&str, &this_str))
    {
      found_match = TRUE;
      gtk_combo_box_set_active_iter (combo_box, &iter);
      break;
    } else {
      have_iter = gtk_tree_model_iter_next(model, &iter);
    }
  }
  
  if (!found_match)
  {
    gtk_combo_box_set_active (combo_box, -1);
  }
  
  g_signal_handlers_unblock_by_func (combo_box,
                                     gtk_combo_box_entry_active_changed,
                                     NULL);
}

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2
9922 7989
email: dkasak nusconsulting com au
website:
http://www.nusconsulting.com.au




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]