-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqtwscomctrls.pp
2520 lines (2272 loc) · 82.9 KB
/
qtwscomctrls.pp
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
{
*****************************************************************************
* QtWSComCtrls.pp *
* --------------- *
* *
* *
*****************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit QtWSComCtrls;
{$mode objfpc}{$H+}
interface
{$I qtdefines.inc}
uses
// Bindings
qt6,
qtwidgets, qtobjects, qtproc,
// LCL
SysUtils, Classes, Types, ComCtrls, Controls, LCLType, Graphics, StdCtrls,
LCLIntf, Forms, ImgList,
// Widgetset
WSProc, WSComCtrls, WSLCLClasses;
type
{ TQtWSCustomPage }
TQtWSCustomPage = class(TWSCustomPage)
protected
class procedure UpdateTabFontColor(APage: TCustomPage; AFont: TFont);
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
end;
{ TQtWSCustomTabControl }
TQtWSCustomTabControl = class(TWSCustomTabControl)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class function GetDefaultClientRect(const AWinControl: TWinControl;
const {%H-}aLeft, {%H-}aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override;
class procedure AddPage(const ATabControl: TCustomTabControl;
const AChild: TCustomPage; const AIndex: integer); override;
class procedure MovePage(const ATabControl: TCustomTabControl;
const AChild: TCustomPage; const NewIndex: integer); override;
class procedure RemovePage(const ATabControl: TCustomTabControl;
const AIndex: integer); override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl
): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl
): integer; override;
class function GetCapabilities: TCTabControlCapabilities; override;
class function GetDesignInteractive(const AWinControl: TWinControl; AClientPos: TPoint): Boolean; override;
class function GetTabIndexAtPos(const ATabControl: TCustomTabControl; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ATabControl: TCustomTabControl; const AIndex: Integer): TRect; override;
class procedure SetPageIndex(const ATabControl: TCustomTabControl; const AIndex: integer); override;
class procedure SetTabCaption(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AText: string); override;
class procedure SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition); override;
class procedure SetTabSize(const ATabControl: TCustomTabControl; const ATabWidth, ATabHeight: integer); override;
class procedure ShowTabs(const ATabControl: TCustomTabControl; AShowTabs: boolean); override;
class procedure UpdateProperties(const ATabControl: TCustomTabControl); override;
end;
{ TQtWSStatusBar }
TQtWSStatusBar = class(TWSStatusBar)
protected
class procedure ClearPanels(const Widget: TQtStatusBar);
class procedure RecreatePanels(const AStatusBar: TStatusBar; const Widget: TQtStatusBar);
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer); override;
class procedure SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer); override;
class procedure SetSizeGrip(const AStatusBar: TStatusBar; SizeGrip: Boolean); override;
class procedure Update(const AStatusBar: TStatusBar); override;
end;
{ TQtWSTabSheet }
TQtWSTabSheet = class(TWSTabSheet)
published
end;
{ TQtWSPageControl }
TQtWSPageControl = class(TWSPageControl)
published
end;
{ TQtWSCustomListView }
TQtWSCustomListView = class(TWSCustomListView)
protected
class function IsIconView(const AList: TCustomListView): boolean;
class procedure InternalUpdateItems(const AList: TCustomListView);
class procedure GetCurrentImages(const ALV: TCustomListView;
out AImgListRes: TScaledImageListResolution);
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure ColumnDelete(const ALV: TCustomListView; const AIndex: Integer); override;
class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
class function ColumnGetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn): Integer; override;
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer); override;
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean); override;
class procedure ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment); override;
class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean); override;
class procedure ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String); override;
class procedure ColumnSetImage(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer); override;
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); override;
class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn); override;
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer;
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
override;
{items}
class procedure ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem); override;
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
class procedure ItemExchange(const ALV: TCustomListView; AItem: TListItem; const AIndex1, AIndex2: Integer); override;
class procedure ItemMove(const ALV: TCustomListView; AItem: TListItem; const AFromIndex, AToIndex: Integer); override;
class function ItemGetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem): Boolean; override;
class procedure ItemSetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean); override;
class function ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint; override;
class function ItemGetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
class procedure ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AImageIndex: Integer); override;
class procedure ItemSetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean); override;
class procedure ItemSetStateImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AStateImageIndex: Integer); override;
class procedure ItemSetText(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer; const AText: String); override;
class procedure ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean); override;
class function ItemDisplayRect(const ALV: TCustomListView; const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; override;
{parent}
class procedure BeginUpdate(const ALV: TCustomListView); override;
class procedure EndUpdate(const ALV: TCustomListView); override;
class function GetFocused(const ALV: TCustomListView): Integer; override;
class function GetHitTestInfoAt( const ALV: TCustomListView; X, Y: Integer ) : THitTests; override;
class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
class function GetSelCount(const ALV: TCustomListView): Integer; override;
class function GetSelection(const ALV: TCustomListView): Integer; override;
class function GetTopItem(const ALV: TCustomListView): Integer; override;
class procedure SetSort(const ALV: TCustomListView; const AType: TSortType; const AColumn: Integer;
const ASortDirection: TSortDirection); override;
class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
class function GetViewOrigin(const ALV: TCustomListView): TPoint; override;
class function GetVisibleRowCount(const ALV: TCustomListView): Integer; override;
class function RestoreItemCheckedAfterSort(const ALV: TCustomListView): Boolean; override;
class procedure SelectAll(const ALV: TCustomListView; const AIsSet: Boolean); override;
class procedure SetAllocBy(const ALV: TCustomListView; const AValue: Integer); override;
class procedure SetIconArrangement(const ALV: TCustomListView; const AValue: TIconArrangement); override;
class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageListResolution); override;
class procedure SetItemsCount(const ALV: TCustomListView; const Avalue: Integer); override;
class procedure SetOwnerData(const ALV: TCustomListView; const AValue: Boolean); override;
class procedure SetProperty(const ALV: TCustomListView; const AProp: TListViewProperty; const AIsSet: Boolean); override;
class procedure SetProperties(const ALV: TCustomListView; const AProps: TListViewProperties); override;
class procedure SetScrollBars(const ALV: TCustomListView; const AValue: TScrollStyle); override;
class procedure SetViewStyle(const ALV: TCustomListView; const Avalue: TViewStyle); override;
(*
// Column
class procedure ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer); override;
// Item
class function ItemSetPosition(const ALV: TCustomListView; const AIndex: Integer; const ANewPosition: TPoint): Boolean; virtual;
// LV
class function GetDropTarget(const ALV: TCustomListView): Integer; virtual;
class function GetHoverTime(const ALV: TCustomListView): Integer; virtual;
class function GetViewOrigin(const ALV: TCustomListView): TPoint; virtual;
class procedure SetDefaultItemHeight(const ALV: TCustomListView; const AValue: Integer); virtual;
class procedure SetHotTrackStyles(const ALV: TCustomListView; const AValue: TListHotTrackStyles); virtual;
class procedure SetHoverTime(const ALV: TCustomListView; const AValue: Integer); virtual;
class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageList); virtual;
class procedure SetViewOrigin(const ALV: TCustomListView; const AValue: TPoint); virtual;
*)
end;
{ TQtWSListView }
TQtWSListView = class(TWSListView)
published
end;
{ TQtWSProgressBar }
TQtWSProgressBar = class(TWSProgressBar)
protected
class procedure SetRangeStyle(AProgressBar: TQtProgressBar;
AStyle: TProgressBarStyle; AMin, AMax: Integer; const AIsDesign: Boolean);
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure ApplyChanges(const AProgressBar: TCustomProgressBar); override;
class procedure SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer); override;
class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
end;
{ TQtWSCustomUpDown }
TQtWSCustomUpDown = class(TWSCustomUpDown)
published
end;
{ TQtWSUpDown }
TQtWSUpDown = class(TWSUpDown)
published
end;
{ TQtWSToolButton }
TQtWSToolButton = class(TWSToolButton)
published
end;
{ TQtWSToolBar }
TQtWSToolBar = class(TWSToolBar)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
end;
{ TQtWSTrackBar }
TQtWSTrackBar = class(TWSTrackBar)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure ApplyChanges(const ATrackBar: TCustomTrackBar); override;
class function GetPosition(const ATrackBar: TCustomTrackBar): integer; override;
class procedure SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer); override;
class procedure SetOrientation(const ATrackBar: TCustomTrackBar; const AOrientation: TTrackBarOrientation); override;
end;
{ TQtWSCustomTreeView }
TQtWSCustomTreeView = class(TWSCustomTreeView)
published
end;
{ TQtWSTreeView }
TQtWSTreeView = class(TWSTreeView)
published
end;
implementation
uses qtint, math;
{$include qtpagecontrol.inc}
const
TickMarkToQtSliderTickPositionMap: array[TTickMark] of QSliderTickPosition =
(
{tmBottomRight} QSliderTicksBelow,
{tmTopLeft } QSliderTicksAbove,
{tmBoth } QSliderTicksBothSides
);
TrackBarOrientationToQtOrientationMap: array[TTrackBarOrientation] of QtOrientation =
(
{trHorizontal} QtHorizontal,
{trVertical } QtVertical
);
AlignmentToQtAlignmentMap: array[TAlignment] of QtAlignment =
(
{taLeftJustify } QtAlignLeft,
{taRightJustify} QtAlignRight,
{taCenter } QtAlignCenter
);
IconArngToQListFlow: array[TIconArrangement] of QListViewFlow =
(
{iaTop} QListViewLeftToRight,
{iaLeft}QListViewTopToBottom
);
{ TQtWSToolBar }
class function TQtWSToolBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtToolBar: TQtCustomControl;
begin
{$note TToolBar implementation under LCL is wrong. TToolBar isn't
TCustomControl but TWinControl.
To avoid theoretical crashes we use TQtCustomControl here, but indeed it
should be TQtWidget - so no viewport.}
QtToolBar := TQtCustomControl.Create(AWinControl, AParams);
QtToolBar.setFrameShape(QFrameNoFrame);
QtToolBar.viewportNeeded;
QtToolBar.setFocusPolicy(QtTabFocus);
QtToolBar.AttachEvents;
Result := TLCLHandle(QtToolBar);
end;
{ TQtWSTrackBar }
class function TQtWSTrackBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtTrackBar: TQtTrackBar;
begin
QtTrackBar := TQtTrackBar.Create(AWinControl, AParams);
QtTrackBar.AttachEvents;
Result := TLCLHandle(QtTrackBar);
end;
function TrackBarReversed(const ATrackBar: TCustomTrackBar;
const AQtTrackBar: TQtTrackBar): Boolean;
begin
Result :=
((ATrackBar.Orientation = trHorizontal) and
(AQtTrackbar.getInvertedAppereance <> ATrackBar.Reversed))
or
((ATrackBar.Orientation = trVertical) and
(AQtTrackbar.getInvertedAppereance <> not ATrackBar.Reversed))
end;
class procedure TQtWSTrackBar.ApplyChanges(const ATrackBar: TCustomTrackBar);
var
QtTrackBar: TQtTrackBar;
begin
if not WSCheckHandleAllocated(ATrackBar, 'ApplyChanges') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
QtTrackBar.BeginUpdate;
try
QtTrackBar.setRange(ATrackBar.Min, ATrackBar.Max);
if ATrackBar.TickStyle = tsNone then
QtTrackBar.SetTickPosition(QSliderNoTicks)
else
QtTrackBar.SetTickPosition(TickMarkToQtSliderTickPositionMap[ATrackBar.TickMarks]);
if QtTrackBar.getPageStep <> ATrackBar.PageSize then
QtTrackBar.setPageStep(ATrackBar.PageSize);
if QtTrackBar.getSingleStep <> ATrackBar.LineSize then
QtTrackBar.setSingleStep(ATrackBar.LineSize);
if QtTrackBar.getTickInterval <> ATrackBar.Frequency then
QtTrackBar.setTickInterval(ATrackBar.Frequency);
if QtTrackBar.getSliderPosition <> ATrackBar.Position then
QtTrackBar.setSliderPosition(ATrackBar.Position);
if (QtTrackBar.getOrientation <>
TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation])
or TrackBarReversed(ATrackBar, QtTrackBar) then
begin
QtTrackBar.Hide;
QtTrackBar.setOrientation(TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation]);
if ATrackBar.Orientation = trHorizontal then
QtTrackBar.setInvertedAppereance(ATrackBar.Reversed)
else
{make it delphi and msdn compatibile when vertical then 0 = top}
QtTrackBar.setInvertedAppereance(not ATrackBar.Reversed);
QtTrackBar.setInvertedControls(False);
QtTrackBar.Show;
end;
finally
QtTrackBar.EndUpdate;
end;
end;
class function TQtWSTrackBar.GetPosition(const ATrackBar: TCustomTrackBar): integer;
var
QtTrackBar: TQtTrackBar;
begin
Result := 0;
if not WSCheckHandleAllocated(ATrackBar, 'GetPosition') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
Result := QtTrackBar.getSliderPosition;
end;
class procedure TQtWSTrackBar.SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer);
var
QtTrackBar: TQtTrackBar;
begin
if not WSCheckHandleAllocated(ATrackBar, 'SetPosition') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
QtTrackBar.BeginUpdate;
try
QtTrackBar.setSliderPosition(NewPosition);
finally
QtTrackBar.EndUpdate;
end;
end;
class procedure TQtWSTrackBar.SetOrientation(const ATrackBar: TCustomTrackBar;
const AOrientation: TTrackBarOrientation);
var
QtTrackBar: TQtTrackBar;
begin
if not WSCheckHandleAllocated(ATrackBar, 'SetOrientation') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
QtTrackBar.BeginUpdate;
try
if (QtTrackBar.getOrientation <>
TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation])
or TrackBarReversed(ATrackBar, QtTrackBar) then
begin
QtTrackBar.Hide;
QtTrackBar.setOrientation(TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation]);
if ATrackBar.Orientation = trHorizontal then
QtTrackBar.setInvertedAppereance(ATrackBar.Reversed)
else
{make it delphi and msdn compatibile when vertical then 0 = top}
QtTrackBar.setInvertedAppereance(not ATrackBar.Reversed);
QtTrackBar.setInvertedControls(False);
QtTrackBar.Show;
end;
finally
QtTrackBar.EndUpdate;
end;
end;
{ TQtWSProgressBar }
class procedure TQtWSProgressBar.SetRangeStyle(AProgressBar: TQtProgressBar;
AStyle: TProgressBarStyle; AMin, AMax: Integer; const AIsDesign: Boolean);
begin
if AStyle = pbstNormal then
begin
if (AMin = 0) and (AMax = 0) then
AProgressBar.setRange(0, 1)
else
AProgressBar.setRange(AMin, AMax)
end
else
AProgressBar.setRange(0, Integer(AIsDesign));
end;
class function TQtWSProgressBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtProgressBar: TQtProgressBar;
begin
QtProgressBar := TQtProgressBar.Create(AWinControl, AParams);
QtProgressBar.AttachEvents;
Result := TLCLHandle(QtProgressBar);
end;
class procedure TQtWSProgressBar.ApplyChanges(const AProgressBar: TCustomProgressBar);
var
QtProgressBar: TQtProgressBar;
begin
QtProgressBar := TQtProgressBar(AProgressBar.Handle);
// AProgressBar.Smooth is not supported by qt
case AProgressBar.Orientation of
pbVertical:
begin
QtProgressBar.setOrientation(QtVertical);
QtProgressBar.setInvertedAppearance(False);
end;
pbRightToLeft:
begin
QtProgressBar.setOrientation(QtHorizontal);
QtProgressBar.setInvertedAppearance(True);
end;
pbTopDown:
begin
QtProgressBar.setOrientation(QtVertical);
QtProgressBar.setInvertedAppearance(True);
end;
else { pbHorizontal is default }
begin
QtProgressBar.setOrientation(QtHorizontal);
QtProgressBar.setInvertedAppearance(False);
end;
end;
QtProgressBar.setTextVisible(AProgressBar.BarShowText);
// The position, minumum and maximum values
SetRangeStyle(QtProgressBar, AProgressBar.Style,
AProgressBar.Min, AProgressBar.Max,
csDesigning in AProgressBar.ComponentState);
QtProgressBar.BeginUpdate;
QtProgressBar.setValue(AProgressBar.Position);
QtProgressBar.EndUpdate;
end;
class procedure TQtWSProgressBar.SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer);
begin
TQtProgressBar(AProgressBar.Handle).BeginUpdate;
TQtProgressBar(AProgressBar.Handle).setValue(NewPosition);
TQtProgressBar(AProgressBar.Handle).EndUpdate;
end;
class procedure TQtWSProgressBar.SetStyle(
const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle);
var
QProgressBar: TQtProgressBar;
begin
if not WSCheckHandleAllocated(AProgressBar, 'SetStyle') then
Exit;
QProgressBar := TQtProgressBar(AProgressBar.Handle);
QProgressBar.reset;
SetRangeStyle(QProgressBar, NewStyle, AProgressBar.Min, AProgressBar.Max,
csDesigning in AProgressBar.ComponentState);
if NewStyle = pbstNormal then
QProgressBar.setValue(AProgressBar.Position);
end;
{ TQtWSStatusBar }
class procedure TQtWSStatusBar.ClearPanels(const Widget: TQtStatusBar);
var
i: integer;
begin
if length(Widget.Panels) > 0 then
begin
Widget.setUpdatesEnabled(False);
for i := High(Widget.Panels) downto 0 do
begin
Widget.removeWidget(Widget.Panels[i].Widget);
Widget.Panels[i].DetachEvents;
QLabel_destroy(QLabelH(Widget.Panels[i].Widget));
Widget.Panels[i].Widget := nil;
Widget.Panels[i].Free;
end;
Widget.setUpdatesEnabled(True);
SetLength(Widget.Panels, 0);
end;
end;
class procedure TQtWSStatusBar.RecreatePanels(const AStatusBar: TStatusBar;
const Widget: TQtStatusBar);
var
Str: WideString;
i: Integer;
begin
// issues #18683 and #28307
QStatusBar_clearMessage(QStatusBarH(Widget.Widget));
ClearPanels(Widget);
if AStatusBar.SimplePanel then
begin
Str := AStatusBar{%H-}.SimpleText;
Widget.showMessage(@Str);
end else
if AStatusBar.Panels.Count > 0 then
begin
Widget.setUpdatesEnabled(False);
SetLength(Widget.Panels, AStatusBar.Panels.Count);
for i := 0 to AStatusBar.Panels.Count - 1 do
begin
Str := AStatusBar{%H-}.Panels[i].Text;
Widget.Panels[i] := TQtStatusBarPanel.CreateFrom(AStatusBar,
QLabel_create(@Str, Widget.Widget));
Widget.Panels[i].HasPaint := AStatusBar.Panels[i].Style = psOwnerDraw;
Widget.Panels[i].ID := AStatusBar.Panels[i].ID;
QLabel_setText(QLabelH(Widget.Panels[i].Widget), @Str);
QLabel_setAlignment(QLabelH(Widget.Panels[i].Widget),
AlignmentToQtAlignmentMap[AStatusBar.Panels[i].Alignment]);
QWidget_setMinimumWidth(Widget.Panels[i].Widget, Max(0, AStatusBar.Panels[i].Width));
QWidget_setVisible(Widget.Panels[i].Widget,
AStatusBar.Panels[i].Width > 0);
Widget.Panels[i].AttachEvents;
Widget.addWidget(Widget.Panels[i].Widget, ord(i = AStatusBar.Panels.Count - 1));
end;
Widget.setUpdatesEnabled(True);
end;
end;
class function TQtWSStatusBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtStatusBar: TQtStatusBar;
begin
QtStatusBar := TQtStatusBar.Create(AWinControl, AParams);
QtStatusBar.setSizeGripEnabled(TStatusBar(AWinControl).SizeGrip and
TStatusBar(AWinControl).SizeGripEnabled);
RecreatePanels(TStatusBar(AWinControl), QtStatusBar);
QtStatusBar.AttachEvents;
// Return handle
Result := TLCLHandle(QtStatusBar);
end;
class procedure TQtWSStatusBar.DestroyHandle(const AWinControl: TWinControl);
var
QtStatusBar: TQtStatusBar;
begin
QtStatusBar := TQtStatusBar(AWinControl.Handle);
ClearPanels(QtStatusBar);
QtStatusBar.Release;
end;
class procedure TQtWSStatusBar.PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer);
var
QtStatusBar: TQtStatusBar;
Str: Widestring;
begin
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
if AStatusBar.SimplePanel then
begin
ClearPanels(QtStatusBar);
Str := AStatusBar{%H-}.SimpleText;
QtStatusBar.showMessage(@Str);
end else
if AStatusBar.Panels.Count > 0 then
begin
QStatusBar_clearMessage(QStatusBarH(QtStatusBar.Widget));
if (PanelIndex >= Low(QtStatusBar.Panels)) and
(PanelIndex <= High(QtStatusBar.Panels)) then
begin
Str := AStatusBar{%H-}.Panels[PanelIndex].Text;
QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
QLabel_setAlignment(QLabelH(QtStatusBar.Panels[PanelIndex].Widget),
AlignmentToQtAlignmentMap[AStatusBar.Panels[PanelIndex].Alignment]);
QWidget_setMinimumWidth(QtStatusBar.Panels[PanelIndex].Widget,
Max(0, AStatusBar.Panels[PanelIndex].Width));
QWidget_setVisible(QtStatusBar.Panels[PanelIndex].Widget,
AStatusBar.Panels[PanelIndex].Width > 0);
end;
end;
end;
class procedure TQtWSStatusBar.SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer);
var
QtStatusBar: TQtStatusBar;
Str: Widestring;
begin
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
if AStatusBar.SimplePanel then
begin
Str := AStatusBar{%H-}.SimpleText;
QtStatusBar.showMessage(@Str);
end else
begin
if (PanelIndex >= Low(QtStatusBar.Panels)) and
(PanelIndex <= High(QtStatusBar.Panels)) then
begin
Str := AStatusBar{%H-}.Panels[PanelIndex].Text;
QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
end;
end;
end;
class procedure TQtWSStatusBar.SetSizeGrip(const AStatusBar: TStatusBar;
SizeGrip: Boolean);
var
QtStatusBar: TQtStatusBar;
begin
if not WSCheckHandleAllocated(AStatusBar, 'SetSizeGrip') then
Exit;
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
QtStatusBar.setSizeGripEnabled(SizeGrip and AStatusBar.SizeGripEnabled);
end;
class procedure TQtWSStatusBar.Update(const AStatusBar: TStatusBar);
var
QtStatusBar: TQtStatusBar;
begin
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
RecreatePanels(AStatusBar, QtStatusBar);
end;
{ TQtWSCustomListView }
type
TCustomListViewHack = class(TCustomListView);
class function TQtWSCustomListView.IsIconView(const AList: TCustomListView): boolean;
begin
Result := TCustomListViewHack(AList).ViewStyle <> vsReport;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.CreateHandle
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
QtTreeWidget: TQtTreeWidget;
QtListWidget: TQtListWidget;
ALV: TCustomListViewHack;
begin
ALV := TCustomListViewHack(AWinControl);
if IsIconView(TCustomListView(AWinControl)) then
begin
QtListWidget := TQtListWidget.Create(AWinControl, AParams);
QtListWidget.ViewStyle := Ord(TCustomListViewHack(AWinControl).ViewStyle);
if TCustomListViewHack(AWinControl).ViewStyle in [vsIcon, vsSmallIcon] then
begin
// emabarcadero docs says
// vsIcon, vsSmallIcon
// Each item appears as a full-sized icon with a label below it.
// The user can drag the items to any location in the list view window.
QtListWidget.setViewMode(QListViewIconMode);
QtListWidget.setResizeMode(QListViewAdjust);
QtListWidget.setMovement(QListViewFree);
with TCustomListView(AWinControl) do
begin
QtListWidget.setWrapping(IconOptions.AutoArrange);
QtListWidget.setViewFlow(IconArngToQListFlow[IconOptions.Arrangement]);
QtListWidget.setWordWrap(IconOptions.WrapText);
end;
end else
QtListWidget.setViewMode(QListViewListMode);
QtListWidget.Checkable := TCustomListView(AWinControl).Checkboxes;
QtListWidget.OwnerDrawn := ALV.IsCustomDrawn(dtControl, cdPrePaint);
QtListWidget.AttachEvents;
Result := TLCLHandle(QtListWidget);
end else
begin
QtTreeWidget := TQtTreeWidget.Create(AWinControl, AParams);
QtTreeWidget.ViewStyle := Ord(TCustomListViewHack(AWinControl).ViewStyle);
QtTreeWidget.OwnerDrawn := ALV.IsCustomDrawn(dtControl, cdPrePaint) or (ALV.OwnerDraw and
(ALV.ViewStyle = vsReport));
QtTreeWidget.setStretchLastSection(ALV.AutoWidthLastColumn);
QTreeView_setItemsExpandable(QTreeViewH(QtTreeWidget.Widget), False);
QtTreeWidget.setRootIsDecorated(False);
QtTreeWidget.AttachEvents;
Result := TLCLHandle(QtTreeWidget);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnDelete
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnDelete(const ALV: TCustomListView;
const AIndex: Integer);
begin
if not WSCheckHandleAllocated(ALV, 'ColumnDelete') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
// we must recreate handle since there's no column removal support
// in our bindings (protected methods in qt).
RecreateWnd(ALV);
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnInsert
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnInsert(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn);
var
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
TWIChild: QTreeWidgetItemH;
Str: WideString;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnInsert') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if QtTreeWidget.ColCount <> TCustomListViewHack(ALV).Columns.Count then
QtTreeWidget.ColCount := TCustomListViewHack(ALV).Columns.Count;
if (QtTreeWidget.ColCount <= 1) and TCustomListViewHack(ALV).ShowColumnHeaders then
QtTreeWidget.setHeaderVisible(True);
TWI := QtTreeWidget.headerItem;
if QTreeWidgetItem_childCount(TWI) < (AIndex + 1) then
begin
TWIChild := QTreeWidgetItem_create(Ord(QTreeWidgetItemType));
QTreeWidgetItem_setFlags(TWIChild, QtItemIsEnabled);
QTreeWidgetItem_addChild(TWI, TWIChild);
Str := ALV{%H-}.Column[AIndex].Caption;
QTreeWidgetItem_setText(TWI, AIndex, @Str);
end;
if (csDesigning in ALV.ComponentState) then
exit;
QtTreeWidget.Header.Clickable := TCustomListViewHack(ALV).ColumnClick;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnGetWidth
Params: None
Returns: Integer
------------------------------------------------------------------------------}
class function TQtWSCustomListView.ColumnGetWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn): Integer;
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnGetWidth') then
Exit(-1);
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit(0);
QtTreeWidget := TQtTreeWidget(ALV.Handle);
{Issue #39353.Such scenario happens only when SetStyle() calls RecreateWnd
while designing control.Default width for TListColumn is 50,
unfortunatelly it''s hardcoded in listcolumn.inc.}
if (csDesigning in ALV.ComponentState) and (QtTreeWidget.ColCount <> ALV.ColumnCount) then
exit(50);
Result := QtTreeWidget.ColWidth[AIndex];
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnMove
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnMove(const ALV: TCustomListView;
const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnMove') then
Exit;
if (csDesigning in ALV.ComponentState) then
exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.Header.moveSection(AOldIndex, ANewIndex);
end;
class procedure TQtWSCustomListView.ColumnSetSortIndicator(
const ALV: TCustomListView; const AIndex: Integer;
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
const
QtSortOrder : array [TSortIndicator] of QtSortOrder = (QtAscendingOrder, QtAscendingOrder, QtDescendingOrder);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetSortIndicator') then
Exit;
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if Assigned(QtTreeWidget) and
not (csDesigning in ALV.ComponentState) then
begin
if ASortIndicator = siNone then
QtTreeWidget.Header.SetSortIndicatorVisible(false)
else
begin
QtTreeWidget.Header.SetSortIndicatorVisible(true);
QtTreeWidget.Header.SetSortIndicator(AIndex, QtSortOrder[ASortIndicator]);
end;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetAlignment
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetAlignment(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment);
var
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
i: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAlignment') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.headerItem;
QTreeWidgetItem_setTextAlignment(TWI, AIndex,
AlignmentToQtAlignmentMap[AAlignment]);
if not (csLoading in ALV.ComponentState) then
for i := 0 to QtTreeWidget.ItemCount - 1 do
begin
TWI := QtTreeWidget.topLevelItem(i);
if TWI <> nil then
QTreeWidgetItem_setTextAlignment(TWI, AIndex,
AlignmentToQtAlignmentMap[AAlignment]);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetAutoSize
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetAutoSize(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAutoSize') then
Exit;
if (csDesigning in ALV.ComponentState) then
exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if AAutoSize then
QtTreeWidget.Header.setResizeMode(AIndex, QHeaderViewResizeToContents)
else
QtTreeWidget.Header.setResizeMode(AIndex, QHeaderViewInteractive);
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetCaption
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetCaption(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
var
Str: WideString;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.headerItem;
if TWI <> NiL then
begin
Str := {%H-}ACaption;
QTreeWidgetItem_setText(TWI, AIndex, @Str);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetImage
Params: None