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