diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 17:06:21 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 17:06:21 +0000 |
commit | 7209cb729d172a9aa8999dac0c9f6bd80f23c4c2 (patch) | |
tree | 5b0c62d482856faf0982378528031c1c8c4c9eff /chrome/browser/gtk/menu_gtk.cc | |
parent | 7838c2502799cbfe33ba16575b0e7d0b03740dd1 (diff) | |
download | chromium_src-7209cb729d172a9aa8999dac0c9f6bd80f23c4c2.zip chromium_src-7209cb729d172a9aa8999dac0c9f6bd80f23c4c2.tar.gz chromium_src-7209cb729d172a9aa8999dac0c9f6bd80f23c4c2.tar.bz2 |
GTK: Cleanups to the new wrench menu.
- Make the rendering for multiple buttons pretty by unifying sequnces of
buttons.
- Add the zoom label control and make the wrench menu model listen for
notifications about zoom percentage changing.
- Fixes crash that would have gone away once this was taken out from behind a flag
BUG=45757
TEST=none
Review URL: http://codereview.chromium.org/2799043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/menu_gtk.cc')
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 104b39f..d38b505 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -72,6 +72,33 @@ void OnSubmenuShow(GtkWidget* widget, gpointer user_data) { #endif } +void OnSubmenuShowButtonMenuItem(GtkWidget* widget, GtkButton* button) { + menus::ButtonMenuItemModel* model = + reinterpret_cast<menus::ButtonMenuItemModel*>( + g_object_get_data(G_OBJECT(button), "button-model")); + int index = GPOINTER_TO_INT(g_object_get_data( + G_OBJECT(button), "button-model-id")); + + std::string label = + ConvertAcceleratorsFromWindowsStyle( + UTF16ToUTF8(model->GetLabelAt(index))); + gtk_button_set_label(GTK_BUTTON(button), label.c_str()); +} + +void SetupDynamicLabelMenuButton(GtkWidget* button, + GtkWidget* menu, + menus::ButtonMenuItemModel* model, + int index) { + if (model->IsLabelDynamicAt(index)) { + g_object_set_data(G_OBJECT(button), "button-model", + reinterpret_cast<void*>(model)); + g_object_set_data(G_OBJECT(button), "button-model-id", + GINT_TO_POINTER(index)); + g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonMenuItem), + button); + } +} + // Popup menus may get squished if they open up too close to the bottom of the // screen. This function takes the size of the screen, the size of the menu, // an optional widget, the Y position of the mouse click, and adjusts the popup @@ -269,9 +296,7 @@ void MenuGtk::BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu) { case menus::MenuModel::TYPE_BUTTON_ITEM: { menus::ButtonMenuItemModel* button_menu_item_model = model->GetButtonMenuItemAt(i); - - menu_item = BuildButtomMenuItem(button_menu_item_model); - + menu_item = BuildButtomMenuItem(button_menu_item_model, menu); connect_to_activate = false; break; } @@ -316,9 +341,17 @@ void MenuGtk::BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu) { } } -GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model) { +GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model, + GtkWidget* menu) { GtkWidget* menu_item = gtk_custom_menu_item_new( RemoveWindowsStyleAccelerators(UTF16ToUTF8(model->label())).c_str()); + + // Set up the callback to the model for when it is clicked. + g_object_set_data(G_OBJECT(menu_item), "button-model", + reinterpret_cast<void*>(model)); + g_signal_connect(menu_item, "button-pushed", + G_CALLBACK(OnMenuButtonPressed), this); + for (int i = 0; i < model->GetItemCount(); ++i) { switch (model->GetTypeAt(i)) { case menus::ButtonMenuItemModel::TYPE_SPACE: { @@ -346,17 +379,23 @@ GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model) { UTF16ToUTF8(model->GetLabelAt(i))).c_str()); } - // TODO(erg): Set up dynamic labels here. + SetupDynamicLabelMenuButton(button, menu, model, i); + break; + } + case menus::ButtonMenuItemModel::TYPE_BUTTON_LABEL: { + GtkWidget* button = gtk_custom_menu_item_add_button_label( + GTK_CUSTOM_MENU_ITEM(menu_item), + model->GetCommandIdAt(i)); + gtk_button_set_label( + GTK_BUTTON(button), + RemoveWindowsStyleAccelerators( + UTF16ToUTF8(model->GetLabelAt(i))).c_str()); + SetupDynamicLabelMenuButton(button, menu, model, i); break; } } } - // Set up the callback to the model for when it is clicked. - g_object_set_data(G_OBJECT(menu_item), "button-model", - reinterpret_cast<void*>(model)); - g_signal_connect(menu_item, "button-pushed", - G_CALLBACK(OnMenuButtonPressed), this); return menu_item; } |