Re: [gtk-list] Re: bug in notebook, or not good behavior ?
- From: Antonio Campos <acampos ceronet com>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: bug in notebook, or not good behavior ?
- Date: Fri, 28 Jan 2000 00:46:16 +0100
Antonio Campos wrote:
> Damon Chaplin wrote:
>
> > Antonio Campos wrote:
> > >
> > > 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.
For all of those interested, I have done it!!. It's not a nice way at
all. Indeed it's an ugly way, but better is nothing.
>
> > > 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:
> >
> > You forgot to show the label. You need to do something like:
> >
> > hbox=gtk_hbox_new(TRUE,0);
> > label = gtk_label_new("hbox with label");
> > gtk_widget_show (label);
> > gtk_box_pack_start_defaults(GTK_BOX(hbox), label);
> >
>
> I do a gtk_widget_show_all(w); where w is the toplevel window that holds the
> notebook.
> I thought that this call would show all children of the toplevel window,
> including the notebook, the event_box and the hbox in the notebook, and the
> labels inside the event_box and the hbox (as a recursive show).
> But now I understand, that this call only shows the direct children of the
> widget we pass to the function. So only the notebook is shown. Then when the
> notebook is shown, it shows the labels. But I understand now that the
> event_box and the hbox are shown, but not their children, unless I do what you
> say.
> Sorry, stupid of me.
>
> >
> > > * The eventbox isn't correctly resized to show the label either. In the
> > > same way, if you uncomment the line:
> >
> > This is the same mistake.
> >
> > > - 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).
> >
> > It looks like GtkNotebook can't really handle child tab widgets which have
> > their own windows.
> >
>
> Yes, it looks like that.
>
> >
> > > - 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?).
> >
> > This is a similar problem with windows. GtkNotebook just ignores the button
> > press event, since it only takes notice of events in its own windows:
> >
> > if (event->window == notebook->panel)
> >
> > I think your only hope for getting notified when the mouse moves over a tab
> > label is to subclass GtkNotebook and add your own "tab_enter"/"tab_leave"
> > signals to that.
> >
>
A simpler and uglier solution: gtknotebook ignores the press event on
the eventbox (because the eventbox has its own window). Well, there is
still
a way.
Simple connect the press event
gtk_signal_connect(GTK_OBJECT(notebook),"button_press_event",
GTK_SIGNAL_FUNC(press_cb),(gpointer) notebook);
of the eventbox to a press_cb, passing the notebook as an additional
argument.
Now in the press_cb:
int press_cb(GtkWidget *widget,GdkEvent *event,gpointer data)
{
g_print("Got an press event on the label\n");
gtk_notebook_set_page(GTK_NOTEBOOK(data),3);
return TRUE;
}
So when you press the button over the eventbox label inside
the notebook, the press_cb sets the right page explicitly (were 3
should be replaced by the page number where the eventbox resides,
that obviusly was 3 in my case).
Very ugly, but it works!.
Hey, I'm willing to put an AVI movie on the label of a notebook :*)
>
> Any good documentation for making widget subclasses?. Better than the
> Tutorial, please...
>
> >
> > Damon
> >
> > --
> > To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
>
> Many, many thanks for your patience. There is always a kind soul.
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
I attach the updated source code for those interested
#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 press_cb(GtkWidget *widget,GdkEvent *event,gpointer data)
{
g_print("Got an press event on the label\n");
gtk_notebook_set_page(GTK_NOTEBOOK(data),3);
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_show_all(hbox);
//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_container_add(GTK_CONTAINER(eventbox),gtk_label_new("label inside eventbox"));
//gtk_widget_set_usize(eventbox,200,20);
gtk_widget_show_all(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_signal_connect(GTK_OBJECT(eventbox),"button_press_event",GTK_SIGNAL_FUNC(press_cb),
(gpointer) notebook);
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]