diff options
-rw-r--r-- | chrome/browser/views/options/cookies_view.cc | 3 | ||||
-rw-r--r-- | views/controls/tree/tree_view.cc | 9 | ||||
-rw-r--r-- | views/controls/tree/tree_view.h | 27 |
3 files changed, 35 insertions, 4 deletions
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 2fe5ac7..b287582 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -415,8 +415,9 @@ void CookiesView::Init() { layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(1, single_column_layout_id); + cookies_tree_->set_lines_at_root(true); + cookies_tree_->set_auto_expand_children(true); layout->AddView(cookies_tree_); - cookies_tree_->ExpandAll(); cookies_tree_->SetController(this); diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index f3888e6..0c2a7c6 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -26,11 +26,13 @@ namespace views { TreeView::TreeView() : tree_view_(NULL), model_(NULL), + auto_expand_children_(false), editable_(true), next_id_(0), controller_(NULL), editing_node_(NULL), root_shown_(true), + lines_at_root_(false), process_enter_(false), show_context_menu_only_when_node_selected_(true), select_on_right_mouse_down_(true), @@ -351,6 +353,8 @@ HWND TreeView::CreateNativeControl(HWND parent_container) { style |= TVS_DISABLEDRAGDROP; if (editable_) style |= TVS_EDITLABELS; + if (lines_at_root_) + style |= TVS_LINESATROOT; tree_view_ = ::CreateWindowEx(WS_EX_CLIENTEDGE | GetAdditionalExStyle(), WC_TREEVIEW, L"", @@ -415,9 +419,12 @@ LRESULT TreeView::OnNotify(int w_param, LPNMHDR l_param) { GetNodeDetailsByID(static_cast<int>(info->itemNew.lParam)); if (!details->loaded_children) { details->loaded_children = true; - for (int i = 0; i < model_->GetChildCount(details->node); ++i) + for (int i = 0; i < model_->GetChildCount(details->node); ++i) { CreateItem(details->tree_item, TVI_LAST, model_->GetChild(details->node, i)); + if (auto_expand_children_) + Expand(model_->GetChild(details->node, i)); + } } // Return FALSE to allow the item to be expanded. return FALSE; diff --git a/views/controls/tree/tree_view.h b/views/controls/tree/tree_view.h index c81452c..cc2c8a1 100644 --- a/views/controls/tree/tree_view.h +++ b/views/controls/tree/tree_view.h @@ -57,10 +57,27 @@ class TreeView : public NativeControl, TreeModelObserver { void SetModel(TreeModel* model); TreeModel* model() const { return model_; } + // Sets whether to automatically expand children when a parent node is + // expanded. The default is false. If true, when a node in the tree is + // expanded for the first time, its children are also automatically expanded. + // If a node is subsequently collapsed and expanded again, the children + // will not be automatically expanded. + void set_auto_expand_children(bool auto_expand_children) { + auto_expand_children_ = auto_expand_children; + } + // Sets whether the user can edit the nodes. The default is true. If true, // the Controller is queried to determine if a particular node can be edited. void SetEditable(bool editable); + // Sets whether lines are drawn from the root node to child nodes (and + // whether plus boxes show up next to the root node.) The default is false. + // If root_shown_ is false, the children of the root act as the roots in the + // native control, and so this setting takes effect for them. + void set_lines_at_root(bool lines_at_root) { + lines_at_root_ = lines_at_root; + } + // Edits the specified node. This cancels the current edit and expands // all parents of node. void StartEditing(TreeModelNode* node); @@ -257,10 +274,13 @@ class TreeView : public NativeControl, TreeModelObserver { TreeModel* model_; // Maps from id to NodeDetails. - std::map<int,NodeDetails*> id_to_details_map_; + std::map<int, NodeDetails*> id_to_details_map_; // Maps from model entry to NodeDetails. - std::map<TreeModelNode*,NodeDetails*> node_to_details_map_; + std::map<TreeModelNode*, NodeDetails*> node_to_details_map_; + + // Whether to automatically expand children when a parent node is expanded. + bool auto_expand_children_; // Whether the user can edit the items. bool editable_; @@ -277,6 +297,9 @@ class TreeView : public NativeControl, TreeModelObserver { // Whether or not the root is shown in the tree. bool root_shown_; + // Whether lines are drawn from the root to the children. + bool lines_at_root_; + // Whether enter should be processed by the tree when not editing. bool process_enter_; |