-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Controls.VirtualTable.pas
2363 lines (2158 loc) · 61.2 KB
/
HGM.Controls.VirtualTable.pas
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit HGM.Controls.VirtualTable;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls,
System.Generics.Collections, Vcl.ComCtrls, Winapi.CommCtrl, Vcl.ExtCtrls, System.UITypes, Vcl.Grids, Vcl.Mask,
Direct2D, Winapi.D2D1, HGM.Common, HGM.Common.Utils;
type
TOnTablePaint = procedure(Sender: TObject; Canvas: TCanvas) of object;
TTableEx = class;
TTableColumn = class;
TTableColumnClass = class of TTableColumn;
TCheckList = array of Boolean;
TTableData<T> = class(TList<T>)
type
TTables = TList<TTableEx>;
private
FTables: TTables;
FCheck: TCheckList;
FUpdate: Integer;
function GetTable(Index: Integer): TTableEx;
procedure InitNotif(Sender: TObject; const Item: T; Action: TCollectionNotification);
function GetChecked(Index: Integer): Boolean;
procedure SetChecked(Index: Integer; const Value: Boolean);
function GetCheckedCount: Integer;
function GetIsUpdate: Boolean;
public
procedure BeginUpdate;
procedure EndUpdate(Force: Boolean = False);
constructor Create(AOwner: TTableEx); overload; virtual;
constructor Create; overload; virtual;
destructor Destroy; override;
function Add(Value: T): Integer; virtual;
procedure Clear; virtual;
procedure Delete(Index: Integer); virtual;
//
procedure AddTable(pTable: TTableEx);
function IndexIn(Index: Integer): Boolean;
function GetFirstTableSelectedIndex: Integer;
procedure UnAssignTables;
procedure UnAssignTable(pTable: TTableEx);
procedure UpdateTable(Table: TTableEx = nil); virtual;
procedure CheckAll; virtual;
procedure UnCheckAll; virtual;
procedure SelectInTable(Index: Integer; Table: TTableEx = nil); virtual;
property CheckedCount: Integer read GetCheckedCount;
property Tables[Index: Integer]: TTableEx read GetTable;
property Checked[Index: Integer]: Boolean read GetChecked write SetChecked;
property IsUpdate: Boolean read GetIsUpdate;
end;
TTableObjectData<T: class> = class(TTableData<T>)
procedure Clear; override;
end;
TEditMode = (teText, teList, teDate, teMask, teTime, teInt, teFloat);
TTableEditStruct = record
EditMode: TEditMode;
EditMask: string;
TextValue: string;
ItemValue: Integer;
FixedList: Boolean;
Items: TStringList;
ReadOnly: Boolean;
ListDrop: Boolean;
Color: TColor;
FontColor: TColor;
end;
TFieldMaskEdit = class(TMaskEdit)
protected
procedure ValidateError; override;
public
function Validate(const Value: string; var Pos: Integer): Boolean; override;
end;
TGetTableDataProc = procedure(FCol, FRow: Integer; var Value: string) of object;
TItemClick = procedure(Sender: TObject; MouseButton: TMouseButton; const Index: Integer) of object;
TColumnClick = procedure(Sender: TObject; MouseButton: TMouseButton; const Index: Integer) of object;
TOnChangeItem = procedure(Sender: TObject; const Old: Integer; var New: Integer) of object;
TOnEdit = procedure(Sender: TObject; var Data: TTableEditStruct; ACol, ARow: Integer; var Allow: Boolean) of object;
TOnEditOK = procedure(Sender: TObject; Value: string; ItemValue: Integer; ACol, ARow: Integer) of object;
TOnEditCancel = procedure(Sender: TObject; ACol, ARow: Integer) of object;
TTableColumn = class(TCollectionItem)
private
FIndex: Cardinal;
FAsButton: Boolean;
FCaption: string;
FShowButtonOnlySelect: Boolean;
FMinWidth: Cardinal;
FTextFormat: TTextFormat;
FFormatColumns: TTextFormat;
FWidth: Cardinal;
procedure SetWidth(const Value: Cardinal); virtual;
function GetColumnIndex: Cardinal; virtual;
procedure SetCaption(const Value: string); virtual;
procedure SetColumnIndex(const Value: Cardinal);
procedure SetTextFormat(const Value: TTextFormat);
procedure SetFormatColumns(const Value: TTextFormat);
protected
function GetDisplayName: string; override;
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
property Index: Cardinal read GetColumnIndex write SetColumnIndex;
published
property Caption: string read FCaption write SetCaption;
property Width: Cardinal read FWidth write SetWidth default 100;
property Format: TTextFormat read FTextFormat write SetTextFormat default[tfVerticalCenter, tfLeft, tfSingleLine];
property FormatColumns: TTextFormat read FFormatColumns write SetFormatColumns default[tfVerticalCenter,
tfCenter, tfSingleLine];
property MinWidth: Cardinal read FMinWidth write FMinWidth default 60;
property AsButton: Boolean read FAsButton write FAsButton default False;
property ShowButtonOnlySelect: Boolean read FShowButtonOnlySelect write FShowButtonOnlySelect default False;
end;
TTableColumns = class(TCollection)
private
FTableEx: TTableEx;
function GetItem(Index: Integer): TTableColumn;
procedure SetItem(Index: Integer; Value: TTableColumn);
protected
function GetOwner: TPersistent; override;
public
procedure Update(Item: TCollectionItem); override;
constructor Create(TableEx: TTableEx);
function Add: TTableColumn;
function AddItem(Item: TTableColumn; Index: Integer): TTableColumn;
function Insert(Index: Integer): TTableColumn;
property Items[Index: Integer]: TTableColumn read GetItem write SetItem; default;
end;
TTableEx = class(TCustomDrawGrid)
private
FColumnsStream: TMemoryStream;
FUpdatesCount: Integer;
FItemDowned: Boolean;
FEditData: TTableEditStruct;
FEditCellRect: TRect;
FItemIndex: Integer;
FOnEdit: TOnEdit;
FOnEditCancel: TOnEditCancel;
FOnEditOk: TOnEditOK;
FOnPaint: TOnTablePaint;
FCordHot: TGridCoord;
FSetFocusOnEnter: Boolean;
FGetDataProc: TGetTableDataProc;
FWheelDown: TMouseWheelUpDownEvent;
FWheelUp: TMouseWheelUpDownEvent;
FOnMouseMove: TMouseMoveEvent;
FOnMouseLeave: TNotifyEvent;
FOnMouseDown: TMouseEvent;
FOnItemClick: TItemClick;
FOnItemColClick: TItemClick;
FOnColumnClick: TColumnClick;
FOnChangeItem: TOnChangeItem;
FOnDrawCell: TDrawCellEvent;
FAfterDrawText: TDrawCellEvent;
FOnDrawColumn: TDrawCellEvent;
FDefDrawing: Boolean;
FColumns: TTableColumns;
FShowColumns: Boolean;
FColumnsHeight: Integer;
FOnKeyUp: TKeyEvent;
FOnKeyDown: TKeyEvent;
FOnMouseUp: TMouseEvent;
FLineColor: TColor;
FLineColorXor: TColor;
FLineHotColor: TColor;
FLineSelColor: TColor;
FColumnsColor: TColor;
FFontHotLine: TFont;
FFontLine: TFont;
FFontSelLine: TFont;
FColumnsFont: TFont;
FShowFocus: Boolean;
FOnActivate: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FEditingCell: TGridCoord;
FEditing: Boolean;
FFieldEdit: TFieldMaskEdit;
FFieldCombo: TComboBox;
FVisibleEdit: Boolean;
FItemCount: Integer;
FCanNoSelect: Boolean;
FDrawColumnBorded: Boolean;
FFlashSelectedCol: Boolean;
FRoundLineRect: Integer;
FProcEmpty: Boolean;
FDrawColumnSections: Boolean;
FMouseRightClickTooClick: Boolean;
FItIsDblClick: Boolean;
FLastTimeClick: Cardinal;
FPaintGrid: Boolean;
FLastColumnAutoSize: Boolean;
FEditOnDblClick: Boolean;
FAddingColumns: Boolean;
FCanClickToUnfocused: Boolean;
FOnHotOver: TNotifyEvent;
FActiveCursor: TCursor;
FShowScrollBar: Boolean;
function DataRow: Integer;
procedure CloseControl(Sender: TObject);
procedure DoEditCancel;
procedure DoEditOk;
procedure HideEditField;
procedure KeyPressControl(Sender: TObject; var Key: Char);
procedure FFieldKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure FMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FMouseLeave(Sender: TObject);
procedure FMouseEnter(Sender: TObject);
procedure FOnEditChange(Sender: TObject);
procedure FOnComboMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled:
Boolean);
procedure FMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure SetRowCount(Value: Integer);
function GetRowCount: Longint;
procedure SetWidth(const Value: Integer);
function GetWidth: Integer;
procedure SetItemIndex(const Value: Integer);
procedure SetShowScrollBar(const Value: Boolean);
procedure SetDefDrawing(const Value: Boolean);
function GetColumnCount: Integer;
procedure SetItemDowned(const Value: Boolean);
procedure SetShowColumns(const Value: Boolean);
procedure UpdateItemCount;
function GetDefRowH: Integer;
procedure SetDefRowH(const Value: Integer);
function GetColumnsHeight: Integer;
procedure SetColumnsHeight(const Value: Integer);
procedure UpdateMouse(Cord: TGridCoord; Force: Boolean = False);
procedure FListKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
function GetFocusedColumn: Integer;
procedure SetFlashSelectedCol(const Value: Boolean);
procedure SetRoundLineRect(const Value: Integer);
procedure SetProcEmpty(const Value: Boolean);
procedure SetShowFocus(const Value: Boolean);
procedure SetDrawColumnBorded(const Value: Boolean);
procedure SetColumnsFont(const Value: TFont);
procedure SetFontSelLine(const Value: TFont);
procedure SetFontLine(const Value: TFont);
procedure SetFontHotLine(const Value: TFont);
procedure SetColumnsColor(const Value: TColor);
procedure SetLineSelColor(const Value: TColor);
procedure SetLineHotColor(const Value: TColor);
procedure SetLineColorXor(const Value: TColor);
procedure SetLineColor(const Value: TColor);
procedure SetDrawColumnSections(const Value: Boolean);
function GetItemUnderMouse: Integer;
procedure UpdateColumn(Index: Integer);
procedure SetPaintGrid(const Value: Boolean);
procedure SetLastColumnAutoSize(const Value: Boolean);
procedure SetEditOnDblClick(const Value: Boolean);
procedure UpdateColumnList;
procedure SetCanClickToUnfocused(const Value: Boolean);
procedure SetOnHotOver(const Value: TNotifyEvent);
procedure SetScrollVisible(const Value: Boolean);
property ItemDowned: Boolean read FItemDowned write SetItemDowned;
procedure UpdateColumnIndex;
procedure FUpdateColumnsHeight;
procedure WMReSize(var Msg: TWMSize); message WM_SIZE;
protected
procedure CreateWnd; override;
procedure ColWidthsChanged; override;
procedure LastFocus(var Msg: TMessage); message WM_ACTIVATE;
procedure FOnDblClick;
procedure SetEditing(Value: Boolean);
procedure UpdateColumns;
property RowHeights;
property ColWidths;
procedure DefineProperties(Filer: TFiler); override;
procedure TimedScroll(Direction: TGridScrollDirection); override;
public
function CreateColumn: TTableColumn;
function CreateColumns: TTableColumns;
function AddColumn: Integer; overload;
function FirstColumn(aCaption: string; aWidth: Integer; aButton: Boolean = False): Integer; deprecated;
function AddColumn(aCaption: string; aWidth: Integer; aButton: Boolean = False): Integer; overload;
procedure DeleteColumn(Index: Integer); override;
property ColumnCount: Integer read GetColumnCount;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DoItemClick;
procedure SetMaxColumn(ColumnID: Integer);
procedure Repaint; override;
procedure MouseToItem(Position: TPoint; var Index, Column: Integer);
procedure CloseEdit;
procedure CancelEdit;
procedure Paint; override;
property Editing: Boolean read FEditing;
function Edit(AItem, ACol: Integer): Boolean;
property Col;
property CordHot: TGridCoord read FCordHot;
property FocusedColumn: Integer read GetFocusedColumn;
property ItemUnderMouse: Integer read GetItemUnderMouse;
procedure BeginAddColumns;
procedure EndAddColumns;
procedure SetRowHeight(Index, Value: Integer);
procedure UpdateMaxColumn;
function GetRowHeight(Index: Integer): Integer;
published
property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
property ColumnsHeight: Integer read GetColumnsHeight write SetColumnsHeight default 30;
property Align;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelKind;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property DefaultRowHeight: Integer read GetDefRowH write SetDefRowH;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property Touch;
property Visible;
property VisibleRowCount;
property StyleElements;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnKeyPress;
property OnMouseActivate;
property OnSetEditText;
property OnStartDock;
property OnStartDrag;
property OnTopLeftChanged;
property OnMouseEnter;
property Width: Integer read GetWidth write SetWidth;
property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
property OnKeyUp: TKeyEvent read FOnKeyUp write FOnKeyUp;
property OnKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;
property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
property OnMouseWheelDown: TMouseWheelUpDownEvent read FWheelDown write FWheelDown;
property OnMouseWheelUp: TMouseWheelUpDownEvent read FWheelUp write FWheelUp;
property AfterDrawText: TDrawCellEvent read FAfterDrawText write FAfterDrawText;
property OnDrawCellData: TDrawCellEvent read FOnDrawCell write FOnDrawCell;
property OnDrawColumnData: TDrawCellEvent read FOnDrawColumn write FOnDrawColumn;
property ItemIndex: Integer read FItemIndex write SetItemIndex;
property OnColumnClick: TColumnClick read FOnColumnClick write FOnColumnClick;
property OnChangeItem: TOnChangeItem read FOnChangeItem write FOnChangeItem;
property OnItemClick: TItemClick read FOnItemClick write FOnItemClick;
property OnItemColClick: TItemClick read FOnItemColClick write FOnItemColClick;
property GetData: TGetTableDataProc read FGetDataProc write FGetDataProc;
property OnEdit: TOnEdit read FOnEdit write FOnEdit;
property OnEditCancel: TOnEditCancel read FOnEditCancel write FOnEditCancel;
property OnEditOk: TOnEditOk read FOnEditOk write FOnEditOk;
property OnPaint: TOnTablePaint read FOnPaint write FOnPaint;
property OnHotOver: TNotifyEvent read FOnHotOver write SetOnHotOver;
property ProcEmpty: Boolean read FProcEmpty write SetProcEmpty default False;
property Columns: TTableColumns read FColumns write FColumns;
property DefaultDataDrawing: Boolean read FDefDrawing write SetDefDrawing default True;
property ShowScrollBar: Boolean read FShowScrollBar write SetShowScrollBar default True;
property CanNoSelect: Boolean read FCanNoSelect write FCanNoSelect default True;
property VisibleEdit: Boolean read FVisibleEdit write FVisibleEdit default True;
property ItemCount: Integer read GetRowCount write SetRowCount default 5;
property LineColor: TColor read FLineColor write SetLineColor default $00F1F2F2;
property LineColorXor: TColor read FLineColorXor write SetLineColorXor default $00E7E8E8;
property LineHotColor: TColor read FLineHotColor write SetLineHotColor default $00DCDCDC;
property LineSelColor: TColor read FLineSelColor write SetLineSelColor default $006C6C6C;
property ColumnsColor: TColor read FColumnsColor write SetColumnsColor default $00DCDCDC;
property FontHotLine: TFont read FFontHotLine write SetFontHotLine;
property FontLine: TFont read FFontLine write SetFontLine;
property FontSelLine: TFont read FFontSelLine write SetFontSelLine;
property ShowColumns: Boolean read FShowColumns write SetShowColumns default True;
property RoundLineRect: Integer read FRoundLineRect write SetRoundLineRect default 0;
property ColumnsFont: TFont read FColumnsFont write SetColumnsFont;
property SetFocusOnEnter: Boolean read FSetFocusOnEnter write FSetFocusOnEnter default False;
property ShowFocus: Boolean read FShowFocus write SetShowFocus default False;
property DrawColumnBorded: Boolean read FDrawColumnBorded write SetDrawColumnBorded default True;
property DrawColumnSections: Boolean read FDrawColumnSections write SetDrawColumnSections default True;
property FlashSelectedCol: Boolean read FFlashSelectedCol write SetFlashSelectedCol default False;
property MouseRightClickTooClick: Boolean read FMouseRightClickTooClick write FMouseRightClickTooClick default False;
property PaintGrid: Boolean read FPaintGrid write SetPaintGrid default False;
property LastColumnAutoSize: Boolean read FLastColumnAutoSize write SetLastColumnAutoSize default True;
property EditOnDblClick: Boolean read FEditOnDblClick write SetEditOnDblClick default True;
property CanClickToUnfocused: Boolean read FCanClickToUnfocused write SetCanClickToUnfocused default False;
property CursorActive: TCursor read FActiveCursor write FActiveCursor default crHandPoint;
end;
function IndexInList(const Index: Integer; ListCount: Integer): Boolean;
procedure Register;
implementation
uses
Math, TypInfo;
function IndexInList(const Index: Integer; ListCount: Integer): Boolean;
begin
Result := (Index >= 0) and (Index <= ListCount - 1) and (ListCount > 0);
end;
procedure Register;
begin
RegisterComponents(PackageName, [TTableEx]);
end;
{ TTableData<T> }
constructor TTableData<T>.Create(AOwner: TTableEx);
begin
Create;
if Assigned(AOwner) then
FTables.Add(AOwner);
UpdateTable;
end;
function TTableData<T>.Add(Value: T): Integer;
begin
Result := inherited Add(Value);
end;
procedure TTableData<T>.AddTable(pTable: TTableEx);
begin
FTables.Add(pTable);
end;
function TTableData<T>.IndexIn(Index: Integer): Boolean;
begin
Result := IndexInList(Index, Count);
end;
procedure TTableData<T>.InitNotif(Sender: TObject; const Item: T; Action: TCollectionNotification);
begin
UpdateTable;
end;
procedure TTableData<T>.SelectInTable(Index: Integer; Table: TTableEx);
var
i: Integer;
begin
for i := 0 to FTables.Count - 1 do
if (Table = nil) or (Table = FTables[i]) then
FTables[i].ItemIndex := Index;
end;
procedure TTableData<T>.SetChecked(Index: Integer; const Value: Boolean);
begin
if Length(FCheck) - 1 < Index then
SetLength(FCheck, Index + 1);
FCheck[Index] := Value;
end;
procedure TTableData<T>.BeginUpdate;
begin
Inc(FUpdate);
end;
procedure TTableData<T>.CheckAll;
var
i: Integer;
begin
for i := Low(FCheck) to High(FCheck) do
FCheck[i] := True;
end;
procedure TTableData<T>.Clear;
begin
SetLength(FCheck, 0);
inherited Clear;
end;
constructor TTableData<T>.Create;
begin
inherited;
OnNotify := InitNotif;
FTables := TTables.Create;
FUpdate := 0;
end;
procedure TTableData<T>.Delete(Index: Integer);
begin
if Length(FCheck) - 1 < Index then
SetLength(FCheck, Index + 1);
System.Delete(FCheck, Index, 1);
inherited Delete(Index);
end;
destructor TTableData<T>.Destroy;
begin
Clear;
FTables.Free;
inherited;
end;
procedure TTableData<T>.EndUpdate;
begin
if Force then
FUpdate := 0
else
FUpdate := Max(0, FUpdate - 1);
if FUpdate = 0 then
UpdateTable;
end;
function TTableData<T>.GetChecked(Index: Integer): Boolean;
begin
if Length(FCheck) - 1 < Index then
begin
SetLength(FCheck, Index + 1);
Exit(False);
end
else
Result := FCheck[Index];
end;
function TTableData<T>.GetCheckedCount: Integer;
var
i: Integer;
begin
Result := 0;
for i := Low(FCheck) to High(FCheck) do
if FCheck[i] then
Inc(Result);
end;
function TTableData<T>.GetFirstTableSelectedIndex: Integer;
begin
Result := -1;
if FTables.Count > 0 then
Result := FTables[0].ItemIndex;
end;
function TTableData<T>.GetIsUpdate: Boolean;
begin
Result := FUpdate > 0;
end;
function TTableData<T>.GetTable(Index: Integer): TTableEx;
begin
if not IndexInList(Index, FTables.Count) then
Exit(nil);
Result := FTables[Index];
end;
procedure TTableData<T>.UnAssignTable(pTable: TTableEx);
var
i: Integer;
begin
for i := 0 to FTables.Count - 1 do
if Assigned(FTables[i]) and (FTables[i] = pTable) then
begin
FTables.Delete(i);
Exit;
end;
end;
procedure TTableData<T>.UnAssignTables;
begin
FTables.Clear;
end;
procedure TTableData<T>.UnCheckAll;
var
i: Integer;
begin
for i := Low(FCheck) to High(FCheck) do
FCheck[i] := False;
end;
procedure TTableData<T>.UpdateTable;
var
i: Integer;
begin
if FUpdate > 0 then
Exit;
//Îáíîâèòü òîëüêî îäíó òàáëèöó
if Assigned(Table) then
begin
Table.ItemCount := Count;
Exit;
end;
for i := 0 to FTables.Count - 1 do
if Assigned(FTables[i]) then
begin
FTables[i].ItemCount := Count;
end;
end;
{ TTableEx }
procedure TTableEx.CreateWnd;
procedure ReadSections;
var
Reader: TReader;
begin
if FColumnsStream = nil then
Exit;
FColumns.Free;
FColumns := CreateColumns; // Ensure ID's start at zero
Reader := TReader.Create(FColumnsStream, 1024);
try
Reader.ReadValue;
Reader.ReadCollection(Columns);
finally
Reader.Free;
end;
FColumnsStream.Free;
FColumnsStream := nil;
end;
begin
inherited CreateWnd;
if FColumnsStream <> nil then
ReadSections
else
UpdateColumns;
end;
procedure TTableEx.UpdateColumns;
var
i: Integer;
begin
if HandleAllocated then
begin
//for I := 0 to SendMessage(Handle, HDM_GETITEMCOUNT, 0, 0) - 1 do SendMessage(Handle, HDM_DELETEITEM, 0, 0);
ColCount := Columns.Count;
BeginAddColumns;
for i := 0 to Columns.Count - 1 do
ColWidths[i] := Columns[i].Width;
EndAddColumns;
end;
end;
procedure TTableEx.UpdateColumnList;
var
i: Integer;
begin
if HandleAllocated and (not FAddingColumns) then
begin
for i := 0 to Columns.Count - 1 do
Columns[i].Width := ColWidths[i];
end;
end;
procedure TTableEx.UpdateColumn(Index: Integer);
begin
//if HandleAllocated then UpdateItem(_HDM_SETITEM, Index);
if not IndexInList(Index, ColCount) then
UpdateColumns
else
ColWidths[Index] := Columns[Index].Width;
Repaint;
end;
function TTableEx.CreateColumn: TTableColumn;
var
LClass: TTableColumnClass;
begin
LClass := TTableColumn;
//if Assigned(FOnCreateSectionClass) then FOnCreateSectionClass(Self, LClass);
Result := LClass.Create(FColumns);
end;
function TTableEx.CreateColumns: TTableColumns;
begin
Result := TTableColumns.Create(Self);
end;
procedure TTableEx.SetRoundLineRect(const Value: Integer);
begin
FRoundLineRect := Value;
Repaint;
end;
procedure TTableEx.SetRowCount(Value: Longint);
var
msg: TWMSize;
begin
if (csDestroying in ComponentState) then
Exit;
if FItemCount <> Value then
begin
FItemCount := Value;
UpdateItemCount;
end;
if FEditing then
DoEditCancel;
WMReSize(msg);
Repaint;
end;
procedure TTableEx.SetRowHeight(Index, Value: Integer);
begin
inherited RowHeights[Index] := Value;
end;
function TTableEx.GetRowCount: Longint;
begin
Result := FItemCount;
end;
function TTableEx.GetRowHeight(Index: Integer): Integer;
begin
Result := inherited RowHeights[Index];
end;
procedure TTableEx.SetShowColumns(const Value: Boolean);
begin
if FShowColumns = Value then
Exit;
FShowColumns := Value;
UpdateItemCount;
FUpdateColumnsHeight;
Repaint;
end;
procedure TTableEx.SetShowFocus(const Value: Boolean);
begin
FShowFocus := Value;
Repaint;
end;
procedure TTableEx.SetScrollVisible(const Value: Boolean);
begin
case Value of
True:
ScrollBars := ssBoth;
False:
ScrollBars := ssNone;
end;
end;
procedure TTableEx.SetShowScrollBar(const Value: Boolean);
begin
FShowScrollBar := Value;
SetScrollVisible(Value);
end;
procedure TTableEx.SetWidth(const Value: Integer);
begin
inherited Width := Value;
end;
procedure TTableEx.TimedScroll(Direction: TGridScrollDirection);
begin
// inherited;
//Áëî÷èì àâòîñêðîë ïðè çàæàòèè ìûøè
end;
procedure TTableEx.UpdateColumnIndex;
//var i:Integer;
begin
//if FColumns.Count > 0 then
// for i:= 0 to FColumns.Count - 1 do FColumns[i].Index:=i;
end;
procedure TTableEx.UpdateItemCount;
begin
case FItemCount of
0:
begin
FixedRows := 0;
RowCount := 1;
end;
1:
begin
if FShowColumns then
begin
RowCount := 2;
FixedRows := 1;
end
else
begin
FixedRows := 0;
RowCount := 1;
end;
end;
else
begin
if FShowColumns then
begin
RowCount := FItemCount + 1;
FixedRows := 1;
end
else
begin
FixedRows := 0;
RowCount := FItemCount;
end;
end;
end;
if ItemIndex > (FItemCount - 1) then
ItemIndex := Max(-1, FItemCount - 1);
end;
procedure TTableEx.WMReSize(var Msg: TWMSize);
begin
if csReading in ComponentState then
Exit;
UpdateMaxColumn;
end;
procedure TTableEx.UpdateMaxColumn;
begin
if FLastColumnAutoSize and (not FAddingColumns) then
begin
if not Assigned(Parent) then
Exit;
if ColumnCount <= 0 then
Exit;
SetMaxColumn(ColumnCount - 1);
end;
end;
procedure TTableEx.SetCanClickToUnfocused(const Value: Boolean);
begin
FCanClickToUnfocused := Value;
end;
procedure TTableEx.SetColumnsColor(const Value: TColor);
begin
FColumnsColor := Value;
Repaint;
end;
procedure TTableEx.SetColumnsFont(const Value: TFont);
begin
FColumnsFont := Value;
Repaint;
end;
procedure TTableEx.SetColumnsHeight(const Value: Integer);
begin
FColumnsHeight := Value;
FUpdateColumnsHeight;
end;
procedure TTableEx.SetDefDrawing(const Value: Boolean);
begin
FDefDrawing := Value;
Repaint;
end;
procedure TTableEx.SetDefRowH(const Value: Integer);
begin
inherited DefaultRowHeight := Value;
FUpdateColumnsHeight;
end;
procedure TTableEx.SetDrawColumnBorded(const Value: Boolean);
begin
FDrawColumnBorded := Value;
Repaint;
end;
procedure TTableEx.SetDrawColumnSections(const Value: Boolean);
begin
FDrawColumnSections := Value;
Repaint;
end;
procedure TTableEx.SetEditing(Value: Boolean);
begin
FEditing := Value;
end;
procedure TTableEx.SetEditOnDblClick(const Value: Boolean);
begin
FEditOnDblClick := Value;
end;
procedure TTableEx.SetFlashSelectedCol(const Value: Boolean);
begin
FFlashSelectedCol := Value;
Repaint;
end;
procedure TTableEx.SetFontHotLine(const Value: TFont);
begin
FFontHotLine := Value;
Repaint;
end;
procedure TTableEx.SetFontLine(const Value: TFont);
begin
FFontLine := Value;
Repaint;
end;
procedure TTableEx.SetFontSelLine(const Value: TFont);
begin
FFontSelLine := Value;
Repaint;
end;
procedure TTableEx.SetItemDowned(const Value: Boolean);
begin
FItemDowned := Value;
Repaint;
end;
procedure TTableEx.SetItemIndex(const Value: Integer);
begin
if (csDestroying in ComponentState) then
Exit;
if FItemIndex <> Value then
begin
FItemIndex := Value;
if FItemIndex >= 0 then
Row := Max(0, Min(ItemCount, FItemIndex + Ord(FShowColumns)))
else
begin {
Col := 0;
Row := 0;
if not (csLoading in ComponentState) then
SendMessage(Handle, WM_VSCROLL, SB_THUMBPOSITION, 0); }
end;
end;
UpdateMouse(FCordHot, True);
Repaint;
end;
procedure TTableEx.SetLastColumnAutoSize(const Value: Boolean);
begin
FLastColumnAutoSize := Value;
UpdateMaxColumn;
Repaint;
end;
procedure TTableEx.SetLineColor(const Value: TColor);
begin
FLineColor := Value;
Repaint;
end;
procedure TTableEx.SetLineColorXor(const Value: TColor);
begin
FLineColorXor := Value;
Repaint;
end;
procedure TTableEx.SetLineHotColor(const Value: TColor);
begin
FLineHotColor := Value;
Repaint;
end;
procedure TTableEx.SetLineSelColor(const Value: TColor);
begin
FLineSelColor := Value;
Repaint;
end;
procedure TTableEx.SetMaxColumn(ColumnID: Integer);
var
i: Integer;