Repository navigation
Expand file tree
/
Copy pathTableRow.cs
More file actions
395 lines (355 loc) · 11.6 KB
/
Copy pathTableRow.cs
File metadata and controls
395 lines (355 loc) · 11.6 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using FastReport.Data;
using FastReport.Utils;
namespace FastReport.Table
{
/// <summary>
/// Represents a table row.
/// </summary>
/// <remarks>
/// Use the <see cref="Height"/> property to set the height of a row. If <see cref="AutoSize"/>
/// property is <b>true</b>, the row will calculate its height automatically.
/// <para/>You can also set the <see cref="MinHeight"/> and <see cref="MaxHeight"/> properties
/// to restrict the row's height.
/// </remarks>
public partial class TableRow : ComponentBase, IParent
{
#region Fields
private List<TableCellData> cells;
private float minHeight;
private float maxHeight;
private bool autoSize;
private bool canBreak;
private bool pageBreak;
private int keepRows;
private int index;
private float saveHeight;
private bool saveVisible;
private bool serializingToPreview;
#endregion
#region Properties
/// <summary>
/// Gets or sets a height of the row, in pixels.
/// </summary>
/// <remarks>
/// The row height cannot exceed the range defined by the <see cref="MinHeight"/>
/// and <see cref="MaxHeight"/> properties.
/// <note>To convert between pixels and report units, use the constants defined
/// in the <see cref="Units"/> class.</note>
/// </remarks>
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public override float Height
{
get { return base.Height; }
set
{
value = Converter.DecreasePrecision(value, 2);
if (value > MaxHeight && !canBreak)
value = MaxHeight;
if (value < MinHeight)
value = MinHeight;
base.Height = value;
}
}
/// <summary>
/// Gets or sets the minimal height for this row, in pixels.
/// </summary>
[DefaultValue(0f)]
[Category("Layout")]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float MinHeight
{
get { return minHeight; }
set { minHeight = value; }
}
/// <summary>
/// Gets or sets the maximal height for this row, in pixels.
/// </summary>
[DefaultValue(1000f)]
[Category("Layout")]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float MaxHeight
{
get { return maxHeight; }
set { maxHeight = value; }
}
/// <summary>
/// Gets or sets a value determines if the row should calculate its height automatically.
/// </summary>
/// <remarks>
/// The row height cannot exceed the range defined by the <see cref="MinHeight"/>
/// and <see cref="MaxHeight"/> properties.
/// </remarks>
[DefaultValue(false)]
[Category("Behavior")]
public bool AutoSize
{
get { return autoSize; }
set { autoSize = value; }
}
/// <summary>
/// Gets or sets a value that determines if the component can break its contents across pages.
/// </summary>
[DefaultValue(false)]
[Category("Behavior")]
public bool CanBreak
{
get { return canBreak; }
set { canBreak = value; }
}
/// <summary>
/// Gets the index of this row.
/// </summary>
[Browsable(false)]
public int Index
{
get { return index; }
}
/// <inheritdoc/>
[Browsable(false)]
public override float Top
{
get
{
TableBase table = Parent as TableBase;
if (table == null)
return 0;
float result = 0;
for (int i = 0; i < Index; i++)
{
result += table.Rows[i].Height;
}
return result;
}
set { base.Top = value; }
}
/// <summary>
/// Gets or sets the cell with specified index.
/// </summary>
/// <param name="col">Column index.</param>
/// <returns>The <b>TableCell</b> object.</returns>
[Browsable(false)]
public TableCell this[int col]
{
get
{
TableCellData cellData = CellData(col);
TableCell cell = cellData.Cell;
cell.SetParent(this);
cell.SetValue(cellData.Value);
return cell;
}
set
{
TableCellData cellData = CellData(col);
cellData.AttachCell(value);
}
}
/// <summary>
/// Gets or sets the page break flag for this row.
/// </summary>
[Browsable(false)]
public bool PageBreak
{
get { return pageBreak; }
set { pageBreak = value; }
}
/// <summary>
/// Gets or sets the number of rows to keep on the same page.
/// </summary>
[Browsable(false)]
public int KeepRows
{
get { return keepRows; }
set { keepRows = value; }
}
internal static float DefaultHeight
{
get { return (int)Math.Round(18 / (0.25f * Units.Centimeters)) * (0.25f * Units.Centimeters); }
}
#endregion
#region IParent Members
/// <inheritdoc/>
public bool CanContain(Base child)
{
return child is TableCell;
}
/// <inheritdoc/>
public void GetChildObjects(ObjectCollection list)
{
TableBase table = Parent as TableBase;
if (table == null)
return;
for (int i = 0; i < table.Columns.Count; i++)
{
if (!serializingToPreview || table.Columns[i].Visible)
list.Add(this[i]);
}
}
/// <inheritdoc/>
public void AddChild(Base child)
{
// support deserializing the cells
if (child is TableCell)
{
this[cells.Count] = child as TableCell;
child.SetParent(this);
}
}
/// <inheritdoc/>
public void RemoveChild(Base child)
{
}
private TableCellData FindCellData(TableCell cell)
{
foreach (TableCellData cellData in cells)
{
if (cellData.Cell == cell)
return cellData;
}
return null;
}
/// <inheritdoc/>
public int GetChildOrder(Base child)
{
TableCellData cellData = FindCellData(child as TableCell);
return cellData == null ? 0 : cells.IndexOf(cellData);
}
/// <inheritdoc/>
public void SetChildOrder(Base child, int order)
{
TableCellData cellData = FindCellData(child as TableCell);
if (cellData == null)
return;
int oldOrder = child.ZOrder;
if (oldOrder != -1 && order != -1 && oldOrder != order)
{
if (order > cells.Count)
order = cells.Count;
if (oldOrder <= order)
order--;
cells.Remove(cellData);
cells.Insert(order, cellData);
}
}
/// <inheritdoc/>
public void UpdateLayout(float dx, float dy)
{
TableBase table = Parent as TableBase;
if (table == null)
return;
// update this row cells
for (int i = 0; i < table.Columns.Count; i++)
{
this.CellData(i).UpdateLayout(dx, dy);
}
// update spanned cells that contains this row
List<Rectangle> spanList = table.GetSpanList();
foreach (Rectangle span in spanList)
{
if (Index > span.Top && Index < span.Bottom)
table[span.Left, span.Top].CellData.UpdateLayout(dx, dy);
}
}
#endregion
#region Public Methods
/// <inheritdoc/>
public override void Assign(Base source)
{
TableRow src = source as TableRow;
MinHeight = src.MinHeight;
MaxHeight = src.MaxHeight;
AutoSize = src.AutoSize;
KeepRows = src.KeepRows;
CanBreak = src.CanBreak;
base.Assign(source);
}
internal TableCellData CellData(int col)
{
while (col >= cells.Count)
{
cells.Add(new TableCellData());
}
TableCellData cellData = cells[col];
cellData.Table = Parent as TableBase;
cellData.Address = new Point(col, Index);
return cellData;
}
internal void CorrectCellsOnColumnChange(int index, int correct)
{
if (correct == 1)
cells.Insert(index, new TableCellData());
else if (index < cells.Count)
cells.RemoveAt(index);
}
internal void SetIndex(int value)
{
index = value;
}
/// <inheritdoc/>
public override void Serialize(FRWriter writer)
{
TableRow c = writer.DiffObject as TableRow;
serializingToPreview = writer.SerializeTo == SerializeTo.Preview;
base.Serialize(writer);
if (FloatDiff(MinHeight, c.MinHeight))
writer.WriteFloat("MinHeight", MinHeight);
if (FloatDiff(MaxHeight, c.MaxHeight))
writer.WriteFloat("MaxHeight", MaxHeight);
if (FloatDiff(Height, c.Height))
writer.WriteFloat("Height", Height);
if (AutoSize != c.AutoSize)
writer.WriteBool("AutoSize", AutoSize);
if (CanBreak != c.CanBreak)
writer.WriteBool("CanBreak", CanBreak);
if (Parent is TableResult)
{
// write children by itself
SetFlags(Flags.CanWriteChildren, true);
writer.SaveChildren = true;
TableResult table = Parent as TableResult;
foreach (TableColumn column in table.ColumnsToSerialize)
{
TableCell cell = this[column.Index];
writer.Write(cell);
}
}
}
/// <inheritdoc/>
public override void Clear()
{
base.Clear();
foreach (TableCellData cell in cells)
{
cell.Dispose();
}
cells.Clear();
}
internal void SaveState()
{
saveHeight = Height;
saveVisible = Visible;
}
internal void RestoreState()
{
Height = saveHeight;
Visible = saveVisible;
}
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="TableRow"/> class.
/// </summary>
public TableRow()
{
cells = new List<TableCellData>();
maxHeight = 1000;
Height = DefaultHeight;
SetFlags(Flags.CanCopy | Flags.CanDelete | Flags.CanWriteBounds, false);
BaseName = "Row";
}
}
}