-
Notifications
You must be signed in to change notification settings - Fork 3
/
uCheckStringGrid.pas
3200 lines (2798 loc) · 98.3 KB
/
uCheckStringGrid.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 uCheckStringGrid;
{
uCheckStringGrid
TetzkatLipHoka 2017-2019
}
{$DEFINE SORTING}
{$DEFINE CELLTYPES} // uses uTLH.ComponentTools
{.$DEFINE EXTENDED_STRINGGRID}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
interface
uses
Classes, Windows, Controls, Grids, Graphics, Menus, SysUtils, Messages
{$IFDEF CELLTYPES},uTLH.ComponentTools{$ENDIF}
;
type
{$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF} = class;
TCheckStringGridState = ( csNone, csInactiveUnchecked, csInactiveChecked, csUnchecked, csChecked );
TCheckStringGridSortCompare = function ( Grid: {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}; ACol, Index1, Index2: Integer ): Integer;
TCheckStringGridSortType = ( cstAscending, cstDescending, cstAscendingCaseSensitive, cstDescendingCaseSensitive, cstAscendingDate, cstDescendingDate, cstAscendingDateTime, cstDescendingDateTime );
TCheckStringGridOnCheckBox = procedure( Sender : TObject; ACol, ARow : Integer; checkState : TCheckStringGridState ) of object;
{$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF} = class( Grids.TStringGrid )
private
{ Private declarations }
myPopUpMenu : TPopUpMenu;
fComponent : Array of Array of TCheckStringGridState;
fColor : Array of Array of TColor;
fFontColor : Array of Array of TColor;
fTextFormat : Array of Array of Cardinal;
fReadOnly : Array of Array of Boolean;
fCellHint : Array of Array of String;
fSelectable : Array of Array of Boolean;
{$IFDEF CELLTYPES}
fCellType : Array of Array of TOnKeyPressMode;
{$ENDIF}
fLastClickCol,
fLastClickRow : Integer;
fSelectedRowColoring : boolean;
fSelectedRowColor : TColor;
fSelectedRowHeight : Byte;
fCheckedRowColoring : boolean;
fCheckedRowColor : TColor;
fSelectedCellColor : TColor;
fSelectedTextColor : TColor;
fModernScrolling : Boolean;
{$IFDEF SORTING}
fSortCol : Integer;
fSortDescending : Boolean;
fSortColAllowed : Array of Boolean;
fSortColAsDate : Array of Boolean;
fDateFormat : string;
fTimeFormat : string;
fFloatFormat : string;
fLFS : TFormatSettings;
fOnCheckBox : TCheckStringGridOnCheckBox;
fHint : String;
fValueAsHint : Boolean;
procedure QuickSort( ACol : Integer; StartId, EndId: Integer; SCompare: TCheckStringGridSortCompare );
function GetSortAllowedCol( ACol : Integer ) : Boolean;
procedure SetSortAllowedCol( ACol : Integer; value : Boolean );
function GetSortColAsDate( ACol : Integer ) : Boolean;
procedure SetSortColAsDate( ACol : Integer; value : Boolean );
{$ENDIF}
function GetRowCount: Integer;
procedure SetRowCount( v: integer ); reintroduce;
function GetColCount: Integer;
procedure SetColCount( v: integer ); reintroduce;
function GetComponent( ACol, ARow: Integer ): TCheckStringGridState;
procedure SetComponent( ACol, ARow: Integer; value : TCheckStringGridState );
function GetDeleteMenu : boolean;
procedure SetDeleteMenu( value : boolean );
function GetMenuEnabled : boolean;
procedure SetMenuEnabled( value : boolean );
function GetCellColor( ACol, ARow : Integer ) : TColor;
procedure SetCellColor( ACol, ARow : Integer; value : TColor );
function GetFontColor( ACol, ARow : Integer ) : TColor;
procedure SetFontColor( ACol, ARow : Integer; value : TColor );
function GetTextFormat( ACol, ARow : Integer ) : Cardinal;
procedure SetTextFormat( ACol, ARow : Integer; value : Cardinal );
function GetReadOnly( ACol, ARow : Integer ) : Boolean;
procedure SetReadOnly( ACol, ARow : Integer; value : Boolean );
function GetCellHint( ACol, ARow : Integer ) : String;
procedure SetCellHint( ACol, ARow : Integer; value : String );
function GetReadOnlyCol( ACol : Integer ) : Boolean;
procedure SetReadOnlyCol( ACol : Integer; value : Boolean );
function GetReadOnlyRow( ARow : Integer ) : Boolean;
procedure SetReadOnlyRow( ARow : Integer; value : Boolean );
function GetSelectable( ACol, ARow : Integer ) : Boolean;
procedure SetSelectable( ACol, ARow : Integer; value : Boolean );
function GetSelectableCol( ACol : Integer ) : Boolean;
procedure SetSelectableCol( ACol : Integer; value : Boolean );
function GetSelectableRow( ARow : Integer ) : Boolean;
procedure SetSelectableRow( ARow : Integer; value : Boolean );
function GetCells( ACol, ARow: Integer ) : string; reintroduce;
procedure SetCells( ACol, ARow: Integer; const Value: string ); reintroduce;
function GetCellsAsBoolean( ACol, ARow: Integer ): Boolean;
procedure SetCellsAsBoolean( ACol, ARow: Integer; const Value: Boolean );
function GetCellsAsByte( ACol, ARow: Integer ): Byte;
procedure SetCellsAsByte( ACol, ARow: Integer; const Value: Byte );
function GetCellsAsShortInt( ACol, ARow: Integer ): ShortInt;
procedure SetCellsAsShortInt( ACol, ARow: Integer; const Value: ShortInt );
function GetCellsAsWord( ACol, ARow: Integer ): Word;
procedure SetCellsAsWord( ACol, ARow: Integer; const Value: Word );
function GetCellsAsSmallInt( ACol, ARow: Integer ): SmallInt;
procedure SetCellsAsSmallInt( ACol, ARow: Integer; const Value: SmallInt );
function GetCellsAsCardinal( ACol, ARow: Integer ): Cardinal;
procedure SetCellsAsCardinal( ACol, ARow: Integer; const Value: Cardinal );
function GetCellsAsInteger( ACol, ARow: Integer ): Integer;
procedure SetCellsAsInteger( ACol, ARow: Integer; const Value: Integer );
function GetCellsAsInt64( ACol, ARow: Integer ): Int64;
procedure SetCellsAsInt64( ACol, ARow: Integer; const Value: Int64 );
{$IF CompilerVersion > 23}
function GetCellsAsUInt64( ACol, ARow: Integer ): UInt64;
procedure SetCellsAsUInt64( ACol, ARow: Integer; const Value: UInt64 );
{$IFEND}
function GetCellsAsSingle( ACol, ARow: Integer ): Single;
procedure SetCellsAsSingle( ACol, ARow: Integer; const Value: Single );
function GetCellsAsDouble( ACol, ARow: Integer ): Double;
procedure SetCellsAsDouble( ACol, ARow: Integer; const Value: Double );
function GetCellsAsExtended( ACol, ARow: Integer ): Extended;
procedure SetCellsAsExtended( ACol, ARow: Integer; const Value: Extended );
function GetCellsAsDate( ACol, ARow: Integer ): TDate;
procedure SetCellsAsDate( ACol, ARow: Integer; const Value: TDate );
function GetCellsAsTime( ACol, ARow: Integer ): TTime;
procedure SetCellsAsTime( ACol, ARow: Integer; const Value: TTime );
function GetCellsAsDateTime( ACol, ARow: Integer ): TDateTime;
procedure SetCellsAsDateTime( ACol, ARow: Integer; const Value: TDateTime );
{$IFDEF CELLTYPES}
function GetCellType( ACol, ARow : Integer ) : TOnKeyPressMode;
procedure SetCellType( ACol, ARow : Integer; value : TOnKeyPressMode );
function GetColType( ACol : Integer ) : TOnKeyPressMode;
procedure SetColType( ACol : Integer; value : TOnKeyPressMode );
function GetRowType( ARow : Integer ) : TOnKeyPressMode;
procedure SetRowType( ARow : Integer; value : TOnKeyPressMode );
{$ENDIF}
procedure CheckStringGridPopUpClick( Sender : TObject );
procedure WMChar( var Message: TWMChar ); message WM_CHAR;
procedure SelectionChanged( OldCol, OldRow, NewCol, NewRow : Integer );
procedure SetSelectedRowHeight( value : Byte );
function GetRow : Integer;
procedure SetRow( Value: Integer ); reintroduce;
function GetScrollbarH : Boolean;
function GetScrollbarV : Boolean;
protected
{ Protected declarations }
procedure DrawCell( ACol, ARow : LongInt; vRect : TRect; State : TGridDrawState ); override;
procedure ColumnMoved( FromIndex, ToIndex: Longint ); override;
procedure RowMoved( FromIndex, ToIndex: Longint ); override;
procedure MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ); override;
procedure KeyDown( var Key: Word; Shift: TShiftState ); override;
procedure DblClick; override;
function DoMouseWheelDown( Shift: TShiftState; MousePos: TPoint ): Boolean; override;
function DoMouseWheelUp( Shift: TShiftState; MousePos: TPoint ): Boolean; override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure SetHint( value : string );
{$IFDEF CELLTYPES}
procedure KeyPress(var Key: Char); override;
{$ENDIF}
// function CreateEditor: TInplaceEdit; override;
function GetSelStart : Integer;
procedure SetSelStart( Value : Integer );
function GetSelEnd : Integer;
procedure SetSelEnd( Value : Integer );
function GetSelText : String;
procedure SetSelText( Value : String );
public
{ Public declarations }
constructor Create( AOwner: TComponent ); reintroduce;
destructor Destroy; override;
procedure DelCol( v: integer );
procedure DelRow( v: integer );
procedure Clear( Full : boolean = True; IgnoreFixed : boolean = True );
procedure ClearCol( ACol : Integer; Full : boolean = True; IgnoreFixed : boolean = True );
procedure ClearRow( ARow : Integer; Full : boolean = True; IgnoreFixed : boolean = True );
procedure ClearCell( ACol, ARow : Integer; Full : boolean = True );
procedure ExchangeItems( sCol, sRow, tCol, tRow : Integer );
procedure ExchangeCols( sCol, tCol : Integer );
procedure ExchangeRows( sRow, tRow : Integer );
procedure MoveCol( sCol, tCol : Integer );
procedure MoveRow( sRow, tRow : Integer );
procedure InflateColumns( DontShrink : boolean = false );
procedure SaveToFile( FileName : string; Separator : Char = ';' );
procedure GetSelection( var SelStart : Integer; var SelEnd : Integer );
procedure SetSelection( SelStart : Integer; SelEnd : Integer );
{$IFDEF SORTING}
procedure Sort( ACol: Integer; Order : TCheckStringGridSortType );
procedure CustomSort( ACol : Integer; Compare: TCheckStringGridSortCompare );
{$ENDIF}
property Component[ ACol, ARow : Integer ] : TCheckStringGridState read GetComponent write SetComponent;
property CellColor[ ACol, ARow : Integer ] : TColor read GetCellColor write SetCellColor;
property FontColor[ ACol, ARow : Integer ] : TColor read GetFontColor write SetFontColor;
property TextFormat[ ACol, ARow : Integer ] : Cardinal read GetTextFormat write SetTextFormat;
property ReadOnly[ ACol, ARow : Integer ] : Boolean read GetReadOnly write SetReadOnly;
property ReadOnlyCol[ ACol : Integer ] : Boolean read GetReadOnlyCol write SetReadOnlyCol;
property ReadOnlyRow[ ACol : Integer ] : Boolean read GetReadOnlyRow write SetReadOnlyRow;
property CellHint[ ACol, ARow : Integer ] : String read GetCellHint write SetCellHint;
property Selectable[ ACol, ARow : Integer ] : Boolean read GetSelectable write SetSelectable;
property SelectableCol[ ACol : Integer ] : Boolean read GetSelectableCol write SetSelectableCol;
property SelectableRow[ ACol : Integer ] : Boolean read GetSelectableRow write SetSelectableRow;
{$IFDEF CELLTYPES}
property CellType[ ACol, ARow : Integer ] : TOnKeyPressMode read GetCellType write SetCellType;
property ColType[ ACol : Integer ] : TOnKeyPressMode read GetColType write SetColType;
property RowType[ ARow : Integer ] : TOnKeyPressMode read GetRowType write SetRowType;
{$ENDIF}
{$IFDEF SORTING}
property SortColAllowed[ ACol : Integer ] : Boolean read GetSortAllowedCol write SetSortAllowedCol;
property SortColAsDate[ ACol : Integer ] : Boolean read GetSortColAsDate write SetSortColAsDate;
{$ENDIF}
property Row : integer read GetRow write SetRow;
property OnCheckBox : TCheckStringGridOnCheckBox read fOnCheckBox write fOnCheckBox;
property Cells[ ACol, ARow: Integer ] : string read GetCells write SetCells;
property CellsAsBoolean[ ACol, ARow: Integer ] : Boolean read GetCellsAsBoolean write SetCellsAsBoolean;
property CellsAsByte[ ACol, ARow: Integer ] : Byte read GetCellsAsByte write SetCellsAsByte;
property CellsAsShortInt[ ACol, ARow: Integer ]: ShortInt read GetCellsAsShortInt write SetCellsAsShortInt;
property CellsAsWord[ ACol, ARow: Integer ] : Word read GetCellsAsWord write SetCellsAsWord;
property CellsAsSmallInt[ ACol, ARow: Integer ]: SmallInt read GetCellsAsSmallInt write SetCellsAsSmallInt;
property CellsAsCardinal[ ACol, ARow: Integer ]: Cardinal read GetCellsAsCardinal write SetCellsAsCardinal;
property CellsAsInteger[ ACol, ARow: Integer] : Integer read GetCellsAsInteger write SetCellsAsInteger;
property CellsAsInt64[ ACol, ARow: Integer ] : Int64 read GetCellsAsInt64 write SetCellsAsInt64;
{$IF CompilerVersion > 23}
property CellsAsUInt64[ ACol, ARow: Integer ] : UInt64 read GetCellsAsUInt64 write SetCellsAsUInt64;
{$IFEND}
property CellsAsSingle[ ACol, ARow: Integer ] : Single read GetCellsAsSingle write SetCellsAsSingle;
property CellsAsDouble[ ACol, ARow: Integer ] : Double read GetCellsAsDouble write SetCellsAsDouble;
property CellsAsExtended[ ACol, ARow: Integer ]: Extended read GetCellsAsExtended write SetCellsAsExtended;
property CellsAsDate[ ACol, ARow: Integer ] : TDate read GetCellsAsDate write SetCellsAsDate;
property CellsAsTime[ ACol, ARow: Integer ] : TTime read GetCellsAsTime write SetCellsAsTime;
property CellsAsDateTime[ ACol, ARow: Integer ]: TDateTime read GetCellsAsDateTime write SetCellsAsDateTime;
published
{ Published declarations }
property RowCount : integer read GetRowCount write SetRowCount;
property ColCount : integer read GetColCount write SetColCount;
property MenuEnabled : boolean read GetMenuEnabled write SetMenuEnabled;
property DeleteMenu : boolean read GetDeleteMenu write SetDeleteMenu;
property SelectedRowColoring : Boolean read fSelectedRowColoring write fSelectedRowColoring;
property SelectedRowColor : TColor read fSelectedRowColor write fSelectedRowColor;
property SelectedRowHeight : Byte read fSelectedRowHeight write SetSelectedRowHeight;
property CheckedRowColoring : Boolean read fCheckedRowColoring write fCheckedRowColoring;
property CheckedRowColor : TColor read fCheckedRowColor write fCheckedRowColor;
property SelectedCellColor : TColor read fSelectedCellColor write fSelectedCellColor;
property SelectedTextColor : TColor read fSelectedTextColor write fSelectedTextColor;
property ModernScrolling : Boolean read fModernScrolling write fModernScrolling;
property DateFormat : string read fDateFormat write fDateFormat;
property TimeFormat : string read fTimeFormat write fTimeFormat;
property OnResize;
property Hint : string read fHint write SetHint;
property ValueAsHint : boolean read fValueAsHint write fValueAsHint;
property ScrollbarH : boolean read GetScrollbarH;
property ScrollbarV : boolean read GetScrollbarV;
property SelStart : Integer read GetSelStart write SetSelStart;
property SelEnd : Integer read GetSelEnd write SetSelEnd;
property SelText : String read GetSelText write SetSelText;
end;
{$IFDEF EXTENDED_STRINGGRID}
TCheckStringGrid = class( TStringGrid );
{$ENDIF}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
implementation
uses
Math, Forms;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const
DEFAULT_SELECTED_LINE_COLOR_ : TColor = clBlue;
DEFAULT_SELECTED_CELL_COLOR_ : TColor = clBlue;
DEFAULT_SELECTED_TEXT_COLOR_ : TColor = clWhite;
DEFAULT_CHECKED_LINE_COLOR_ : TColor = clGray;
DEFAULT_TEXT_FORMAT_ = DT_LEFT;
DEFAULT_DATE_FORMAT_ = 'yyyy/mm/dd';
DEFAULT_TIME_FORMAT_ = 'hh:nn:ss,zzz';
DEFAULT_FLOAT_FORMAT_ = '%.3f';
CAPTION_SELECT_ALL_ : string = 'Select all';
CAPTION_SELECT_NONE_ : string = 'Select none';
CAPTION_SELECT_INVERSE_ : string = 'Inverse selection';
CAPTION_DELETE_ROW_ : string = 'Delete Row';
CAPTION_DELETE_COL_ : string = 'Delete Col';
// CAPTION_SELECT_ALL_ : string = 'Alle auswählen';
// CAPTION_SELECT_NONE_ : string = 'Keine auswählen';
// CAPTION_SELECT_INVERSE_ : string = 'Auswahl umkehren';
// CAPTION_DELETE_ROW_ : string = 'Zeile Löschen';
// CAPTION_DELETE_COL_ : string = 'Spalte Löschen';
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constructor {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.Create( AOwner: TComponent );
var
i : Integer;
Item : TMenuItem;
begin
inherited Create( AOwner );
fLastClickCol := 0;
fLastClickRow := 0;
fSelectedRowColoring := false;
fSelectedRowColor := DEFAULT_SELECTED_LINE_COLOR_;
fSelectedRowHeight := 0;
fCheckedRowColoring := false;
fCheckedRowColor := DEFAULT_CHECKED_LINE_COLOR_;
fSelectedTextColor := DEFAULT_SELECTED_TEXT_COLOR_;
fSelectedCellColor := DEFAULT_SELECTED_CELL_COLOR_;
fModernScrolling := True;
fDateFormat := DEFAULT_DATE_FORMAT_;
fTimeFormat := DEFAULT_TIME_FORMAT_;
fFloatFormat := DEFAULT_FLOAT_FORMAT_;
fHint := '';
fValueAsHint := false;
{$IFDEF SORTING}
fSortCol := -1;
fSortDescending := false;
{$ENDIF}
Options := [ goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goDrawFocusSelected,goColSizing,goTabs,goAlwaysShowEditor];
DefaultDrawing := False;
SetLength( fComponent, ColCount, RowCount );
SetLength( fColor, ColCount, RowCount );
SetLength( fFontColor, ColCount, RowCount );
SetLength( fTextFormat, ColCount, RowCount );
SetLength( fReadOnly, ColCount, RowCount );
SetLength( fCellHint, ColCount, RowCount );
SetLength( fSelectable, ColCount, RowCount );
{$IFDEF CELLTYPES}
SetLength( fCellType, ColCount, RowCount );
{$ENDIF}
{$IFDEF SORTING}
SetLength( fSortColAllowed, ColCount );
SetLength( fSortColAsDate, ColCount );
{$ENDIF}
Clear( True, True );
myPopUpMenu := TPopUpMenu.Create( Self );
// myPopUpMenu.Name := name + '_PopUpMenu';
for i := 0 to 4 do
begin
Item := TMenuItem.Create( myPopUpMenu );
with Item do
begin
// Item.Name := name + '_PopUpMenuItem_' + IntToStr( i+1 );
OnClick := CheckStringGridPopUpClick;
case i of
0 : Caption := CAPTION_SELECT_ALL_;
1 : Caption := CAPTION_SELECT_NONE_;
2 : Caption := CAPTION_SELECT_INVERSE_;
3 : Caption := CAPTION_DELETE_ROW_;
4 : Caption := CAPTION_DELETE_COL_;
end;
end;
myPopUpMenu.Items.Add( Item );
end;
PopUpMenu := myPopUpMenu;
GetLocaleFormatSettings( 0, fLFS );
end;
destructor {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.Destroy;
begin
if NOT Assigned( self ) then
Exit;
SetLength( fComponent, 0 );
SetLength( fColor, 0 );
SetLength( fFontColor, 0 );
SetLength( fTextFormat, 0 );
SetLength( fReadOnly, 0 );
SetLength( fCellHint, 0 );
SetLength( fSelectable, 0 );
{$IFDEF CELLTYPES}
SetLength( fCellType, 0 );
{$ENDIF}
{$IFDEF SORTING}
SetLength( fSortColAllowed, 0 );
SetLength( fSortColAsDate, 0 );
{$ENDIF}
myPopUpMenu.Free;
inherited;
end;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.DrawCell( ACol, ARow : LongInt; vRect : TRect; State : TGridDrawState );
procedure DrawArrow( Canvas : TCanvas; vRect : TRect; Offset : Byte; Orientation : Byte = 0; Color : TColor = clBlack; FillColor : TColor = clBlack );
var
C1, C2 : TColor;
begin
C1 := Canvas.Pen.Color;
C2 := Canvas.Brush.Color;
Canvas.Pen.Color := clBlack;
Canvas.Brush.Color := clBlack;
case Orientation of
0 : begin // Up
Canvas.Polygon( [
Point( vRect.Left + ( ( vRect.Right-vRect.Left ) div 2 ), vRect.Top+Offset ),
Point( vRect.Left+Offset, vRect.Bottom-Offset ),
Point( vRect.Right-Offset, vRect.Bottom-Offset )
] );
end;
1 : begin // Down
Canvas.Polygon( [
Point( vRect.Left + ( ( vRect.Right-vRect.Left ) div 2 ), vRect.Bottom-Offset ),
Point( vRect.Left+Offset, vRect.Top+Offset ),
Point( vRect.Right-Offset, vRect.Top+Offset )
] );
end;
else
Exit;
end;
Canvas.Pen.Color := C1;
Canvas.Brush.Color := C2;
end;
var
cs : Cardinal;
clr : TColor;
bs : TBrushStyle;
SelCellColor : boolean;
FrameFlags1,
FrameFlags2 : Cardinal;
TempRect : TRect;
DrawInfo : TGridDrawInfo;
begin
if NOT Assigned( self ) then
Exit;
inherited DrawCell( ACol, ARow, vRect, State );
Canvas.Font := Font;
if ( fFontColor[ ACol, ARow ] <> -1 ) then
Canvas.Font.Color := fFontColor[ ACol, ARow ];
FrameFlags1 := 0;
FrameFlags2 := 0;
if goFixedVertLine in Options then
begin
FrameFlags1 := BF_RIGHT;
FrameFlags2 := BF_LEFT;
end;
if goFixedHorzLine in Options then
begin
FrameFlags1 := FrameFlags1 or BF_BOTTOM;
FrameFlags2 := FrameFlags2 or BF_TOP;
end;
SelCellColor := ( goDrawFocusSelected in Options );
clr := -1;
if ( fColor[ ACol, ARow ] <> -1 ) then
begin
clr := Canvas.Brush.Color;
Canvas.Brush.Color := fColor[ ACol, ARow ];
Canvas.FillRect( vRect );
end
else if ( gdFixed in State ) and Ctl3D and ( ( FrameFlags1 or FrameFlags2 ) <> 0 ) then
begin
Canvas.FillRect( vRect );
CalcDrawInfo( DrawInfo );
TempRect := vRect;
if ( FrameFlags1 and BF_RIGHT ) = 0 then
Inc( TempRect.Right, DrawInfo.Horz.EffectiveLineWidth )
else if ( FrameFlags1 and BF_BOTTOM ) = 0 then
Inc( TempRect.Bottom, DrawInfo.Vert.EffectiveLineWidth );
DrawEdge( Canvas.Handle, TempRect, BDR_RAISEDINNER, FrameFlags1 );
DrawEdge( Canvas.Handle, TempRect, BDR_RAISEDINNER, FrameFlags2 );
end
else if ( NOT ( gdFixed in State ) AND ( ARow = Row ) AND ( ( fSelectedRowColoring OR ( goRowSelect in Options ) ) OR ( ( ACol = Col ) AND SelCellColor ) ) ) or // SelectedRow
( ( goRangeSelect in Options ) AND ( ( ACol >= Selection.Left ) AND ( ACol <= Selection.Right ) AND ( ARow >= Selection.Top ) AND ( ARow <= Selection.Bottom ) ) ) then // Selected Range
begin
clr := Canvas.Brush.Color;
if ( ACol = Col ) AND ( ARow = Row ) AND SelCellColor then
Canvas.Brush.Color := fSelectedCellColor
else
Canvas.Brush.Color := fSelectedRowColor;
Canvas.FillRect( vRect );
Canvas.Font.Color := fSelectedTextColor
end
else if fCheckedRowColoring AND ( fComponent[ 0, ARow ] in [ csChecked, csInActiveChecked ] ) then // Checked
begin
clr := Canvas.Brush.Color;
Canvas.Brush.Color := fCheckedRowColor;
Canvas.FillRect( vRect );
Canvas.Font.Color := fSelectedTextColor
end
else
Canvas.FillRect( vRect );
if ( fComponent[ ACol, aRow ] <> csNone ) then
begin
InflateRect( vRect, -1, -1 );
case fComponent[ ACol, ARow ] of
csNone : cs := DFCS_INACTIVE;
csInactiveUnchecked : cs := DFCS_BUTTONCHECK OR DFCS_MONO;
csInactiveChecked : cs := DFCS_BUTTONCHECK or DFCS_CHECKED OR DFCS_MONO;
csUnChecked : cs := DFCS_BUTTONCHECK;
csChecked : cs := DFCS_BUTTONCHECK or DFCS_CHECKED;
else
cs := DFCS_INACTIVE;
end;
if ( Cells[ ACol, ARow ] <> '' ) then
begin
TempRect := vRect;
TempRect.Right := vRect.Left + ( vRect.Bottom - vRect.Top );
DrawFrameControl( Canvas.Handle, TempRect, DFC_Button, cs );
TempRect := vRect;
TempRect.Left := vRect.Left + ( vRect.Bottom - vRect.Top ) + 2;
DrawText( Canvas.Handle, PChar( Cells[ ACol, ARow ] ), Length( Cells[ ACol, ARow ] ), TempRect, fTextFormat[ ACol, ARow ] );
end
else
DrawFrameControl( Canvas.Handle, vRect, DFC_Button, cs );
end
else
begin
vRect.Left := vRect.Left+2;
vRect.Top := vRect.Top+2;
bs := Canvas.Brush.Style;
Canvas.Brush.Style := bsClear;
DrawText( Canvas.Handle, PChar( Cells[ ACol, ARow ] ), Length( Cells[ ACol, ARow ] ), vRect, fTextFormat[ ACol, ARow ] );
Canvas.Brush.Style := bs;
end;
if ( ARow = 0 ) AND ( ACol = fSortCol ) then
DrawArrow( Canvas, Rect( vRect.Right-( ( vRect.Bottom-vRect.Top ) div 2 ), vRect.Top, vRect.Right, vRect.Top+( ( vRect.Bottom-vRect.Top ) div 2 ) ), 2, Byte( fSortDescending ) );
if ( clr <> -1 ) then
Canvas.Brush.Color := clr;
// if SelCellColor AND ( gdFocused in State ) then
// Canvas.DrawFocusRect( vRect ); // Fail if ( goRowSelect in Options )
end;
procedure {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.ColumnMoved( FromIndex, ToIndex: Longint );
var
i : Integer;
css : TCheckStringGridState;
clr : TColor;
tf : Cardinal;
b : boolean;
s : string;
{$IFDEF CELLTYPES}
k : TOnKeyPressMode;
{$ENDIF}
begin
if NOT Assigned( self ) then
Exit;
for i := 0 to RowCount-1 do
begin
css := fComponent[ ToIndex, i ];
fComponent[ ToIndex, i ] := fComponent[ FromIndex, i ];
fComponent[ FromIndex, i ] := css;
clr := fColor[ ToIndex, i ];
fColor[ ToIndex, i ] := fColor[ FromIndex, i ];
fColor[ FromIndex, i ] := clr;
clr := fFontColor[ ToIndex, i ];
fFontColor[ ToIndex, i ] := fFontColor[ FromIndex, i ];
fFontColor[ FromIndex, i ] := clr;
tf := fTextFormat[ ToIndex, i ];
fTextFormat[ ToIndex, i ] := fTextFormat[ FromIndex, i ];
fTextFormat[ FromIndex, i ] := tf;
b := fReadOnly[ ToIndex, i ];
fReadOnly[ ToIndex, i ] := fReadOnly[ FromIndex, i ];
fReadOnly[ FromIndex, i ] := b;
{$IFDEF CELLTYPES}
k := fCellType[ ToIndex, i ];
fCellType[ ToIndex, i ] := fCellType[ FromIndex, i ];
fCellType[ FromIndex, i ] := k;
{$ENDIF}
s := fCellHint[ ToIndex, i ];
fCellHint[ ToIndex, i ] := fCellHint[ FromIndex, i ];
fCellHint[ FromIndex, i ] := s;
b := fSelectable[ ToIndex, i ];
fSelectable[ ToIndex, i ] := fSelectable[ FromIndex, i ];
fSelectable[ FromIndex, i ] := b;
end;
inherited;
SelectionChanged( FromIndex, Row, ToIndex, Row );
end;
procedure {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.RowMoved( FromIndex, ToIndex: Longint );
var
i : Integer;
css : TCheckStringGridState;
clr : TColor;
tf : Cardinal;
b : boolean;
s : String;
{$IFDEF CELLTYPES}
k : TOnKeyPressMode;
{$ENDIF}
begin
if NOT Assigned( self ) then
Exit;
for i := 0 to ColCount-1 do
begin
css := fComponent[ i, ToIndex ];
fComponent[ i, ToIndex ] := fComponent[ i, FromIndex ];
fComponent[ i, FromIndex ] := css;
clr := fColor[ i, ToIndex ];
fColor[ i, ToIndex ] := fColor[ i, FromIndex ];
fColor[ i, FromIndex ] := clr;
clr := fFontColor[ i, ToIndex ];
fFontColor[ i, ToIndex ] := fFontColor[ i, FromIndex ];
fFontColor[ i, FromIndex ] := clr;
tf := fTextFormat[ i, ToIndex ];
fTextFormat[ i, ToIndex ] := fTextFormat[ i, FromIndex ];
fTextFormat[ i, FromIndex ] := tf;
b := fReadOnly[ i, ToIndex ];
fReadOnly[ i, ToIndex ] := fReadOnly[ i, FromIndex ];
fReadOnly[ i, FromIndex ] := b;
{$IFDEF CELLTYPES}
k := fCellType[ i, ToIndex ];
fCellType[ i, ToIndex ] := fCellType[ i, FromIndex ];
fCellType[ i, FromIndex ] := k;
{$ENDIF}
s := fCellHint[ i, ToIndex ];
fCellHint[ i, ToIndex ] := fCellHint[ i, FromIndex ];
fCellHint[ i, FromIndex ] := s;
b := fSelectable[ i, ToIndex ];
fSelectable[ i, ToIndex ] := fSelectable[ i, FromIndex ];
fSelectable[ i, FromIndex ] := b;
end;
inherited;
SelectionChanged( Col, FromIndex, Col, ToIndex );
end;
procedure {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
var
iCol, iRow : Integer;
sCol, eCol : Integer;
sRow, eRow : Integer;
i, j : integer;
R : TRect;
bCompClicked : boolean;
begin
sCol := Col;
sRow := Row;
// inherited;
if ( Button <> mbLeft ) then
begin
inherited;
Exit;
end;
MouseToCell( x, y, iCol, iRow );
if ( iCol < 0 ) or ( iRow < 0 ) then
Exit;
if NOT fSelectable[ iCol, iRow ] then
begin
Col := sCol;
Row := sRow;
Exit;
end;
inherited;
if ( iCol >= ColCount ) OR ( iRow >= RowCount ) then
Exit;
fLastClickCol := iCol;
fLastClickRow := iRow;
if ( ssShift in Shift ) then
begin
if ( sRow > Row ) then
begin
sRow := Row;
eRow := sRow;
end
else
begin
sRow := sRow;
eRow := Row;
end;
if ( goRowSelect in Options ) then
begin
sCol := 0;
eCol := ColCount-1;
end
else
begin
if ( Col > iCol ) then
begin
sCol := iCol;
eCol := Col;
end
else
begin
sCol := Col;
eCol := iCol;
end;
end;
for i := sCol to eCol do
begin
for j := sRow to eRow do
begin
if ( ssCTRL in Shift ) then
begin
if fComponent[ i, j ] = csUnchecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ i, j ] <> csChecked ) then
fOnCheckBox( Self, i, j, csChecked );
fComponent[ i, j ] := csChecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, j );
end
else if fComponent[ i, j ] = csChecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ i, j ] <> csUnChecked ) then
fOnCheckBox( Self, i, j, csUnchecked );
fComponent[ i, j ] := csUnchecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, j );
end;
end
else
begin
if fComponent[ i, j ] = csUnchecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ i, j ] <> csChecked ) then
fOnCheckBox( Self, i, j, csChecked );
fComponent[ i, j ] := csChecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, j );
end;
end;
if fCheckedRowColoring then
InvalidateRow( j );
end;
end;
Exit;
end
else if ( ssCTRL in Shift ) then
begin
if ( goRowSelect in Options ) then
begin
for i := 0 to ColCount-1 do
begin
if fComponent[ i, iRow ] = csUnchecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ i, iRow ] <> csChecked ) then
fOnCheckBox( Self, i, iRow, csChecked );
fComponent[ i, iRow ] := csChecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, iRow );
end
else if fComponent[ i, iRow ] = csChecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ i, iRow ] <> csUnChecked ) then
fOnCheckBox( Self, i, iRow, csUnChecked );
fComponent[ i, iRow ] := csUnchecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, iRow );
end;
end;
if fCheckedRowColoring then
InvalidateRow( iRow );
end
else
begin
if fComponent[ iCol, iRow ] = csUnchecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ iCol, iRow ] <> csChecked ) then
fOnCheckBox( Self, iCol, iRow, csChecked );
fComponent[ iCol, iRow ] := csChecked;
if NOT fCheckedRowColoring then
InvalidateCell( iCol, iRow )
else
InvalidateRow( iRow );
end
else if fComponent[ iCol, iRow ] = csChecked then
begin
if Assigned( fOnCheckBox ) AND ( fComponent[ iCol, iRow ] <> csUnChecked ) then
fOnCheckBox( Self, iCol, iRow, csUnChecked );
fComponent[ iCol, iRow ] := csUnchecked;
if NOT fCheckedRowColoring then
InvalidateCell( iCol, iRow )
else
InvalidateRow( iRow );
end;
end;
Exit;
end;
bCompClicked := false;
if ( Cells[ iCol, iRow ] = '' ) then
begin
case fComponent[ iCol, iRow ] of
csUnchecked : begin
fComponent[ iCol, iRow ] := csChecked;
bCompClicked := True;
end;
csChecked : begin
fComponent[ iCol, iRow ] := csUnchecked;
bCompClicked := True;
end;
end;
if bCompClicked AND Assigned( fOnCheckBox ) then
fOnCheckBox( Self, iCol, iRow, fComponent[ iCol, iRow ] );
end
else
begin
R := CellRect( iCol, iRow );
if ( x <= R.Left + ( R.Bottom - R.Top ) ) then
begin
case fComponent[ iCol, iRow ] of
csUnchecked : begin
fComponent[ iCol, iRow ] := csChecked;
bCompClicked := True;
end;
csChecked : begin
fComponent[ iCol, iRow ] := csUnchecked;
bCompClicked := True;
end;
end;
if bCompClicked AND Assigned( fOnCheckBox ) then
fOnCheckBox( Self, iCol, iRow, fComponent[ iCol, iRow ] );
end;
end;
if bCompClicked AND ( ( iCol <= FixedCols-1 ) OR ( iRow <= FixedRows-1 ) ) then
begin
if NOT fCheckedRowColoring then
InvalidateCell( iCol, iRow )
else
InvalidateRow( iRow );
end;
if ( goEditing in Options ) AND EditorMode AND ( fReadOnly[ iCol, iRow ] OR bCompClicked ) then
HideEditor;
SelectionChanged( sCol, sRow, Col, Row );
end;
procedure {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.KeyDown(var Key: Word; Shift: TShiftState);
var
i : Integer;
sCol, eCol : Integer;
sRow : Integer;
begin
sCol := Col;
sRow := Row;
inherited;
if ( Key in [ VK_SPACE ] ) then
begin
for i := 0 to ColCount-1 do
begin
if ( NOT ( goRowSelect in Options ) ) AND NOT ( i = Col ) then
Continue;
if fComponent[ i, Row ] = csUnchecked then
begin
fComponent[ i, Row ] := csChecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, Row );
end
else if fComponent[ i, Row ] = csChecked then
begin
fComponent[ i, Row ] := csUnchecked;
if NOT fCheckedRowColoring then
InvalidateCell( i, Row );
end;
end;
if fCheckedRowColoring then
InvalidateRow( Row );
Exit;
end;
if NOT fSelectable[ Col, Row ] then
begin
Col := sCol;
Row := sRow;
Exit;
end;
SelectionChanged( sCol, sRow, Col, Row );
if NOT ( Key in [ VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN ] ) then
Exit;
eCol := Col;
if ( ssShift in Shift ) then
begin
if ( goRowSelect in Options ) then
begin
sCol := 0;
eCol := ColCount-1;
end
else
begin
if ( sCol > Col ) then
begin
eCol := sCol;
sCol := Col;
end;
end;
for i := sCol to eCol do
begin
if fComponent[ i, Row ] = csUnchecked then
begin
fComponent[ i, Row ] := csChecked;
InvalidateCell( i, Row );
end
else if fComponent[ i, Row ] = csChecked then
begin
fComponent[ i, Row ] := csUnchecked;
InvalidateCell( i, Row );
end;
end;
end;
end;
procedure {$IFDEF EXTENDED_STRINGGRID}TStringGrid{$ELSE}TCheckStringGrid{$ENDIF}.DblClick;
var
Order : TCheckStringGridSortType;
begin
if ( fLastClickRow < FixedRows ) AND ( fLastClickCol >= FixedCols ) then
begin
{$IFDEF SORTING}
if NOT fSortColAllowed[ fLastClickCol ] then
Exit;
if fSortColAsDate[ fLastClickCol ] then
Order := cstAscendingDate
else
Order := cstAscending;
if ( fSortCol = fLastClickCol ) AND NOT fSortDescending then
begin
if fSortColAsDate[ fLastClickCol ] then
Order := cstDescendingDate