[gtk-list] bug in notebook, or not good behavior ?



Nobody answered to this e-mail, so I will re-post it in the hope of some
interest:


I asked someday for a way to be notified of enter or leave events in a
notebook sheet.
Havoc answered that I should insert a eventbox with a label as the label
for the notebook, for being notified of those events.
I made a simple test program to check this, that is attached to the
mail.
To compile: gcc prog.c -o prog `gtk-config --cflags --libs`, as you all
know.

As you can see, I insert a two normal labels, and then a hbox with a
label, and a eventbox with a label as notebook labels.
A lot of strange behaviors show:

* The hbox isn't correctly resized to show the label. Even more, if you
uncomment the line:
gtk_widget_set_usize(hbox,200,20);
the hbox gets that size, but the label inside it is not shown.
* The eventbox isn't correctly resized to show the label either. In the
same way, if you uncomment the line:
gtk_widget_set_usize(eventbox,200,20);
the eventbox gets that size, but the label inside it is not shown.
* More problems:
- The eventbox color is not the expected one inside the notebook label
as you can see. (Maybe this is not an incorrect behavior, because the
eventbox has an associated window, from where the background color is
taken, and that color is the "abnormal"? color showing).
- The most serious problem is that although the eventbox widget gets the
enter or leave notifications (that was the main reason why I made this
test program), when you click on the eventbox inside the notebook, you
will see that the notebook doesn't change the page. However, if you
press the Tab key to change the focus over the eventbox widget, and then
press Space to select it, then the notebook DOES change the page. (Very
strange, isn't it?).

Better explanation of the above:
First uncomment the line:
gtk_widget_set_usize(eventbox,200,20);
to make the eventbox size useful.
If you click inside the eventbox, (the strange colored part of the
notebook sheet where the eventbox resides), then no page change occurs.
But if you press inside the notebook sheet that contains the eventbox
widget, but outside the colored part where the eventbox widget resides,
then a PAGE CHANGE WILL OCCUR.
I am guessing that taking care of the enter or leave events by myself of
the eventbox widget gets the notebook confused. But I don't understand
why, because in the enter_cb and leave_cb event callbacks, I return
TRUE, which should continue the event propagation to the widgets that
contain the eventbox (the notebook in this case), if I am not wrong.
#include <gtk/gtk.h>

int leave_cb(GtkWidget *widget,GdkEvent *event,gpointer data)
{
  g_print("Got a leave event on the label\n");
  return TRUE;
}

int enter_cb(GtkWidget *widget,GdkEvent *event,gpointer data)
{
  g_print("Got an enter event on the label\n");
  return TRUE;
}

int main(int argc,char **argv)
{
  GtkWidget *notebook,*hbox,*eventbox,*w;

  gtk_init(&argc,&argv);

  w=gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_signal_connect(GTK_OBJECT(w),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL);

  notebook=gtk_notebook_new();

  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),gtk_frame_new("Fool frame"),
  			   gtk_label_new("Fool"));
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),gtk_frame_new("Bar frame"),  			
  			   gtk_label_new("Bar"));
  // Here we add a "hbox with a label" as a label for the notebook
  hbox=gtk_hbox_new(TRUE,0);
  gtk_box_pack_start_defaults(GTK_BOX(hbox),gtk_label_new("hbox with label"));
  //gtk_widget_set_usize(hbox,200,20);
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),gtk_frame_new("Hbox with a label frame"),
      			   hbox);
  // Here we add a "eventbox with a label" as a label for the notebook, so we can be notified of some events
  eventbox=gtk_event_box_new();
  //gtk_widget_set_usize(eventbox,200,20);
  gtk_container_add(GTK_CONTAINER(eventbox),gtk_label_new("label inside eventbox"));
  gtk_widget_set_events(GTK_WIDGET(eventbox),GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
  gtk_signal_connect(GTK_OBJECT(eventbox),"enter_notify_event",GTK_SIGNAL_FUNC(enter_cb),NULL);
  gtk_signal_connect(GTK_OBJECT(eventbox),"leave_notify_event",GTK_SIGNAL_FUNC(leave_cb),NULL);
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),gtk_frame_new("Eventbox with a label frame"),
      			   eventbox);

  gtk_container_add(GTK_CONTAINER(w),notebook);

  gtk_widget_set_usize(w,400,300);

  gtk_widget_show_all(GTK_WIDGET(w));

  gtk_main();

  return 0;
}


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