diff options
author | Javier <dev.git@javispedro.com> | 2014-12-14 23:16:55 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2014-12-14 23:16:55 +0100 |
commit | 6af9136bfd1abad3d9ac282339917f1c5570fd74 (patch) | |
tree | 4df0ba472fb555cd59424c33eda1d5490970e2d4 /module | |
parent | e46ff747b5c5dcc865d09071118cfa0a2e9a356f (diff) | |
download | topmenu-gtk-6af9136bfd1abad3d9ac282339917f1c5570fd74.tar.gz topmenu-gtk-6af9136bfd1abad3d9ac282339917f1c5570fd74.zip |
also update menuitem labels when the child label widget changes
Diffstat (limited to 'module')
-rw-r--r-- | module/menuitem-proxy.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/module/menuitem-proxy.c b/module/menuitem-proxy.c index 58db6c1..deac447 100644 --- a/module/menuitem-proxy.c +++ b/module/menuitem-proxy.c @@ -575,6 +575,15 @@ menu_item_position_menu (GtkMenu *menu, #endif } +static void handle_menuitem_child_notify(GtkLabel *item, GParamSpec *pspec, GtkMenuItem *proxy) +{ + // Note that it is OK to compare strings by pointer as they are all interned + if (pspec->name == pname_label) { + const gchar *label = gtk_label_get_label(item); + gtk_menu_item_set_label(proxy, label); + } +} + static void handle_menuitem_notify(GtkMenuItem *item, GParamSpec *pspec, GtkMenuItem *proxy) { // Note that it is OK to compare strings by pointer as they are all interned @@ -732,8 +741,10 @@ GtkMenuItem *topmenu_create_proxy_menu_item(GtkMenuItem *item) if (gtk_image_menu_item_get_use_stock(iitem)) { proxy = GTK_MENU_ITEM(gtk_image_menu_item_new_from_stock(label, NULL)); } else { - GtkWidget *iwidget = gtk_image_menu_item_get_image(iitem); proxy = GTK_MENU_ITEM(gtk_image_menu_item_new_with_mnemonic(label)); + + // Try to get the image widget type. + GtkWidget *iwidget = gtk_image_menu_item_get_image(iitem); if (iwidget) { // Let's suppport some common widget types if (GTK_IS_IMAGE(iwidget)) { @@ -758,6 +769,12 @@ GtkMenuItem *topmenu_create_proxy_menu_item(GtkMenuItem *item) gtk_widget_show(GTK_WIDGET(proxy)); } + GtkWidget *child = gtk_bin_get_child(GTK_BIN(item)); + if (child && GTK_IS_LABEL(child)) { + g_signal_connect_object(child, "notify", + G_CALLBACK(handle_menuitem_child_notify), proxy, 0); + } + g_signal_connect_object(item, "notify", G_CALLBACK(handle_menuitem_notify), proxy, 0); g_signal_connect_object(item, "mnemonic-activate", |