summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorian@chromium.org <ian@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-18 17:27:45 +0000
committerian@chromium.org <ian@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-18 17:27:45 +0000
commit9f07e60d403013e3f17b5dd55e5031318c34d4cd (patch)
tree2a77f71eec1bfe99effe284cea5e6b127ec3e3ee /views
parent5d71030fd14f4481f1e574d28042c9f86731c933 (diff)
downloadchromium_src-9f07e60d403013e3f17b5dd55e5031318c34d4cd.zip
chromium_src-9f07e60d403013e3f17b5dd55e5031318c34d4cd.tar.gz
chromium_src-9f07e60d403013e3f17b5dd55e5031318c34d4cd.tar.bz2
Add an option to tree_view for whether to show lines from the root node
to children nodes (sets TVS_LINESATROOT). Set this to false by default (maintaining existing behaviour by default), except for cookies_view where we set it to true. BUG=27657 TEST=open cookies dialog, make sure the origins have a + box next to them, and that expanding these also expands the cookies folder beneath them. Review URL: http://codereview.chromium.org/399030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32334 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/tree/tree_view.cc9
-rw-r--r--views/controls/tree/tree_view.h27
2 files changed, 33 insertions, 3 deletions
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_;