diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-08 20:10:32 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-08 20:10:32 +0000 |
commit | 7c320794d5ec9f5a1540590e2587cb63565b0d3b (patch) | |
tree | c779a9a75c6c770496e0116766322cba1463df1d /chrome/browser/gtk/menu_gtk.cc | |
parent | ea127857621dd27718f34791e1ba103881a37257 (diff) | |
download | chromium_src-7c320794d5ec9f5a1540590e2587cb63565b0d3b.zip chromium_src-7c320794d5ec9f5a1540590e2587cb63565b0d3b.tar.gz chromium_src-7c320794d5ec9f5a1540590e2587cb63565b0d3b.tar.bz2 |
GTK: support dynamic labels in GtkMenus
BUG=32115
TEST=show app menu, then toggle bookmark sync (on->off or off->on), show app menu again and confirm that the sync label has changed
Review URL: http://codereview.chromium.org/573037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/menu_gtk.cc')
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index acdb461..324f37e 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -52,6 +52,28 @@ bool GetMenuItemID(GtkWidget* menu_item, int* menu_id) { return false; } +menus::MenuModel* ModelForMenuItem(GtkMenuItem* menu_item) { + return reinterpret_cast<menus::MenuModel*>( + g_object_get_data(G_OBJECT(menu_item), "model")); +} + +void OnSubmenuShow(GtkWidget* widget, gpointer user_data) { + gint index = GPOINTER_TO_INT(user_data); + + GtkMenuItem* item = + GTK_MENU_ITEM(g_list_nth(GTK_MENU_SHELL(widget)->children, index)->data); + menus::MenuModel* model = ModelForMenuItem(item); + std::string label = + ConvertAcceleratorsFromWindowsStyle( + UTF16ToUTF8(model->GetLabelAt(index))); + +#if GTK_CHECK_VERSION(2, 16, 0) + gtk_menu_item_set_label(item, label.c_str()); +#else + gtk_label_set_label(GTK_LABEL(GTK_BIN(item)->child), label.c_str()); +#endif +} + } // namespace MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, @@ -346,6 +368,11 @@ void MenuGtk::BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu) { reinterpret_cast<void*>(model)); AppendMenuItemToMenu(i, menu_item, menu); + if (model->IsLabelDynamicAt(i)) { + g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShow), + GINT_TO_POINTER(i)); + } + menu_item = NULL; } } @@ -371,9 +398,7 @@ void MenuGtk::OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu) { if (!GetMenuItemID(GTK_WIDGET(menuitem), &id)) return; - menus::MenuModel* model = - reinterpret_cast<menus::MenuModel*>( - g_object_get_data(G_OBJECT(menuitem), "model")); + menus::MenuModel* model = ModelForMenuItem(menuitem); // The menu item can still be activated by hotkeys even if it is disabled. if (menu->IsCommandEnabled(model, id)) @@ -493,9 +518,7 @@ void MenuGtk::SetMenuItemInfo(GtkWidget* widget, gpointer userdata) { return; MenuGtk* menu = reinterpret_cast<MenuGtk*>(userdata); - menus::MenuModel* model = - reinterpret_cast<menus::MenuModel*>( - g_object_get_data(G_OBJECT(widget), "model")); + menus::MenuModel* model = ModelForMenuItem(GTK_MENU_ITEM(widget)); if (GTK_IS_CHECK_MENU_ITEM(widget)) { GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(widget); |