This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GroupRowSummaryHelper.cs
114 lines (105 loc) · 4.24 KB
/
GroupRowSummaryHelper.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
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraGrid.Views.Grid;
using System.Collections;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid;
using System.Drawing;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Drawing;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.Data;
using DevExpress.Utils.Text;
namespace AlignSummaries
{
public class GroupRowSummaryHelper
{
public ArrayList ExtractSummaryItems(GridView view)
{
ArrayList items = new ArrayList();
foreach (GridSummaryItem si in view.GroupSummary)
if (si is GridGroupSummaryItem && si.SummaryType != SummaryItemType.None)
items.Add(si);
return items;
}
public void DrawBackground(RowObjectCustomDrawEventArgs e, GridView view)
{
GridGroupRowPainter painter;
GridGroupRowInfo info;
painter = e.Painter as GridGroupRowPainter;
info = e.Info as GridGroupRowInfo;
int level = view.GetRowLevel(e.RowHandle);
int row = view.GetDataRowHandleByGroupRowHandle(e.RowHandle);
info.GroupText = string.Format("{0}: {1}", view.GroupedColumns[level].Caption,
view.GetRowCellDisplayText(row, view.GroupedColumns[level]));
e.Appearance.DrawBackground(e.Cache, info.Bounds);
painter.ElementsPainter.GroupRow.DrawObject(info);
}
public void DrawSummaryValues(RowObjectCustomDrawEventArgs e, GridView view, ArrayList items)
{
Hashtable values = view.GetGroupSummaryValues(e.RowHandle);
foreach (GridGroupSummaryItem item in items)
{
Rectangle rect = GetColumnBounds(view, item);
if (rect.IsEmpty) continue;
string text = item.GetDisplayText(values[item], false);
rect = CalcSummaryRect(text, e, view.Columns[item.FieldName]);
e.Appearance.DrawString(e.Cache, text, rect);
}
}
private Rectangle GetColumnBounds(GridView view, GridGroupSummaryItem item)
{
GridColumn column = view.Columns[item.FieldName];
return GetColumnBounds(column);
}
public Rectangle GetColumnBounds(GridColumn column)
{
GridViewInfo gridInfo = (GridViewInfo)column.View.GetViewInfo();
GridColumnInfoArgs colInfo = gridInfo.ColumnsInfo[column];
if (colInfo != null)
return colInfo.Bounds;
else
return Rectangle.Empty;
}
private Rectangle CalcSummaryRect(string text, RowObjectCustomDrawEventArgs e, GridColumn column)
{
SizeF sz = TextUtils.GetStringSize(e.Cache.Graphics, text, e.Appearance.Font);
int width = Convert.ToInt32(sz.Width) + 1;
Rectangle result = GetColumnBounds(column);
result = FixLeftEdge(width, result);
result.Width = result.Width;
result.Y = e.Bounds.Y;
result.Height = e.Bounds.Height - 2;
return PreventSummaryTextOverlapping(e, result);
}
private Rectangle FixLeftEdge(int width, Rectangle result)
{
int delta = result.Width - width - 2;
if (delta > 0)
{
result.X += delta;
result.Width -= delta;
}
return result;
}
private Rectangle PreventSummaryTextOverlapping(RowObjectCustomDrawEventArgs e, Rectangle rect)
{
GridGroupRowInfo gInfo = (GridGroupRowInfo)e.Info;
int groupTextLocation = gInfo.ButtonBounds.Right + 10;
int groupTextWidth = TextUtils.GetStringSize(e.Cache.Graphics, gInfo.GroupText, e.Appearance.Font).Width;
Rectangle r = new Rectangle(groupTextLocation, 0, groupTextWidth, e.Info.Bounds.Height);
if (r.Right > rect.X)
{
if (r.Right > rect.Right)
rect.Width = 0;
else
{
rect.Width -= r.Right - rect.X;
rect.X = r.Right;
}
}
return rect;
}
}
}