-
Notifications
You must be signed in to change notification settings - Fork 41
/
FMX.ListView.Types.pas
3520 lines (3032 loc) · 105 KB
/
FMX.ListView.Types.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
{ ******************************************************* }
{ }
{ Delphi FireMonkey Platform }
{ }
{ Copyright(c) 2016 Embarcadero Technologies, Inc. }
{ All rights reserved }
{ }
{ ******************************************************* }
unit FMX.ListView.Types;
interface
{$SCOPEDENUMS ON}
uses
System.Types, System.UITypes, System.Classes, System.Generics.Collections,
System.Generics.Defaults, System.SysUtils,
FMX.Types, FMX.Controls, FMX.TextLayout, System.Math.Vectors, System.Rtti, FMX.Objects,
FMX.Graphics, FMX.ActnList,
FMX.Styles.Objects, FMX.ImgList;
{$IF DEFINED(IOS) OR DEFINED(ANDROID)}
{$DEFINE LISTVIEW_TOUCH}
{$ENDIF}
{ .$DEFINE PIXEL_ALIGNMENT }
{ .$DEFINE DRAW_ITEM_MARGINS }
type
TListItemAlign = (Leading, Center, Trailing);
TListItemPurpose = (None, Header, Footer);
TListItemPurposes = set of TListItemPurpose;
TListItemPurposeHelper = record helper for TListItemPurpose
function ToString: string;
end;
TListItem = class;
IListViewAdapter = interface;
IListViewController = interface;
TListItemStyleResources = class;
TListItemDrawState = (Selected, Deleting, EditMode);
TListItemDrawStates = set of TListItemDrawState;
TListItemDrawable = class;
TListItemView = class;
TListItemCallbackOp = (CreateDrawables, InvalidateOwner, Click);
TListItemCallback = TProc<TListItemView, TListItemDrawable, TListItemCallbackOp>;
/// <summary>TListItem view is comprised of TListViewDrawables. These are the actual
/// view elements that are being painted in the item cells.</summary>
TListItemDrawable = class(TInterfacedPersistent)
public type
TParams = record
AbsoluteOpacity: Single;
ItemSelectedAlpha: Single;
DeletingUnwantedOpacity: Single;
EditModeTransitionAlpha: Single;
ParentAbsoluteRect: TRectF;
Images: TCustomImageList;
end;
strict private
FPlaceOffsetX: TPosition;
protected type
TStyleResource = (FontSize, FontFamily, FontStyle, TextColor, SelectedTextColor,
TextShadowColor, PressedTextColor);
TStyleResources = set of TStyleResource;
protected const
TextResources: set of TStyleResource = [TStyleResource.FontFamily, TStyleResource.FontSize,
TStyleResource.FontStyle, TStyleResource.TextColor, TStyleResource.TextShadowColor,
TStyleResource.SelectedTextColor, TStyleResource.PressedTextColor];
private
FAlign: TListItemAlign;
FVertAlign: TListItemAlign;
FVisible: Boolean;
FWidth: Single;
FHeight: Single;
FOpacity: Single;
FUpdating: Integer;
NeedRepaint: Boolean;
FOnSelect: TNotifyEvent;
FName: string;
[Weak]
FTagObject: TObject;
FTagFloat: Single;
FTagString: string;
FLocalRect: TRectF;
FStyleValuesNeedUpdate: TStyleResources;
FController: IListViewController;
FCallback: TListItemCallback;
procedure SetOneDimension(const Index: Integer; const Value: Single);
procedure SetSize(const Value: TPointF);
function GetSize: TPointF;
procedure SetOpacity(const Value: Single);
procedure SetAlign(const Value: TListItemAlign);
procedure SetVertAlign(const Value: TListItemAlign);
procedure SetVisible(const Value: Boolean);
function GetData: TValue; virtual;
procedure SetData(const Value: TValue); virtual;
function GetPlaceOffset: TPosition; inline;
procedure SetInvalidateCallback(const Callback: TListItemCallback); virtual;
procedure PlaceOffsetChanged(Sender: TObject);
protected
/// <summary>Called when the size of this drawable changes. See SetSize</summary>
procedure DoResize; virtual;
/// <summary>Called when the opacity of this drawable changes.</summary>
procedure DoOpacityChange; virtual;
/// <summary>Called when ListItem holding this drawable is selected.</summary>
procedure DoSelect; virtual;
/// <summary>Called when PlaceOffset property changes.</summary>
procedure DoPlaceOffsetChanged; virtual;
/// <summary>Called when Align or VertAlign changes.</summary>
procedure DoAlignChanged; virtual;
/// <summary>Finds an embedded control at given Point</summary>
function ObjectAtPoint(const Point: TPointF): TControl; virtual;
/// <summary>Called by host TListItem.MouseDown</summary>
function MouseDown(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF): Boolean; virtual;
/// <summary>Called by host TListItem.MouseMove</summary>
procedure MouseMove(const Shift: TShiftState; const MousePos: TPointF); virtual;
/// <summary>Called by host TListItem.MouseUp</summary>
procedure MouseUp(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF); virtual;
procedure DoUpdateValuesFromResources(const Resources: TListItemStyleResources;
const Purpose: TListItemPurpose); virtual;
public
constructor Create(const AOwner: TListItem); virtual;
destructor Destroy; override;
function ToString: string; override;
/// <summary>Return amount of rendering passes. See TListViewBase.DrawListItems</summary>
function GetRenderPassCount: Integer; virtual;
/// <summary>Align and calculate this drawable's local rect for given item's DestRect and DrawStates</summary>
procedure CalculateLocalRect(const DestRect: TRectF; const SceneScale: Single;
const DrawStates: TListItemDrawStates; const Item: TListItem); virtual;
/// <summary>Return True if Point is inside local rect</summary>
function InLocalRect(const Point: TPointF): Boolean;
/// <summary>Request repaint</summary>
procedure Invalidate;
/// <summary>Render this drawable</summary>
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TParams; const SubPassNo: Integer = 0); virtual; abstract;
procedure UpdateValuesFromStyle;
/// <summary>Begin bulk change</summary>
procedure BeginUpdate;
/// <summary>End bulk change</summary>
procedure EndUpdate;
procedure UpdateValuesFromResources(const Resources: TListItemStyleResources;
const Purpose: TListItemPurpose);
/// <summary>Local width of list item inside its designated area.</summary>
property Width: Single index 0 read FWidth write SetOneDimension;
/// <summary>Local height of list item inside its designated area.</summary>
property Height: Single index 1 read FHeight write SetOneDimension;
property Size: TPointF read GetSize write SetSize;
/// <summary>Horizontal alignment of drawable inside its designated area.</summary>
property Align: TListItemAlign read FAlign write SetAlign;
/// <summary>Vertical alignment of drawable inside its designated area.</summary>
property VertAlign: TListItemAlign read FVertAlign write SetVertAlign;
/// <summary>Determines whether the current drawable is visible or not.</summary>
property Visible: Boolean read FVisible write SetVisible;
/// <summary>The offset in logical units regarding aligned location for finer placement control.</summary>
property PlaceOffset: TPosition read GetPlaceOffset;
/// <summary>Name of this drawable</summary>
property Name: string read FName write FName;
/// <summary>Drawing opacity</summary>
property Opacity: Single read FOpacity write SetOpacity;
/// <summary>LocalRect of this drawable</summary>
property LocalRect: TRectF read FLocalRect;
/// <summary>Invoked when owner TListItem is selected</summary>
property OnSelect: TNotifyEvent read FOnSelect write FOnSelect;
// <summary>Polymorphic property access</summary>
property Data: TValue read GetData write SetData;
/// <summary>User-defined object reference for this item.</summary>
property TagObject: TObject read FTagObject write FTagObject;
/// <summary>User-defined floating-point number for this item.</summary>
property TagFloat: Single read FTagFloat write FTagFloat;
/// <summary>User-defined string for this item.</summary>
property TagString: string read FTagString write FTagString;
property InvalidateCallback: TListItemCallback write SetInvalidateCallback;
end;
/// <summary>Declared for compatibility</summary>
TListItemObject = class(TListItemDrawable)
end;
/// <summary>Represents a text drawable in ListView items</summary>
TListItemText = class(TListItemDrawable)
private const
DefaultFontFamily = 'Helvetica'; // do not localize
DefaultFontSize = 14;
ShadowOffset: TPointF = (X: 0; Y: 1);
type
TFontSettings = record
Family: string;
Size: Single;
Style: TFontStyles;
end;
strict private
FFontX: TFont;
FFontSettings: TFontSettings;
private
FTextLayout: TTextLayout;
FText: string;
FTextAlign: TTextAlign;
FTextVertAlign: TTextAlign;
FWordWrap: Boolean;
LayoutChanged: Boolean;
FTextColor: TAlphaColor;
FSelectedTextColor: TAlphaColor;
FTrimming: TTextTrimming;
FTextShadowOffsetX: TPosition;
FTextShadowColor: TAlphaColor;
FIsDetailText: Boolean;
procedure FontChanged(Sender: TObject);
procedure TextShadowOffsetChanged(Sender: TObject);
procedure SetText(const Value: string);
procedure SetTextAlign(const Value: TTextAlign);
procedure SetTextVertAlign(const Value: TTextAlign);
procedure SetWordWrap(const Value: Boolean);
procedure SetTextColor(const Value: TAlphaColor);
procedure SetTrimming(const Value: TTextTrimming);
procedure SetSelectedTextColor(const Value: TAlphaColor);
procedure SetTextShadowColor(const Value: TAlphaColor);
procedure SetIsDetailText(const Value: Boolean);
procedure SetData(const AValue: TValue); override;
function GetData: TValue; override;
function GetShadowOffset: TPosition; inline;
function GetFont: TFont;
protected
procedure DoResize; override;
procedure DoUpdateValuesFromResources(const Resources: TListItemStyleResources;
const Purpose: TListItemPurpose); override;
function FontSettingsSnapshot: TFontSettings;
public
constructor Create(const AOwner: TListItem); override;
destructor Destroy; override;
procedure CalculateLocalRect(const DestRect: TRectF; const SceneScale: Single;
const DrawStates: TListItemDrawStates; const Item: TListItem); override;
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
property Font: TFont read GetFont;
property Text: string read FText write SetText;
// Horizontal text alignment inside local item rectangle.
property TextAlign: TTextAlign read FTextAlign write SetTextAlign;
// Vertical text alignment inside local item rectangle.
property TextVertAlign: TTextAlign read FTextVertAlign write SetTextVertAlign;
property WordWrap: Boolean read FWordWrap write SetWordWrap;
property TextColor: TAlphaColor read FTextColor write SetTextColor;
property SelectedTextColor: TAlphaColor read FSelectedTextColor write SetSelectedTextColor;
{ Text shadow color and offset. The text shadow will appear behind normal text and only when its color is
set to non-zero value (default). This is useful for headers or other gradient fills to improve readability. }
property TextShadowColor: TAlphaColor read FTextShadowColor write SetTextShadowColor;
property TextShadowOffset: TPosition read GetShadowOffset;
property Trimming: TTextTrimming read FTrimming write SetTrimming;
// Hints regarding the contents of this text object, which affecs visual style.
property IsDetailText: Boolean read FIsDetailText write SetIsDetailText;
end;
TListItemDummy = class(TListItemDrawable)
public
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
end;
TImageScalingMode = (StretchWithAspect, Original, Stretch);
TImageScalingModeHelper = record helper for TImageScalingMode
const
smStretchWithAspect = TImageScalingMode.StretchWithAspect deprecated
'Use TImageScalingMode.StretchWithAspect';
smOriginal = TImageScalingMode.Original deprecated 'Use TImageScalingMode.Original';
smStretch = TImageScalingMode.Stretch deprecated 'Use TImageScalingMode.Stretch';
end;
TListItemImage = class(TListItemDrawable)
public type
TImageSource = (None, Bitmap, ImageList);
private
FStaticBitmap: TBitmap;
[Weak]
FReferBitmap: TBitmap;
FSrcRect: TRectF;
FOwnsBitmap: Boolean;
FImageScalingMode: TImageScalingMode;
FImageIndex: TImageIndex;
FImageSource: TImageSource;
function GetBitmap: TBitmap;
procedure SetBitmap(const Value: TBitmap);
procedure SetOwnsBitmap(const Value: Boolean);
procedure SetSrcRect(const Value: TRectF);
procedure SetImageScalingMode(const Value: TImageScalingMode);
procedure SetImageIndex(const Value: TImageIndex);
function GetImageSource: TImageSource; inline;
procedure SetData(const Value: TValue); override;
public
constructor Create(const AOwner: TListItem); override;
destructor Destroy; override;
procedure CalculateLocalRect(const DestRect: TRectF; const SceneScale: Single;
const DrawStates: TListItemDrawStates; const Item: TListItem); override;
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
property Bitmap: TBitmap read GetBitmap write SetBitmap;
{ Determines whether this list owns and maintains the bitmap, or whether it is a reference only. It is must faster
(and memory efficient) to have multiple references to a single bitmap rather than multiple copies of the same
bitmap copied across the items. }
property OwnsBitmap: Boolean read FOwnsBitmap write SetOwnsBitmap;
procedure FitInto(const Bitmap: TBitmap; var InputRect, DestinationRect: TRectF);
property SrcRect: TRectF read FSrcRect write SetSrcRect;
property ScalingMode: TImageScalingMode read FImageScalingMode write SetImageScalingMode
default TImageScalingMode.StretchWithAspect;
/// <summary>Indicates whether the images are obtained from TImageList or directly by using Bitmap property.</summary>
property ImageSource: TImageSource read GetImageSource;
/// <summary> Zero based index of an image. The default is <c>-1</c>.
/// <para> See also <b>FMX.ActnList.IGlyph</b></para></summary>
/// <remarks> If non-existing index is specified, an image is not drawn and no exception is raised</remarks>
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
end;
TListItemEmbeddedControl = class;
TListItemControlScene = class(TFmxObject, IStyleBookOwner, IScene)
strict private
FCanvas: TCanvas;
[Weak]
FContainer: TControl;
[Weak]
FOwnerItem: TListItem;
FDrawing: Boolean;
FDisableUpdating: Integer;
private
FLayoutSize: TPoint;
function GetRealScene: IScene;
protected
// TFmxObject
procedure DoAddObject(const AObject: TFmxObject); override;
procedure DoRemoveObject(const AObject: TFmxObject); override;
// IStyleBookOwner
function GetStyleBook: TStyleBook;
procedure SetStyleBook(const Value: TStyleBook);
// IScene
function GetCanvas: TCanvas;
function GetSceneScale: Single;
function GetObject: TFmxObject;
procedure AddUpdateRect(R: TRectF);
function GetUpdateRectsCount: Integer;
function GetUpdateRect(const Index: Integer): TRectF;
function LocalToScreen(P: TPointF): TPointF;
function ScreenToLocal(P: TPointF): TPointF;
procedure ChangeScrollingState(const AControl: TControl; const Active: Boolean);
procedure DisableUpdating;
procedure EnableUpdating;
procedure SetOwnerItem(const Item: TListItem);
procedure SetContainer(const Container: TControl);
property RealScene: IScene read GetRealScene;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure RepaintScene(const Canvas: TCanvas);
property Container: TControl read FContainer;
end;
TListItemControlContainer = class(TControl)
private
[Weak]
FItemOwner: TListItemEmbeddedControl;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TListItemEmbeddedControl = class(TListItemDrawable)
private
FScene: TListItemControlScene;
FContainer: TListItemControlContainer;
protected
function ObjectAtPoint(const Point: TPointF): TControl; override;
public
constructor Create(const AOwner: TListItem); override;
destructor Destroy; override;
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
property Container: TListItemControlContainer read FContainer;
end;
TListItemSimpleControl = class(TListItemDrawable)
private const
DisabledOpacity = 0.6;
private
FEnabled: Boolean;
FPressed: Boolean;
FMouseOver: Boolean;
FTouchExpand: Single;
procedure SetEnabled(const Value: Boolean);
protected
function IsClickOpaque: Boolean; virtual;
function MouseDown(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF): Boolean; override;
procedure MouseMove(const Shift: TShiftState; const MousePos: TPointF); override;
procedure MouseUp(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF); override;
procedure DoClick; virtual;
procedure DoEnabledChange; virtual;
public
constructor Create(const AOwner: TListItem); override;
function PointInLocalRect(const Pos: TPointF): Boolean;
/// <summary>This method is called when click event is sent to the control to handle any actions associated
/// with this item.</summary>
procedure Click;
property Enabled: Boolean read FEnabled write SetEnabled;
property Pressed: Boolean read FPressed;
property MouseOver: Boolean read FMouseOver;
// Additional area (in logical units) around the control that is sensitive to touch.
property TouchExpand: Single read FTouchExpand write FTouchExpand;
end;
TAccessoryType = (More, Checkmark, Detail);
TListItemAccessory = class(TListItemDrawable)
private
FAccessoryType: TAccessoryType;
protected
procedure SetAccessoryType(Value: TAccessoryType);
public
constructor Create(const AOwner: TListItem); override;
procedure CalculateLocalRect(const DestRect: TRectF; const SceneScale: Single;
const DrawStates: TListItemDrawStates; const Item: TListItem); override;
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
property AccessoryType: TAccessoryType read FAccessoryType write SetAccessoryType;
end;
TGlyphButtonType = (Add, Delete, Checkbox);
TListItemGlyphButton = class(TListItemSimpleControl)
private const
CheckedAnimationFrameRate = 60;
CheckedAnimationDuration = 0.15; // in seconds
private
FButtonType: TGlyphButtonType;
FClickOnSelect: Boolean;
FChecked: Boolean;
FTransitionEnabled: Boolean;
FTransitionAlpha: Single;
FTransitionTimer: TTimer;
FTransitionStartTicks: Double;
FTimerService: IFMXTimerService;
procedure SetButtonType(const Value: TGlyphButtonType);
procedure SetChecked(const Value: Boolean);
procedure InitCheckedTransition;
procedure ResetCheckedTransition;
procedure TransitionTimerNotify(Sender: TObject);
protected
procedure DoSelect; override;
procedure DoClick; override;
function MouseDown(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF): Boolean; override;
procedure SetData(const AValue: TValue); override;
public
constructor Create(const AOwner: TListItem); override;
destructor Destroy; override;
procedure CalculateLocalRect(const DestRect: TRectF; const SceneScale: Single;
const DrawStates: TListItemDrawStates; const Item: TListItem); override;
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
property ButtonType: TGlyphButtonType read FButtonType write SetButtonType;
// If set to True, this button will receive click events from entire list by using of selection.
property ClickOnSelect: Boolean read FClickOnSelect write FClickOnSelect;
// Determines whether checkbox is checked, has no effect for other button types.
property Checked: Boolean read FChecked write SetChecked;
end;
TTextButtonType = (Normal, Delete);
TListItemTextButton = class(TListItemSimpleControl)
private
FTextDrawable: TListItemText;
FButtonType: TTextButtonType;
FTintColor: TAlphaColor;
FPressedTextColor: TAlphaColor;
FTextColor: TAlphaColor;
// getters routing to FTextDrawable
function GetFont: TFont;
function GetText: string;
procedure SetText(const Value: string);
procedure SetTextAlign(const Value: TTextAlign);
function GetTextAlign: TTextAlign;
procedure SetTextVertAlign(const Value: TTextAlign);
function GetTextVertAlign: TTextAlign;
procedure SetWordWrap(const Value: Boolean);
function GetWordWrap: Boolean;
procedure SetTextColor(const Value: TAlphaColor);
function GetTextColor: TAlphaColor;
procedure SetTrimming(const Value: TTextTrimming);
function GetTrimming: TTextTrimming;
procedure SetTextShadowColor(const Value: TAlphaColor);
function GetTextShadowColor: TAlphaColor;
// button-specific text properties
procedure SetPressedTextColor(const Value: TAlphaColor);
function GetTextShadowOffset: TPosition; inline;
procedure SetButtonType(const Value: TTextButtonType);
procedure SetTintColor(const Value: TAlphaColor);
procedure SetInvalidateCallback(const Callback: TListItemCallback); override;
protected
function IsClickOpaque: Boolean; override;
procedure DoResize; override;
procedure DoOpacityChange; override;
procedure DoPlaceOffsetChanged; override;
procedure DoAlignChanged; override;
procedure SetData(const AValue: TValue); override;
public
constructor Create(const AOwner: TListItem); override;
destructor Destroy; override;
procedure DoUpdateValuesFromResources(const Resources: TListItemStyleResources;
const Purpose: TListItemPurpose); override;
function GetRenderPassCount: Integer; override;
procedure CalculateLocalRect(const DestRect: TRectF; const SceneScale: Single;
const DrawStates: TListItemDrawStates; const Item: TListItem); override;
procedure Render(const Canvas: TCanvas; const DrawItemIndex: Integer;
const DrawStates: TListItemDrawStates; const Resources: TListItemStyleResources;
const Params: TListItemDrawable.TParams; const SubPassNo: Integer = 0); override;
property ButtonType: TTextButtonType read FButtonType write SetButtonType;
property TintColor: TAlphaColor read FTintColor write SetTintColor;
property Font: TFont read GetFont;
property Text: string read GetText write SetText;
property TextAlign: TTextAlign read GetTextAlign write SetTextAlign;
property TextVertAlign: TTextAlign read GetTextVertAlign write SetTextVertAlign;
property WordWrap: Boolean read GetWordWrap write SetWordWrap;
property TextColor: TAlphaColor read GetTextColor write SetTextColor;
property PressedTextColor: TAlphaColor read FPressedTextColor write SetPressedTextColor;
property TextShadowColor: TAlphaColor read GetTextShadowColor write SetTextShadowColor;
property TextShadowOffset: TPosition read GetTextShadowOffset;
property Trimming: TTextTrimming read GetTrimming write SetTrimming;
end;
TListItemView = class
private type
TViewList = TObjectList<TListItemDrawable>;
private
FCallback: TListItemCallback;
FViewList: TListItemView.TViewList;
FInitialized: Boolean;
function GetCount: Integer;
function GetObject(const Index: Integer): TListItemDrawable;
function GetViewList: TViewList; inline;
protected
procedure Include(const AItem: TListItemDrawable);
procedure Exclude(const AItem: TListItemDrawable);
function GetInitialized: Boolean;
procedure SetInitialized(const Value: Boolean);
public
constructor Create(const AOwner: TListItem);
destructor Destroy; override;
function Add(const AItem: TListItemDrawable): Integer;
procedure Insert(const Index: Integer; const Value: TListItemDrawable);
procedure Clear; virtual;
procedure Delete(Index: Integer);
function FindDrawable(const AName: string): TListItemDrawable;
function FindObject(const AName: string): TListItemDrawable; deprecated 'Use FindDrawable';
function DrawableByName(const AName: string): TListItemDrawable;
function ObjectByName(const AName: string): TListItemDrawable; deprecated 'Use DrawableByName';
property Count: Integer read GetCount;
property Drawables[const Index: Integer]: TListItemDrawable read GetObject; default;
property ViewList: TViewList read GetViewList;
property Callback: TListItemCallback write FCallback;
property Initialized: Boolean read GetInitialized write SetInitialized;
end;
TListItemObjects = class(TListItemView)
end;
TListItem = class
public type
TListItemViewType = class of TListItemView;
TListItemNotifyEvent = procedure(const Item: TListItem) of object;
strict private
FHeaderRef: Integer;
FAdapter: IListViewAdapter;
FController: IListViewController;
private
FIndex: Integer;
FHeight: Integer;
FPurpose: TListItemPurpose;
FUpdating: Integer;
FNeedRepaint: Boolean;
FView: TListItemView;
function GetCount: Integer;
procedure SetHeight(const Value: Integer);
function GetController: IListViewController;
protected
procedure InvalidateHeights; virtual;
procedure SetPurpose(const AValue: TListItemPurpose); virtual;
procedure Repaint; virtual;
function ListItemObjectsClass: TListItemViewType; virtual;
function GetIndex: Integer; virtual;
procedure SetIndex(const Value: Integer); virtual;
public
constructor Create(const AAdapter: IListViewAdapter;
const AController: IListViewController = nil);
destructor Destroy; override;
function ToString: string; override;
procedure Invalidate;
procedure BeginUpdate;
procedure EndUpdate;
procedure CreateObjects; virtual;
procedure WillBePainted; virtual;
function ObjectAtPoint(const Point: TPointF): TControl;
function MouseDown(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF): Boolean;
procedure MouseMove(const Shift: TShiftState; const MousePos: TPointF);
procedure MouseUp(const Button: TMouseButton; const Shift: TShiftState;
const MousePos: TPointF);
procedure MouseSelect;
function HasClickOnSelectItems: Boolean;
property Adapter: IListViewAdapter read FAdapter;
property Count: Integer read GetCount;
property View: TListItemView read FView;
property Height: Integer read FHeight write SetHeight;
property Controller: IListViewController read GetController;
// Which purpose item serves for: normal item (none), header or footer.
property Purpose: TListItemPurpose read FPurpose write SetPurpose;
property HeaderRef: Integer read FHeaderRef write FHeaderRef;
/// <summary>Index of this item in TListView.Adapter</summary>
property Index: Integer read GetIndex write SetIndex;
end;
TListItemStyleResources = class
private
FOwnsObjects: Boolean;
public type
TAccessoryStyleObject = record [Weak]
Normal: TStyleObject;
[Weak]
Selected: TStyleObject;
end;
TButtonStyleObject = record [Weak]
Normal: TStyleObject;
[Weak]
Pressed: TStyleObject;
end;
public
AccessoryImages: array [TAccessoryType] of TAccessoryStyleObject;
HeaderTextFont: TFont;
HeaderTextColor: TAlphaColor;
HeaderTextShadowColor: TAlphaColor;
DefaultTextFont: TFont;
DefaultTextColor: TAlphaColor;
DetailTextFont: TFont;
DetailTextColor: TAlphaColor;
DefaultTextSelectedColor: TAlphaColor;
ButtonAddItemStyleImage: TButtonStyleObject;
ButtonDeleteItemStyleImage: TButtonStyleObject;
ButtonNormalStyleImage: TButtonStyleObject;
ButtonDeleteStyleImage: TButtonStyleObject;
ButtonCheckboxStyleImage: TButtonStyleObject;
ButtonTextFont: TFont;
ButtonTextColor: TAlphaColor;
ButtonTextPressedColor: TAlphaColor;
DeleteButtonTextFont: TFont;
DeleteButtonTextColor: TAlphaColor;
DeleteButtonTextPressedColor: TAlphaColor;
ScrollingStretchGlowColor: TAlphaColor;
PullRefreshIndicatorColor: TAlphaColor;
PullRefreshStrokeColor: TAlphaColor;
constructor Create; overload;
constructor Create(const Source: TListItemStyleResources); overload;
destructor Destroy; override;
end;
IListItemStyleResources = interface
['{0328C6F1-432C-4F8B-994B-7AB2543CD172}']
function GetStyleResources: TListItemStyleResources;
property StyleResources: TListItemStyleResources read GetStyleResources;
function StyleResourcesNeedUpdate: Boolean;
end;
IListViewController = interface
['{3855EF72-3B32-41BE-9068-7B109B2DD8E5}']
function GetEditModeTransitionAlpha: Single;
function GetDeleteModeTransitionAlpha: Single;
function IsDeleteModeAllowed: Boolean;
function GetItemEditOffset(const Item: TListItem): Single;
function GetItemDeleteCutoff(const Item: TListItem): Single;
function GetItemSelectionAlpha(const Item: TListItem): Single;
function GetClientMargins: TRectF;
function GetScene: IScene;
procedure RequestReindexing(const Item: TListItem);
procedure ItemResized(const Item: TListItem);
procedure ItemInvalidated(const Item: TListItem);
procedure ControlClicked(const Item: TListItem; const Control: TListItemDrawable);
procedure CheckStateChanged(const Item: TListItem; const Control: TListItemDrawable);
/// <summary>
/// Returns reference to instance of TCustomImageList which used for displays images in items
/// </summary>
function GetImages: TCustomImageList;
property EditModeTransitionAlpha: Single read GetEditModeTransitionAlpha;
property DeleteModeTransitionAlpha: Single read GetDeleteModeTransitionAlpha;
/// <summary> The list of images. Can be <c>nil</c>. <para>See also <b>GetImages</b></para></summary>
property Images: TCustomImageList read GetImages;
end;
IListViewPresentation = interface
['{85C07617-2BB7-44DC-BBCB-2E3FE422B006}']
/// <summary>Called when ancestor's visible property is changed</summary>
procedure AncestorVisibleChanged(const Visible: Boolean);
/// <summary>Called when Parent is changed</summary>
procedure ParentChanged;
/// <summary>Called when position in parent list is changed</summary>
procedure OrderChanged;
procedure SizeChanged;
procedure EditModeChanged;
procedure StatusChanged;
procedure ItemsUpdated;
procedure ItemInvalidated(const Item: TListItem);
procedure SetItemSelected(const ItemIndex: Integer; const Value: Boolean);
procedure SetItemIndex(const ItemIndex: Integer);
procedure StopPullRefresh;
end;
IListViewCustomPresentationParent = interface
['{EBBE5FAA-F2B3-4606-AE32-8027DB97EC92}']
function GetRootObject: TObject;
function GetContentFrame: TRect;
function GetControlOpacity: Single;
end;
TListViewModeFlag = (Edit, Enabled, Visible, Deletion, PullRefresh, Buttons, Search, SearchOnTop,
PullRefreshWait, SwipeDelete);
TListViewModeFlags = set of TListViewModeFlag;
TListViewNativeOption = (Grouped, Indexed, Styled);
TListViewNativeOptions = set of TListViewNativeOption;
IListViewPresentationParent = interface(IListViewCustomPresentationParent)
['{F5657E45-0955-4A9F-9FE6-6C5E019846E4}']
function GetAdapter: IListViewAdapter;
function GetItemClientRect(const ItemIndex: Integer): TRectF;
function GetItemCount: Integer;
function GetItemHeight(const ItemIndex: Integer): Integer;
function GetEstimatedItemHeight: Single;
function GetEstimatedHeaderHeight: Single;
function GetEstimatedFooterHeight: Single;
function GetItemText(const ItemIndex: Integer): string;
function GetItemIndexTitle(const ItemIndex: Integer): string;
function CanSelectItem(const ItemIndex: Integer): Boolean;
procedure DidSelectItem(const ItemIndex: Integer);
function CanUnselectItem(const ItemIndex: Integer): Boolean;
procedure DidUnselectItem(const ItemIndex: Integer);
procedure ItemButtonClicked(const ItemIndex: Integer);
function GetFlags: TListViewModeFlags;
function GetOptions: TListViewNativeOptions;
function DeleteItem(const ItemIndex: Integer): Boolean;
procedure InvokePullRefresh;
procedure SetSearchFilter(const Filter: string);
procedure SetScrollViewPos(const Value: Single);
procedure RebuildList;
procedure SetCreatingNativeView(const Value: Boolean);
function GetIsTransparent: Boolean;
function GetOpacity: Single;
function GetBackgroundStyleColor: TAlphaColor;
procedure RecreateNativePresentation;
end;
/// <summary>Used to check if there is a design presentation attached to ListView</summary>
IListViewDesignPresentationParent = interface
['{C62F3FE5-FE96-47A7-99CB-2EEBC85664FA}']
/// <summary>True if design presentation is attached</summary>
function HasDesignPresentationAttached: Boolean;
end;
/// <summary>A drawable shim extension to apply bounds changes from
/// the designer.</summary>
IListViewDrawableShim = interface
['{9FB67E2A-37B9-473B-A95A-13EDD19ED91B}']
/// <summary>Calculate appearance PlaceOffset, Width, Height for given rect from designer</summary>
function CalcAppearanceBounds(const AValue: TRect; const CurrentBounds: TRectF): TRectF;
end;
TFilterPredicate = TPredicate<string>;
TListItemsList = TList<TListItem>;
/// <summary>IListViewAdapter provides interface between the data and their representation.
/// The essential part of this interface is implemented in FMX.ListView.Adapters.Base.TAbstractListViewAdapter
/// </summary>
IListViewAdapter = interface
['{6E850F76-BABD-4756-BF05-A30C66A692AD}']
/// <summary>Return number of items that this Adapter represents. See Item[Index]. </summary>
function GetCount: Integer;
/// <summary>Get TListItem by index Index</summary>
function GetItem(const Index: Integer): TListItem;
/// <summary>Get index of given TListItem</summary>
function IndexOf(const AItem: TListItem): Integer;
/// <summary>Return TEnumerator<TListItem></summary>
function GetEnumerator: TEnumerator<TListItem>;
/// <summary>Height of items that do not have it explicitly defined</summary>
function GetDefaultViewHeight: Integer;
/// <summary>Subscribe to OnChanged event</summary>
procedure SetOnChanged(const Value: TNotifyEvent);
/// <summary>Subscribe to OnItemsMayChange event</summary>
procedure SetOnItemsMayChange(const Value: TNotifyEvent);
/// <summary>Subscribe to OnItemsCouldHaveChanged event</summary>
procedure SetOnItemsCouldHaveChanged(const Value: TNotifyEvent);
/// <summary>Subscribe to OnItemsInvalidate event</summary>
procedure SetOnItemsInvalidate(const Value: TNotifyEvent);
/// <summary>Subscribe to OnItemsResize event</summary>
procedure SetOnItemsResize(const Value: TNotifyEvent);
/// <summary>Subscribe to OnResetView event</summary>
procedure SetOnResetView(const Value: TNotifyEvent);
/// <summary>Sort data</summary>
procedure Sort(AComparer: IComparer<TListItem>);
/// <summary>Called by TListView every time it needs to paint. In dynamic adapters this is where
/// new TListItems should be created for data.</summary>
procedure CreateNewViews;
/// <summary>Recreate views for items that have specified purposes. May be called when item
/// views may need update, for example when host TListView is being resized</summary>
procedure ResetViews(const Purposes: TListItemPurposes);
// <summary>Called by ResetViews to invoke OnResetView event for each ListItem</summary>
procedure ResetView(const Item: TListItem);
/// <summary>Get item by Index. Items would normally be already created by CreateNewViews by the time
/// this property is accessed. Index should be in range of [0, Count)</summary>
property Item[const Index: Integer]: TListItem read GetItem; default;
/// <summary>Count of items</summary>
property Count: Integer read GetCount;
/// <summary>Invoked when items have changed</summary>
property OnChanged: TNotifyEvent write SetOnChanged;
/// <summary>Invoked before an edit operation, items or their contents may change</summary>
property OnItemsMayChange: TNotifyEvent write SetOnItemsMayChange;
/// <summary>Invoked after an edit operation, items could have been changed</summary>
property OnItemsCouldHaveChanged: TNotifyEvent write SetOnItemsCouldHaveChanged;
/// <summary>Invoked when items are invalidated and a repaint is necessary</summary>
property OnItemsInvalidate: TNotifyEvent write SetOnItemsInvalidate;
/// <summary>Item sizes were changed, notify the view that the sizes of items need recalculation</summary>
property OnItemsResize: TNotifyEvent write SetOnItemsResize;
/// <summary>View has been reset</summary>
property OnResetView: TNotifyEvent write SetOnResetView;
end;
IListViewEditor = interface;
TBeforeItemAddedNotify = procedure(Sender: IListViewEditor) of object;
TAfterItemAddedNotify = procedure(Sender: IListViewEditor; const Item: TListItem) of object;
TBeforeItemDeletedNotify = procedure(Sender: IListViewEditor; const Index: Integer) of object;
TAfterItemDeletedNotify = procedure(Sender: IListViewEditor) of object;
/// <summary>Extension of IListViewAdapter for editable content. Implemented by TAppearanceListViewItems</summary>
IListViewEditor = interface
['{19A0606B-8C8E-49B2-A6B3-A708B7B8AD46}']
/// <summary>Create a new Item and append at end</summary>
function Add: TListItem;
/// <summary>Delete Item at Index</summary>
procedure Delete(const Index: Integer);
/// <summary>Create a new Item and insert at Index</summary>
function Insert(const Index: Integer): TListItem;
/// <summary>Delete all items</summary>
procedure Clear;
/// <summary>Set OnBeforeItemAdded handler</summary>
procedure SetBeforeItemAdded(const AHandler: TBeforeItemAddedNotify);
/// <summary>Set OnAfterItemAdded handler</summary>
procedure SetAfterItemAdded(const AHandler: TAfterItemAddedNotify);
/// <summary>Set OnBeforeItemDeleted handler</summary>
procedure SetBeforeItemDeleted(const AHandler: TBeforeItemDeletedNotify);
/// <summary>Set OnAfterItemDeleted handler</summary>
procedure SetAfterItemDeleted(const AHandler: TAfterItemDeletedNotify);
/// <summary>Notification before item is added</summary>
property OnBeforeItemAdded: TBeforeItemAddedNotify write SetBeforeItemAdded;
/// <summary>Notification after item is added</summary>
property OnAfterItemAdded: TAfterItemAddedNotify write SetAfterItemAdded;
/// <summary>Notification before item is deleted</summary>
property OnBeforeItemDeleted: TBeforeItemDeletedNotify write SetBeforeItemDeleted;
/// <summary>Notification after item is deleted</summary>
property OnAfterItemDeleted: TAfterItemDeletedNotify write SetAfterItemDeleted;
end;
/// <summary>Extension of IListViewAdapter for items with checkboxes.
/// Implemented by TAppearanceListViewItems</summary>
IListViewCheckProvider = interface
['{032EB974-1C25-4B5E-BB07-01FA82554748}']
/// <summary>Index of first checked item</summary>
function FirstChecked(const Checked: Boolean = True): Integer;
/// <summary>A quick query to see if one or all of the items are in checked state.</summary>
/// <returns><para>If AChecked = True, True if at least one item is checked</para>
/// <para> If AChecked = False, True if every item is checked</para>
/// </returns>
function AnyChecked(const AChecked: Boolean = True): Boolean;
/// <summary>Change check state of all items</summary>
procedure CheckAll(const NewState: Boolean = True);
/// <summary>Get checked state for item at Index</summary>
function GetChecked(const Index: Integer): Boolean;
/// <summary>Set checked state for item at Index</summary>
procedure SetChecked(const Index: Integer; const Value: Boolean);
/// <summary>Get/set checked state of item at Index</summary>
property Checked[const Index: Integer]: Boolean read GetChecked write SetChecked; default;
end;
/// <summary>Extension of IListViewAdapter for items with text and indexes.
/// Implemented by TAppearanceListViewItems</summary>
IListViewTextProvider = interface
['{C6D52C15-423D-4B2F-AC87-7D7D47A9C7CC}']
/// <summary>Get primary text of item at Index</summary>
function GetText(const Index: Integer): string;
/// <summary>Get index title at Index</summary>
function GetIndexTitle(const Index: Integer): string;
/// <summary>Primary text of item at Index</summary>
property Text[const Index: Integer]: string read GetText;
/// <summary>Index title of item at Index</summary>
property IndexTitle[const Index: Integer]: string read GetIndexTitle;
end;
/// <summary>Extension of IListViewAdapter for items with embedded text buttons.
/// Implemented by TAppearanceListViewItems</summary>
IListViewTextButtonProvider = interface
['{42CC3926-0A23-465B-9ECE-229C60B3BA8E}']
/// <summary>Get drawable of text button for item at Index</summary>
function GetTextButtonDrawable(const Index: Integer): TListItemTextButton;
/// <summary>Drawable of text button for item at Index</summary>
property TextButtonDrawable[const Index: Integer]: TListItemTextButton
read GetTextButtonDrawable;
end;
/// <summary>Extension of IListViewAdapter for items with glyph buttons.
/// Implemented by TAppearanceListViewItems</summary>
IListViewGlyphButtonProvider = interface
['{64FF4B01-E378-4F40-A9A5-E4C1A7C942D6}']
/// <summary>Get drawable of ïäíçð button for item at Index</summary>
function GetGlyphButtonDrawable(const Index: Integer): TListItemGlyphButton;
/// <summary>Drawable of ïäíçð button for item at Index</summary>
property GlyphButtonDrawable[const Index: Integer]: TListItemGlyphButton
read GetGlyphButtonDrawable;
end;
/// <summary>Extension of IListViewAdapter for items with data.
/// Implemented by TAppearanceListViewItems</summary>
IListViewExtrasProvider = interface
['{0BCFB611-3763-4C49-974F-1104F6116D6E}']
/// <summary>Get indexed data DataIndex for item at Index</summary>
function GetItemData(const Index: Integer; const DataIndex: string): TValue;