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
| ///////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2015 by Charta Software B.V. //
// All rights reserved //
// //
// Version: 1.7.0.83525 //
// Web site: https://pascal.chartasoftware.com/ //
// //
// This code and information are provided "as is" without warranty of //
// any kind. Dissemination of this information or reproduction of //
// this material is strictly forbidden unless prior written permission //
// is obtained from Charta Software B.V.. //
// //
///////////////////////////////////////////////////////////////////////////
unit Table.Cells;
interface
uses
Collection.List,
Geometry._2d.Integer32.Point,
Geometry._2d.Integer32.Rectangle,
Integer._32,
Table.Row;
type
TTableCells = class(TObject)
private
FRows: TList<TTableRow>;
FBounds: TInteger32Rectangle;
procedure SetBounds(const Bounds: TInteger32Rectangle);
function GetRows(Index: TInteger32): TTableRow;
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Clear();
procedure CopyValuesFrom(Source: TTableCells); overload;
procedure CopyValuesFrom(const TargetLocation: TInteger32Point; Source: TTableCells; const SourceLocation: TInteger32Point); overload;
procedure MoveValuesFrom(const TargetLocation: TInteger32Point; Source: TTableCells; const SourceLocation: TInteger32Point); overload;
procedure AddRow(Row: TTableRow);
procedure InsertRow(Index: TInteger32; Row: TTableRow);
function ExtractRow(Index: TInteger32): TTableRow;
procedure RemoveRow(Index: TInteger32);
function CoalesceToRows(): TList<TTableRow>;
property Bounds: TInteger32Rectangle read FBounds write SetBounds;
property Rows[Index: TInteger32]: TTableRow read GetRows; default;
end;
implementation
uses
Geometry._2d.Integer32.Size,
Mathematics,
Object_.List;
{ TTableCells }
procedure TTableCells.AddRow(Row: TTableRow);
begin
FRows.Add(Row);
Inc(FBounds.Bottom);
end;
procedure TTableCells.Clear();
begin
FRows.Clear();
FBounds := TInteger32Rectangle.New(TInteger32Point.New(0, 0), TInteger32Size.New(0, 0));
end;
function TTableCells.CoalesceToRows(): TList<TTableRow>;
begin
Result := FRows;
FRows := nil;
Free();
end;
procedure TTableCells.CopyValuesFrom(const TargetLocation: TInteger32Point; Source: TTableCells; const SourceLocation: TInteger32Point);
var
i: TInteger32;
begin
for i := 0 to Bounds.Height - 1 do
Self[TargetLocation.Y + i].CopyValuesFrom(TargetLocation.X, Source[SourceLocation.Y + i], SourceLocation.X);
end;
procedure TTableCells.CopyValuesFrom(Source: TTableCells);
begin
CopyValuesFrom(TInteger32Point.New(0, 0), Source, TInteger32Point.New(Bounds.Left - Source.Bounds.Left, Bounds.Top - Source.Bounds.Top));
end;
constructor TTableCells.Create();
begin
inherited Create();
FRows := TObjectList<TTableRow>.Create();
FBounds := TInteger32Rectangle.New(TInteger32Point.New(0, 0), TInteger32Size.New(0, 0));
end;
destructor TTableCells.Destroy();
begin
FRows.Free();
inherited Destroy();
end;
function TTableCells.ExtractRow(Index: TInteger32): TTableRow;
begin
Result := FRows.ExtractAt(Index);
Dec(FBounds.Bottom);
end;
function TTableCells.GetRows(Index: TInteger32): TTableRow;
begin
Result := FRows[Index];
end;
procedure TTableCells.InsertRow(Index: TInteger32; Row: TTableRow);
begin
FRows.AddAt(Index, Row);
Inc(FBounds.Bottom);
end;
procedure TTableCells.MoveValuesFrom(const TargetLocation: TInteger32Point; Source: TTableCells; const SourceLocation: TInteger32Point);
var
i: TInteger32;
begin
for i := 0 to Source.Bounds.Height - 1 do
Self[TargetLocation.Y + i].MoveValuesFrom(TargetLocation.X, Source[SourceLocation.Y + i], SourceLocation.X);
end;
procedure TTableCells.RemoveRow(Index: TInteger32);
begin
ExtractRow(Index).Free();
end;
procedure TTableCells.SetBounds(const Bounds: TInteger32Rectangle);
var
i: TInteger32;
OldRowCount: TInteger32;
begin
OldRowCount := FRows.Count;
FBounds := Bounds;
FRows.Count := Bounds.Height;
for i := 0 to Minimum(OldRowCount, Bounds.Height) - 1 do
FRows[i].ColumnCount := Bounds.Width;
for i := OldRowCount to Bounds.Height - 1 do
FRows[i] := TTableRow.Create(Bounds.Width);
end;
end.
|