-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLISTVIEW.PAS
1420 lines (1286 loc) · 35.5 KB
/
LISTVIEW.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
{$I COMPILER.INC}
unit ListView;
interface
uses
AplTypes,
AplObj,
Drawing,
Lists,
AplMath,
VeriType,
Controls,
Standard,
Views;
type
PListView = ^TListView;
PListItem = ^TListItem;
PCheckListItem = ^TCheckListItem;
PListItems = ^TListItems;
PCheckListItems = ^TCheckListItems;
PIndexChangedProc = ^TIndexChangedProc;
PDropDownList = ^TDropDownList;
PDropDownButton = ^TDropDownButton;
PIndexChangedEvent = ^TIndexChangedEvent;
PDropDownListView = ^TDropDownListView;
PCheckListView = ^TCheckListView;
TIndexChangeTrigger = (ctMouse, ctKeyboard);
TIndexChangedEvent = object(TEvent)
private
public
OldIndex: integer;
NewIndex: integer;
Trigger: TIndexChangeTrigger;
procedure Assign(var ASource: TObject); virtual;
procedure Clear; virtual;
end;
TIndexChangedProc = procedure(var AEvent: TIndexChangedEvent);
TListItem = object(TObject)
private
public
Owner: PListView;
Text: PChar;
Value: pointer;
Tag: longint;
constructor CreateText(const AText: string);
constructor CreateTextValue(const AText: string; AValue: pointer);
constructor CreateAll(const AText: string; AValue: pointer; ATag: longint);
procedure SetText(const AText: string);
procedure Init; virtual;
destructor Free; virtual;
end;
TCheckListItem = object(TListItem)
private
public
CheckBox: PCheckBox;
procedure Init; virtual;
function Checked: boolean;
procedure SetChecked(AValue: boolean);
end;
TListItems = object(TObjectList)
private
public
Owner: PListView;
constructor Create(AOwner: PListView);
function GetItem(AIndex: integer): PListItem;
function GetItemByValue(AValue: pointer): PListItem;
function Add(AItem: PListItem): integer;
function IndexOf(AItem: PListItem): integer;
function IndexOfValue(AValue: pointer): integer;
function IndexOfTag(ATag: longint): integer;
procedure SetItem(AIndex: integer; AItem: PListItem);
procedure Insert(AIndex: integer; AItem: PListItem);
procedure RemoveItem(AItem: PListItem);
procedure Delete(AIndex: integer); virtual;
end;
TCheckListItems = object(TListItems)
private
public
function GetItem(AIndex: integer): PCheckListItem;
function GetItemByValue(AValue: pointer): PCheckListItem;
function Add(AItem: PCheckListItem): integer;
function IndexOf(AItem: PCheckListItem): integer;
function Checked(AIndex: integer): boolean;
procedure Delete(AIndex: integer); virtual;
procedure SetChecked(AIndex: integer; AChecked: boolean);
procedure SetItem(AIndex: integer; AItem: PCheckListItem);
procedure Insert(AIndex: integer; AItem: PCheckListItem);
procedure RemoveItem(AItem: PCheckListItem);
end;
TListView = object(TView)
private
public
Items: PListItems;
SelectedIndex: integer;
SelectedColor: byte;
SelectedBackColor: byte;
UnfocusedSelectForeColor: byte;
UnfocusedSelectBackColor: byte;
OnSelectedIndexChanged: PIndexChangedProc;
ItemSpacing: integer;
VisibleItems: integer;
AutoHeight: boolean;
TextOffsetX, TextOffsetY: integer;
function SelectedItem: PListItem;
function GetSelectedIndex(AEvent: TMouseEvent): integer;
function ItemHeight: integer; virtual;
function ContentWidth: integer; virtual;
function ContentHeight: integer; virtual;
function ContentX: integer; virtual;
function ContentY: integer; virtual;
function CreateItems: PListItems; virtual;
function CreateItem: PListItem; virtual;
function AddItem(const AText: string): PListItem;
function AddItemValue(const AText: string; AValue: pointer): PListItem;
function AddItemTag(const AText: string; ATag: longint): PListItem;
function AddItemAll(const AText: string; AValue: pointer;
ATag: longint): PListItem;
function InsertItem(AIndex: integer; const AText: string): PListItem;
function InsertItemValue(AIndex: integer; const AText: string;
AValue: pointer): PListItem;
function InsertItemTag(AIndex: integer; const AText: string;
ATag: longint): PListItem;
function InsertItemAll(AIndex: integer; const AText: string;
AValue: pointer; ATag: longint): PListItem;
procedure PaintItem(AIndex: integer); virtual;
procedure GetContentExtent(var ASize: TSize); virtual;
procedure Focus; virtual;
procedure UnFocus; virtual;
procedure Init; virtual;
procedure Paint(ARect: TRect); virtual;
procedure Layout; virtual;
procedure SetSelectedIndex(AIndex: integer);
procedure KeyPress(var AEvent: TKeyEvent); virtual;
procedure MouseDown(var AEvent: TMouseEvent); virtual;
procedure MouseWheelChanged(var AEvent: TMouseEvent); virtual;
procedure SelectedIndexChanged(var AEvent: TIndexChangedEvent); virtual;
procedure GetItemRect(AIndex: integer; var ARect: TRect); virtual;
procedure GetItemLayout(AIndex: integer; var ARect: TRect); virtual;
procedure ChangeSelect(ADelta: integer); virtual;
procedure SetScrollBarBounds(AOrientation: TScrollOrientation); virtual;
procedure Clear; virtual;
procedure DrawControls; virtual;
procedure Draw; virtual;
destructor Free; virtual;
end;
TDropDownButton = object(TButton)
private
public
procedure Init; virtual;
procedure Paint(ARect: TRect); virtual;
procedure MouseDown(var AEvent: TMouseEvent); virtual;
end;
TDropDownListView = object(TListView)
private
public
procedure Layout; virtual;
procedure SelectedIndexChanged(var AEvent: TIndexChangedEvent); virtual;
end;
TDropDownList = object(TFocusControl)
private
FButton: PDropDownButton;
FList: PDropDownListView;
FButtonSize: integer;
FOldIndex: integer;
public
MaxItems: integer;
Text: PChar;
OnSelectedIndexChanged: PIndexChangedProc;
procedure ShowList;
procedure HideList;
procedure Paint(ARect: TRect); virtual;
function Items: PListItems;
function SelectedIndex: integer;
function SelectedItem: PListItem;
function GetText: string;
function List: PListView;
procedure SetSelectedIndex(AIndex: integer);
procedure SelectedIndexChanged(var AEvent: TIndexChangedEvent);
procedure MouseDown(var AEvent: TMouseEvent); virtual;
procedure Unfocus; virtual;
procedure KeyPress(var AEvent: TKeyEvent); virtual;
procedure Init; virtual;
procedure Layout; virtual;
procedure SetText(const AText: string); virtual;
procedure AutoSizeControl; virtual;
destructor Free; virtual;
end;
TCheckListView = object(TListView)
private
public
procedure PaintItem(AIndex: integer); virtual;
procedure Init; virtual;
function CheckListItems: PCheckListItems; virtual;
function CreateItems: PListItems; virtual;
function CreateItem: PListItem; virtual;
function Checked(AIndex: integer): boolean;
function AddItem(const AText: string): PCheckListItem;
function AddItemValue(const AText: string; AValue: pointer): PCheckListItem;
function AddItemTag(const AText: string; ATag: longint): PCheckListItem;
function AddItemAll(const AText: string; AValue: pointer;
ATag: longint): PCheckListItem;
function InsertItem(AIndex: integer; const AText: string): PCheckListItem;
function InsertItemValue(AIndex: integer; const AText: string;
AValue: pointer): PCheckListItem;
function InsertItemTag(AIndex: integer; const AText: string;
ATag: longint): PCheckListItem;
function InsertItemAll(AIndex: integer; const AText: string;
AValue: pointer; ATag: longint): PCheckListItem;
function ItemHeight: integer; virtual;
procedure SetChecked(AIndex: integer; AChecked: boolean);
procedure Layout; virtual;
end;
implementation
uses
AplStr,
AplUtils,
Graphics,
KeyDrv,
Strings,
Veridian;
constructor TListItem.CreateText(const AText: string);
begin
inherited Create;
TString.AssignString(Text, AText);
end;
constructor TListItem.CreateTextValue(const AText: string; AValue: pointer);
begin
CreateText(AText);
Value := AValue;
end;
constructor TListItem.CreateAll(const AText: string; AValue: pointer; ATag: longint);
begin
CreateTextValue(AText, AValue);
Tag := ATag;
end;
procedure TListItem.SetText(const AText: string);
var
index: integer;
begin
TString.AssignString(Text, AText);
index := Owner^.Items^.IndexOf(@self);
Owner^.BeginDrawing;
Owner^.PaintItem(index);
Owner^.EndDrawing;
end;
procedure TListItem.Init;
begin
inherited Init;
Text := nil;
Value := nil;
Owner := nil;
Tag := 0;
end;
destructor TListItem.Free;
begin
TString.Free(Text);
inherited Free;
end;
procedure TListView.GetContentExtent(var ASize: TSize);
var
index: integer;
item: PListItem;
begin
ASize.Create;
for index := 0 to Items^.Count - 1 do begin
item := Items^.GetItem(index);
ASize.Width := Max(ASize.Width, Font^.TextWidthLarge(item^.Text)
+ Padding.Width);
end;
ASize.Height := Items^.Count * ItemHeight;
end;
procedure TListView.Init;
begin
inherited Init;
TextOffsetX := 0;
TextOffsetY := 0;
TransparentBack := false;
ScrollType := scAsNeeded;
CanFocus := true;
Items := CreateItems;
OnSelectedIndexChanged := nil;
SelectedIndex := -1;
BorderStyle := bsSingle;
BevelStyle := bvNone;
VertScrollBar^.Position := rpParentRelative;
HorzScrollBar^.Position := rpParentRelative;
Font := VeridianApp^.GetFont('editor');
SelectedColor := VeridianApp^.Colors.ListSelected;
SelectedBackColor := VeridianApp^.Colors.ListSelectedBack;
UnfocusedSelectForeColor := VeridianApp^.Colors.ListUnfocusedSelect;
UnfocusedSelectBackColor := VeridianApp^.Colors.ListUnfocusedSelectBack;
Padding.CreateAll(2, 0, 2, 0);
ItemSpacing := 4;
VisibleItems := 10;
AutoHeight := false;
end;
procedure TListView.SetSelectedIndex(AIndex: integer);
var
index: integer;
rect, itemRect: TRect;
previousIndex: integer;
event: TIndexChangedEvent;
listHeight: integer;
begin
index := Clamp(AIndex, 0, Items^.Count - 1);
if index = SelectedIndex then
exit;
previousindex := SelectedIndex;
SelectedIndex := index;
GetContentDrawRect(rect);
GetItemRect(SelectedIndex, itemRect);
if itemRect.Y >= rect.Bottom then
ScrollVert((SelectedIndex - previousIndex) * itemRect.Height);
if itemRect.Y < rect.Y then
ScrollVert((SelectedIndex - previousIndex) * itemRect.Height);
BeginDrawing;
GetClipRect(rect);
rect.Intersect(Graph^.State^.ViewPort);
Graph^.SetViewPort(rect);
PaintItem(previousIndex);
PaintItem(SelectedIndex);
EndDrawing;
event.Create;
event.NewIndex := SelectedIndex;
event.OldIndex := previousIndex;
event.Trigger := ctKeyboard;
SelectedIndexChanged(event);
end;
function TListView.SelectedItem: PListItem;
begin
SelectedItem := nil;
if (SelectedIndex < 0) or (SelectedIndex > Items^.Count - 1) then
exit;
SelectedItem := Items^.GetItem(SelectedIndex);
end;
destructor TListView.Free;
begin
FreeAndNil(Items);
inherited Free;
end;
procedure TListView.Focus;
begin
BeginDrawing;
SetFocus(true, false);
PaintItem(SelectedIndex);
EndDrawing;
end;
procedure TListView.Unfocus;
begin
BeginDrawing;
SetFocus(false, false);
PaintItem(SelectedIndex);
EndDrawing;
end;
function TListView.AddItem(const AText: string): PListItem;
var
index: integer;
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
index := Items^.Add(result);
AddItem := Items^.GetItem(index);
end;
function TListView.AddItemValue(const AText: string; AValue: pointer): PListItem;
var
index: integer;
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
result^.Value := AValue;
index := Items^.Add(result);
AddItemValue := Items^.GetItem(index);
end;
function TListView.AddItemTag(const AText: string; ATag: longint): PListItem;
var
index: integer;
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
result^.Tag := ATag;
index := Items^.Add(result);
AddItemTag := Items^.GetItem(index);
end;
function TListView.AddItemAll(const AText: string; AValue: pointer; ATag: longint): PListItem;
var
index: integer;
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
result^.Value := AValue;
result^.Tag := ATag;
index := Items^.Add(result);
AddItemAll := Items^.GetItem(index);
end;
function TListView.InsertItem(AIndex: integer; const AText: string): PListItem;
var
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
Items^.Insert(AIndex, result);
InsertItem := result;
end;
function TListView.InsertItemValue(AIndex: integer; const AText: string;
AValue: pointer): PListItem;
var
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
result^.Value := AValue;
Items^.Insert(AIndex, result);
InsertItemValue := result;
end;
function TListView.InsertItemTag(AIndex: integer; const AText: string;
ATag: longint): PListItem;
var
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
result^.Tag := ATag;
Items^.Insert(AIndex, result);
InsertItemTag := result;
end;
function TListView.InsertItemAll(AIndex: integer; const AText: string;
AValue: pointer; ATag: longint): PListItem;
var
result: PListItem;
begin
result := CreateItem;
TString.AssignString(result^.Text, AText);
result^.Value := AValue;
result^.Tag := ATag;
Items^.Insert(AIndex, result);
InsertItemAll := result;
end;
function TListView.CreateItem: PListItem;
var
result: PListItem;
begin
result := New(PListItem, Create);
result^.Owner := @self;
CreateItem := result;
end;
procedure TListView.GetItemRect(AIndex: integer; var ARect: TRect);
var
cx: integer;
cy: integer;
rect: TRect;
begin
GetContentDrawRect(rect);
rect.Translate(ContentOffsetX, ContentOffsetY);
cy := rect.Y + AIndex * ItemHeight;
ARect.CreateDims(rect.X, cy, rect.Width, ItemHeight);
end;
procedure TListView.GetItemLayout(AIndex: integer; var ARect: TRect);
var
cx: integer;
cy: integer;
rect: TRect;
begin
GetContentRect(rect);
rect.Translate(ContentOffsetX, ContentOffsetY);
cy := rect.Y + AIndex * ItemHeight;
ARect.CreateDims(rect.X, cy, rect.Width, ItemHeight);
end;
function TListView.ItemHeight: integer;
var
result: integer;
begin
result := Font^.Height + ItemSpacing;
ItemHeight := result;
end;
procedure TListView.PaintItem(AIndex: integer);
var
rect, itemRect: TRect;
item: PListItem;
clipRect, viewRect: TRect;
begin
if not VeridianApp^.State.DrawEnabled then
exit;
if not IsVisible then
exit;
if (AIndex < 0) or (AIndex > Items^.Count - 1) then
exit;
item := Items^.GetItem(AIndex);
Graph^.SetForeColor(ForeColor);
Graph^.SetBackColor(BackColor);
if AIndex = SelectedIndex then begin
if Focused then begin
Graph^.SetForeColor(SelectedColor);
Graph^.SetBackColor(SelectedBackColor);
end
else begin
Graph^.SetForeColor(UnfocusedSelectForeColor);
Graph^.SetBackColor(UnfocusedSelectBackColor);
end;
end;
Graph^.PushState;
GetItemRect(AIndex, itemRect);
GetClipRect(clipRect);
clipRect.Translate(OuterWidth, OuterWidth);
clipRect.Grow(-2 * OuterWidth, -2 * OuterWidth);
clipRect.Intersect(Graph^.State^.ViewPort);
Graph^.SetViewPort(clipRect);
Graph^.FillRect(itemRect);
Graph^.DrawTextLarge(itemRect.X + Padding.Left + TextOffsetX,
itemRect.Y + TextOffsetY + ItemSpacing div 2, item^.Text);
Graph^.PopState;
end;
function TListView.ContentX: integer;
var
result: integer;
begin
result := inherited ContentX;
Dec(result, Padding.Left);
ContentX := result;
end;
function TListView.ContentY: integer;
var
result: integer;
begin
result := inherited ContentY;
Dec(result, Padding.Top);
ContentY := result;
end;
function TListView.ContentWidth: integer;
var
result: integer;
begin
result := inherited ContentWidth;
Inc(result, Padding.Width);
ContentWidth := result;
end;
function TListView.ContentHeight: integer;
var
result: integer;
begin
result := inherited ContentHeight;
Inc(result, Padding.Height);
ContentHeight := result;
end;
function TListView.CreateItems: PListItems;
begin
CreateItems := New(PListItems, Create(@self));
end;
function TListView.GetSelectedIndex(AEvent: TMouseEvent): integer;
begin
Inc(AEvent.Y, ScrollY);
GetSelectedIndex := AEvent.Y div ItemHeight;
end;
procedure TListView.SelectedIndexChanged(var AEvent: TIndexChangedEvent);
begin
if AEvent.OldIndex = AEvent.NewIndex then
exit;
Invoke(OnSelectedIndexChanged, AEvent);
end;
procedure TListView.MouseWheelChanged(var AEvent: TMouseEvent);
var
amount: integer;
begin
inherited MouseWheelChanged(AEvent);
if not VertScrollBar^.Visible then
exit;
amount := AEvent.NewMouseState.WheelCounter * ItemHeight;
if AEvent.NewMouseState.WheelCounter > 0 then
ScrollVert(amount)
else if AEvent.NewMouseState.WheelCounter < 0 then
ScrollVert(amount);
end;
procedure TListView.MouseDown(var AEvent: TMouseEvent);
var
index: integer;
previousIndex: integer;
event: TIndexChangedEvent;
rect: TRect;
begin
if not IsVisibleAndEnabled then
exit;
if CanFocus and not Focused then
Focus;
previousindex := SelectedIndex;
SelectedIndex := GetSelectedIndex(AEvent);
SelectedIndex := Clamp(SelectedIndex, 0, Items^.Count - 1);
GetClipRect(rect);
BeginDrawing;
PaintItem(previousIndex);
PaintItem(SelectedIndex);
EndDrawing;
event.Create;
event.NewIndex := SelectedIndex;
event.OldIndex := previousIndex;
event.Trigger := ctMouse;
event.Sender := @self;
SelectedIndexChanged(event);
inherited MouseDown(AEvent);
end;
procedure TListView.ChangeSelect(ADelta: integer);
begin
SetSelectedIndex(SelectedIndex + ADelta);
end;
procedure TListView.KeyPress(var AEvent: TKeyEvent);
var
rect: TRect;
begin
if not IsVisibleAndEnabled then
exit;
if not Focused then
exit;
AEvent.Handled := true;
GetDrawRect(rect);
case AEvent.Key of
kyDown: ChangeSelect(1);
kyUp: ChangeSelect(-1);
kyPageDown: ChangeSelect(rect.Height div ItemHeight);
kyPageUp: ChangeSelect(-rect.Height div ItemHeight );
kyEnd: ChangeSelect(Items^.Count - 1);
kyHome: ChangeSelect(-Items^.Count - 1);
else AEvent.Handled := false;
end;
if not AEvent.Handled then
inherited KeyPress(AEvent);
end;
procedure TListView.SetScrollBarBounds(AOrientation: TScrollOrientation);
begin
inherited SetScrollBarBounds(AOrientation);
if AOrientation = soHorizontal then begin
Dec(HorzScrollBar^.X, OuterWidth);
Inc(HorzScrollBar^.X, OuterWidth);
Inc(HorzScrollBar^.Width, 2 * OuterWidth);
end
else begin
Dec(VertScrollBar^.Y, OuterWidth);
Inc(VertScrollBar^.X, OuterWidth);
Inc(VertScrollBar^.Height, 2 * OuterWidth);
end;
end;
procedure TListView.Draw;
begin
inherited Draw;
end;
procedure TListView.DrawControls;
begin
inherited DrawControls;
end;
procedure TListView.Layout;
var
max: longint;
rect: TRect;
size: integer;
begin
if AutoHeight then begin
size := VisibleItems * ItemHeight + 2 * OuterWidth
+ Padding.Height;
SetBounds(X, Y, Width, Size);
end;
inherited Layout;
GetBounds(rect);
VertScrollbar^.Increment := ItemHeight;
VertScrollbar^.PageIncrement := Round(rect.Height / ItemHeight) * ItemHeight;
max := Items^.Count * ItemHeight + 2 * OuterWidth;
Dec(max, rect.Height);
VertScrollBar^.Max := AplMath.MaxL(0, max);
end;
procedure TListView.Clear;
begin
Items^.Clear;
SelectedIndex := 0;
VertScrollbar^.SetScrollPosition(0);
HorzScrollbar^.SetScrollPosition(0);
end;
procedure TListView.Paint(ARect: TRect);
var
index: integer;
oldFocusedColor: longint;
oldFocusedBackColor: longint;
yPos: integer;
clipRect: TRect;
begin
if not IsVisible then
exit;
oldFocusedColor := FocusedColor;
oldFocusedBackColor := FocusedBackColor;
FocusedColor := ForeColor;
FocusedBackColor := BackColor;
inherited Paint(ARect);
FocusedColor := oldFocusedColor;
FocusedBackColor := oldFocusedBackColor;
for index := 0 to Items^.Count - 1 do
PaintItem(index);
Graph^.SetBackColor(BackColor);
if Items^.Count * ItemHeight < ARect.Height then begin
yPos := ARect.Y + Items^.Count * ItemHeight + OuterWidth;
ARect.CreateDims(ARect.X + OuterWidth, yPos, ARect.Width - 2 * OuterWidth, ARect.Bottom - yPos);
Graph^.FillRect(ARect);
end;
end;
constructor TListItems.Create(AOwner: PListView);
begin
inherited Create;
Owner := AOwner;
end;
function TListItems.GetItem(AIndex: integer): PListItem;
begin
GetItem := PListItem(inherited GetItem(AIndex));
end;
function TListItems.Add(AItem: PListItem): integer;
begin
Add := inherited Add(AItem);
end;
function TListItems.IndexOf(AItem: PListItem): integer;
begin
IndexOf := inherited IndexOf(AItem);
end;
function TListItems.IndexOfValue(AValue: pointer): integer;
var
index: integer;
begin
IndexOfValue := -1;
for index := 0 to Count - 1 do begin
if GetItem(index)^.Value = AValue then begin
IndexOfValue := index;
break;
end;
end;
end;
function TListItems.IndexOfTag(ATag: longint): integer;
var
index: integer;
begin
IndexOfTag := -1;
for index := 0 to Count - 1 do begin
if GetItem(index)^.Tag = ATag then begin
IndexOfTag := index;
break;
end;
end;
end;
procedure TListItems.SetItem(AIndex: integer; AItem: PListItem);
begin
inherited SetItem(AIndex, AItem);
end;
procedure TListItems.Delete(AIndex: integer);
begin
inherited Delete(AIndex);
end;
procedure TListItems.Insert(AIndex: integer; AItem: PListItem);
begin
inherited Insert(AIndex, AItem);
end;
procedure TListItems.RemoveItem(AItem: PListItem);
var
index: integer;
begin
index := IndexOf(AItem);
if index = -1 then
exit;
inherited Remove(index);
end;
function TListItems.GetItemByValue(AValue: pointer): PListItem;
var
index: integer;
begin
GetItemByValue := nil;
for index := 0 to Count - 1 do begin
if GetItem(index)^.Value = AValue then begin
GetItemByValue := GetItem(index);
break;
end;
end;
end;
procedure TDropDownList.SelectedIndexChanged(var AEvent: TIndexChangedEvent);
var
item: PListItem;
begin
if AEvent.Trigger = ctKeyboard then
exit;
item := FList^.Items^.GetItem(AEvent.NewIndex);
HideList;
SetText(TString.GetString(item^.Text));
Invoke(OnSelectedIndexChanged, AEvent);
end;
procedure TDropDownButton.Init;
begin
inherited Init;
Position := rpParentRelative;
end;
procedure TDropDownButton.Paint(ARect: TRect);
begin
inherited Paint(ARect);
end;
procedure TDropDownButton.MouseDown(var AEvent: TMouseEvent);
var
dropDown: PDropDownList;
begin
Inherited MouseDown(AEvent);
dropDown := PDropDownList(Parent);
if not dropDown^.FList^.IsVisible then begin
dropDown^.ShowList;
end
else begin
dropDown^.HideList;
end;
end;
procedure TDropDownListView.Layout;
var
max: longint;
maxItems, itemCount, listHeight, size: integer;
begin
inherited Layout;
maxItems := PDropDownList(Parent)^.MaxItems;
itemCount := Min(Items^.Count, maxItems);
listHeight := itemCount * ItemHeight + 2 * Parent^.OuterWidth;
VertScrollBar^.Height := listHeight;
Height := listHeight;
VertScrollBar^.Visible := Items^.Count > maxItems;
VertScrollbar^.Increment := ItemHeight;
VertScrollbar^.PageIncrement := Round(Height / ItemHeight) * ItemHeight;
max := Items^.Count * ItemHeight;
Dec(max, Height);
VertScrollBar^.Max := AplMath.MaxL(0, max);
end;
procedure TDropDownListView.SelectedIndexChanged(var AEvent: TIndexChangedEvent);
begin
inherited SelectedIndexChanged(AEvent);
PDropDownList(Parent)^.SelectedIndexChanged(AEvent);
end;
procedure ListKeyPress(var AEvent: TKeyEvent); far;
var
dropDown: PDropDownList;
self: PListView;
event: TIndexChangedEvent;
begin
self := PListView(AEvent.Sender);
if AEvent.Handled then
exit;
dropDown := PDropDownList(self^.Parent);
case AEvent.Key of
kyEnter: begin
dropDown^.HideList;
dropDown^.SetText(TString.GetString(self^.Items^.GetItem(self^.SelectedIndex)^.Text));
AEvent.Handled := true;
event.Create;
event.OldIndex := dropDown^.FOldIndex;
event.NewIndex := dropDown^.SelectedIndex;
dropDown^.SelectedIndexChanged(event);
end;
end;
end;
procedure TDropDownList.Unfocus;
begin
if FList^.IsVisible then
HideList;
inherited Unfocus;
end;
procedure TDropDownList.KeyPress(var AEvent: TKeyEvent);
begin
if (not FList^.IsVisible) and not (CanFocus and Focused) then
exit;
if FList^.IsVisible and not (FList^.CanFocus and FList^.Focused) then
exit;
case AEvent.Key of
kyDown: begin
if FList^.IsVisible then
exit;
AEvent.Handled := true;
UnFocus;
ShowList;
exit;
end;
kyEnter: begin
if not FList^.IsVisible then begin
AEvent.Handled := true;
UnFocus;
ShowList;
exit;
end
else begin
end;
end;
kyEsc: begin
if FList^.IsVisible then
HideList;
AEvent.Handled := true;
FList^.SelectedIndex := FOldIndex;
end;
end;
if not AEvent.Handled then
inherited KeyPress(AEvent);
end;
procedure TDropDownList.Paint(ARect: TRect);
var
pos: TPoint;
txt: string;
begin
if not IsVisible then
exit;
Graph^.State^.Font := Font;
Graph^.SetForeColor(ForeColor);
Graph^.SetBackColor(BackColor);
txt := GetText;
TControl.Paint(ARect);
if CanFocus and Focused then
Graph^.SetBackColor(FocusedBackColor);
if not TransparentBack then
Graph^.FillRect(ARect);
GetTextAlign(ARect, pos);
Graph^.SetForeColor(ForeColor);
Graph^.SetBackColor(BackColor);
if not IsEnabled then begin
Graph^.SetForeColor(DisabledColor);
Graph^.SetBackColor(DisabledBackColor);