2
// <copyright see="prj:///doc/copyright.txt"/>
3
// <license see="prj:///doc/license.txt"/>
4
// <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
5
// <version>$Revision$</version>
9
using System.Collections;
10
using System.Reflection;
11
using System.Windows.Forms;
15
namespace NoGoop.Controls
17
// You must add the parent of this control to the control
18
// you want to be the parent. The parent of this control
19
// is a TreeListPanel which does some funny things in the
21
public class TreeListView : TreeView
23
protected TreeListPanel _panel;
26
protected bool _inMouseDown;
27
protected bool _selected;
29
protected bool _useCompareTo;
31
// For now, just make this an untyped array list
32
// Though its really supposed to contain only column headers
33
public class ColumnHeaderCollection : ArrayList
37
protected ColumnHeaderCollection _columns;
39
internal Panel Panel {
45
internal bool UseCompareTo {
50
_useCompareTo = value;
56
_columns = new ColumnHeaderCollection();
57
_panel = new TreeListPanel();
58
_panel.TreeListView = this;
62
// Called after this control is set up with its properties
63
internal void SetupPanel()
68
internal ColumnHeaderCollection Columns {
74
internal TreeNode FindNodeByFullPath(String fullPath)
76
return FindNodeByFullPathInt(Nodes, fullPath);
79
internal TreeNode FindNodeByFullPathInt(TreeNodeCollection nodes, String fullPath)
81
int pathSep = fullPath.IndexOf(PathSeparator);
86
partPath = fullPath.Substring(0, pathSep);
88
foreach (TreeNode node in nodes)
90
if (node.Text.Equals(partPath))
92
// We are at the bottom
95
String restPath = fullPath.Substring
96
(PathSeparator.Length + pathSep);
97
return FindNodeByFullPathInt(node.Nodes,
105
// Used to allow normal selection processing if the node
106
// is explicitly selected
107
// This must be used instead of the SelectedNode property to
108
// *set* the SelectedNode
109
public void SetSelectedNode(TreeNode node)
111
// Allow selection processing to happen
116
// This is here just to invoke this private method using
118
internal TreeListNode GetNodeFromHandle(int handle)
120
MethodInfo m = typeof(TreeView).GetMethod("NodeFromHandle",
121
BindingFlags.Instance |
122
BindingFlags.NonPublic);
123
ParameterInfo[] p = m.GetParameters();
124
Object[] paramValues = new Object[1];
125
paramValues[0] = (IntPtr)handle;
126
return (TreeListNode)m.Invoke(this, paramValues);
129
internal virtual void HScrolled()
131
// Meant to be overridden
134
internal virtual void VScrolled()
136
// Meant to be overridden
139
internal void Add(TreeNodeCollection parent, TreeListNode node)
147
Console.WriteLine("AddSorted: " + node);
148
Console.WriteLine("Current nodes: ");
149
for (int j = 0; j < parent.Count; j++)
150
Console.WriteLine(" " + parent[j]);
153
for (i = parent.Count - 1; i >= 0; i--)
155
TreeListNode lookNode = (TreeListNode)parent[i];
156
// Console.WriteLine("looking at: " + lookNode
157
// + " (" + i + ")");
158
if (lookNode.CompareTo(node) <= 0)
161
parent.Insert(i + 1, node);
164
// Called by the OnBeforeSelect handler to determine
165
// if its valid to respond to the event. If this is response
166
// to a mouse down event, because of the code below that selects
167
// the mode in response to the mouse down event we have to do
168
// some special things. The problem is, we select the node below
169
// but then if the tree shifts, later, in handling the same mouse
170
// down event, the regular TreeView processing selects the node
171
// at the original mouse position causing the wrong node to end
172
// up being selected. This way, we allow only one select per
174
protected bool CanSelectNode()
185
// Make sure we select the node if its clicked anywhere
186
protected override void OnMouseDown(MouseEventArgs e)
188
TreeNode node = GetNodeAt(0, e.Y);
190
// Prevent further selections in this event sequence,
191
// see comment above.
196
protected override void WndProc(ref Message m)
198
bool mouseDown = false;
200
case Windows.WM_HSCROLL:
203
case Windows.WM_VSCROLL:
206
case Windows.WM_LBUTTONDOWN:
209
case Windows.WM_RBUTTONDOWN:
221
_inMouseDown = false;