summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/menu_gtk.h
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-17 19:02:45 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-17 19:02:45 +0000
commitfa990bb1e3c09ffb4f47418fcad2b8f6d322a75a (patch)
tree28d314754a9859626f9d66518912761e86502b2e /chrome/browser/gtk/menu_gtk.h
parent500c9f12f3f90e82ad0108edbfd35fc499d5b21d (diff)
downloadchromium_src-fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a.zip
chromium_src-fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a.tar.gz
chromium_src-fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a.tar.bz2
Create a menu wrapper class for GTK menus, and use it for the page and app menus.
Review URL: http://codereview.chromium.org/20245 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/menu_gtk.h')
-rw-r--r--chrome/browser/gtk/menu_gtk.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h
new file mode 100644
index 0000000..462c122
--- /dev/null
+++ b/chrome/browser/gtk/menu_gtk.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_GTK_MENU_GTK_H_
+#define CHROME_BROWSER_GTK_MENU_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/gtk/standard_menus.h"
+
+class MenuGtk {
+ public:
+ // Delegate class that lets another class control the status of the menu.
+ class Delegate {
+ public:
+ virtual ~Delegate() { }
+
+ // Returns whether the menu item for this command should be enabled.
+ virtual bool IsCommandEnabled(int command_id) const = 0;
+
+ // Returns whether this command.
+ virtual bool IsItemChecked(int command_id) const = 0;
+
+ // Executes the command.
+ virtual void ExecuteCommand(int command_id) = 0;
+ };
+
+ MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data);
+ ~MenuGtk();
+
+ // Displays the menu
+ void Popup(GtkWidget* widget, GdkEvent* event);
+
+ private:
+ // A recursive function that transforms a MenuCreateMaterial tree into a set
+ // of GtkMenuItems.
+ void BuildMenuIn(GtkWidget* menu, const MenuCreateMaterial* menu_data);
+
+ // Callback for when a menu item is clicked.
+ static void OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu);
+
+ // Repositions the menu to be right under the button.
+ static void MenuPositionFunc(GtkMenu* menu,
+ int* x,
+ int* y,
+ gboolean* push_in,
+ void* void_widget);
+
+ // Sets the check mark and enabled/disabled state on our menu items.
+ static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu);
+
+ // Queries this object about the menu state.
+ MenuGtk::Delegate* delegate_;
+
+ // gtk_menu_popup() does not appear to take ownership of popup menus, so
+ // MenuGtk explicitly manages the lifetime of the menu.
+ GtkWidget* menu_;
+};
+
+#endif // CHROME_BROWSER_GTK_MENU_GTK_H_