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.
5 #ifndef UI_VIEWS_EXAMPLES_TREE_VIEW_EXAMPLE_H_
6 #define UI_VIEWS_EXAMPLES_TREE_VIEW_EXAMPLE_H_
8 #include "base/macros.h"
9 #include "ui/base/models/simple_menu_model.h"
10 #include "ui/base/models/tree_node_model.h"
11 #include "ui/views/context_menu_controller.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/tree/tree_view_controller.h"
14 #include "ui/views/examples/example_base.h"
23 class VIEWS_EXAMPLES_EXPORT TreeViewExample
25 public ButtonListener
,
26 public TreeViewController
,
27 public ContextMenuController
,
28 public ui::SimpleMenuModel::Delegate
{
31 ~TreeViewExample() override
;
34 void CreateExampleView(View
* container
) override
;
37 // IDs used by the context menu.
47 // Non-const version of IsCommandIdEnabled.
48 bool IsCommandIdEnabled(int command_id
);
51 void ButtonPressed(Button
* sender
, const ui::Event
& event
) override
;
53 // TreeViewController:
54 void OnTreeViewSelectionChanged(TreeView
* tree_view
) override
;
55 bool CanEdit(TreeView
* tree_view
, ui::TreeModelNode
* node
) override
;
57 // ContextMenuController:
58 void ShowContextMenuForView(View
* source
,
59 const gfx::Point
& point
,
60 ui::MenuSourceType source_type
) override
;
62 // SimpleMenuModel::Delegate:
63 bool IsCommandIdChecked(int command_id
) const override
;
64 bool IsCommandIdEnabled(int command_id
) const override
;
65 bool GetAcceleratorForCommandId(int command_id
,
66 ui::Accelerator
* accelerator
) override
;
67 void ExecuteCommand(int command_id
, int event_flags
) override
;
69 // The tree view to be tested.
72 // Control buttons to modify the model.
75 Button
* change_title_
;
77 typedef ui::TreeNodeWithValue
<int> NodeType
;
79 ui::TreeNodeModel
<NodeType
> model_
;
81 scoped_ptr
<MenuRunner
> context_menu_runner_
;
83 DISALLOW_COPY_AND_ASSIGN(TreeViewExample
);
86 } // namespace examples
89 #endif // UI_VIEWS_EXAMPLES_TREE_VIEW_EXAMPLE_H_