OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 |
| 5 #ifndef CHROME_BROWSER_GTK_MENU_GTK_H_ |
| 6 #define CHROME_BROWSER_GTK_MENU_GTK_H_ |
| 7 |
| 8 #include <gtk/gtk.h> |
| 9 |
| 10 #include "chrome/browser/gtk/standard_menus.h" |
| 11 |
| 12 class MenuGtk { |
| 13 public: |
| 14 // Delegate class that lets another class control the status of the menu. |
| 15 class Delegate { |
| 16 public: |
| 17 virtual ~Delegate() { } |
| 18 |
| 19 // Returns whether the menu item for this command should be enabled. |
| 20 virtual bool IsCommandEnabled(int command_id) const = 0; |
| 21 |
| 22 // Returns whether this command. |
| 23 virtual bool IsItemChecked(int command_id) const = 0; |
| 24 |
| 25 // Executes the command. |
| 26 virtual void ExecuteCommand(int command_id) = 0; |
| 27 }; |
| 28 |
| 29 MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data); |
| 30 ~MenuGtk(); |
| 31 |
| 32 // Displays the menu |
| 33 void Popup(GtkWidget* widget, GdkEvent* event); |
| 34 |
| 35 private: |
| 36 // A recursive function that transforms a MenuCreateMaterial tree into a set |
| 37 // of GtkMenuItems. |
| 38 void BuildMenuIn(GtkWidget* menu, const MenuCreateMaterial* menu_data); |
| 39 |
| 40 // Callback for when a menu item is clicked. |
| 41 static void OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu); |
| 42 |
| 43 // Repositions the menu to be right under the button. |
| 44 static void MenuPositionFunc(GtkMenu* menu, |
| 45 int* x, |
| 46 int* y, |
| 47 gboolean* push_in, |
| 48 void* void_widget); |
| 49 |
| 50 // Sets the check mark and enabled/disabled state on our menu items. |
| 51 static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu); |
| 52 |
| 53 // Queries this object about the menu state. |
| 54 MenuGtk::Delegate* delegate_; |
| 55 |
| 56 // gtk_menu_popup() does not appear to take ownership of popup menus, so |
| 57 // MenuGtk explicitly manages the lifetime of the menu. |
| 58 GtkWidget* menu_; |
| 59 }; |
| 60 |
| 61 #endif // CHROME_BROWSER_GTK_MENU_GTK_H_ |
OLD | NEW |