-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
FMX.ListBox12.pas
5730 lines (5185 loc) · 162 KB
/
FMX.ListBox12.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) 2011-2023 Embarcadero Technologies, Inc. }
{ All rights reserved }
{ }
{*******************************************************}
unit FMX.ListBox;
interface
{$SCOPEDENUMS ON}
uses
System.Classes, System.Types, System.UITypes, System.SysUtils, System.Rtti, System.Generics.Collections,
System.ImageList, FMX.Types, FMX.ActnList, FMX.StdCtrls, FMX.Layouts, FMX.Objects, FMX.Pickers, FMX.Controls,
FMX.Graphics, FMX.ListBox.Selection, FMX.ImgList;
type
TCustomListBox = class;
TCustomComboBox = class;
TListBoxItemData = class;
TListBoxItemStyleDefaults = class;
TListBoxSelector = class;
{ TListBoxItem }
TListBoxItem = class(TTextControl, IGlyph)
private type
TBackgroundShape = (SeparatorBottom, Sharp, RoundTop, RoundBottom, RoundAll);
private
FIsChecked: Boolean;
FCheck: TCheckBox;
FIsSelected: Boolean;
FIsSelectable: Boolean;
FData: TObject;
FItemData: TListBoxItemData;
FBitmap: TBitmap;
FIcon: TImage;
FOldIconVisible: Boolean;
FOldCheckAlign: TAlignLayout;
FGlyph: TGlyph;
FBackgroundShape: TBackgroundShape;
FImageLink: TGlyphImageLink;
procedure SetIsChecked(const Value: Boolean);
procedure DoCheckClick(Sender: TObject);
procedure InitCheckBox(Visible: Boolean);
procedure UpdateCheck;
procedure SetIsSelected(const Value: Boolean);
procedure SetSelectable(const Value: Boolean);
function GetImages: TCustomImageList;
procedure SetImages(const Value: TCustomImageList);
{ IGlyph }
function GetImageIndex: TImageIndex;
procedure SetImageIndex(const Value: TImageIndex);
function GetImageList: TBaseImageList; inline;
procedure SetImageList(const Value: TBaseImageList);
function IGlyph.GetImages = GetImageList;
procedure IGlyph.SetImages = SetImageList;
procedure SetItemData(const Value: TListBoxItemData);
protected
procedure ChangeOrder; override;
function ListBox: TCustomListBox;
function ComboBox: TCustomComboBox;
function GetDefaultSize: TSizeF; override;
procedure ApplyStyle; override;
procedure FreeStyle; override;
function EnterChildren(AObject: IControl): Boolean; override;
procedure DragOver(const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation); override;
procedure DragEnd; override;
procedure Paint; override;
function GetHeight: Single; override;
function GetWidth: Single; override;
procedure SetHeight(const Value: Single); override;
function DoSetSize(const ASize: TControlSize; const NewPlatformDefault: Boolean; ANewWidth, ANewHeight: Single;
var ALastWidth, ALastHeight: Single): Boolean; override;
procedure SelectBackground(const Shape: TBackgroundShape);
procedure OnBitmapChanged(Sender: TObject);
function StyledSettingsStored: Boolean; override;
property Align;
property RotationAngle;
property RotationCenter;
function GetTextSettingsClass: TTextSettingsInfo.TCustomTextSettingsClass; override;
function GetDefaultStyleLookupName: string; override;
function DoGetDefaultStyleLookupName(const Defaults: TListBoxItemStyleDefaults): string; virtual;
/// <summary> Should be called when you change an instance or reference to instance of <b>TBaseImageList</b> or the
/// <b>ImageIndex</b> property
/// <para>See also <b>FMX.ActnList.IGlyph</b></para></summary>
procedure ImagesChanged; virtual;
/// <summary> Determines whether the <b>ImageIndex</b> property needs to be stored in the fmx-file</summary>
/// <returns> <c>True</c> if the <b>ImageIndex</b> property needs to be stored in the fmx-file</returns>
function ImageIndexStored: Boolean; virtual;
procedure SetVisible(const Value: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Data: TObject read FData write FData;
function GetParentComponent: TComponent; override;
procedure ApplyTriggerEffect(const AInstance: TFmxObject; const ATrigger: string); override;
/// <summary>Used internally to modify Selected state of an item</summary>
procedure SetIsSelectedInternal(const Value: Boolean; const UserChange: Boolean);
property Font;
property TextAlign;
property WordWrap;
///<summary> The list of images. Can be <c>nil</c>. <para>See also <b>FMX.ActnList.IGlyph</b></para></summary>
property Images: TCustomImageList read GetImages;
published
property AutoTranslate default True;
property ClipChildren;
property ClipParent;
property Cursor;
property DragMode;
property EnableDragHighlight;
property Selectable: Boolean read FIsSelectable write SetSelectable default True;
property TextSettings;
property StyledSettings;
property Locked;
property Height;
property HelpContext;
property HelpKeyword;
property HelpType;
property HitTest default False;
property IsChecked: Boolean read FIsChecked write SetIsChecked default False;
property IsSelected: Boolean read FIsSelected write SetIsSelected default False;
property ItemData: TListBoxItemData read FItemData write SetItemData;
///<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 GetImageIndex write SetImageIndex stored ImageIndexStored;
property Padding;
property Opacity;
property Margins;
property PopupMenu;
property Position;
property Scale;
property Size;
property StyleLookup;
property TabOrder;
property TabStop;
property Text;
property Width;
property Visible;
property ParentShowHint;
{events}
property OnApplyStyleLookup;
{Drag and Drop events}
property OnDragEnter;
property OnDragLeave;
property OnDragOver;
property OnDragDrop;
property OnDragEnd;
{Mouse events}
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseEnter;
property OnMouseLeave;
property OnClick;
property OnPainting;
property OnPaint;
property OnResize;
property OnResized;
end;
{ TListBoxItemData }
TListBoxItemData = class(TPersistent)
public type
TAccessory = (aNone=0, aMore=1, aDetail=2, aCheckmark=3);
strict private
const
StyleSelectorMore = 'accessorymore.Visible';
StyleSelectorDetail = 'accessorydetail.Visible';
StyleSelectorCheckmark = 'accessorycheckmark.Visible';
private
[Weak] FItem: TListBoxItem;
FAccessory: TAccessory;
procedure SetText(const Text: String);
function GetText: String;
procedure SetDetail(const Detail: String);
function GetDetail: String;
procedure SetBitmap(const Bitmap: TBitmap);
function GetBitmap: TBitmap;
function GetAccessory: TAccessory;
procedure SetAccessory(const Accessory: TAccessory);
public
constructor Create(const HostItem: TListBoxItem);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Disappear;
published
property Text: string read GetText write SetText stored false;
property Detail: string read GetDetail write SetDetail;
property Accessory: TAccessory read GetAccessory write SetAccessory default TAccessory.aNone;
property Bitmap: TBitmap read GetBitmap write SetBitmap;
end;
{ TCustomListBox }
TListStyle = (Vertical, Horizontal);
TListGroupingKind = (Plain, Grouped);
TOnCompareListBoxItemEvent = procedure(Item1, Item2: TListBoxItem; var Result: Integer) of object;
TOnListBoxDragChange = procedure(SourceItem, DestItem: TListBoxItem; var Allow: Boolean) of object;
TListBoxItemStyleDefaults = class(TPersistent)
strict private
FItemStyle : string;
FHeaderStyle : string;
FFooterStyle : string;
[Weak] FListBox: TCustomListBox;
private
function GetItemStyle: string;
procedure SetItemStyle(const Value: string);
function GetGroupHeaderStyle: string;
procedure SetGroupHeaderStyle(const Value: string);
function GetGroupFooterStyle: string;
procedure SetGroupFooterStyle(const Value: string);
procedure RefreshListBox;
constructor Create(const ListBox: TCustomListBox);
public
procedure Assign(Source: TPersistent); override;
property ListBox: TCustomListBox read FListBox;
published
property ItemStyle: string read GetItemStyle write SetItemStyle nodefault;
property GroupHeaderStyle: string read GetGroupHeaderStyle write SetGroupHeaderStyle nodefault;
property GroupFooterStyle: string read GetGroupFooterStyle write SetGroupFooterStyle nodefault;
end;
TMultiSelectStyle = (None, Default, Extended);
TCustomListBox = class(TScrollBox, IItemsContainer, IInflatableContent<TListBoxItem>, ISearchResponder, IGlyph)
private const
UnfocusedSelectionOpacity = 0.7;
ExtendedSelectionOpacity = 0.7;
public type
TStringsChangeOp = (Added, Deleted, Clear);
TStringsChangedEvent = procedure(const S: String; const StringsEvent: TCustomListBox.TStringsChangeOp) of object;
TItemClickEvent = procedure(const Sender: TCustomListBox; const Item: TListBoxItem) of object;
private type
TListBoxStrings = class(TStrings)
private
[Weak] FListBox: TCustomListBox;
procedure ReadData(Reader: TReader);
procedure WriteData(Writer: TWriter);
protected
procedure Put(Index: Integer; const S: string); override;
function Get(Index: Integer): string; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
procedure PutObject(Index: Integer; AObject: TObject); override;
procedure SetUpdateState(Updating: Boolean); override;
procedure DefineProperties(Filer: TFiler); override;
public
function Add(const S: string): Integer; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Exchange(Index1, Index2: Integer); override;
function IndexOf(const S: string): Integer; override;
procedure Insert(Index: Integer; const S: string); override;
end;
TGroup = record
First: Integer;
Length: Integer;
constructor Create(const AFirst, ALength: Integer);
end;
TGroups = class(TList<TGroup>)
public
function FindGroup(const Index: Integer): Integer;
end;
/// <summary>
/// Visual display of the selection based on style controls. It makes copies of specified style object,
/// which represent selection for focused and unfocused states. And align styled selection in specified positions.
/// </summary>
TStyledSelection = class
private
FListBox: TCustomListBox;
FUnfocusedObjectsPool: TControlList;
FFocusedObjectsPool: TControlList;
FCurrentObjects: TControlList; // Reference
FIsFocused: Boolean;
{ Style objects }
FUnfocusedSelection: TControl;
FFocusedSelection: TControl;
procedure SetIsFocused(const Value: Boolean);
private
function CreateSelectionControl(const AIsFocused: Boolean): TControl;
public
constructor Create(const AListBox: TCustomListBox);
destructor Destroy; override;
/// <summary>Aligns the style selection controls according to the passed areas.</summary>
procedure Realign(const ASelectionRects: TList<TRectF>);
/// <summary>Clear all style selection controls for focused and unfocused states.</summary>
procedure ClearPools;
public
/// <summary>The reference on style object that is used to create controls for unfocused selection.</summary>
property UnfocusedSelection: TControl read FUnfocusedSelection write FUnfocusedSelection;
/// <summary>The reference on style object that is used to create controls for focused selection.</summary>
property FocusedSelection: TControl read FFocusedSelection write FFocusedSelection;
property IsFocused: Boolean read FIsFocused write SetIsFocused;
end;
strict private
FBeingPainted: Boolean;
FRealignRequested: Boolean;
FUpdateGroupsRequested: Boolean;
FToInflate: TList<TListBoxItem>;
FInflater: TContentInflater<TListBoxItem>;
FStringsChanged: TStringsChangedEvent;
FOnItemClick: TItemClickEvent;
[Weak] FItemDown: TListBoxItem;
FOnChange: TNotifyEvent;
FShowCheckboxes: Boolean;
FOnChangeCheck: TNotifyEvent;
FSorted: Boolean;
FOnCompare: TOnCompareListBoxItemEvent;
FAlternatingRowBackground: Boolean;
FAllowDrag: Boolean;
FOnDragChange: TOnListBoxDragChange;
FNoItemsContent: TContent;
FHeaderCompartment: TContent;
FFooterCompartment: TContent;
FContentOverlay: TContent;
FDefaultStyles: TListBoxItemStyleDefaults;
FGroups: TGroups;
FGroupingKind: TListGroupingKind;
FClickEnable: Boolean;
FSelection: TControl;
FExtendedSelection: TControl;
FFocusedSelection: TControl;
FSelector: TListBoxSelector;
FImageLink: TGlyphImageLink;
[Weak] FImages: TCustomImageList;
function GetInflatableItems: TList<TListBoxItem>;
procedure CalcSelectionRects(const SelRects: TList<TRectF>);
procedure PerformInternalDrag;
function GetImages: TCustomImageList;
procedure SetImages(const Value: TCustomImageList);
{ IGlyph }
function GetImageIndex: TImageIndex;
procedure SetImageIndex(const Value: TImageIndex);
function GetImageList: TBaseImageList; inline;
procedure SetImageList(const Value: TBaseImageList);
function IGlyph.GetImages = GetImageList;
procedure IGlyph.SetImages = SetImageList;
private
FDragItem: TListBoxItem;
FFirstVisibleItem, FLastVisibleItem: Integer;
FItems: TStrings;
FColumns: Integer;
FItemWidth: Single;
FItemHeight: Single;
FListStyle: TListStyle;
FOddFill: TBrush;
FContentInsets: TRectF;
FSelectionObjects: TStyledSelection;
procedure IgnoreString(Reader: TReader);
procedure ReadMultiSelect(Reader: TReader);
function GetCount: Integer;
function GetSelected: TListBoxItem;
procedure SetColumns(const Value: Integer);
procedure SetItemHeight(const Value: Single);
procedure SetItemWidth(const Value: Single);
procedure SetListStyle(const Value: TListStyle);
procedure SetShowCheckboxes(const Value: Boolean);
function GetListItem(Index: Integer): TListBoxItem;
procedure SetSorted(const Value: Boolean);
procedure SetAlternatingRowBackground(const Value: Boolean);
procedure SetItems(const Value: TStrings);
procedure SetMultiSelectStyle(const Value: TMultiSelectStyle);
function GetMultiSelectStyle: TMultiSelectStyle;
procedure SetAllowDrag(const Value: Boolean);
function GetMultiSelect: Boolean;
procedure SetMultiSelect(const Value: Boolean);
{ IItemsContainer }
function IItemsContainer.GetItemsCount = GetCount;
function GetItem(const AIndex: Integer): TFmxObject;
function GetFilterPredicate: TPredicate<string>;
procedure SetFilterPredicate(const Predicate: TPredicate<string>);
procedure SetItemDown(const Value: TListBoxItem);
function ItemsStored: Boolean;
protected
procedure DefineProperties(Filer: TFiler); override;
function GetData: TValue; override;
procedure SetData(const Value: TValue); override;
function CanObserve(const ID: Integer): Boolean; override;
procedure DoChangeCheck(const Item: TListBoxItem); dynamic;
function CompareItems(const Item1, Item2: TListBoxItem): Integer; virtual;
procedure DoChange; dynamic;
procedure SortItems; virtual;
/// <summary>Set active selection to item with given index.</summary>
procedure SetItemIndex(const Value: Integer); virtual;
/// <summary>Return index of currently selected Item</summary>
function GetItemIndex: Integer; virtual;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
procedure MouseMove(Shift: TShiftState; X, Y: Single); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
procedure MouseClick(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); override;
procedure DragOver(const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation); override;
procedure DragDrop(const Data: TDragObject; const Point: TPointF); override;
function GetDefaultSize: TSizeF; override;
procedure ApplyStyle; override;
procedure FreeStyle; override;
procedure DoEnter; override;
procedure DoExit; override;
procedure DoAddObject(const AObject: TFmxObject); override;
procedure DoInsertObject(Index: Integer; const AObject: TFmxObject); override;
procedure DoRemoveObject(const AObject: TFmxObject); override;
function GetBorderHeight: Single;
function CreateScrollContent: TScrollContent; override;
function DoCalcContentBounds: TRectF; override;
procedure DoEndUpdate; override;
/// <summary> Should be called when you change an instance or reference to instance of <b>TBaseImageList</b> or the
/// <b>ImageIndex</b> property
/// <para>See also <b>FMX.ActnList.IGlyph</b></para></summary>
procedure ImagesChanged; virtual;
procedure Loaded; override;
procedure DoContentPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
procedure Painting; override;
procedure AfterPaint; override;
procedure ViewportPositionChange(const OldViewportPosition, NewViewportPosition: TPointF;
const ContentSizeChanged: Boolean); override;
procedure DoUpdateAniCalculations(const AAniCalculations: TScrollCalculations); override;
function IsAddToContent(const AObject: TFmxObject): Boolean; override;
procedure ContentAddObject(const AObject: TFmxObject); override;
procedure ContentInsertObject(Index: Integer; const AObject: TFmxObject); override;
procedure ContentBeforeRemoveObject(AObject: TFmxObject); override;
procedure ContentRemoveObject(const AObject: TFmxObject); override;
function IsOpaque: Boolean; override;
procedure UpdateVisibleItems;
procedure UpdateSelection;
procedure UpdateGroups;
procedure RealUpdateGroups; virtual;
procedure UpdateStickyHeader;
procedure SetGroupingKind(const Value: TListGroupingKind);
procedure DoRealign; override;
procedure DispatchStringsChangeEvent(const S: String; const Op: TStringsChangeOp);
procedure Show; override;
property CanFocus default True;
property CanParentFocus;
property Selection: TControl read FSelection;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
/// <summary>Property getter FirstSelectedItem</summary>
function GetFirstSelect: TListBoxItem;
property AllowDrag: Boolean read FAllowDrag write SetAllowDrag default False;
property AlternatingRowBackground: Boolean read FAlternatingRowBackground write SetAlternatingRowBackground default False;
property Columns: Integer read FColumns write SetColumns default 1;
property ItemWidth: Single read FItemWidth write SetItemWidth;
property ItemHeight: Single read FItemHeight write SetItemHeight;
property ListStyle: TListStyle read FListStyle write SetListStyle
default TListStyle.Vertical;
property MultiSelectStyle: TMultiSelectStyle read GetMultiSelectStyle write SetMultiSelectStyle default TMultiSelectStyle.None;
property Sorted: Boolean read FSorted write SetSorted default False;
property ShowCheckboxes: Boolean read FShowCheckboxes write SetShowCheckboxes default False;
/// <summary>First item in the selection or nil if nothing is selected</summary>
property FirstSelectedItem: TListBoxItem read GetFirstSelect;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChangeCheck: TNotifyEvent read FOnChangeCheck write FOnChangeCheck;
property OnCompare: TOnCompareListBoxItemEvent read FOnCompare write FOnCompare;
property OnDragChange: TOnListBoxDragChange read FOnDragChange write FOnDragChange;
property OnStringsChanged: TStringsChangedEvent read FStringsChanged write FStringsChanged;
/// <summary>Current selection controller. Selector is chosen by MultiSelectStyle property.</summary>
property SelectionController: TListBoxSelector read FSelector;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Clear; virtual;
function DragChange(const SourceItem, DestItem: TListBoxItem): Boolean; dynamic;
procedure SelectAll;
procedure ClearSelection;
procedure SelectRange(const Item1, Item2: TListBoxItem);
///<summary>Scroll the view to make Item visible</summary>
procedure ScrollToItem(const Item: TListBoxItem);
function FirstSelectedItemFrom(const Item: TListboxItem): TListBoxItem;
function LastSelectedItemFrom(const Item: TListboxItem): TListBoxItem;
function ItemByPoint(const X, Y: Single): TListBoxItem;
function ItemByIndex(const Idx: Integer): TListBoxItem;
procedure ItemsExchange(Item1, Item2: TListBoxItem);
procedure Sort(Compare: TFmxObjectSortCompare); override;
procedure NotifyInflated;
property BorderHeight: Single read GetBorderHeight;
property Count: Integer read GetCount;
property Selected: TListBoxItem read GetSelected;
property Items: TStrings read FItems write SetItems stored ItemsStored;
property ItemDown: TListBoxItem read FItemDown write SetItemDown;
///<summary> The list of images. Can be <c>nil</c>. <para>See also <b>FMX.ActnList.IGlyph</b></para></summary>
property Images: TCustomImageList read GetImages write SetImages;
property ListItems[Index: Integer]: TListBoxItem read GetListItem;
property ItemIndex: Integer read GetItemIndex write SetItemIndex default -1;
property GroupingKind: TListGroupingKind read FGroupingKind write SetGroupingKind default TListGroupingKind.Plain;
property FilterPredicate: TPredicate<string> read GetFilterPredicate write SetFilterPredicate stored False;
property MultiSelect: Boolean read GetMultiSelect write SetMultiSelect; // deprecated - use MultiSelectStyle
property DefaultItemStyles: TListBoxItemStyleDefaults read FDefaultStyles write FDefaultStyles;
property OnItemClick: TItemClickEvent read FOnItemClick write FOnItemClick;
end;
{ TListBox }
TListBox = class(TCustomListBox)
published
property Align;
property AllowDrag;
property AlternatingRowBackground;
property Anchors;
property CanFocus;
property CanParentFocus;
property ClipChildren;
property ClipParent;
property Columns;
property Cursor;
property DisableFocusEffect;
property DragMode;
property EnableDragHighlight;
property Enabled;
property Locked;
property Height;
property HitTest;
property Hint;
property ItemIndex;
property ItemHeight;
property Items;
property ItemWidth;
property Images;
property DefaultItemStyles;
property GroupingKind;
property ListStyle;
property Padding;
property MultiSelectStyle;
property Opacity;
property Margins;
property PopupMenu;
property Position;
property RotationAngle;
property RotationCenter;
property Scale;
property Size;
property ShowCheckboxes;
property Sorted;
property StyleLookup;
property TabOrder;
property TabStop;
property Visible;
property Width;
property ParentShowHint;
property ShowHint;
{events}
property OnApplyStyleLookup;
property OnChange;
property OnChangeCheck;
property OnCompare;
{Drag and Drop events}
property OnDragChange;
property OnDragEnter;
property OnDragLeave;
property OnDragOver;
property OnDragDrop;
property OnDragEnd;
{Keyboard events}
property OnKeyDown;
property OnKeyUp;
{Mouse events}
property OnCanFocus;
property OnItemClick;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseEnter;
property OnMouseLeave;
property OnPainting;
property OnPaint;
property OnResize;
property OnResized;
end;
TListBoxHeader = class(TToolBar, IListBoxHeaderTrait)
protected
function GetDefaultStyleLookupName: string; override;
public
end;
TListBoxSeparatorItem = class(TListBoxItem)
public
/// <summary>Gets default style for Group Header, which is used if TListBox.DefaultItemStyles.GroupHeaderStyle
/// is empty</summary>
function GetDefaultGroupHeaderStyle: string;
end;
TListBoxGroupHeader = class(TListBoxSeparatorItem)
strict private
[Weak] FCloneRef: TListBoxGroupHeader;
protected
function DoGetDefaultStyleLookupName(const Defaults: TListBoxItemStyleDefaults): string; override;
procedure DoTextChanged; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
/// <summary>Reference to sticky TListBoxGroupHeader clone in Plain grouping mode</summary>
property CloneRef: TListBoxGroupHeader read FCloneRef write FCloneRef;
end;
TListBoxGroupFooter = class(TListBoxSeparatorItem)
protected
function DoGetDefaultStyleLookupName(const Defaults: TListBoxItemStyleDefaults): string; override;
public
constructor Create(AOwner: TComponent); override;
end;
/// <summary>Base class for selection controllers. Selection controllers handle various types of selection.
/// Normally TListBox.MultiSelectStyle property selects one of the three predefined ones:
/// TSingleSelectionController, TMutiselectSelectionController, TExtendedSelectionController
/// </summary>
TListBoxSelector = class abstract
public type
/// <summary>Keyboard selection action: Move (arrow keys) or Toggle (space)</summary>
TKeyAction = (Move, Toggle);
strict protected
/// <summary>Reference to TListBox that hosts this controller</summary>
[Weak] FListBox: TCustomListBox;
/// <summary>Index of currently selected item, -1 if none</summary>
FCurrent: Integer;
/// <summary>Index of first selected item, -1 if none</summary>
FFirst: Integer;
/// <summary>Timer used for DelayedMouseDown</summary>
FSelectionTimer: TTimer;
/// <summary>Item that's going to be acted upon if DelayedMouseDown is employed</summary>
FSelectionTimerTarget: TListBoxItem;
/// <summary>Flag used to prevent sending change notification</summary>
FInternalChange: Boolean;
/// <summary>True during mouse selection</summary>
FMouseSelectActive: Boolean;
protected
/// <summary>Create a new instance of TSelectionController</summary>
constructor Create(const ListBox: TCustomListBox); virtual;
/// <summary>Getter for MutliSelectStyle</summary>
function GetMultiSelectStyle: TMultiSelectStyle; virtual; abstract;
/// <summary>Make host TListBox update selection visuals</summary>
procedure UpdateSelection;
/// <summary>Initiate a delayed mouse down action</summary>
procedure DelayedMouseDown(const ItemDown: TListBoxItem; const Shift: TShiftState);
/// <summary>Abort delayed mouse down action, if any</summary>
procedure AbortDelayed;
function GetMouseSelectActive: Boolean;
procedure SetMouseSelectActive(const Value: Boolean); virtual;
public
destructor Destroy; override;
/// <summary>Get first item index, -1 if none</summary>
function GetFirst: Integer;
/// <summary>Get current item index, -1 if none</summary>
function GetCurrent: Integer;
/// <summary>Get current TListBoxItem, nil if none selected</summary>
function GetCurrentItem: TListBoxItem;
/// <summary>Clear selection</summary>
procedure ClearSelection;
/// <summary>Attempt to copy selection from another selector</summary>
procedure CopySelection(const Other: TListBoxSelector); virtual; abstract;
/// <summary>Select everything</summary>
procedure SelectAll;
/// <summary>Select range between TListBoxItems Item1 and Item2</summary>
function SelectRange(const Item1, Item2: TListBoxItem): Boolean;
/// <summary>Mark TListBoxItem Item as Selected if Value is True, as not selected if Value is False.
/// No notification. Return true if Item.Selected has been changed.</summary>
function SetSelected(const Item: TListBoxItem; const Value: Boolean): Boolean;
/// <summary>Set item with index Index as current. Return True if the value of Current has been changed.</summary>
function SetCurrent(const Index: Integer): Boolean;
/// <summary>Used to notify this TSelectionController when item state was changed externally. See DoItemStateChanged.</summary>
procedure ItemStateChanged(const Item: TListBoxItem; const UserChange: Boolean);
/// <summary>Start mouse selection</summary>
procedure MouseSelectStart(const Item: TListBoxItem; const Button: TMouseButton; const Shift: TShiftState); virtual;
/// <summary>Handle mouse move during selection</summary>
procedure MouseSelectMove(const Item: TListBoxItem; const Shift: TShiftState); virtual;
/// <summary>Before mouse selection is finished</summary>
procedure MouseSelectFinishing(const Item: TListBoxItem; const Button: TMouseButton; const Shift: TShiftState); virtual;
/// <summary>Finish mouse selection</summary>
procedure MouseSelectFinish(const Item: TListBoxItem; const Button: TMouseButton; const Shift: TShiftState); virtual;
/// <summary>Select using keyboard, e.g. by pressing space. KeyAction is one of: Move or Toggle</summary>
procedure KeyboardSelect(const KeyAction: TKeyAction; const Shift: TShiftState; const Item: TListBoxItem); virtual;
/// <summary>Invoked when item index is set programmatically by user</summary>
procedure UserSetIndex(const Index: Integer); virtual;
/// <summary>Dispatch change notification</summary>
procedure Change;
/// <summary>MouseSelectStart implementation</summary>
procedure DoMouseSelectStart(const Item: TListBoxItem; const Shift: TShiftState); virtual; abstract;
/// <summary>MouseSelectMove implementation</summary>
procedure DoMouseSelectMove(const Item: TListBoxItem; const Shift: TShiftState); virtual; abstract;
/// <summary>MouseSelectFinishing implementation</summary>
procedure DoMouseSelectFinishing(const Item: TListBoxItem; const Shift: TShiftState); virtual;
/// <summary>MouseSelectFinish implementation</summary>
procedure DoMouseSelectFinish(const Item: TListBoxItem; const Shift: TShiftState); virtual; abstract;
/// <summary>KeyboardSelect implementation</summary>
procedure DoKeyboardSelect(const KeyAction: TKeyAction; const Shift: TShiftState; const Item: TListBoxItem); virtual; abstract;
/// <summary>UserSetIndex implementation</summary>
procedure DoUserSetIndex(const Index: Integer); virtual; abstract;
/// <summary>ItemStateChanged implementation</summary>
procedure DoItemStateChanged(const Item: TListBoxItem; const UserChange: Boolean); virtual;
/// <summary>MultiSelectStyle that this selection controller implements</summary>
property MultiSelectStyle: TMultiSelectStyle read GetMultiSelectStyle;
/// <summary>True during mouse selection</summary>
property MouseSelectActive: Boolean read GetMouseSelectActive write SetMouseSelectActive;
end;
TListBoxSelectorClass = class of TListBoxSelector;
/// <summary>A factory to create and register selectors based on multi-
/// selection styles.</summary>
TListBoxSelectorFactory = class
private
class var FSelectors: array[TMultiSelectStyle] of TListBoxSelectorClass;
public
/// <summary>Create TListBoxSelector for ListBox based on MultiSelectStyle</summary>
class function CreateSelector(const ListBox: TCustomListBox; const MultiSelectStyle: TMultiSelectStyle): TListBoxSelector;
/// <summary>Register a selector that handles given MultiSelectStyle. Used during framework initialization</summary>
class procedure RegisterSelector(MultiSelectStyle: TMultiSelectStyle; Selector: TListBoxSelectorClass);
end;
{ TComboListBox }
TComboListBox = class(TCustomListBox, IContent)
protected
[Weak] FComboBox: TCustomComboBox;
FInKeyDown: Boolean;
procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); override;
function GetObservers: TObservers; override;
function GetDefaultStyleLookupName: string; override;
procedure IContent.Changed = ContentChanged;
procedure ContentChanged; virtual;
public
constructor Create(AOwner: TComponent); override;
procedure MouseMove(Shift: TShiftState; X, Y: Single); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
end;
{ TCustomComboBox }
TCustomComboBox = class(TStyledControl, IItemsContainer, IGlyph)
private
FDropDownCount: Integer;
FDroppedDown: Boolean;
FIsPressed: Boolean;
FOldItemIndex: Integer;
FItemWidth: Single;
FOnChange: TNotifyEvent;
FOnClosePopup: TNotifyEvent;
FOnPopup: TNotifyEvent;
FImageLink: TGlyphImageLink;
FDropDownKind: TDropDownKind;
FPopup: TPopup;
FListBox: TComboListBox;
FItemIndex: Integer;
FListPicker: TCustomListPicker;
[Weak] FImages: TCustomImageList;
FItemsChanged: Boolean;
procedure SetItemIndex(const Value: Integer);
function GetItemIndex: Integer;
function GetCount: Integer;
procedure SetListBoxResource(const Value: string);
function GetListBoxResource: string;
function GetItemHeight: Single;
procedure SetItemHeight(const Value: Single);
procedure SetItemWidth(const Value: Single);
function GetPlacement: TPlacement;
function GetPlacementRectangle: TBounds;
procedure SetPlacement(const Value: TPlacement);
procedure SetPlacementRectangle(const Value: TBounds);
procedure UpdateCurrentItem;
function GetItems: TStrings;
function GetListItem(Index: Integer): TListBoxItem;
function GetSelected: TListBoxItem;
procedure SetItems(const Value: TStrings);
function GetImages: TCustomImageList;
procedure SetImages(const Value: TCustomImageList);
{ IGlyph }
function GetImageIndex: TImageIndex;
procedure SetImageIndex(const Value: TImageIndex);
function GetImageList: TBaseImageList; inline;
procedure SetImageList(const Value: TBaseImageList);
function IGlyph.GetImages = GetImageList;
procedure IGlyph.SetImages = SetImageList;
{ IItemContainer }
function GetItemsCount: Integer;
function GetItem(const AIndex: Integer): TFmxObject;
function UseNativePicker: Boolean;
function ItemsStored: Boolean;
procedure HandleStringsChanged(const S: string; const Op: TCustomListBox.TStringsChangeOp);
protected
procedure DefineProperties(Filer: TFiler); override;
procedure DoOnValueChangedFromDropDownList(Sender: TObject; const AValueIndex: Integer);
procedure DoChange; dynamic;
procedure DoPopup(Sender: TObject);
procedure DoClosePopup(Sender: TObject);
procedure DoClosePicker(Sender: TObject);
function CreateListBox: TComboListBox; virtual;
function CanObserve(const ID: Integer): Boolean; override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
function GetDefaultSize: TSizeF; override;
procedure ApplyStyle; override;
procedure DoRealign; override;
procedure DoContentPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); virtual;
procedure DoExit; override;
procedure DoAddObject(const AObject: TFmxObject); override;
procedure DoInsertObject(Index: Integer; const AObject: TFmxObject); override;
procedure DoRemoveObject(const AObject: TFmxObject); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X: Single; Y: Single); override;
procedure MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean); override;
procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); override;
procedure Loaded; override;
/// <summary>Initialization of List Picker</summary>
procedure InitPicker(AListPicker: TCustomListPicker); virtual;
/// <summary>Recalculates popup size based on items</summary>
procedure RecalculatePopupSize; virtual;
/// <summary> Should be called when you change an instance or reference to instance of <b>TBaseImageList</b> or the
/// <b>ImageIndex</b> property
/// <para>See also <b>FMX.ActnList.IGlyph</b></para></summary>
procedure ImagesChanged; virtual;
property Popup: TPopup read FPopup;
property CanFocus default True;
property CanParentFocus;
property ItemHeight: Single read GetItemHeight write SetItemHeight;
property ItemWidth: Single read FItemWidth write SetItemWidth;
property DropDownCount: Integer read FDropDownCount write FDropDownCount default 8;
property Placement: TPlacement read GetPlacement write SetPlacement default TPlacement.Bottom;
property PlacementRectangle: TBounds read GetPlacementRectangle write SetPlacementRectangle;
property DropDownKind: TDropDownKind read FDropDownKind write FDropDownKind default TDropDownKind.Native;
property ListBoxResource: string read GetListBoxResource write SetListBoxResource;
property Picker: TCustomListPicker read FListPicker;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnClosePopup: TNotifyEvent read FOnClosePopup write FOnClosePopup;
property OnPopup: TNotifyEvent read FOnPopup write FOnPopup;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetNewScene(AScene: IScene); override;
procedure Clear; virtual;
procedure DropDown; virtual;
procedure Sort(Compare: TFmxObjectSortCompare); override;
property ListBox: TComboListBox read FListBox;
property Count: Integer read GetCount;
property Selected: TListBoxItem read GetSelected;
property Items: TStrings read GetItems write SetItems stored ItemsStored;
///<summary> The list of images. Can be <c>nil</c>. <para>See also <b>FMX.ActnList.IGlyph</b></para></summary>
property Images: TCustomImageList read GetImages write SetImages;
property ListItems[Index: Integer]: TListBoxItem read GetListItem;
property ItemIndex: Integer read GetItemIndex write SetItemIndex;
property DroppedDown: Boolean read FDroppedDown;
property IsPressed: Boolean read FIsPressed;
end;
{ TComboBox }
TComboBox = class(TCustomComboBox)
public
property PlacementRectangle;
published
property Align;
property Anchors;
property CanFocus;
property CanParentFocus;
property ClipChildren;
property ClipParent;
property Cursor;
property DisableFocusEffect;
property DragMode;
property DropDownCount;
property EnableDragHighlight;
property Enabled;
property Locked;
property Height;
property HelpContext;
property HelpKeyword;
property HelpType;
property Hint;
property HitTest;
property Items;
property Images;
property ItemIndex default -1;
property ItemWidth;
property ItemHeight;
property ListBoxResource;
property Padding;
property DropDownKind;
property Opacity;
property Margins;
property Placement;
property PopupMenu;
property Position;
property RotationAngle;
property RotationCenter;
property Scale;
property Size;
property StyleLookup;
property TabOrder;
property TabStop;
property TouchTargetExpansion;
property Visible;
property Width;
property ParentShowHint;
property ShowHint;
{events}
property OnApplyStyleLookup;
property OnChange;
property OnClosePopup;
property OnPopup;
{Drag and Drop events}
property OnDragEnter;
property OnDragLeave;
property OnDragOver;
property OnDragDrop;
property OnDragEnd;
{Keyboard events}
property OnKeyDown;
property OnKeyUp;
{Mouse events}
property OnCanFocus;
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseEnter;
property OnMouseLeave;
property OnPainting;
property OnPaint;
property OnResize;
property OnResized;
end;
TMetropolisUIListBoxItem = class(TListBoxItem)
private
FImage: TImage;
FText: TLayout;
FTextPanel: TPanel;
FTitle: TLabel;
FSubTitle: TLabel;
FDescription: TLabel;
FIconSize: Integer;
procedure SkipIconSize(Reader: TReader);
procedure SkipAlign(Reader: TReader);
protected
procedure SetIcon(const Bitmap: TBitmap); virtual;
function GetIcon : TBitmap; virtual;
procedure SetTitle(const Title: String); virtual;
function GetTitle: String; virtual;
procedure SetSubTitle(const SubTitle: String); virtual;
function GetSubTitle: String; virtual;
procedure SetDescription(const Description: String); virtual;
function GetDescription: String; virtual;
procedure SetIconSize(Value: Integer); virtual;
procedure SetParent(const AParent: TFmxObject); override;
procedure ApplyStyle; override;
procedure FreeStyle; override;
procedure OnBitmapChanged(Sender: TObject);
procedure Resize; override;
procedure DoRealign; override;
procedure DefineProperties(Filer: TFiler); override;
function GetDefaultStyleLookupName: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property IconSize: Integer read FIconSize write SetIconSize;
published
property Title: String read GetTitle write SetTitle nodefault;
property SubTitle: String read GetSubTitle write SetSubTitle nodefault;
property Description: String read GetDescription write SetDescription nodefault;
property Icon: TBitmap read GetIcon write SetIcon;
property Padding;
property Margins;
end;
implementation
uses
{$IFDEF MACOS}Macapi.CoreFoundation, {$ENDIF} System.Character,
System.Math, System.Generics.Defaults, System.Math.Vectors, System.TypInfo, FMX.Consts, FMX.BehaviorManager,
FMX.Forms, FMX.Utils, FMX.Platform;
type