| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/gfx/gtk_util.h" | 8 #include "base/gfx/gtk_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 GtkAccelGroup* accel_group) { | 118 GtkAccelGroup* accel_group) { |
| 119 // We keep track of the last menu item in order to group radio items. | 119 // We keep track of the last menu item in order to group radio items. |
| 120 GtkWidget* last_menu_item = NULL; | 120 GtkWidget* last_menu_item = NULL; |
| 121 for (; menu_data->type != MENU_END; ++menu_data) { | 121 for (; menu_data->type != MENU_END; ++menu_data) { |
| 122 GtkWidget* menu_item = NULL; | 122 GtkWidget* menu_item = NULL; |
| 123 | 123 |
| 124 std::string label; | 124 std::string label; |
| 125 if (menu_data->label_argument) { | 125 if (menu_data->label_argument) { |
| 126 label = l10n_util::GetStringFUTF8( | 126 label = l10n_util::GetStringFUTF8( |
| 127 menu_data->label_id, | 127 menu_data->label_id, |
| 128 WideToUTF16(l10n_util::GetString(menu_data->label_argument))); | 128 l10n_util::GetStringUTF16(menu_data->label_argument)); |
| 129 } else if (menu_data->label_id) { | 129 } else if (menu_data->label_id) { |
| 130 label = l10n_util::GetStringUTF8(menu_data->label_id); | 130 label = l10n_util::GetStringUTF8(menu_data->label_id); |
| 131 } else if (menu_data->type != MENU_SEPARATOR) { | 131 } else if (menu_data->type != MENU_SEPARATOR) { |
| 132 label = delegate_->GetLabel(menu_data->id); | 132 label = delegate_->GetLabel(menu_data->id); |
| 133 DCHECK(!label.empty()); | 133 DCHECK(!label.empty()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 label = GtkUtil::ConvertAcceleratorsFromWindowsStyle(label); | 136 label = GtkUtil::ConvertAcceleratorsFromWindowsStyle(label); |
| 137 | 137 |
| 138 switch (menu_data->type) { | 138 switch (menu_data->type) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 159 | 159 |
| 160 if (menu_data->submenu) { | 160 if (menu_data->submenu) { |
| 161 GtkWidget* submenu = gtk_menu_new(); | 161 GtkWidget* submenu = gtk_menu_new(); |
| 162 BuildMenuIn(submenu, menu_data->submenu, accel_group); | 162 BuildMenuIn(submenu, menu_data->submenu, accel_group); |
| 163 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); | 163 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); |
| 164 } else if (menu_data->custom_submenu) { | 164 } else if (menu_data->custom_submenu) { |
| 165 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), | 165 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), |
| 166 menu_data->custom_submenu->menu_.get()); | 166 menu_data->custom_submenu->menu_.get()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (accel_group && menu_data->accel_key) { | 169 if ((menu_data->only_show || accel_group) && menu_data->accel_key) { |
| 170 // If we ever want to let the user do any key remaping, we'll need to | 170 // If we ever want to let the user do any key remaping, we'll need to |
| 171 // change the following so we make a gtk_accel_map which keeps the actual | 171 // change the following so we make a gtk_accel_map which keeps the actual |
| 172 // keys. | 172 // keys. |
| 173 gtk_widget_add_accelerator(menu_item, | 173 gtk_widget_add_accelerator(menu_item, |
| 174 "activate", | 174 "activate", |
| 175 menu_data->only_show ? dummy_accel_group_ : | 175 menu_data->only_show ? dummy_accel_group_ : |
| 176 accel_group, | 176 accel_group, |
| 177 menu_data->accel_key, | 177 menu_data->accel_key, |
| 178 GdkModifierType(menu_data->accel_modifiers), | 178 GdkModifierType(menu_data->accel_modifiers), |
| 179 GTK_ACCEL_VISIBLE); | 179 GTK_ACCEL_VISIBLE); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 gtk_widget_set_sensitive( | 343 gtk_widget_set_sensitive( |
| 344 widget, menu->delegate_->IsCommandEnabled(id)); | 344 widget, menu->delegate_->IsCommandEnabled(id)); |
| 345 | 345 |
| 346 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); | 346 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); |
| 347 if (submenu) { | 347 if (submenu) { |
| 348 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, | 348 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, |
| 349 userdata); | 349 userdata); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 } | 352 } |
| OLD | NEW |