[maemo-developers] [maemo-developers] Way to get a reference to parent HildonAppView from its menu
From: Luca Donaggio donaggio at gmail.comDate: Thu Jan 19 14:46:50 EET 2006
- Previous message: [maemo-developers] Way to get a reference to parent HildonAppView from its menu
- Next message: [maemo-developers] Way to get a reference to parent HildonAppView from its menu
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2006/1/19, Kalle Vahlman <kalle.vahlman at gmail.com>: > > On 1/18/06, Fred Lefévère-Laaoide <Fred at lefevere-laoide.net> wrote: > > Have you try gtk_widget_get_toplevel ? > > That would give the HildonApp, as AppViews are not toplevels. You > could then of course iterate over the list of appviews and check which > has the menu... > > > Luca Donaggio wrote: > > > How can I get a reference to the parent AppView giving a pointer to > its > > > GtkMenu? > > ...but best would be to determine if there was a way around it. What > exactly is the use case? > > > > gtk_menu_get_attach_widget() doesn't work and gtk_widget_get_parent() > > > returns a pointer to some unknown object (I checked it). > > The menu is not attached to any widget, nor is it strictly tied to the > AppView. I'm a bit surprised thet the get_parent() actually returns > anything, as menus should be toplevel widgets. You could print the > name of the widget with gtk_widget_name() and the type with > G_OBJECT_TYPE_NAME() to see what it is. > > As you see, the menu has no good connection to the view it belongs to, > so it's probably better to rethink what you are doing in a different > way if possible. > > -- > Kalle Vahlman, zuh at iki.fi > Powered by http://movial.fi > Interesting stuff at http://syslog.movial.fi > _______________________________________________ > maemo-developers mailing list > maemo-developers at maemo.org > https://maemo.org/mailman/listinfo/maemo-developers > gtk_widget_get_name() returns "GtkWindow" as well as G_OBJECT_TYPE_NAME(). I'm tryng to port grsync to maemo, it's almost done really, but for this menu related issue. Grsync has been made with Glade and Glade uses a lookup_widget() function to retrieve widgets programmatically by their names. It takes two input parameters: a GtkWidget reference and a string with the name of the widget to look for. the widget reference can be ANY widget, so the first thing it does is trying to get the "top level" widget - ie the widget which has been used as a container of all the others in all the g_object_set_data and g_object_set_data_full previous calls, which in my case is the (only one) HildonAppView. If lookup_widget is invoked from one of the menu items, it first gets a reference of its parent menu and then a reference to this "phantom" GtkWindow (which has no parent) and that's all - no reference to the AppView. Here is lookup_widget() code (I tweaked it a little to recognize a HildonAppView and stop looking further): [code] GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name) { GtkWidget *parent, *found_widget; for (;;) { if (GTK_IS_MENU (widget)) { // parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); // <- THIS DOESN'T WORK parent = gtk_widget_get_parent(widget); // <- THIS RETURNS A REFERENCE TO A GtkWindow } else if (HILDON_IS_APPVIEW (widget)) break; else parent = widget->parent; if (!parent) parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey"); if (parent == NULL) break; widget = parent; } found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget), widget_name); if (!found_widget) g_warning ("Widget not found: %s", widget_name); return found_widget; } [/end code] Luca Donaggio -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20060119/e3ebab04/attachment.htm
- Previous message: [maemo-developers] Way to get a reference to parent HildonAppView from its menu
- Next message: [maemo-developers] Way to get a reference to parent HildonAppView from its menu
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]