clist/notebook bug?



Hello,

I noticed some strange behaivor with gtk+-1.1.12 in relation to CLists and
NoteBooks.  

I have a notebook widget with several pages, one of which contains a
GtkCList as it's child.

I use gtk_signal_connect() to connect a signal handler function to the clist
to handle the signal "select_row".  inside this handler function, I check to
see if the event is a GDK_2BUTTON_PRESS.. if it is, i call
gtk_notebook_set_page() to switch the currently active page of the parent
notebook.

This results in most of the application becoming unresponsive to any mouse
clicks.  The notebook is still responsive, (it seems like all parent widgets
of the clist which got the GDK_2BUTTON_CLICK are still responsive, but
nothing else) but children widgets inside other notebook pages become
completely unresponsive.

If I go back to the notebook page with the clist, and click an entry again
ONCE, the entire app returns to normal and all widgets become responsive again.

note: no lockup behaivor seems to occur unless i call
gtk_notebook_set_page() from inside the 2BUTTON_PRESS handler routine. 

Below is an example program which demonstrates this behaivor.  Compile it,
and go to the middle notebook page.  doubleclick on the entry inside the
clist (there is only one).  The notebook should then switch to the third
page and all children widgets should become unresponsive (a button and a
combo).  switching back to page 2 and clicking on the clist item again one
time (not a doubleclick) will return the app to normal.
cheers,

Elliot Turner

--snip---


#include <gtk/gtk.h>

/* ignore these two funcs they are autogenerated by glade */
GtkWidget*
get_widget                             (GtkWidget       *widget,
                                        gchar           *widget_name);
void
set_notebook_tab                       (GtkWidget       *notebook,
                                        gint             page_num,
                                        GtkWidget       *widget);
GtkWidget* create_window1              (void);

int
main (int argc, char *argv[])
{
  GtkWidget *window1;
  GtkWidget *clist1;
  gchar     *textData[2];

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  window1 = create_window1 ();
  gtk_widget_show (window1);

  clist1 = get_widget(window1, "clist1");

  textData[0] = g_strdup("column a");
  textData[1] = g_strdup("column b");

  gtk_clist_append(GTK_CLIST(clist1), textData);

  gtk_main ();
  return 0;
}


void
on_clist1_select_row                   (GtkCList        *clist,
                                        gint             row,
                                        gint             column,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
  GtkWidget *mainNotebook;	

  mainNotebook = (GtkWidget *)user_data;

  if ((event) && (event->type == GDK_2BUTTON_PRESS))
    {
        /* switch notebook page on a 2BUTTON_PRESS event */
      gtk_notebook_set_page(GTK_NOTEBOOK(mainNotebook), 2);
    }
}


GtkWidget*
get_widget                             (GtkWidget       *widget,
                                        gchar           *widget_name)
{
  GtkWidget *found_widget;

  if (widget->parent)
    widget = gtk_widget_get_toplevel (widget);
  found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
                                                   widget_name);
  if (!found_widget)
    g_warning ("Widget not found: %s", widget_name);
  return found_widget;
}

void
set_notebook_tab                       (GtkWidget       *notebook,
                                        gint             page_num,
                                        GtkWidget       *widget)
{
  GtkNotebookPage *page;
  GtkWidget *notebook_page;

  page = (GtkNotebookPage*) g_list_nth (GTK_NOTEBOOK(notebook)->children,
page_num)->data;
  notebook_page = page->child;
  gtk_widget_ref (notebook_page);
  gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
  gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), notebook_page,
                            widget, page_num);
  gtk_widget_unref (notebook_page);
}

GtkWidget*
create_window1 ()
{
  GtkWidget *window1;
  GtkWidget *mainNotebook;
  GtkWidget *text1;
  GtkWidget *clist1;
  GtkWidget *label4;
  GtkWidget *label5;
  GtkWidget *vbox1;
  GtkWidget *button1;
  GtkWidget *combo1;
  GList *combo1_items = NULL;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *label3;

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
  gtk_window_set_title (GTK_WINDOW (window1), "window1");
  gtk_window_set_policy (GTK_WINDOW (window1), TRUE, TRUE, FALSE);

  mainNotebook = gtk_notebook_new ();
  gtk_object_set_data (GTK_OBJECT (window1), "mainNotebook", mainNotebook);
  gtk_widget_show (mainNotebook);
  gtk_container_add (GTK_CONTAINER (window1), mainNotebook);

  text1 = gtk_text_new (NULL, NULL);
  gtk_object_set_data (GTK_OBJECT (window1), "text1", text1);
  gtk_widget_show (text1);
  gtk_container_add (GTK_CONTAINER (mainNotebook), text1);
  gtk_widget_realize (text1);
  gtk_text_insert (GTK_TEXT (text1), NULL, NULL, NULL,
                   "text data", 9);

  clist1 = gtk_clist_new (2);
  gtk_object_set_data (GTK_OBJECT (window1), "clist1", clist1);
  gtk_widget_show (clist1);
  gtk_container_add (GTK_CONTAINER (mainNotebook), clist1);
  gtk_signal_connect (GTK_OBJECT (clist1), "select_row",
                      GTK_SIGNAL_FUNC (on_clist1_select_row),
                      mainNotebook);
  gtk_clist_set_column_width (GTK_CLIST (clist1), 0, 80);
  gtk_clist_set_column_width (GTK_CLIST (clist1), 1, 80);
  gtk_clist_column_titles_show (GTK_CLIST (clist1));

  label4 = gtk_label_new ("label4");
  gtk_object_set_data (GTK_OBJECT (window1), "label4", label4);
  gtk_widget_show (label4);
  gtk_clist_set_column_widget (GTK_CLIST (clist1), 0, label4);

  label5 = gtk_label_new ("label5");
  gtk_object_set_data (GTK_OBJECT (window1), "label5", label5);
  gtk_widget_show (label5);
  gtk_clist_set_column_widget (GTK_CLIST (clist1), 1, label5);

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_object_set_data (GTK_OBJECT (window1), "vbox1", vbox1);
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (mainNotebook), vbox1);

  button1 = gtk_button_new_with_label ("try clicking me");
  gtk_object_set_data (GTK_OBJECT (window1), "button1", button1);
  gtk_widget_show (button1);
  gtk_box_pack_start (GTK_BOX (vbox1), button1, TRUE, TRUE, 0);

  combo1 = gtk_combo_new ();
  gtk_object_set_data (GTK_OBJECT (window1), "combo1", combo1);
  gtk_widget_show (combo1);
  gtk_box_pack_start (GTK_BOX (vbox1), combo1, TRUE, TRUE, 0);
  combo1_items = g_list_append (combo1_items, "don't forget me!");
  combo1_items = g_list_append (combo1_items, "do i work?");
  gtk_combo_set_popdown_strings (GTK_COMBO (combo1), combo1_items);
  g_list_free (combo1_items);

  label1 = gtk_label_new ("label1");
  gtk_object_set_data (GTK_OBJECT (window1), "label1", label1);
  gtk_widget_show (label1);
  set_notebook_tab (mainNotebook, 0, label1);

  label2 = gtk_label_new ("label2");
  gtk_object_set_data (GTK_OBJECT (window1), "label2", label2);
  gtk_widget_show (label2);
  set_notebook_tab (mainNotebook, 1, label2);

  label3 = gtk_label_new ("label3");
  gtk_object_set_data (GTK_OBJECT (window1), "label3", label3);
  gtk_widget_show (label3);
  set_notebook_tab (mainNotebook, 2, label3);

  return window1;
}




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