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/gfx/gtk_util.h" | 7 #include "app/gfx/gtk_util.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_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 24 matching lines...) Expand all Loading... |
35 if (dummy_accel_group_) | 35 if (dummy_accel_group_) |
36 g_object_unref(dummy_accel_group_); | 36 g_object_unref(dummy_accel_group_); |
37 } | 37 } |
38 | 38 |
39 void MenuGtk::ConnectSignalHandlers() { | 39 void MenuGtk::ConnectSignalHandlers() { |
40 g_signal_connect(menu_.get(), "hide", G_CALLBACK(OnMenuHidden), this); | 40 g_signal_connect(menu_.get(), "hide", G_CALLBACK(OnMenuHidden), this); |
41 } | 41 } |
42 | 42 |
43 void MenuGtk::AppendMenuItemWithLabel(int command_id, | 43 void MenuGtk::AppendMenuItemWithLabel(int command_id, |
44 const std::string& label) { | 44 const std::string& label) { |
45 GtkWidget* menu_item = gtk_menu_item_new_with_mnemonic(label.c_str()); | 45 std::string converted_label = ConvertAcceleratorsFromWindowsStyle(label); |
| 46 GtkWidget* menu_item = |
| 47 gtk_menu_item_new_with_mnemonic(converted_label.c_str()); |
46 AddMenuItemWithId(menu_item, command_id); | 48 AddMenuItemWithId(menu_item, command_id); |
47 } | 49 } |
48 | 50 |
49 void MenuGtk::AppendMenuItemWithIcon(int command_id, | 51 void MenuGtk::AppendMenuItemWithIcon(int command_id, |
50 const std::string& label, | 52 const std::string& label, |
51 const SkBitmap& icon) { | 53 const SkBitmap& icon) { |
52 GtkWidget* menu_item = BuildMenuItemWithImage(label, icon); | 54 GtkWidget* menu_item = BuildMenuItemWithImage(label, icon); |
53 AddMenuItemWithId(menu_item, command_id); | 55 AddMenuItemWithId(menu_item, command_id); |
54 } | 56 } |
55 | 57 |
56 void MenuGtk::AppendCheckMenuItemWithLabel(int command_id, | 58 void MenuGtk::AppendCheckMenuItemWithLabel(int command_id, |
57 const std::string& label) { | 59 const std::string& label) { |
58 GtkWidget* menu_item = gtk_check_menu_item_new_with_mnemonic(label.c_str()); | 60 std::string converted_label = ConvertAcceleratorsFromWindowsStyle(label); |
| 61 GtkWidget* menu_item = |
| 62 gtk_check_menu_item_new_with_mnemonic(converted_label.c_str()); |
59 AddMenuItemWithId(menu_item, command_id); | 63 AddMenuItemWithId(menu_item, command_id); |
60 } | 64 } |
61 | 65 |
62 void MenuGtk::AppendSeparator() { | 66 void MenuGtk::AppendSeparator() { |
63 GtkWidget* menu_item = gtk_separator_menu_item_new(); | 67 GtkWidget* menu_item = gtk_separator_menu_item_new(); |
64 gtk_widget_show(menu_item); | 68 gtk_widget_show(menu_item); |
65 gtk_menu_shell_append(GTK_MENU_SHELL(menu_.get()), menu_item); | 69 gtk_menu_shell_append(GTK_MENU_SHELL(menu_.get()), menu_item); |
66 } | 70 } |
67 | 71 |
68 void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) { | 72 void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 G_CALLBACK(OnMenuItemActivated), this); | 189 G_CALLBACK(OnMenuItemActivated), this); |
186 | 190 |
187 gtk_widget_show(menu_item); | 191 gtk_widget_show(menu_item); |
188 gtk_menu_append(menu, menu_item); | 192 gtk_menu_append(menu, menu_item); |
189 last_menu_item = menu_item; | 193 last_menu_item = menu_item; |
190 } | 194 } |
191 } | 195 } |
192 | 196 |
193 GtkWidget* MenuGtk::BuildMenuItemWithImage(const std::string& label, | 197 GtkWidget* MenuGtk::BuildMenuItemWithImage(const std::string& label, |
194 const SkBitmap& icon) { | 198 const SkBitmap& icon) { |
195 GtkWidget* menu_item = gtk_image_menu_item_new_with_mnemonic(label.c_str()); | 199 std::string converted_label = ConvertAcceleratorsFromWindowsStyle(label); |
| 200 GtkWidget* menu_item = |
| 201 gtk_image_menu_item_new_with_mnemonic(converted_label.c_str()); |
196 | 202 |
197 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); | 203 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); |
198 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), | 204 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), |
199 gtk_image_new_from_pixbuf(pixbuf)); | 205 gtk_image_new_from_pixbuf(pixbuf)); |
200 g_object_unref(pixbuf); | 206 g_object_unref(pixbuf); |
201 | 207 |
202 return menu_item; | 208 return menu_item; |
203 } | 209 } |
204 | 210 |
205 void MenuGtk::BuildMenuFromDelegate() { | 211 void MenuGtk::BuildMenuFromDelegate() { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 gtk_widget_set_sensitive( | 357 gtk_widget_set_sensitive( |
352 widget, menu->delegate_->IsCommandEnabled(id)); | 358 widget, menu->delegate_->IsCommandEnabled(id)); |
353 | 359 |
354 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); | 360 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); |
355 if (submenu) { | 361 if (submenu) { |
356 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, | 362 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, |
357 userdata); | 363 userdata); |
358 } | 364 } |
359 } | 365 } |
360 } | 366 } |
OLD | NEW |