From fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a Mon Sep 17 00:00:00 2001 From: "erg@google.com" Date: Tue, 17 Feb 2009 19:02:45 +0000 Subject: 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 --- chrome/browser/gtk/menu_gtk.h | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 chrome/browser/gtk/menu_gtk.h (limited to 'chrome/browser/gtk/menu_gtk.h') 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 + +#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_ -- cgit v1.1