[email protected] | 405ed12 | 2008-11-14 17:48:40 | [diff] [blame] | 1 | // 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] | 992c625 | 2009-05-13 18:54:20 | [diff] [blame^] | 5 | #ifndef APP_TREE_MODEL_H_ |
| 6 | #define APP_TREE_MODEL_H_ |
[email protected] | 405ed12 | 2008-11-14 17:48:40 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/logging.h" |
| 11 | |
| 12 | class SkBitmap; |
| 13 | |
[email protected] | 405ed12 | 2008-11-14 17:48:40 | [diff] [blame] | 14 | class TreeModel; |
| 15 | |
| 16 | // TreeModelNode -------------------------------------------------------------- |
| 17 | |
| 18 | // Type of class returned from the model. |
| 19 | class 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. |
| 26 | class 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] | 56c66f21 | 2009-02-26 17:51:54 | [diff] [blame] | 40 | // Notification the children of |parent| have been reordered. Note, only |
| 41 | // the direct children of |parent| have been reordered, not descendants. |
[email protected] | 56c66f21 | 2009-02-26 17:51:54 | [diff] [blame] | 42 | virtual void TreeNodeChildrenReordered(TreeModel* model, |
[email protected] | 58b359d | 2009-02-27 22:05:08 | [diff] [blame] | 43 | TreeModelNode* parent) = 0; |
[email protected] | 56c66f21 | 2009-02-26 17:51:54 | [diff] [blame] | 44 | |
[email protected] | 405ed12 | 2008-11-14 17:48:40 | [diff] [blame] | 45 | // 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. |
| 52 | class 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] | 992c625 | 2009-05-13 18:54:20 | [diff] [blame^] | 87 | #endif // APP_TREE_TREE_MODEL_H_ |