OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 UI_VIEWS_CONTROLS_MENU_MENU_WRAPPER_H_ | |
6 #define UI_VIEWS_CONTROLS_MENU_MENU_WRAPPER_H_ | |
7 | |
8 #include "ui/gfx/native_widget_types.h" | |
9 #include "ui/views/views_export.h" | |
10 | |
11 namespace gfx { | |
12 class Point; | |
13 } | |
14 | |
15 namespace ui { | |
16 class MenuModel; | |
17 } | |
18 | |
19 namespace views { | |
20 | |
21 class MenuListener; | |
22 | |
23 // An interface that wraps an object that implements a menu. | |
24 class VIEWS_EXPORT MenuWrapper { | |
25 public: | |
26 class InsertionDelegate { | |
27 public: | |
28 // Returns the index to insert items into the menu at. | |
29 virtual int GetInsertionIndex(HMENU native_menu) = 0; | |
30 | |
31 protected: | |
32 virtual ~InsertionDelegate() {} | |
33 }; | |
34 | |
35 // All of the possible actions that can result from RunMenuAt. | |
36 enum MenuAction { | |
37 MENU_ACTION_NONE, // Menu cancelled, or never opened. | |
38 MENU_ACTION_SELECTED, // An item was selected. | |
39 MENU_ACTION_PREVIOUS, // User wants to navigate to the previous menu. | |
40 MENU_ACTION_NEXT, // User wants to navigate to the next menu. | |
41 }; | |
42 | |
43 virtual ~MenuWrapper() {} | |
44 | |
45 // Creates the appropriate instance of this wrapper for the current platform. | |
46 static MenuWrapper* CreateWrapper(ui::MenuModel* model); | |
47 | |
48 // Runs the menu at the specified point. This blocks until done. | |
49 virtual void RunMenuAt(const gfx::Point& point, int alignment) = 0; | |
50 | |
51 // Cancels the active menu. | |
52 virtual void CancelMenu() = 0; | |
53 | |
54 // Called when the model supplying data to this menu has changed, and the menu | |
55 // must be rebuilt. | |
56 virtual void Rebuild(InsertionDelegate* delegate) = 0; | |
57 | |
58 // Called when the states of the items in the menu must be updated from the | |
59 // model. | |
60 virtual void UpdateStates() = 0; | |
61 | |
62 // Retrieve a native menu handle. | |
63 virtual HMENU GetNativeMenu() const = 0; | |
64 | |
65 // Get the result of the last call to RunMenuAt to determine whether an | |
66 // item was selected, the user navigated to a next or previous menu, or | |
67 // nothing. | |
68 virtual MenuAction GetMenuAction() const = 0; | |
69 | |
70 // Add a listener to receive a callback when the menu opens. | |
71 virtual void AddMenuListener(MenuListener* listener) = 0; | |
72 | |
73 // Remove a menu listener. | |
74 virtual void RemoveMenuListener(MenuListener* listener) = 0; | |
75 | |
76 // Sets the minimum width of the menu. | |
77 virtual void SetMinimumWidth(int width) = 0; | |
78 }; | |
79 | |
80 } // namespace views | |
81 | |
82 #endif // UI_VIEWS_CONTROLS_MENU_MENU_WRAPPER_H_ | |
OLD | NEW |