Re: GtkNotebook and callback



TORRI Vincent wrote:

On Sun, 17 Nov 2002, Arno wrote:

Hello,

I make a callback on my GtkNotebook :
g_signal_connect (G_OBJECT (notebook), "switch_page",
           G_CALLBACK (notebook_changed_cb),
           NULL);

And in my fonction I do :
notebook_changed_cb (GtkNotebook *notebook, GtkNotebookPage *page,
            guint numero_page, gpointer data)
{
 const gchar *text;

 text = gtk_notebook_get_menu_label_text(notebook, GTK_WIDGET(page));

You have to pass the child of your page, not page itself (a GtkNotebookPage is not a GtkWidget). You can get the child of your current page with

 GtkWidget *child;
child = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
Thank you. I didn't know how I could get the child.

 printf("Label: %s\n", text);
}

But I have a little pb when I use this solution:
(check_tsr:592): GLib-GObject-WARNING **: invalid uninstantiatable type `(null)' in cast to `GtkWidget'

(check_tsr:592): Gtk-CRITICAL **: file gtknotebook.c: line 4905 (gtk_notebook_get_menu_label_text): assertion `GTK_IS_WIDGET (child)' failed
Label: (null)


It said that it could cast my GtkNotebookPage to a widget. So I search in the code source and I do this :

struct _GtkNotebookPage
{
 GtkWidget *child;
 GtkWidget *tab_label;
 GtkWidget *menu_label;
GtkWidget *last_focus_child; /* Last descendant of the page that had focus */

 guint default_menu : 1;    /* If true, we create the menu label ourself */
 guint default_tab  : 1;    /* If true, we create the tab label ourself */
 guint expand       : 1;
 guint fill         : 1;
 guint pack         : 1;

 GtkRequisition requisition;
 GtkAllocation allocation;

 guint mnemonic_activate_signal;
};

void
notebook_changed_cb (GtkNotebook *notebook, GtkNotebookPage *page,
            guint numero_page, gpointer data)
{
 const gchar *text;

 printf("Page: %p,   Child:%p\n", page, page->child);
 printf("Diff: %d\n", (int)page->child - (int)page);
text = gtk_notebook_get_menu_label_text(notebook, GTK_WIDGET(page->child));
 printf("Label: %s\n", text);
}

And I obtain :

Page: 0x80c8e00,   Child:0x80c8be8
Diff: -536
Label: List of packets


With this solution I obtain the name of the current menu but I need to copy the struct _GtkNotebookPage from the source to my project. I don't think that it's the good solution. So if you could help me. I use GTK2.

Also, I don't understand why (int)page->child - (int)page) equal to -536

What kind of result would you want to have ? You compute the difference of two adresses, so the result could be (almost) every number, I think.

Yes, in fact I don't know :)

regards

Vincent TORRI

Thx ;)
Arno


__________________________________________________
Modem offert : 150,92 euros remboursés sur le Pack eXtense de Wanadoo ! Haut débit à partir de 30 euros/mois : http://www.ifrance.com/_reloc/w

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






__________________________________________________
Modem offert : 150,92 euros remboursés sur le Pack eXtense de Wanadoo ! Haut débit à partir de 30 euros/mois : http://www.ifrance.com/_reloc/w




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