OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GTK_MENU_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_MENU_GTK_H_ |
6 #define CHROME_BROWSER_GTK_MENU_GTK_H_ | 6 #define CHROME_BROWSER_GTK_MENU_GTK_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "gfx/point.h" | 14 #include "gfx/point.h" |
15 | 15 |
16 class SkBitmap; | 16 class SkBitmap; |
17 | 17 |
18 namespace menus { | 18 namespace menus { |
| 19 class ButtonMenuItemModel; |
19 class MenuModel; | 20 class MenuModel; |
20 } | 21 } |
21 | 22 |
22 class MenuGtk { | 23 class MenuGtk { |
23 public: | 24 public: |
24 // Delegate class that lets another class control the status of the menu. | 25 // Delegate class that lets another class control the status of the menu. |
25 class Delegate { | 26 class Delegate { |
26 public: | 27 public: |
27 virtual ~Delegate() { } | 28 virtual ~Delegate() { } |
28 | 29 |
(...skipping 24 matching lines...) Expand all Loading... |
53 // is the new menu item. | 54 // is the new menu item. |
54 GtkWidget* AppendMenuItemWithLabel(int command_id, const std::string& label); | 55 GtkWidget* AppendMenuItemWithLabel(int command_id, const std::string& label); |
55 GtkWidget* AppendMenuItemWithIcon(int command_id, const std::string& label, | 56 GtkWidget* AppendMenuItemWithIcon(int command_id, const std::string& label, |
56 const SkBitmap& icon); | 57 const SkBitmap& icon); |
57 GtkWidget* AppendCheckMenuItemWithLabel(int command_id, | 58 GtkWidget* AppendCheckMenuItemWithLabel(int command_id, |
58 const std::string& label); | 59 const std::string& label); |
59 GtkWidget* AppendSeparator(); | 60 GtkWidget* AppendSeparator(); |
60 GtkWidget* AppendMenuItem(int command_id, GtkWidget* menu_item); | 61 GtkWidget* AppendMenuItem(int command_id, GtkWidget* menu_item); |
61 GtkWidget* AppendMenuItemToMenu(int command_id, | 62 GtkWidget* AppendMenuItemToMenu(int command_id, |
62 GtkWidget* menu_item, | 63 GtkWidget* menu_item, |
63 GtkWidget* menu); | 64 GtkWidget* menu, |
| 65 bool connect_to_activate); |
64 | 66 |
65 // Displays the menu. |timestamp| is the time of activation. The popup is | 67 // Displays the menu. |timestamp| is the time of activation. The popup is |
66 // statically positioned at |widget|. | 68 // statically positioned at |widget|. |
67 void Popup(GtkWidget* widget, gint button_type, guint32 timestamp); | 69 void Popup(GtkWidget* widget, gint button_type, guint32 timestamp); |
68 | 70 |
69 // Displays the menu using the button type and timestamp of |event|. The popup | 71 // Displays the menu using the button type and timestamp of |event|. The popup |
70 // is statically positioned at |widget|. | 72 // is statically positioned at |widget|. |
71 void Popup(GtkWidget* widget, GdkEvent* event); | 73 void Popup(GtkWidget* widget, GdkEvent* event); |
72 | 74 |
73 // Displays the menu as a context menu, i.e. at the current cursor location. | 75 // Displays the menu as a context menu, i.e. at the current cursor location. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 109 |
108 private: | 110 private: |
109 // Builds a GtkImageMenuItem. | 111 // Builds a GtkImageMenuItem. |
110 GtkWidget* BuildMenuItemWithImage(const std::string& label, | 112 GtkWidget* BuildMenuItemWithImage(const std::string& label, |
111 const SkBitmap& icon); | 113 const SkBitmap& icon); |
112 | 114 |
113 // A function that creates a GtkMenu from |model_|. | 115 // A function that creates a GtkMenu from |model_|. |
114 void BuildMenuFromModel(); | 116 void BuildMenuFromModel(); |
115 // Implementation of the above; called recursively. | 117 // Implementation of the above; called recursively. |
116 void BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu); | 118 void BuildSubmenuFromModel(menus::MenuModel* model, GtkWidget* menu); |
| 119 // Builds a menu item with buttons in it from the data in the model. |
| 120 GtkWidget* BuildButtomMenuItem(menus::ButtonMenuItemModel* model); |
117 | 121 |
118 // Contains implementation for OnMenuShow. | 122 // Contains implementation for OnMenuShow. |
119 void UpdateMenu(); | 123 void UpdateMenu(); |
120 | 124 |
121 void ExecuteCommand(menus::MenuModel* model, int id); | 125 void ExecuteCommand(menus::MenuModel* model, int id); |
122 | 126 |
123 // Callback for when a menu item is clicked. | 127 // Callback for when a menu item is clicked. |
124 static void OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu); | 128 static void OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu); |
125 | 129 |
| 130 // Called when one of the buttons are pressed. |
| 131 static void OnMenuButtonPressed(GtkMenuItem* menuitem, int command_id, |
| 132 MenuGtk* menu); |
| 133 |
126 // Sets the check mark and enabled/disabled state on our menu items. | 134 // Sets the check mark and enabled/disabled state on our menu items. |
127 static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu); | 135 static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu); |
128 | 136 |
129 // Updates all the menu items' state. | 137 // Updates all the menu items' state. |
130 static void OnMenuShow(GtkWidget* widget, MenuGtk* menu); | 138 static void OnMenuShow(GtkWidget* widget, MenuGtk* menu); |
131 | 139 |
132 // Sets the activating widget back to a normal appearance. | 140 // Sets the activating widget back to a normal appearance. |
133 static void OnMenuHidden(GtkWidget* widget, MenuGtk* menu); | 141 static void OnMenuHidden(GtkWidget* widget, MenuGtk* menu); |
134 | 142 |
135 // Queries this object about the menu state. | 143 // Queries this object about the menu state. |
(...skipping 17 matching lines...) Expand all Loading... |
153 // menu. | 161 // menu. |
154 static bool block_activation_; | 162 static bool block_activation_; |
155 | 163 |
156 // We must free these at shutdown. | 164 // We must free these at shutdown. |
157 std::vector<MenuGtk*> submenus_we_own_; | 165 std::vector<MenuGtk*> submenus_we_own_; |
158 | 166 |
159 ScopedRunnableMethodFactory<MenuGtk> factory_; | 167 ScopedRunnableMethodFactory<MenuGtk> factory_; |
160 }; | 168 }; |
161 | 169 |
162 #endif // CHROME_BROWSER_GTK_MENU_GTK_H_ | 170 #endif // CHROME_BROWSER_GTK_MENU_GTK_H_ |
OLD | NEW |