[maemo-developers] [maemo-developers] Way to get a reference to parent HildonAppView from its menu
From: Luca Donaggio donaggio at gmail.comDate: Fri Jan 20 18:34:49 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/20, Luca Donaggio <donaggio at gmail.com>: > > > > 2006/1/19, Kalle Vahlman <kalle.vahlman at gmail.com>: > > > > On 1/19/06, Luca Donaggio <donaggio at gmail.com> wrote: > > [Finding the AppView from a menu reference] > > > 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. > > > > And that's exactly where it fails since it traverses the widget > > hierarchy which the menu is not a part of. It's own hierarchy looks > > something like: > > > > GtkWindow > > \- GtkMenu > > \- (multiple GtkMenuItems) > > > > Looking at the code, the GtkWindow is the menu's toplevel window (the > > menu itself derives from GtkMenuShell which is in turn a GtkContainer > > so it can not be onscreen otherwise) and thus it is in it's own > > hierarchy. > > > > This coupled with the fact that the glade function has no reference to > > menu hierarchy (as it is created by the AppView) makes it impossible > > to find with the standard lookup method. > > > > From the other mail: > > >That would not be a big issue, as this app has only one AppView and a > > simple call > > >to hildon_app_get_appview() would do the trick, but ... it doesn't > > work for me! It > > >seems to return the same value I got before: ie a reference to a > > GtkWindow > > > (probably the window in which the app itself is displayed ?) and not a > > pointer to > > > the HildonApp object. > > > > This sounds a bit strange, since the HildonApp is a GtkWindow (though > > the type and name should state HildonApp of course) which has multiple > > HildonAppViews (derives from GtkBin) as it's children (although it > > only shows one at a time). > > > > -- > > Kalle Vahlman, zuh at iki.fi > > Powered by http://movial.fi > > Interesting stuff at http://syslog.movial.fi > > > > > I understand. So the GtkWindow, which is the top level widget of an > HildonAppView's own menu, is not in any way referrable to the HildonApp to > which that HildonAppView is attached? > If this is the case, I don't see any other way to solve the problem apart > from maintaining a global reference for the HildonApp and modifying the > glade lookup function to get the right pointer to the HildonAppView through > that reference directly, without traversing one object's hierarchy anymore. > > Luca Donaggio > Ok, i finally managed to solve this issue, next week I'm planning to have the packaging work finished too and to release an hildonized version of grsync for all you rsync-lovers ! For those interested (if any ;-)): -first I had to manually add a reference to the HildonAppView to its GtkMenu context: [code] GLADE_HOOKUP_OBJECT_NO_REF (GTK_WIDGET (menu1), main, "main"); [/end code] - secondly, this is the working modified version of the original glade function lookup_widget(): [code] GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name) { GtkWidget *parent, *found_widget; for (;;) { if (GTK_IS_MENU (widget)) { parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "main"); } 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] Thanks Fred and Kalle for all your helpful suggestions! Luca Donaggio. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20060120/409826ee/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 ]