Another take on menu's. This uses the hosting menu scroll view container as a menuba...
[chromium-blink-merge.git] / app / tree_model.h
blobe191745d9f0fbdc24ef6edc8a318b30e56329ac2
1 // Copyright (c) 2009 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 APP_TREE_MODEL_H_
6 #define APP_TREE_MODEL_H_
7 #pragma once
9 #include <string>
10 #include <vector>
12 #include "base/logging.h"
14 class SkBitmap;
16 class TreeModel;
18 // TreeModelNode --------------------------------------------------------------
20 // Type of class returned from the model.
21 class TreeModelNode {
22 public:
23 // Returns the title for the node.
24 virtual std::wstring GetTitle() const = 0;
26 protected:
27 virtual ~TreeModelNode() {}
30 // Observer for the TreeModel. Notified of significant events to the model.
31 class TreeModelObserver {
32 public:
33 // Notification that nodes were added to the specified parent.
34 virtual void TreeNodesAdded(TreeModel* model,
35 TreeModelNode* parent,
36 int start,
37 int count) = 0;
39 // Notification that nodes were removed from the specified parent.
40 virtual void TreeNodesRemoved(TreeModel* model,
41 TreeModelNode* parent,
42 int start,
43 int count) = 0;
45 // Notification that the contents of a node has changed.
46 virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node) = 0;
48 protected:
49 virtual ~TreeModelObserver() {}
52 // TreeModel ------------------------------------------------------------------
54 // The model for TreeView.
55 class 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;
61 // Returns the number of children in the specified node.
62 virtual int GetChildCount(TreeModelNode* parent) = 0;
64 // Returns the child node at the specified index.
65 virtual TreeModelNode* GetChild(TreeModelNode* parent, int index) = 0;
67 // Returns the index of child node at the specified index.
68 virtual int IndexOfChild(TreeModelNode* parent, TreeModelNode* child) = 0;
70 // Returns the parent of a node, or NULL if node is the root.
71 virtual TreeModelNode* GetParent(TreeModelNode* node) = 0;
73 // Adds an observer of the model.
74 virtual void AddObserver(TreeModelObserver* observer) = 0;
76 // Removes an observer of the model.
77 virtual void RemoveObserver(TreeModelObserver* observer) = 0;
79 // Sets the title of the specified node.
80 // This is only invoked if the node is editable and the user edits a node.
81 virtual void SetTitle(TreeModelNode* node,
82 const std::wstring& title) {
83 NOTREACHED();
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<SkBitmap>* 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
92 // GetIcons.
93 virtual int GetIconIndex(TreeModelNode* node) { return -1; }
95 protected:
96 virtual ~TreeModel() {}
99 #endif // APP_TREE_MODEL_H_