callback error II




I have a problem passing a callback argument.

I want that when a button is pushed, and item be added to a
list(gtk_list), but when the button is pushed, no item is added.

The button is calling the function do_search, which works when i call it
from outside the signal_connect.

This is the code(listing what i missed in my previous mail):

void
add_item_to_list(GtkWidget *list, char *buffer)
{
  GtkWidget *item;

  item = gtk_list_item_new_with_label (buffer);
  gtk_container_add (GTK_CONTAINER (list), item);
  g_print ("%s\n", buffer);
}


static void
do_search(GtkWidget *widget, GtkWidget *list)
{
  GtkWidget *item;
  
  if (o_menu_state == 0)
    {
      add_item_to_list(list, "Resultado de rfc");
    }
  else if (o_menu_state == 1)
      add_item_to_list(list, "Test nombre");
}

GtkWidget *
create_search_frame()
{
  GtkWidget *frame;
  GtkWidget *bbox, *bbox2;
  GtkWidget *omenu, *menu;
  GtkWidget *list;
  GtkWidget *scrolled_window;
  GtkWidget *button;

  frame = gtk_frame_new (_("Buscar"));
  bbox = gtk_hbutton_box_new();
  gtk_container_set_border_width (GTK_CONTAINER(bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  bbox2 = gtk_vbutton_box_new();
  gtk_container_set_border_width (GTK_CONTAINER(bbox2), 5);
  gtk_box_pack_start (GTK_BOX(bbox), bbox2, TRUE, TRUE, 5);

  scrolled_window = new_scrolled_window (170, 80);
  list = new_list_in_scrolled_window (scrolled_window);
  gtk_box_pack_start (GTK_BOX(bbox), scrolled_window, TRUE, TRUE, 0);

  omenu = gtk_option_menu_new ();
  gtk_box_pack_start (GTK_BOX(bbox2), omenu, TRUE, TRUE, 0);
  menu = gtk_menu_new ();
  fill_omenu(menu);
  gtk_option_menu_set_menu (GTK_OPTION_MENU(omenu), menu);


  /*
   *Fix me
   *The button callback is not working
   */
  button = gtk_button_new_with_label(_("Buscar"));
  gtk_box_pack_start (GTK_BOX(bbox2), button, TRUE, TRUE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (do_search), list);

  /* The next two work properly.
   *do_search doesn't work(add item to list) with the button, but it works
   *with the next call   
   */
  do_search(button, list);
  add_item_to_list (list, "Mensaje en la lista");

  return frame;
}


In case it be needed, new_scrolled_window and new_list_in_scrolled_window:


GtkWidget *
new_scrolled_window(gint width, gint height)
{
  GtkWidget *scrolled_window;

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_AUTOMATIC);
  gtk_widget_set_usize (scrolled_window, width, height);

  return scrolled_window;
}

GtkWidget *
new_list_in_scrolled_window(GtkWidget *scrolled_window)
{
  GtkWidget *list;

  list = gtk_list_new ();
  gtk_list_set_selection_mode (GTK_LIST(list), GTK_SELECTION_EXTENDED);
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW
(scrolled_window), list);
  gtk_container_set_focus_vadjustment
    (GTK_CONTAINER (list),
     gtk_scrolled_window_get_vadjustment
     (GTK_SCROLLED_WINDOW (scrolled_window)));
  gtk_container_set_focus_hadjustment
    (GTK_CONTAINER (list),
     gtk_scrolled_window_get_hadjustment
     (GTK_SCROLLED_WINDOW (scrolled_window)));

  return list;
}


Thanks

Omar



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