Repository navigation
Expand file tree
/
Copy pathSCVirtualCombobox.pas
More file actions
1924 lines (1625 loc) · 52.7 KB
/
Copy pathSCVirtualCombobox.pas
File metadata and controls
1924 lines (1625 loc) · 52.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
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
{*******************************************************}
{ }
{ CA SweetControls Component Library }
{ }
{ Copyright (c) 1996,2004 CodeAccelerate Corporation }
{ }
{*******************************************************}
unit SCVirtualCombobox;
{$I SweetControls.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Clipbrd, SCConsts, SCCommon, SCControl, SCEdits, SCAdvEdits, SCVirtualListBox;
type
TSCCustomVirtualCombobox = class;
TSCVirtualComboboxScrollbar = class(TSCControlScrollbar)
private
FWidth: Integer;
FStyle: TSCScrollbarStyle;
FButtonsLayout: TSCScrollButtonLayout;
FThumbLines: TSCScrollThumbline;
procedure SetWidth(Value: Integer);
public
constructor Create(AOwner: TSCCustomControl; AKind: TSCScrollbarKind); override;
procedure Assign(Source: TPersistent); override;
published
property Background;
property ButtonColors;
property Icons;
property SlideLine;
property Thumb;
property Width: Integer read FWidth write SetWidth default -1;
property Style: TSCScrollbarStyle read FStyle write FStyle default scssDefault;
property ThumbLines: TSCScrollThumbline read FThumbLines write FThumbLines default sctlNone;
property ButtonsLayout: TSCScrollButtonLayout read FButtonsLayout write FButtonsLayout default scsbDefault;
end;
TSCVirtualComboboxButtonProps = class(TSCCustomDropButtonProps)
published
property ArrowColor;
property Color;
property Visible;
end;
TSCVirtualComboboxCustomPopupProps = class(TPersistent)
private
FOwner: TSCCustomVirtualCombobox;
function GetBorderStyle: TSCEditStyle;
procedure SetBorderStyle(Value: TSCEditStyle);
function GetColor: TColor;
procedure SetColor(Value: TColor);
function GetFont: TFont;
procedure SetFont(Value: TFont);
function GetMaxHeight: Integer;
procedure SetMaxHeight(Value: Integer);
function GetMaxWidth: Integer;
procedure SetMaxWidth(Value: Integer);
function GetMinHeight: Integer;
procedure SetMinHeight(Value: Integer);
function GetMinWidth: Integer;
procedure SetMinWidth(Value: Integer);
function GetScrollbar: TSCVirtualComboboxScrollbar;
procedure SetScrollbar(Value: TSCVirtualComboboxScrollbar);
function GetShowSizeGrip: Boolean;
procedure SetShowSizeGrip(Value: Boolean);
function GetShowStatusbar: Boolean;
procedure SetShowStatusbar(Value: Boolean);
function GetStatusbarAlignment: TAlignment;
procedure SetStatusbarAlignment(Value: TAlignment);
function GetStatusbarColor: TColor;
procedure SetStatusbarColor(Value: TColor);
function GetStatusbarText: String;
procedure SetStatusbarText(Value: String);
protected
function GetOwner: TPersistent; override;
property BorderStyle: TSCEditStyle read GetBorderStyle write SetBorderStyle default scesDefault;
property Color: TColor read GetColor write SetColor default clWindow;
property Font: TFont read GetFont write SetFont;
property MaxHeight: Integer read GetMaxHeight write SetMaxHeight default 0;
property MaxWidth: Integer read GetMaxWidth write SetMaxWidth default 0;
property MinHeight: Integer read GetMinHeight write SetMinHeight default 0;
property MinWidth: Integer read GetMinWidth write SetMinWidth default 0;
property Scrollbar: TSCVirtualComboboxScrollbar read GetScrollbar write SetScrollbar;
property ShowSizeGrip: Boolean read GetShowSizeGrip write SetShowSizeGrip default True;
property ShowStatusbar: Boolean read GetShowStatusbar write SetShowStatusbar default False;
property StatusbarAlignment: TAlignment read GetStatusbarAlignment write SetStatusbarAlignment default taLeftJustify;
property StatusbarColor: TColor read GetStatusbarColor write SetStatusbarColor default clBtnFace;
property StatusbarText: String read GetStatusbarText write SetStatusbarText;
public
constructor Create(AOwner: TSCCustomVirtualCombobox); virtual;
procedure Assign(Source: TPersistent); override;
property Owner: TSCCustomVirtualCombobox read FOwner;
end;
TSCVirtualComboboxPopupPropsClass = class of TSCVirtualComboboxCustomPopupProps;
TSCVirtualComboboxPopupProps = class(TSCVirtualComboboxCustomPopupProps)
published
property BorderStyle;
property Color;
property Font;
property MaxHeight;
property MaxWidth;
property MinHeight;
property MinWidth;
property Scrollbar;
property ShowSizeGrip;
property StatusbarAlignment;
property ShowStatusbar;
property StatusbarColor;
property StatusbarText;
end;
TSCCustomVirtualCombobox = class(TSCCustomDropDown)
private
FAutoWidth: Boolean;
FEndEllipsis: Boolean;
FDblClickReverts: Boolean;
FDropDownColor: TColor;
FDropDownCount: Integer;
FDropDownFont: TFont;
FImmediateDropDown: Boolean;
FImmediateSetText: Boolean;
FItemCount: Integer;
FItemHeight: Integer;
FListBox: TSCCustomVirtualListbox;
FMaxPopupHeight: Integer;
FMaxPopupWidth: Integer;
FMinPopupHeight: Integer;
FMinPopupWidth: Integer;
FScrollbar: TSCVirtualComboboxScrollbar;
FShowItemImages: Boolean;
FShowSizeGrip: Boolean;
FShowStatusbar: Boolean;
FStatusbarAlignment: TAlignment;
FStatusbarColor: TColor;
FStatusbarText: String;
FPopupBorderStyle: TSCEditStyle;
FPopupProps: TSCVirtualComboboxCustomPopupProps;
FRevertable: Boolean;
FSettingText: Boolean;
FInternalItemIndex: Integer;
FListClickType: TSCListClickType;
FStartHeight: Integer;
FStartWidth: Integer;
FStoredHeight: Integer;
FStoredWidth: Integer;
FCreatingWnd: Boolean;
FRowHeight: Integer;
FRowCount: Integer;
FOnGetItem: TSCGetListItemEvent;
FOnGetItemIndex: TSCGetListItemIndexEvent;
procedure SetDropDownCount(Value: Integer);
procedure SetDropDownFont(Value: TFont);
procedure SetMaxPopupHeight(Value: Integer);
procedure SetMaxPopupWidth(Value: Integer);
procedure SetMinPopupHeight(Value: Integer);
procedure SetMinPopupWidth(Value: Integer);
procedure SetPopupProps(Value: TSCVirtualComboboxCustomPopupProps);
procedure SetScrollbar(Value: TSCVirtualComboboxScrollbar);
function GetItem(Index: Integer; var S: String; var ImageIndex: Integer): Boolean;
function GetListItemIndex(S: String): Integer;
function ListGetItem(Sender: TObject; Index: Integer; var S: String;
var ImageIndex: Integer): Boolean;
function ListGetItemIndex(Sender: TObject; S: String): Integer;
procedure ListMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure DropDownFontChanged(Sender: TObject);
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure WMMouseWheel(var Message: TWMMouse); message WM_MOUSEWHEEL;
procedure EMSetReadOnly(var Message: TMessage); message EM_SETREADONLY;
protected
procedure CreateWnd; override;
procedure WndProc(var Message: TMessage); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
procedure Loaded; override;
function DoGetItem(Index: Integer; var S: String; var ImageIndex: Integer): Boolean; dynamic;
function DoGetItemIndex(S: String; var Handled: Boolean): Integer; dynamic;
function GetButtonPropsClass: TSCCustomEditButtonPropsClass; override;
function GetPopupPropsClass: TSCVirtualComboboxPopupPropsClass; dynamic;
procedure DoAutoCompleted; override;
function CompletedText(const S: String; CaseSensitive: Boolean): String; virtual;
function AutoCompleteText: String; override;
procedure SetEditMode(Value: TSCEditMode); override;
procedure BeforeEnterKeyClose; override;
function DoWantKeyDown(var Key: Word; Shift: TShiftState): Boolean; override;
procedure DoInternalChange; override;
procedure DoListClick(Index: Integer; const Item: String); virtual;
function GetTextCalculateFont: TFont; override;
function GetTextHeight: Integer; override;
procedure CalculateRowCount;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure ImageListChange(Sender: TObject); override;
function GetDropDownHeight: Integer; virtual;
function GetPopupStyle: TSCEditStyle; override;
procedure PrepareDropWindow; override;
procedure BeforePrepareDropWindow; override;
procedure AfterDropDown; override;
procedure AfterCloseUp; override;
function DropDownWantKeys(Key: Word; Shift: TShiftState): Boolean; override;
function GetListboxClass: TSCCustomVirtualListboxClass; dynamic;
function CanDropDown: Boolean; override;
function GetDroppedDown: Boolean; override;
function GetDropDownWindow: TWinControl; override;
function GetIsDropDown: Boolean; override;
procedure SetIsDropDown(Value: Boolean); override;
procedure SetDropDownColor(Value: TColor); virtual;
function GetItemIndex: Integer; virtual;
procedure SetEndEllipsis(Value: Boolean); virtual;
procedure SetItemCount(Value: Integer); virtual;
procedure SetItemHeight(Value: Integer); virtual;
procedure SetItemIndex(Value: Integer); virtual;
procedure SetShowItemImages(Value: Boolean); virtual;
property ListBox: TSCCustomVirtualListbox read FListBox;
property ListClickType: TSCListClickType read FListClickType write FListClickType default sclcDefault;
property CreatingWnd: Boolean read FCreatingWnd;
property AutoWidth: Boolean read FAutoWidth write FAutoWidth default False;
property DblClickReverts: Boolean read FDblClickReverts write FDblClickReverts default False;
property DropDownColor: TColor read FDropDownColor write SetDropDownColor default clWindow;
property DropDownCount: Integer read FDropDownCount write SetDropDownCount default 8;
property DropDownFont: TFont read FDropDownFont write SetDropDownFont;
property EndEllipsis: Boolean read FEndEllipsis write SetEndEllipsis default False;
property ImmediateDropDown: Boolean read FImmediateDropDown write FImmediateDropDown default False;
property ImmediateSetText: Boolean read FImmediateSetText write FImmediateSetText default True;
property ItemCount: Integer read FItemCount write SetItemCount default 0;
property ItemHeight: Integer read FItemHeight write SetItemHeight default 0;
property ItemIndex: Integer read GetItemIndex write SetItemIndex;
property IsDropDown default True;
property MaxPopupHeight: Integer read FMaxPopupHeight write SetMaxPopupHeight default 0;
property MaxPopupWidth: Integer read FMaxPopupWidth write SetMaxPopupWidth default 0;
property MinPopupHeight: Integer read FMinPopupHeight write SetMinPopupHeight default 0;
property MinPopupWidth: Integer read FMinPopupWidth write SetMinPopupWidth default 0;
property PopupBorderStyle: TSCEditStyle read FPopupBorderStyle write FPopupBorderStyle default scesDefault;
property PopupProps: TSCVirtualComboboxCustomPopupProps read FPopupProps write SetPopupProps;
property Revertable: Boolean read FRevertable write FRevertable default False;
property Scrollbar: TSCVirtualComboboxScrollbar read FScrollbar write SetScrollbar;
property CheckboxVisible default False;
property ShowItemImages: Boolean read FShowItemImages write SetShowItemImages default False;
property ShowSizeGrip: Boolean read FShowSizeGrip write FShowSizeGrip default True;
property ShowStatusbar: Boolean read FShowStatusbar write FShowStatusbar default False;
property StatusbarAlignment: TAlignment read FStatusbarAlignment write FStatusbarAlignment default taLeftJustify;
property StatusbarColor: TColor read FStatusbarColor write FStatusbarColor default clBtnFace;
property StatusbarText: String read FStatusbarText write FStatusbarText;
property OnGetItem: TSCGetListItemEvent read FOnGetItem write FOnGetItem;
property OnGetItemIndex: TSCGetListItemIndexEvent read FOnGetItemIndex write FOnGetItemIndex;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function IndexOfItem(Str: String): Integer; virtual;
function ItemText(Index: Integer): String; virtual;
end;
TSCVirtualCombobox = class(TSCCustomVirtualCombobox)
public
property ItemIndex;
published
property Align;
property Alignment;
property Anchors;
property AutoSelect;
property AutoSize;
property AutoWidth;
property BiDiMode;
property BorderProps;
property BrowseButtonVisible;
property ButtonProps;
property CanDragSelection;
property CharCase;
property CheckboxStyle;
property Color;
property Colors;
property Constraints;
property DblClickReverts;
property Delimeters;
property Description;
property DescriptionMode;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property DropDownKey;
property EditMask;
property EditMode;
property Enabled;
property EndEllipsis;
property Font;
property HideSelection;
property ImageIndex;
property Images;
property ImeMode;
property ImeName;
property ImmediateDropDown;
property ImmediateSetText;
property Indent;
property InsertChangesEditMode;
property ItemCount;
property ItemHeight;
property MaxLength;
{$IFDEF SC_DELPHI2009_EARLY}
property OEMConvert;
{$ENDIF}
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PasswordImage;
property PasswordStyle;
property Picture;
property PictureProps;
property PopupProps;
property PopupMenu;
property RaiseMaskError;
property ReadOnly;
property Revertable;
property CheckboxVisible;
property ShowItemImages;
property ShowHint;
property Style;
property TabOrder;
property TabStop;
property Text;
property Transparent;
property UseImage;
property UseUndo;
property UndoLimit;
property Visible;
property OnBrowseClick;
property OnCaretMove;
property OnCanResize;
property OnChange;
property OnClick;
property OnClipCut;
property OnClipCopy;
property OnClipPaste;
property OnCloseUp;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDropDown;
property OnEditModeChange;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetItem;
property OnGetItemIndex;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
end;
implementation
type
TSCVirtualListboxScrollbars = class (TSCControlCustomScrollbars);
TSCVirtualComboListbox = class(TSCCustomVirtualListbox);
TSCDropDownVirtualListbox = class(TSCCustomVirtualListbox)
private
FDroppedDown: Boolean;
FSettingHighlight: Boolean;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMVisibleChanged(var Message: TMessage); message CM_VISIBLECHANGED;
procedure WMShowWindow(var Message: TWMShowWindow); message WM_SHOWWINDOW;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure ColorsChanged; override;
property ForceDropdownClick default True;
public
constructor Create(AOwner: TComponent); override;
end;
{ TSCDropDownVirtualListbox }
procedure TSCDropDownVirtualListbox.CMFontChanged(var Message: TMessage);
begin
inherited;
HottrackColor := Font.Color;
end;
procedure TSCDropDownVirtualListbox.CMVisibleChanged(var Message: TMessage);
begin
inherited;
if not Boolean(Message.WParam) then
FDroppedDown := False;
end;
procedure TSCDropDownVirtualListbox.ColorsChanged;
begin
if FSettingHighlight then
Exit;
FSettingHighlight := True;
try
HideSelectionColor := HighlightColor;
HideSelectionTextColor := HighlightTextColor;
HottrackColor := Self.Font.Color;
finally
FSettingHighlight := False;
end;
end;
constructor TSCDropDownVirtualListbox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
HotTrack := True;
Border := sccbFlat;
FlatColor := clWindowFrame;
ForceDropdownClick := True;
ColorsChanged;
end;
procedure TSCDropDownVirtualListbox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
ExStyle := WS_EX_TOOLWINDOW or WS_EX_TOPMOST;
Style := Style and not WS_BORDER;
WindowClass.Style := CS_SAVEBITS;
end;
end;
procedure TSCDropDownVirtualListbox.CreateWnd;
begin
inherited CreateWnd;
Windows.SetParent(Handle, 0);
CallWindowProc(DefWndProc, Handle, WM_SETFOCUS, 0, 0);
end;
procedure TSCDropDownVirtualListbox.MouseMove(Shift: TShiftState; X, Y: Integer);
var
Indx: Integer;
begin
if not FDroppedDown then
begin
FDroppedDown := True;
Exit;
end;
inherited MouseMove(Shift, X, Y);
if not Dropping and HotTrack and (HotIndex <> ItemIndex) then
begin
Indx := ItemAtPos(X, Y, False);
if (Indx = -Maxint) or (Indx = Maxint) then
Indx := -1;
if (Indx <> -1) and (ItemIndex <> Indx) then
ItemIndex := Indx;
end;
end;
procedure TSCDropDownVirtualListbox.WMShowWindow(var Message: TWMShowWindow);
begin
inherited;
if not Message.Show then
FDroppedDown := False;
end;
{ TSCVirtualComboboxScrollbar }
procedure TSCVirtualComboboxScrollbar.Assign(Source: TPersistent);
begin
if Source is TSCVirtualComboboxScrollbar then
with TSCVirtualComboboxScrollbar(Source) do
begin
Width := Self.Width;
Style := Self.Style;
ThumbLines := Self.ThumbLines;
ButtonsLayout := Self.ButtonsLayout;
end;
inherited Assign(Source);
end;
constructor TSCVirtualComboboxScrollbar.Create(AOwner: TSCCustomControl;
AKind: TSCScrollbarKind);
begin
inherited Create(AOwner, AKind);
FWidth := -1;
FStyle := scssDefault;
FThumbLines := sctlNone;
FButtonsLayout := scsbDefault;
end;
procedure TSCVirtualComboboxScrollbar.SetWidth(Value: Integer);
begin
if Value < 0 then Value := -1
else
if Value < 12 then Value := 12
else
if Value > 36 then Value := 36;
FWidth := Value;
end;
{ TSCVirtualComboboxCustomPopupProps }
procedure TSCVirtualComboboxCustomPopupProps.Assign(Source: TPersistent);
begin
if Source is TSCVirtualComboboxCustomPopupProps then
begin
with TSCVirtualComboboxCustomPopupProps(Source) do
begin
Self.BorderStyle := BorderStyle;
Self.Color := Color;
Self.Font := Font;
Self.MaxHeight := MaxHeight;
Self.MaxWidth := MaxWidth;
Self.MinHeight := MinHeight;
Self.MinWidth := MinWidth;
Self.Scrollbar := Scrollbar;
Self.ShowSizeGrip := ShowSizeGrip;
Self.ShowStatusbar := ShowStatusbar;
Self.StatusbarColor := StatusbarColor;
Self.StatusbarText := StatusbarText;
end;
end else
inherited Assign(Source);
end;
constructor TSCVirtualComboboxCustomPopupProps.Create(AOwner: TSCCustomVirtualCombobox);
begin
inherited Create;
FOwner := AOwner;
end;
function TSCVirtualComboboxCustomPopupProps.GetBorderStyle: TSCEditStyle;
begin
Result := scesDefault;
if FOwner <> nil then
Result := FOwner.PopupBorderStyle;
end;
function TSCVirtualComboboxCustomPopupProps.GetColor: TColor;
begin
Result := clWindow;
if FOwner <> nil then
Result := FOwner.DropDownColor;
end;
function TSCVirtualComboboxCustomPopupProps.GetFont: TFont;
begin
Result := nil;
if FOwner <> nil then
Result := FOwner.DropDownFont;
end;
function TSCVirtualComboboxCustomPopupProps.GetMaxHeight: Integer;
begin
Result := 0;
if FOwner <> nil then
Result := FOwner.MaxPopupHeight;
end;
function TSCVirtualComboboxCustomPopupProps.GetMaxWidth: Integer;
begin
Result := 0;
if FOwner <> nil then
Result := FOwner.MaxPopupWidth;
end;
function TSCVirtualComboboxCustomPopupProps.GetMinHeight: Integer;
begin
Result := 0;
if FOwner <> nil then
Result := FOwner.MinPopupHeight;
end;
function TSCVirtualComboboxCustomPopupProps.GetMinWidth: Integer;
begin
Result := 0;
if FOwner <> nil then
Result := FOwner.MinPopupWidth;
end;
function TSCVirtualComboboxCustomPopupProps.GetOwner: TPersistent;
begin
Result := FOwner;
end;
function TSCVirtualComboboxCustomPopupProps.GetScrollbar: TSCVirtualComboboxScrollbar;
begin
Result := nil;
if FOwner <> nil then
Result := FOwner.Scrollbar;
end;
function TSCVirtualComboboxCustomPopupProps.GetShowSizeGrip: Boolean;
begin
Result := True;
if FOwner <> nil then
Result := FOwner.ShowSizeGrip;
end;
function TSCVirtualComboboxCustomPopupProps.GetShowStatusbar: Boolean;
begin
Result := False;
if FOwner <> nil then
Result := FOwner.ShowStatusbar;
end;
function TSCVirtualComboboxCustomPopupProps.GetStatusbarAlignment: TAlignment;
begin
Result := taLeftJustify;
if FOwner <> nil then
Result := FOwner.StatusbarAlignment;
end;
function TSCVirtualComboboxCustomPopupProps.GetStatusbarColor: TColor;
begin
Result := clBtnFace;
if FOwner <> nil then
Result := FOwner.StatusbarColor;
end;
function TSCVirtualComboboxCustomPopupProps.GetStatusbarText: String;
begin
Result := '';
if FOwner <> nil then
Result := FOwner.StatusbarText;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetBorderStyle(Value: TSCEditStyle);
begin
if FOwner <> nil then
FOwner.PopupBorderStyle := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetColor(Value: TColor);
begin
if FOwner <> nil then
FOwner.DropDownColor := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetFont(Value: TFont);
begin
if FOwner <> nil then
FOwner.DropDownFont := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetMaxHeight(Value: Integer);
begin
if FOwner <> nil then
FOwner.MaxPopupHeight := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetMaxWidth(Value: Integer);
begin
if FOwner <> nil then
FOwner.MaxPopupWidth := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetMinHeight(Value: Integer);
begin
if FOwner <> nil then
FOwner.MinPopupHeight := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetMinWidth(Value: Integer);
begin
if FOwner <> nil then
FOwner.MinPopupWidth := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetScrollbar(Value: TSCVirtualComboboxScrollbar);
begin
if FOwner <> nil then
FOwner.Scrollbar := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetShowSizeGrip(Value: Boolean);
begin
if FOwner <> nil then
FOwner.ShowSizeGrip := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetShowStatusbar(Value: Boolean);
begin
if FOwner <> nil then
FOwner.ShowStatusbar := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetStatusbarAlignment(
Value: TAlignment);
begin
if FOwner <> nil then
FOwner.StatusbarAlignment := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetStatusbarColor(Value: TColor);
begin
if FOwner <> nil then
FOwner.StatusbarColor := Value;
end;
procedure TSCVirtualComboboxCustomPopupProps.SetStatusbarText(Value: String);
begin
if FOwner <> nil then
FOwner.StatusbarText := Value;
end;
{ TSCCustomVirtualCombobox }
type
TParentForm = class(TCustomForm);
function TSCCustomVirtualCombobox.CanDropDown: Boolean;
begin
Result := (FListBox <> nil) and not IsDesigning and
(TSCVirtualComboListbox(FListBox).ItemCount > 0);
end;
constructor TSCCustomVirtualCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
AutoComplete := False;
IsDropDown := True;
FDropDownCount := 8;
ControlStyle := ControlStyle - [csSetCaption];
FScrollbar := TSCVirtualComboboxScrollbar.Create(Self, scskVertical);
FDropDownFont := TFont.Create;
FDropDownFont.OnChange := DropDownFontChanged;
FRowHeight := 0;
FRowCount := 0;
FStoredHeight := -1;
FStoredWidth := -1;
FImmediateSetText := True;
FInternalItemIndex := -1;
FDropDownColor := clWindow;
FItemHeight := 0;
FPopupBorderStyle := scesDefault;
FShowSizeGrip := True;
FStatusbarAlignment := taLeftJustify;
FStatusbarColor := clBtnFace;
SetCheckboxEnabled(False);
FListBox := GetListboxClass.Create(Self);
with TSCVirtualComboListbox(FListBox) do
begin
Visible := False;
ControlStyle := ControlStyle + [csReplicatable];
OnMouseUp := ListMouseUp;
end;
FPopupProps := GetPopupPropsClass.Create(Self);
end;
destructor TSCCustomVirtualCombobox.Destroy;
begin
FDropDownFont.OnChange := nil;
FreeAndNil(FDropDownFont);
if (FListBox <> nil) and not FListBox.IsDestroying then
begin
TSCVirtualComboListbox(FListBox).OnMouseUp := nil;
FreeAndNil(FListBox);
end;
FreeAndNil(FScrollbar);
FreeAndNil(FPopupProps);
inherited Destroy;
end;
function TSCCustomVirtualCombobox.DoWantKeyDown(var Key: Word; Shift: TShiftState): Boolean;
begin
Result := (Key in [VK_HOME, VK_END, VK_LEFT, VK_RIGHT]) or
((Key in [VK_UP, VK_DOWN]) and (ListBox = nil) or not DroppedDown) or
((Shift = [ssShift, ssCtrl]) and (Key in [Ord('z'), Ord('Z')])) or
((Shift = [ssCtrl]) and (Key in [Ord('c'), Ord('C'),
Ord('v'), Ord('V'), Ord('x'), Ord('X'), Ord('z'), Ord('Z')]));
end;
procedure TSCCustomVirtualCombobox.DoInternalChange;
begin
if not FSettingText then
begin
FInternalItemIndex := -1;
if (FListBox <> nil) and DroppedDown then
begin
with TSCVirtualComboListbox(FListBox) do
begin
FInternalItemIndex := GetListItemIndex(Self.Text); // IndexOfItem(Self.Text);
if AutoComplete then
begin
ItemIndex := FInternalItemIndex;
MakeVisible(ItemIndex);
Invalidate;
end;
end;
end else
FInternalItemIndex := GetListItemIndex(Self.Text); // IndexOfItem(Self.Text);
end;
end;
function TSCCustomVirtualCombobox.DropDownWantKeys(Key: Word; Shift: TShiftState): Boolean;
begin
Result := (DroppedDownSet and (Key in [VK_UP, VK_DOWN, VK_NEXT, VK_PRIOR])) or
((FListBox <> nil) and IsDropDown and GetDroppedDown and (Key in [VK_LEFT, VK_RIGHT]));
end;
procedure TSCCustomVirtualCombobox.GetChildren(Proc: TGetChildProc;
Root: TComponent);
begin
end;
function TSCCustomVirtualCombobox.GetDropDownWindow: TWinControl;
begin
Result := FListBox;
end;
function TSCCustomVirtualCombobox.GetDroppedDown: Boolean;
begin
Result := inherited GetDroppedDown and (FListbox.Focused or SendChildrenStyle);
end;
function TSCCustomVirtualCombobox.GetItemIndex: Integer;
begin
Result := FInternalItemIndex;
end;
procedure TSCCustomVirtualCombobox.ListMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Index: Integer;
begin
if (Button = mbLeft) and (FListbox <> nil) and
PtInRect(FListbox.ClientRect, Point(X, Y)) then
begin
Index := FListbox.ItemAtPos(X, Y, True);
if Index = -1 then
FInternalItemIndex := Index
else begin
if not ReadOnly then
begin
FSettingText := True;
try
FInternalItemIndex := Index;
SetText(ItemText(FInternalItemIndex));
SelectAll;
ClearUndo;
finally
FSettingText := False;
end;
FListClickType := sclcMouse;
try
DoListClick(FInternalItemIndex, Text);
finally
FListClickType := sclcDefault;
end;
end;
end;
CloseUp;
end;
end;
procedure TSCCustomVirtualCombobox.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
R: TRect;
Index: Integer;
begin
inherited MouseDown(Button, Shift, X, Y);
if (Button = mbLeft) and FDblClickReverts and
(ssDouble in Shift) and not GetIsDropDown and Focused then
begin
R := GetEditRect;
if IsRectEmpty(R) or not PtInRect(R, Point(X, Y)) then
Exit;
Inc(FInternalItemIndex);
if FInternalItemIndex < -1 then
FInternalItemIndex := -1;
if FInternalItemIndex < 0 then
FInternalItemIndex := ItemCount-1
else
if FInternalItemIndex > ItemCount-1 then
FInternalItemIndex := 0;
if FInternalItemIndex > ItemCount-1 then
FInternalItemIndex := ItemCount-1;
if (FInternalItemIndex > -1) and (FInternalItemIndex < ItemCount) then
begin
Index := FInternalItemIndex;
Self.SetText(ItemText(Index));
Self.SelectAll;
ClearUndo;
FListClickType := sclcMouse;
try
DoListClick(Index, Self.Text);
finally
FListClickType := sclcDefault;
end;
end;
end;
end;
procedure TSCCustomVirtualCombobox.MouseMove(Shift: TShiftState; X, Y: Integer);
var
ListPos: TPoint;
MousePos: TSmallPoint;
begin
if DroppedDownSet and (FListbox <> nil) then
begin
ListPos := FListbox.ScreenToClient(ClientToScreen(Point(X, Y)));
if PtInRect(FListbox.ClientRect, ListPos) then
begin
StopTracking;
MousePos := PointToSmallPoint(ListPos);
SendMessage(FListbox.Handle, WM_LBUTTONDOWN, 0, Integer(MousePos));
Exit;
end;
end;
inherited MouseMove(Shift, X, Y);
end;
procedure TSCCustomVirtualCombobox.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FListBox) then
FListBox := nil;
end;
function TSCCustomVirtualCombobox.GetListboxClass: TSCCustomVirtualListboxClass;
begin
Result := TSCDropDownVirtualListbox;
end;