Re: menu doesn't have ancestor?

Havoc Pennington <hp redhat com> writes:

> Pedro Zorzenon Neto <pzn terra com br> writes:
> > 
> >   When I do:
> >   
> >   anc = gtk_widget_get_ancestor (button1, GTK_TYPE_WINDOW);
> > 
> >   inside a button1 callback, it returns a pointer to the ancestor window.
> > 
> >   But if I do it inside a menu item callback (changing button1 to menuitem1)
> >   it doesn't work.
> > 
> >   Any hints?
> GtkMenu is a toplevel, so the menu items are not inside a GtkWindow.

Not since GTK+-1.0.... the menu items are inside a GtkWindow
in GTK+-1.2 and newer. I'm not sure what isn't working here,
especially without seeing more code,

Maybe the problem is that the window that is being retrieved
is the menu's window not the toplevel from which the toplevel
was popped up.

The appended code fragment from memprof may be useful in
such circumstances.


/* Really ugly utility function to retrieve the ProcessWindow from
 * either a menu_item or toolbar item.
ProcessWindow *
pwin_from_widget (GtkWidget *widget)
	GtkWidget *app;

	if (GTK_IS_MENU_ITEM (widget)) {
		GtkWidget *menu_shell = widget->parent;

		while (menu_shell && !GTK_IS_MENU_BAR (menu_shell)) {
			menu_shell = gtk_menu_get_attach_widget (GTK_MENU (menu_shell))->parent;
		g_assert (menu_shell != NULL);

		app = gtk_widget_get_toplevel (menu_shell);
	} else
		app = gtk_widget_get_toplevel (widget);
	return gtk_object_get_data (GTK_OBJECT (app), "process-window");

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