2020-06-03 00:00:20 +00:00
|
|
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_GTK_MENU_UTIL_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_GTK_MENU_UTIL_H_
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2023-10-05 23:59:39 +00:00
|
|
|
#include "base/functional/callback.h"
|
|
|
|
#include "ui/base/glib/scoped_gsignal.h"
|
2020-06-03 00:00:20 +00:00
|
|
|
#include "ui/gfx/image/image.h"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
class MenuModel;
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::gtkui {
|
2020-06-03 00:00:20 +00:00
|
|
|
|
2023-10-05 23:59:39 +00:00
|
|
|
using MenuActivatedCallback = base::RepeatingCallback<void(GtkWidget*)>;
|
|
|
|
|
2020-06-03 00:00:20 +00:00
|
|
|
// Builds GtkImageMenuItems.
|
|
|
|
GtkWidget* BuildMenuItemWithImage(const std::string& label, GtkWidget* image);
|
|
|
|
GtkWidget* BuildMenuItemWithImage(const std::string& label,
|
|
|
|
const gfx::Image& icon);
|
|
|
|
GtkWidget* BuildMenuItemWithLabel(const std::string& label);
|
|
|
|
|
|
|
|
ui::MenuModel* ModelForMenuItem(GtkMenuItem* menu_item);
|
|
|
|
|
|
|
|
// This method is used to build the menu dynamically. The return value is the
|
|
|
|
// new menu item.
|
|
|
|
GtkWidget* AppendMenuItemToMenu(int index,
|
|
|
|
ui::MenuModel* model,
|
|
|
|
GtkWidget* menu_item,
|
|
|
|
GtkWidget* menu,
|
|
|
|
bool connect_to_activate,
|
2023-10-05 23:59:39 +00:00
|
|
|
MenuActivatedCallback item_activated_cb,
|
|
|
|
std::vector<ScopedGSignal>* signals);
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
// Gets the ID of a menu item.
|
|
|
|
// Returns true if the menu item has an ID.
|
|
|
|
bool GetMenuItemID(GtkWidget* menu_item, int* menu_id);
|
|
|
|
|
|
|
|
// Execute command associated with specified id.
|
|
|
|
void ExecuteCommand(ui::MenuModel* model, int id);
|
|
|
|
|
|
|
|
// Creates a GtkMenu from |model_|. block_activation_ptr is used to disable
|
|
|
|
// the item_activated_callback while we set up the set up the menu items.
|
|
|
|
// See comments in definition of SetMenuItemInfo for more info.
|
|
|
|
void BuildSubmenuFromModel(ui::MenuModel* model,
|
|
|
|
GtkWidget* menu,
|
2023-10-05 23:59:39 +00:00
|
|
|
MenuActivatedCallback item_activated_cb,
|
2020-06-03 00:00:20 +00:00
|
|
|
bool* block_activation,
|
2023-10-05 23:59:39 +00:00
|
|
|
std::vector<ScopedGSignal>* signals);
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
// Sets the check mark, enabled/disabled state and dynamic labels on menu items.
|
|
|
|
void SetMenuItemInfo(GtkWidget* widget, void* block_activation_ptr);
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::gtkui
|
2020-06-03 00:00:20 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_GTK_MENU_UTIL_H_
|