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_BASE_MODELS_TREE_MODEL_H_
6 #define UI_BASE_MODELS_TREE_MODEL_H_
10 #include "base/strings/string16.h"
11 #include "ui/base/ui_base_export.h"
21 // TreeModelNode --------------------------------------------------------------
23 // Type of class returned from the model.
26 // Returns the title for the node.
27 virtual const base::string16
& GetTitle() const = 0;
30 virtual ~TreeModelNode() {}
33 // Observer for the TreeModel. Notified of significant events to the model.
34 class UI_BASE_EXPORT TreeModelObserver
{
36 // Notification that nodes were added to the specified parent.
37 virtual void TreeNodesAdded(TreeModel
* model
,
38 TreeModelNode
* parent
,
42 // Notification that nodes were removed from the specified parent.
43 virtual void TreeNodesRemoved(TreeModel
* model
,
44 TreeModelNode
* parent
,
48 // Notification that the contents of a node has changed.
49 virtual void TreeNodeChanged(TreeModel
* model
, TreeModelNode
* node
) = 0;
52 virtual ~TreeModelObserver() {}
55 // TreeModel ------------------------------------------------------------------
57 // The model for TreeView.
58 class UI_BASE_EXPORT TreeModel
{
60 // Returns the root of the tree. This may or may not be shown in the tree,
61 // see SetRootShown for details.
62 virtual TreeModelNode
* GetRoot() = 0;
64 // Returns the number of children in |parent|.
65 virtual int GetChildCount(TreeModelNode
* parent
) = 0;
67 // Returns the child node of |parent| at |index|.
68 virtual TreeModelNode
* GetChild(TreeModelNode
* parent
, int index
) = 0;
70 // Returns the index of |child| in |parent|.
71 virtual int GetIndexOf(TreeModelNode
* parent
, TreeModelNode
* child
) = 0;
73 // Returns the parent of |node|, or NULL if |node| is the root.
74 virtual TreeModelNode
* GetParent(TreeModelNode
* node
) = 0;
76 // Adds an observer of the model.
77 virtual void AddObserver(TreeModelObserver
* observer
) = 0;
79 // Removes an observer of the model.
80 virtual void RemoveObserver(TreeModelObserver
* observer
) = 0;
82 // Sets the title of |node|.
83 // This is only invoked if the node is editable and the user edits a node.
84 virtual void SetTitle(TreeModelNode
* node
, const base::string16
& title
);
86 // Returns the set of icons for the nodes in the tree. You only need override
87 // this if you don't want to use the default folder icons.
88 virtual void GetIcons(std::vector
<gfx::ImageSkia
>* icons
) {}
90 // Returns the index of the icon to use for |node|. Return -1 to use the
91 // default icon. The index is relative to the list of icons returned from
93 virtual int GetIconIndex(TreeModelNode
* node
);
96 virtual ~TreeModel() {}
101 #endif // UI_BASE_MODELS_TREE_MODEL_H_