Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/gtk/menu_gtk.cc

Issue 3032038: The button menu items on GTK menus honor the enabled state of the command.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/menus/button_menu_item_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/menus/accelerator_gtk.h" 10 #include "app/menus/accelerator_gtk.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #endif 73 #endif
74 } 74 }
75 75
76 void OnSubmenuShowButtonMenuItem(GtkWidget* widget, GtkButton* button) { 76 void OnSubmenuShowButtonMenuItem(GtkWidget* widget, GtkButton* button) {
77 menus::ButtonMenuItemModel* model = 77 menus::ButtonMenuItemModel* model =
78 reinterpret_cast<menus::ButtonMenuItemModel*>( 78 reinterpret_cast<menus::ButtonMenuItemModel*>(
79 g_object_get_data(G_OBJECT(button), "button-model")); 79 g_object_get_data(G_OBJECT(button), "button-model"));
80 int index = GPOINTER_TO_INT(g_object_get_data( 80 int index = GPOINTER_TO_INT(g_object_get_data(
81 G_OBJECT(button), "button-model-id")); 81 G_OBJECT(button), "button-model-id"));
82 82
83 std::string label = 83 if (model->IsLabelDynamicAt(index)) {
84 ConvertAcceleratorsFromWindowsStyle( 84 std::string label =
85 UTF16ToUTF8(model->GetLabelAt(index))); 85 ConvertAcceleratorsFromWindowsStyle(
86 gtk_button_set_label(GTK_BUTTON(button), label.c_str()); 86 UTF16ToUTF8(model->GetLabelAt(index)));
87 gtk_button_set_label(GTK_BUTTON(button), label.c_str());
88 }
89 gtk_widget_set_sensitive(GTK_WIDGET(button), model->IsEnabledAt(index));
87 } 90 }
88 91
89 void SetupDynamicLabelMenuButton(GtkWidget* button, 92 void SetupButtonShowHandler(GtkWidget* button,
90 GtkWidget* menu, 93 GtkWidget* menu,
91 menus::ButtonMenuItemModel* model, 94 menus::ButtonMenuItemModel* model,
92 int index) { 95 int index) {
93 if (model->IsLabelDynamicAt(index)) { 96 g_object_set_data(G_OBJECT(button), "button-model",
94 g_object_set_data(G_OBJECT(button), "button-model", 97 model);
95 model); 98 g_object_set_data(G_OBJECT(button), "button-model-id",
96 g_object_set_data(G_OBJECT(button), "button-model-id", 99 GINT_TO_POINTER(index));
97 GINT_TO_POINTER(index)); 100 g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonMenuItem),
98 g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonMenuItem), 101 button);
99 button);
100 }
101 } 102 }
102 103
103 void OnSubmenuShowButtonImage(GtkWidget* widget, GtkButton* button) { 104 void OnSubmenuShowButtonImage(GtkWidget* widget, GtkButton* button) {
104 MenuGtk::Delegate* delegate = reinterpret_cast<MenuGtk::Delegate*>( 105 MenuGtk::Delegate* delegate = reinterpret_cast<MenuGtk::Delegate*>(
105 g_object_get_data(G_OBJECT(button), "menu-gtk-delegate")); 106 g_object_get_data(G_OBJECT(button), "menu-gtk-delegate"));
106 int icon_idr = GPOINTER_TO_INT(g_object_get_data( 107 int icon_idr = GPOINTER_TO_INT(g_object_get_data(
107 G_OBJECT(button), "button-image-idr")); 108 G_OBJECT(button), "button-image-idr"));
108 109
109 GtkIconSet* icon_set = delegate->GetIconSetForId(icon_idr); 110 GtkIconSet* icon_set = delegate->GetIconSetForId(icon_idr);
110 if (icon_set) { 111 if (icon_set) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 int icon_idr; 395 int icon_idr;
395 if (model->GetIconAt(i, &icon_idr)) { 396 if (model->GetIconAt(i, &icon_idr)) {
396 SetupImageIcon(button, menu, icon_idr, delegate_); 397 SetupImageIcon(button, menu, icon_idr, delegate_);
397 } else { 398 } else {
398 gtk_button_set_label( 399 gtk_button_set_label(
399 GTK_BUTTON(button), 400 GTK_BUTTON(button),
400 RemoveWindowsStyleAccelerators( 401 RemoveWindowsStyleAccelerators(
401 UTF16ToUTF8(model->GetLabelAt(i))).c_str()); 402 UTF16ToUTF8(model->GetLabelAt(i))).c_str());
402 } 403 }
403 404
404 SetupDynamicLabelMenuButton(button, menu, model, i); 405 SetupButtonShowHandler(button, menu, model, i);
405 break; 406 break;
406 } 407 }
407 case menus::ButtonMenuItemModel::TYPE_BUTTON_LABEL: { 408 case menus::ButtonMenuItemModel::TYPE_BUTTON_LABEL: {
408 button = gtk_custom_menu_item_add_button_label( 409 button = gtk_custom_menu_item_add_button_label(
409 GTK_CUSTOM_MENU_ITEM(menu_item), 410 GTK_CUSTOM_MENU_ITEM(menu_item),
410 model->GetCommandIdAt(i)); 411 model->GetCommandIdAt(i));
411 gtk_button_set_label( 412 gtk_button_set_label(
412 GTK_BUTTON(button), 413 GTK_BUTTON(button),
413 RemoveWindowsStyleAccelerators( 414 RemoveWindowsStyleAccelerators(
414 UTF16ToUTF8(model->GetLabelAt(i))).c_str()); 415 UTF16ToUTF8(model->GetLabelAt(i))).c_str());
415 SetupDynamicLabelMenuButton(button, menu, model, i); 416 SetupButtonShowHandler(button, menu, model, i);
416 break; 417 break;
417 } 418 }
418 } 419 }
419 420
420 if (button && model->PartOfGroup(i)) { 421 if (button && model->PartOfGroup(i)) {
421 if (!group) 422 if (!group)
422 group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); 423 group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
423 424
424 gtk_size_group_add_widget(group, button); 425 gtk_size_group_add_widget(group, button);
425 } 426 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // The menu item can still be activated by hotkeys even if it is disabled. 459 // The menu item can still be activated by hotkeys even if it is disabled.
459 if (model->IsEnabledAt(id)) 460 if (model->IsEnabledAt(id))
460 menu->ExecuteCommand(model, id); 461 menu->ExecuteCommand(model, id);
461 } 462 }
462 463
463 void MenuGtk::OnMenuButtonPressed(GtkMenuItem* menu_item, int command_id, 464 void MenuGtk::OnMenuButtonPressed(GtkMenuItem* menu_item, int command_id,
464 MenuGtk* menu) { 465 MenuGtk* menu) {
465 menus::ButtonMenuItemModel* model = 466 menus::ButtonMenuItemModel* model =
466 reinterpret_cast<menus::ButtonMenuItemModel*>( 467 reinterpret_cast<menus::ButtonMenuItemModel*>(
467 g_object_get_data(G_OBJECT(menu_item), "button-model")); 468 g_object_get_data(G_OBJECT(menu_item), "button-model"));
468 if (model) { 469 if (model && model->IsCommandIdEnabled(command_id)) {
469 if (menu->delegate_) 470 if (menu->delegate_)
470 menu->delegate_->CommandWillBeExecuted(); 471 menu->delegate_->CommandWillBeExecuted();
471 472
472 model->ActivatedCommand(command_id); 473 model->ActivatedCommand(command_id);
473 } 474 }
474 } 475 }
475 476
476 // static 477 // static
477 void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu, 478 void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu,
478 int* x, 479 int* x,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 if (GTK_IS_MENU_ITEM(widget)) { 599 if (GTK_IS_MENU_ITEM(widget)) {
599 gtk_widget_set_sensitive(widget, model->IsEnabledAt(id)); 600 gtk_widget_set_sensitive(widget, model->IsEnabledAt(id));
600 601
601 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); 602 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget));
602 if (submenu) { 603 if (submenu) {
603 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, 604 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo,
604 userdata); 605 userdata);
605 } 606 }
606 } 607 }
607 } 608 }
OLDNEW
« no previous file with comments | « app/menus/button_menu_item_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698