-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlignControlHelper.pas
More file actions
148 lines (127 loc) · 3.38 KB
/
Copy pathAlignControlHelper.pas
File metadata and controls
148 lines (127 loc) · 3.38 KB
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
Unit AlignControlHelper;
{ Version: 1.5 }
Interface
Uses
windows, sysUtils, controls, ExtCtrls;
Procedure AutoSizeHeight(aControl: TWinControl);
Procedure DeleteAllEmptyRows(aGrid: TGridPanel; aResetGridHeight: boolean = true);
Procedure AdjustTabOrderForControlsInGridPanel(aGrid: TGridPanel);
Function GetControlheightInclMargins(aControl: TControl): integer;
Function GetControlWidthInclMargins(aControl: TControl): integer;
Procedure AlignVerticalCenter(aBase, aMoveThis: TWinControl);
Procedure AlignVerticalBottom(aBase, aMoveThis: TWinControl);
Implementation
Uses
Math;
Procedure AutoSizeHeight(aControl: TWinControl);
Var
x: integer;
h: integer;
cc: TWinControl;
Begin
h := 0;
For x := 0 To aControl.ControlCount - 1 Do
Begin
If Not(aControl.controls[x] Is TWinControl) Then
Continue;
cc := aControl.controls[x] As TWinControl;
If cc.visible Then
h := max(h, cc.top + cc.Height);
End;
If h <> 0 Then
aControl.ClientHeight := h;
End;
Procedure DeleteAllEmptyRows(aGrid: TGridPanel; aResetGridHeight: boolean = true);
Var
i: integer;
ci: TControlItem;
Rowheight: integer;
IsEmpty: boolean;
c: integer;
r: integer;
CellItem: TCellItem;
h: integer;
wc: TControl;
RealHeight: integer;
Begin
RealHeight := 0;
For r := aGrid.RowCollection.Count - 1 Downto 0 Do
Begin
Rowheight := 0;
IsEmpty := true;
For c := 0 To aGrid.ColumnCollection.Count - 1 Do
Begin
wc := aGrid.ControlCollection.controls[c, r];
If wc = NIL Then
Continue;
If wc.visible Then
Begin
IsEmpty := false;
h := wc.Height;
If wc.alignwithMargins Then
h := h + wc.Margins.top + wc.Margins.bottom;
Rowheight := max(Rowheight, h);
End
Else
Begin
wc.parent := aGrid.parent;
aGrid.ControlCollection.RemoveControl(wc);
End;
End;
If IsEmpty Then
Begin
Rowheight := 0;
End;
aGrid.RowCollection.Items[r].SizeStyle := ssAbsolute;
aGrid.RowCollection.Items[r].Value := Rowheight;
Inc(RealHeight, Rowheight);
End;
If aResetGridHeight Then
aGrid.ClientHeight := RealHeight;
End;
Procedure AdjustTabOrderForControlsInGridPanel(aGrid: TGridPanel);
Var
i: integer;
ci: TControlItem;
c: integer;
r: integer;
CellItem: TCellItem;
wc: TControl;
tab: integer;
Begin
tab := 0;
For r := 0 To aGrid.RowCollection.Count - 1 Do
For c := 0 To aGrid.ColumnCollection.Count - 1 Do
Begin
wc := aGrid.ControlCollection.controls[c, r];
If (wc = NIL) Or (Not(wc Is TWinControl)) Then
Continue;
(wc As TWinControl).TabOrder := tab;
Inc(tab);
End;
End;
Function GetControlheightInclMargins(aControl: TControl): integer;
Begin
result := aControl.Height;
If aControl.alignwithMargins Then
result := result + aControl.Margins.bottom + aControl.Margins.top;
End;
Function GetControlWidthInclMargins(aControl: TControl): integer;
Begin
result := aControl.width;
If aControl.alignwithMargins Then
result := result + aControl.Margins.Left + aControl.Margins.Right;
End;
Procedure AlignVerticalCenter(aBase, aMoveThis: TWinControl);
Begin
aMoveThis.top :=
aBase.top +
round(aBase.Height / 2 - aMoveThis.Height / 2);
End;
Procedure AlignVerticalBottom(aBase, aMoveThis: TWinControl);
Begin
aMoveThis.top :=
(aBase.top + aBase.Height) -
aMoveThis.Height;
End;
End.