blob: 3608fbc2cd5604c048444f1f76ccf76f63f4f391 [file] [log] [blame]
[email protected]405ed122008-11-14 17:48:401// Copyright (c) 2008 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 CHROME_VIEWS_TREE_MODEL_H_
6#define CHROME_VIEWS_TREE_MODEL_H_
7
8#include <string>
9
10#include "base/logging.h"
11
12class SkBitmap;
13
14namespace views {
15
16class TreeModel;
17
18// TreeModelNode --------------------------------------------------------------
19
20// Type of class returned from the model.
21class TreeModelNode {
22 public:
23 // Returns the title for the node.
24 virtual std::wstring GetTitle() = 0;
25};
26
27// Observer for the TreeModel. Notified of significant events to the model.
28class TreeModelObserver {
29 public:
30 // Notification that nodes were added to the specified parent.
31 virtual void TreeNodesAdded(TreeModel* model,
32 TreeModelNode* parent,
33 int start,
34 int count) = 0;
35
36 // Notification that nodes were removed from the specified parent.
37 virtual void TreeNodesRemoved(TreeModel* model,
38 TreeModelNode* parent,
39 int start,
40 int count) = 0;
41
[email protected]56c66f212009-02-26 17:51:5442 // Notification the children of |parent| have been reordered. Note, only
43 // the direct children of |parent| have been reordered, not descendants.
44 // TODO(sky): make this pure virtual after all sites have been updated.
45 virtual void TreeNodeChildrenReordered(TreeModel* model,
46 TreeModelNode* parent) {}
47
[email protected]405ed122008-11-14 17:48:4048 // Notification that the contents of a node has changed.
49 virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node) = 0;
50};
51
52// TreeModel ------------------------------------------------------------------
53
54// The model for TreeView.
55class TreeModel {
56 public:
57 // Returns the root of the tree. This may or may not be shown in the tree,
58 // see SetRootShown for details.
59 virtual TreeModelNode* GetRoot() = 0;
60
61 // Returns the number of children in the specified node.
62 virtual int GetChildCount(TreeModelNode* parent) = 0;
63
64 // Returns the child node at the specified index.
65 virtual TreeModelNode* GetChild(TreeModelNode* parent, int index) = 0;
66
67 // Returns the parent of a node, or NULL if node is the root.
68 virtual TreeModelNode* GetParent(TreeModelNode* node) = 0;
69
70 // Sets the observer of the model.
71 virtual void SetObserver(TreeModelObserver* observer) = 0;
72
73 // Sets the title of the specified node.
74 // This is only invoked if the node is editable and the user edits a node.
75 virtual void SetTitle(TreeModelNode* node,
76 const std::wstring& title) {
77 NOTREACHED();
78 }
79
80 // Returns the set of icons for the nodes in the tree. You only need override
81 // this if you don't want to use the default folder icons.
82 virtual void GetIcons(std::vector<SkBitmap>* icons) {}
83
84 // Returns the index of the icon to use for |node|. Return -1 to use the
85 // default icon. The index is relative to the list of icons returned from
86 // GetIcons.
87 virtual int GetIconIndex(TreeModelNode* node) { return -1; }
88};
89
90} // namespace views
91
92#endif // CHROME_VIEWS_TREE_MODEL_H_