1 using System;
  2 using System.Collections;
  3 using System.Windows;
  4 
  5 namespace FileExplorer
  6 {
  7     public nothrow System.Windows.Color DefaultDirectoryTreeViewFrameColor()
  8     {
  9         return System.Windows.Color(204u206u219u);
 10     }
 11 
 12     public nothrow Padding DefaultDirectoryTreeViewNodeImagePadding()
 13     {
 14         return Padding(2222);
 15     }
 16 
 17     public nothrow float DefaultDirectoryTreeViewNodeIndentPercent()
 18     {
 19         return 100.0f;
 20     }
 21 
 22     public class DirectoryTreeView : ContainerControl
 23     {
 24         public DirectoryTreeView(ImageList* imageListComputerNode* computer_) : 
 25             base(ControlCreateParams().SetWindowClassName("FileExplorer.DirectoryTreeView").
 26             SetWindowClassBackgroundColor(SystemColor.COLOR_WINDOW).SetBackgroundColor(Color.White()).SetDock(Dock.fill))
 27             computer(computer_)
 28         {
 29             UniquePtr<TreeView> treeViewPtr(new TreeView(TreeViewCreateParams(TreeViewControlCreateParams(ControlCreateParams().Defaults())).
 30                 SetNodeImagePadding(DefaultDirectoryTreeViewNodeImagePadding()).SetNodeIndentPercent(DefaultDirectoryTreeViewNodeIndentPercent())));
 31             treeView = treeViewPtr.Get();
 32             treeView->SetDoubleBuffered();
 33             treeView->SetScrollSubject();
 34             treeView->SetImageList(imageList);
 35             treeView->NodeClickEvent().AddHandler(TreeViewNodeClick);
 36             treeView->NodeDoubleClickEvent().AddHandler(TreeViewNodeDoubleClick);
 37             UniquePtr<PaddedControl> paddedTreeViewPtr(new PaddedControl(
 38                 PaddedControlCreateParams(
 39                     PaddedControlControlCreateParams(
 40                         ControlCreateParams().Defaults()treeView)
 41                     treeViewPtr.Release()).Defaults()));
 42             PaddedControl* paddedTreeView = paddedTreeViewPtr.Get();
 43             UniquePtr<BorderedControl> borderedTreeViewPtr(new BorderedControl(
 44                 BorderedControlCreateParams(
 45                     BorderedControlControlCreateParams(
 46                         ControlCreateParams().Defaults()paddedTreeView)
 47                     paddedTreeViewPtr.Release()).SetNormalBorderColor(DefaultDirectoryTreeViewFrameColor())));
 48             BorderedControl* borderedTreeView = borderedTreeViewPtr.Get();
 49             UniquePtr<ScrollableControl> scrollableTreeViewPtr(new ScrollableControl(
 50                 ScrollableControlCreateParams(
 51                     ScrollableControlControlCreateParams(
 52                         ControlCreateParams().SetDock(Dock.fill)borderedTreeView)
 53                     borderedTreeViewPtr.Release()).Defaults()));
 54             child = scrollableTreeViewPtr.Get();
 55             AddChild(scrollableTreeViewPtr.Release());
 56             PopulateTreeView(imageList);
 57         }
 58         public nothrow void SetMainWindow(MainWindow* mainWindow_)
 59         {
 60             mainWindow = mainWindow_;
 61         }
 62         public void Open(Node* node)
 63         {
 64             TreeViewNode* treeViewNode = node->GetTreeViewNode();
 65             if (treeViewNode != null)
 66             {
 67                 TreeView* treeView = treeViewNode->GetTreeView();
 68                 treeView->SetContentLocation(Point(00));
 69                 TreeViewNode* parentNode = treeViewNode->Parent();
 70                 while (parentNode != null)
 71                 {
 72                     parentNode->Expand();
 73                     parentNode = parentNode->Parent();
 74                 }
 75                 treeViewNode->Select();
 76             }
 77         }
 78         public nothrow Node* SelectedNode() const
 79         {
 80             if (treeView != null)
 81             {
 82                 TreeViewNode* selectedNode = treeView->SelectedNode();
 83                 if (selectedNode != null)
 84                 {
 85                     void* data = selectedNode->Data();
 86                     if (data != null)
 87                     {
 88                         Node* node = cast<Node*>(data);
 89                         return node;
 90                     }
 91                 }
 92             }
 93             return null;
 94         }
 95         protected override void OnPaint(PaintEventArgs& args)
 96         {
 97             treeView->Invalidate();
 98             child->Invalidate();
 99             base->OnPaint(args);
100         }
101         private void PopulateTreeView(ImageList* imageList)
102         {
103             UniquePtr<TreeViewNode> rootPtr(computer->ToTreeViewNode(trueimageList));
104             TreeViewNode* root = rootPtr.Get();
105             treeView->SetRoot(rootPtr.Release());
106             root->Expand();
107         }
108         private void TreeViewNodeClick(TreeViewNodeMouseClickEventArgs& args)
109         {
110             if (mainWindow != null)
111             {
112                 TreeViewNode* treeViewNode = args.node;
113                 if (treeViewNode != null)
114                 {
115                     void* data = treeViewNode->Data();
116                     if (data != null)
117                     {
118                         Node* node = cast<Node*>(data);
119                         ContentView* contentView = mainWindow->GetContentView();
120                         if (contentView != null)
121                         {
122                             contentView->ViewContent(node);
123                             node->SetCurrentPathNode();
124                         }
125                     }
126                 }
127             }
128         }
129         private void TreeViewNodeDoubleClick(TreeViewNodeMouseClickEventArgs& args)
130         {
131             TreeViewNode* treeViewNode = args.node;
132             if (treeViewNode != null)
133             {
134                 Node* node = null;
135                 if (treeViewNode->Data() != null)
136                 {
137                     node = cast<Node*>(treeViewNode->Data());
138                 }
139                 if (treeViewNode->GetState() == TreeViewNode.State.collapsed)
140                 {
141                     treeViewNode->ExpandAll();
142                 }
143                 else if (treeViewNode->GetState() == TreeViewNode.State.expanded)
144                 {
145                     treeViewNode->CollapseAll();
146                 }
147             }
148         }
149         private MainWindow* mainWindow;
150         private TreeView* treeView;
151         private Control* child;
152         private ComputerNode* computer;
153     }
154 }
155