menu_util.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_GTK_MENU_UTIL_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_GTK_MENU_UTIL_H_
  6. #include <gtk/gtk.h>
  7. #include <string>
  8. #include "ui/gfx/image/image.h"
  9. namespace ui {
  10. class MenuModel;
  11. }
  12. namespace electron::gtkui {
  13. // Builds GtkImageMenuItems.
  14. GtkWidget* BuildMenuItemWithImage(const std::string& label, GtkWidget* image);
  15. GtkWidget* BuildMenuItemWithImage(const std::string& label,
  16. const gfx::Image& icon);
  17. GtkWidget* BuildMenuItemWithLabel(const std::string& label);
  18. ui::MenuModel* ModelForMenuItem(GtkMenuItem* menu_item);
  19. // This method is used to build the menu dynamically. The return value is the
  20. // new menu item.
  21. GtkWidget* AppendMenuItemToMenu(int index,
  22. ui::MenuModel* model,
  23. GtkWidget* menu_item,
  24. GtkWidget* menu,
  25. bool connect_to_activate,
  26. GCallback item_activated_cb,
  27. void* this_ptr);
  28. // Gets the ID of a menu item.
  29. // Returns true if the menu item has an ID.
  30. bool GetMenuItemID(GtkWidget* menu_item, int* menu_id);
  31. // Execute command associated with specified id.
  32. void ExecuteCommand(ui::MenuModel* model, int id);
  33. // Creates a GtkMenu from |model_|. block_activation_ptr is used to disable
  34. // the item_activated_callback while we set up the set up the menu items.
  35. // See comments in definition of SetMenuItemInfo for more info.
  36. void BuildSubmenuFromModel(ui::MenuModel* model,
  37. GtkWidget* menu,
  38. GCallback item_activated_cb,
  39. bool* block_activation,
  40. void* this_ptr);
  41. // Sets the check mark, enabled/disabled state and dynamic labels on menu items.
  42. void SetMenuItemInfo(GtkWidget* widget, void* block_activation_ptr);
  43. } // namespace electron::gtkui
  44. #endif // ELECTRON_SHELL_BROWSER_UI_GTK_MENU_UTIL_H_