1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Collections
.Generic
;
7 using Aga
.Controls
.Tree
.NodeControls
;
9 namespace Aga
.Controls
.Tree
11 public class AutoRowHeightLayout
: IRowLayout
13 private DrawContext _measureContext
;
14 private TreeViewAdv _treeView
;
15 private List
<Rectangle
> _rowCache
;
17 public AutoRowHeightLayout(TreeViewAdv treeView
, int rowHeight
)
19 _rowCache
= new List
<Rectangle
>();
21 PreferredRowHeight
= rowHeight
;
22 _measureContext
= new DrawContext();
23 _measureContext
.Graphics
= Graphics
.FromImage(new Bitmap(1, 1));
26 private int _rowHeight
;
27 public int PreferredRowHeight
29 get { return _rowHeight; }
30 set { _rowHeight = value; }
34 public int PageRowCount
38 if (_treeView
.RowCount
== 0)
42 int pageHeight
= _treeView
.DisplayRectangle
.Height
- _treeView
.ColumnHeaderHeight
;
44 for (int i
= _treeView
.RowCount
- 1; i
>= 0; i
--)
48 return Math
.Max(0, _treeView
.RowCount
- 1 - i
);
50 return _treeView
.RowCount
;
55 public int CurrentPageSize
59 if (_treeView
.RowCount
== 0)
63 int pageHeight
= _treeView
.DisplayRectangle
.Height
- _treeView
.ColumnHeaderHeight
;
65 for (int i
= _treeView
.FirstVisibleRow
; i
< _treeView
.RowCount
; i
++)
69 return Math
.Max(0, i
- _treeView
.FirstVisibleRow
);
71 return Math
.Max(0, _treeView
.RowCount
- _treeView
.FirstVisibleRow
);
76 public Rectangle
GetRowBounds(int rowNo
)
78 if (rowNo
>= _rowCache
.Count
)
80 int count
= _rowCache
.Count
;
81 int y
= count
> 0 ? _rowCache
[count
- 1].Bottom
: 0;
82 for (int i
= count
; i
<= rowNo
; i
++)
84 int height
= GetRowHeight(i
);
85 _rowCache
.Add(new Rectangle(0, y
, 0, height
));
88 if (rowNo
< _rowCache
.Count
- 1)
89 return Rectangle
.Empty
;
91 if (rowNo
>= 0 && rowNo
< _rowCache
.Count
)
92 return _rowCache
[rowNo
];
94 return Rectangle
.Empty
;
97 private int GetRowHeight(int rowNo
)
99 if (rowNo
< _treeView
.RowMap
.Count
)
101 TreeNodeAdv node
= _treeView
.RowMap
[rowNo
];
102 if (node
.Height
== null)
105 _measureContext
.Font
= _treeView
.Font
;
106 foreach (NodeControl nc
in _treeView
.NodeControls
)
108 int h
= nc
.GetActualSize(node
, _measureContext
).Height
;
114 return node
.Height
.Value
;
120 public int GetRowAt(Point point
)
122 int py
= point
.Y
- _treeView
.ColumnHeaderHeight
;
124 for (int i
= _treeView
.FirstVisibleRow
; i
< _treeView
.RowCount
; i
++)
126 int h
= GetRowHeight(i
);
127 if (py
>= y
&& py
< y
+ h
)
135 public int GetFirstRow(int lastPageRow
)
137 int pageHeight
= _treeView
.DisplayRectangle
.Height
- _treeView
.ColumnHeaderHeight
;
139 for (int i
= lastPageRow
; i
>= 0; i
--)
141 y
+= GetRowHeight(i
);
143 return Math
.Max(0, i
+ 1);
148 public void ClearCache()