1 // Copyright (c) 2011 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.
5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_2_H_
6 #define UI_VIEWS_CONTROLS_MENU_MENU_2_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/views/controls/menu/menu_wrapper.h"
12 #include "ui/views/views_export.h"
24 // A menu. Populated from a model, and relies on a delegate to execute commands.
26 // WARNING: do NOT create and use Menu2 on the stack. Menu2 notifies the model
27 // of selection AFTER a delay. This means that if use a Menu2 on the stack
28 // ActivatedAt is never invoked.
29 class VIEWS_EXPORT Menu2
{
31 // How the menu is aligned relative to the point it is shown at.
32 // The alignment is reversed by menu if text direction is right to left.
38 // Creates a new menu populated with the contents of |model|.
39 // WARNING: this populates the menu on construction by invoking methods on
40 // the model. As such, it is typically not safe to use this as the model
41 // from the constructor. EG:
42 // MyClass : menu_(this) {}
43 // is likely to have problems.
44 explicit Menu2(ui::MenuModel
* model
);
47 // Runs the menu at the specified point. This method blocks until done.
48 // RunContextMenuAt is the same, but the alignment is the default for a
50 void RunMenuAt(const gfx::Point
& point
, Alignment alignment
);
51 void RunContextMenuAt(const gfx::Point
& point
);
53 // Cancels the active menu.
56 // Called when the model supplying data to this menu has changed, and the menu
60 // Called when the states of the menu items in the menu should be refreshed
65 HMENU
GetNativeMenu() const;
67 // Get the result of the last call to RunMenuAt to determine whether an
68 // item was selected, the user navigated to a next or previous menu, or
70 MenuWrapper::MenuAction
GetMenuAction() const;
72 // Add a listener to receive a callback when the menu opens.
73 void AddMenuListener(MenuListener
* listener
);
75 // Remove a menu listener.
76 void RemoveMenuListener(MenuListener
* listener
);
79 ui::MenuModel
* model() const { return model_
; }
81 // Sets the minimum width of the menu.
82 void SetMinimumWidth(int width
);
86 ui::MenuModel
* model_
;
88 // The object that actually implements the menu.
89 scoped_ptr
<MenuWrapper
> wrapper_
;
91 DISALLOW_COPY_AND_ASSIGN(Menu2
);
96 #endif // UI_VIEWS_CONTROLS_MENU_MENU_2_H_