OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/menu_gtk.h" | 5 #include "chrome/browser/gtk/menu_gtk.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "app/menus/accelerator_gtk.h" | 9 #include "app/menus/accelerator_gtk.h" |
10 #include "app/menus/button_menu_item_model.h" | 10 #include "app/menus/button_menu_item_model.h" |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } | 737 } |
738 | 738 |
739 // static | 739 // static |
740 void MenuGtk::SetButtonItemInfo(GtkWidget* button, gpointer userdata) { | 740 void MenuGtk::SetButtonItemInfo(GtkWidget* button, gpointer userdata) { |
741 menus::ButtonMenuItemModel* model = | 741 menus::ButtonMenuItemModel* model = |
742 reinterpret_cast<menus::ButtonMenuItemModel*>( | 742 reinterpret_cast<menus::ButtonMenuItemModel*>( |
743 g_object_get_data(G_OBJECT(button), "button-model")); | 743 g_object_get_data(G_OBJECT(button), "button-model")); |
744 int index = GPOINTER_TO_INT(g_object_get_data( | 744 int index = GPOINTER_TO_INT(g_object_get_data( |
745 G_OBJECT(button), "button-model-id")); | 745 G_OBJECT(button), "button-model-id")); |
746 | 746 |
747 if (model->IsLabelDynamicAt(index)) { | 747 if (model->IsItemDynamicAt(index)) { |
748 std::string label = | 748 std::string label = |
749 gfx::ConvertAcceleratorsFromWindowsStyle( | 749 gfx::ConvertAcceleratorsFromWindowsStyle( |
750 UTF16ToUTF8(model->GetLabelAt(index))); | 750 UTF16ToUTF8(model->GetLabelAt(index))); |
751 gtk_button_set_label(GTK_BUTTON(button), label.c_str()); | 751 gtk_button_set_label(GTK_BUTTON(button), label.c_str()); |
752 } | 752 } |
753 | 753 |
754 gtk_widget_set_sensitive(GTK_WIDGET(button), model->IsEnabledAt(index)); | 754 gtk_widget_set_sensitive(GTK_WIDGET(button), model->IsEnabledAt(index)); |
755 } | 755 } |
756 | 756 |
757 // static | 757 // static |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 gtk_custom_menu_item_foreach_button(GTK_CUSTOM_MENU_ITEM(widget), | 796 gtk_custom_menu_item_foreach_button(GTK_CUSTOM_MENU_ITEM(widget), |
797 SetButtonItemInfo, | 797 SetButtonItemInfo, |
798 userdata); | 798 userdata); |
799 } | 799 } |
800 | 800 |
801 if (GTK_IS_MENU_ITEM(widget)) { | 801 if (GTK_IS_MENU_ITEM(widget)) { |
802 gtk_widget_set_sensitive(widget, model->IsEnabledAt(id)); | 802 gtk_widget_set_sensitive(widget, model->IsEnabledAt(id)); |
803 | 803 |
804 if (model->IsVisibleAt(id)) { | 804 if (model->IsVisibleAt(id)) { |
805 // Update the menu item label if it is dynamic. | 805 // Update the menu item label if it is dynamic. |
806 if (model->IsLabelDynamicAt(id)) { | 806 // TODO(atwilson): Update the icon as well (http://crbug.com/66508). |
| 807 if (model->IsItemDynamicAt(id)) { |
807 std::string label = | 808 std::string label = |
808 gfx::ConvertAcceleratorsFromWindowsStyle( | 809 gfx::ConvertAcceleratorsFromWindowsStyle( |
809 UTF16ToUTF8(model->GetLabelAt(id))); | 810 UTF16ToUTF8(model->GetLabelAt(id))); |
810 | 811 |
811 #if GTK_CHECK_VERSION(2, 16, 0) | 812 #if GTK_CHECK_VERSION(2, 16, 0) |
812 gtk_menu_item_set_label(GTK_MENU_ITEM(widget), label.c_str()); | 813 gtk_menu_item_set_label(GTK_MENU_ITEM(widget), label.c_str()); |
813 #else | 814 #else |
814 gtk_label_set_label(GTK_LABEL(GTK_BIN(widget)->child), label.c_str()); | 815 gtk_label_set_label(GTK_LABEL(GTK_BIN(widget)->child), label.c_str()); |
815 #endif | 816 #endif |
816 } | 817 } |
817 | 818 |
818 gtk_widget_show(widget); | 819 gtk_widget_show(widget); |
819 } else { | 820 } else { |
820 gtk_widget_hide(widget); | 821 gtk_widget_hide(widget); |
821 } | 822 } |
822 | 823 |
823 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); | 824 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); |
824 if (submenu) { | 825 if (submenu) { |
825 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, | 826 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, |
826 userdata); | 827 userdata); |
827 } | 828 } |
828 } | 829 } |
829 } | 830 } |
OLD | NEW |