-
Notifications
You must be signed in to change notification settings - Fork 1
/
NodeTreeLayout.cs
235 lines (213 loc) · 6.78 KB
/
NodeTreeLayout.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.Tree
{
/// <summary>
/// Summary description for NodeTreeLayout.
/// </summary>
internal class NodeTreeLayout:NodeLayout
{
//private bool m_LayoutPerformed=false;
public NodeTreeLayout(TreeGX treeControl, Rectangle clientArea):base(treeControl,clientArea)
{
//m_ExpandAreaWidth=16;
m_ExpandPartSize=new Size(9,9);
}
public override void PerformLayout()
{
this.PrepareStyles();
// Get default Columns
ArrayList defaultColInfoList=this.GetDefaultColumnInfo();
Graphics graphics=this.GetGraphics();
try
{
// Loop through each top-level node
Node[] topLevelNodes=this.GetTopLevelNodes();
NodeLayoutContextInfo layoutInfo=GetDefaultNodeLayoutContextInfo(GetGraphics());
foreach(Node childNode in topLevelNodes)
{
layoutInfo.ContextNode=childNode;
ProcessNode(layoutInfo);
}
}
finally
{
graphics.Dispose();
}
}
#region Node routines
private void ProcessNode(NodeLayoutContextInfo layoutInfo)
{
Node node=layoutInfo.ContextNode;
if(node.SizeChanged)
{
// Calculate size of the node itself...
LayoutNode(layoutInfo);
// Calculate size and location of node column header if any
// if(node.NodesColumnHeaderVisible)
// {
// layoutInfo.Left+=this.NodeLevelOffset;
// LayoutColumnHeader(layoutInfo);
// layoutInfo.Left-=this.NodeLevelOffset;
// }
}
else if(node.Bounds.Top!=layoutInfo.Top)
{
// Adjust top position
node.SetBounds(new Rectangle(node.Bounds.X,layoutInfo.Top,node.Bounds.Width,node.Bounds.Height));
foreach(Cell c in node.Cells)
c.SetBounds(new Rectangle(c.Bounds.X,layoutInfo.Top,c.Bounds.Width,c.Bounds.Height));
}
// Need to set the Top position properly
layoutInfo.Top+=(node.Bounds.Height+this.NodeVerticalSpacing);
// if(node.Expanded && node.NodesColumnHeaderVisible && node.NodesColumns.Count>0)
// layoutInfo.Top+=node.ColumnHeaderHeight;
if(node.Expanded)
{
int originalLevelOffset=layoutInfo.Left;
layoutInfo.Left+=this.NodeLevelOffset;
ArrayList parentColumns=layoutInfo.ChildColumns;
ArrayList childColumns=GetNodeColumnInfo(node);
foreach(Node childNode in node.Nodes)
{
layoutInfo.ContextNode=childNode;
layoutInfo.ChildColumns=childColumns;
ProcessNode(layoutInfo);
}
layoutInfo.ChildColumns=parentColumns;
layoutInfo.ContextNode=node;
layoutInfo.Left=originalLevelOffset;
}
}
// private void LayoutNode(NodeLayoutContextInfo layoutInfo)
// {
// if(!layoutInfo.ContextNode.SizeChanged)
// return;
//
// Node node=layoutInfo.ContextNode;
// Rectangle nodeContentRect=Rectangle.Empty; // Node content rect excludes expand rect
//
// Rectangle nodeRect=Rectangle.Empty;
// nodeRect.X=layoutInfo.Left;
// nodeRect.Y=layoutInfo.Top;
//
// int height=0, width=0;
//
// bool bExpandPartAlignedNear=this.ExpandPartAlignedNear(node);
// if(bExpandPartAlignedNear)
// {
// width+=(this.ExpandAreaWidth+this.GetCellLayout().CellPartSpacing);
// }
//
// int x=width; // relative to 0,0 of the node
// int y=0; // Relative to 0,0 of the node
//
// // Apply node style
// ElementStyle nodeStyle=null;
// if(node.Expanded && node.StyleExpanded!=null)
// nodeStyle=node.StyleExpanded;
// else if(node.Style!=null)
// nodeStyle=node.Style;
// else
// nodeStyle=layoutInfo.DefaultNodeStyle;
//
// nodeContentRect.X=x;
//
// if(nodeStyle!=null)
// {
// x+=ElementStyleLayout.LeftWhiteSpace(nodeStyle); // nodeStyle.MarginLeft+nodeStyle.PaddingLeft;
// y+=ElementStyleLayout.TopWhiteSpace(nodeStyle); // nodeStyle.MarginTop+nodeStyle.PaddingTop;
// nodeContentRect.X+=nodeStyle.MarginLeft;
// nodeContentRect.Y+=nodeStyle.MarginTop;
// }
//
// Size size=this.GetCellLayout().LayoutCells(layoutInfo,x,y);
// height=size.Height;
// width+=size.Width;
//
// nodeContentRect.Width=size.Width;
// nodeContentRect.Height=size.Height;
//
// node.SetCellsBounds(new Rectangle(x,y,size.Width,size.Height));
//
// if(nodeStyle!=null)
// {
// nodeContentRect.Width+=(ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Left)+
// ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Right));
// nodeContentRect.Height+=(ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Top)+
// ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Bottom));
//
// width+=(ElementStyleLayout.HorizontalStyleWhiteSpace(nodeStyle));
// height+=(ElementStyleLayout.VerticalStyleWhiteSpace(nodeStyle));
// }
//
// if(!bExpandPartAlignedNear)
// width+=this.ExpandAreaWidth;
//
// nodeRect.Height=height;
// nodeRect.Width=width;
//
// node.SetBounds(nodeRect);
// node.SetContentBounds(nodeContentRect);
//
// LayoutExpandPart(layoutInfo,true);
//
// node.SizeChanged=false;
// }
/// <summary>
/// Returns true if expand part space should be accounted for even if they expand part is not visible or need to be displayed. Default value is false.
/// </summary>
protected override bool ReserveExpandPartSpace
{
get
{
return true;
}
}
//
// private CellLayout m_CellLayout=null;
// private CellLayout GetCellLayout()
// {
// if(m_CellLayout==null)
// m_CellLayout=new CellLayout();
// return m_CellLayout;
// }
// /// <summary>
// /// Determines the rectangle of the +/- part of the tree node that is used to expand node.
// /// </summary>
// /// <param name="layoutInfo">Node layout context information</param>
// private void LayoutExpandPart(NodeLayoutContextInfo layoutInfo)
// {
// Node node=layoutInfo.ContextNode;
//
// Size partSize=new Size(9,9);
//
// // For different styles of the nodes the expand part +/- might be aligned to the right of the node etc.
// // this routine does default left position
// Rectangle bounds=new Rectangle(0,0,partSize.Width,partSize.Height);
// bounds.Y=(node.Bounds.Height-bounds.Height)/2;
// bounds.X=(this.ExpandAreaWidth-bounds.Width)/2;
//
// node.SetExpandPartRectangle(bounds);
// }
/// <summary>
/// Gets whether the expand part of the node +/- is aligned to the left of the node in left-to-right layout.
/// </summary>
/// <param name="node">Node to get expand part alignment for</param>
/// <returns>true if node expand part is aligned to the left in left-to-right layout.</returns>
private bool ExpandPartAlignedNear(Node node)
{
return true; // If changed LayoutExpandPart needs to be updated as well
}
// private NodeCollection GetTopLevelNodes()
// {
// return m_Tree.Nodes;
// }
private int NodeLevelOffset
{
get {return 10;}
}
#endregion
}
}