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
|
{
*****************************************************************************
* QtWSCheckLst.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 QtWSCheckLst;
{$mode objfpc}{$H+}
interface
{$I qtdefines.inc}
uses
// Bindings
qt5,
qtprivate, qtwidgets,
// LCL
SysUtils, Classes, StdCtrls, Controls, Graphics, CheckLst, LCLType,
// Widgetset
WSCheckLst, WSLCLClasses;
type
{ TQtWSCheckListBox }
{ TQtWSCustomCheckListBox }
TQtWSCustomCheckListBox = class(TWSCustomCheckListBox)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class function GetItemEnabled(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer): Boolean; override;
class function GetState(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer): TCheckBoxState; override;
class procedure SetItemEnabled(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer; const AEnabled: Boolean); override;
class procedure SetState(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer; const AState: TCheckBoxState); override;
end;
implementation
uses WSProc;
const
LCLCheckStateToQtCheckStateMap: array[TCheckBoxState] of QtCheckState =
(
{cbUnchecked} QtUnchecked,
{cbChecked } QtChecked,
{cbGrayed } QtPartiallyChecked
);
QtCheckStateToLCLCheckStateMap: array[QtCheckState] of TCheckBoxState =
(
{QtUnchecked } cbUnchecked,
{QtPartiallyChecked} cbGrayed,
{QtChecked } cbChecked
);
class function TQtWSCustomCheckListBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams
): TLCLHandle;
var
QtListWidget: TQtCheckListBox;
SelMode: QAbstractItemViewSelectionMode;
begin
QtListWidget := TQtCheckListBox.Create(AWinControl, AParams);
QtListWidget.Checkable := True;
if TCheckListBox(AWinControl).MultiSelect then
if TCheckListBox(AWinControl).ExtendedSelect then
SelMode := QAbstractItemViewExtendedSelection
else
SelMode := QAbstractItemViewMultiSelection
else
SelMode := QAbstractItemViewSingleSelection;
QtListWidget.setSelectionMode(SelMode);
QtListWidget.AllowGrayed := TCustomCheckListBox(AWinControl).AllowGrayed;
QtListWidget.AttachEvents;
// create our FList helper
QtListWidget.FList := TQtListStrings.Create(AWinControl, QtListWidget);
QtListWidget.OwnerDrawn := TCheckListBox(AWinControl).Style in [lbOwnerDrawFixed, lbOwnerDrawVariable];
Result := TLCLHandle(QtListWidget);
end;
class function TQtWSCustomCheckListBox.GetItemEnabled(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer): Boolean;
var
QtListWidget: TQtCheckListBox;
begin
if not WSCheckHandleAllocated(ACheckListBox, 'GetItemEnabled') then
Exit(False);
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
Result := QtListWidget.Enabled[AIndex];
end;
class function TQtWSCustomCheckListBox.GetState(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer): TCheckBoxState;
var
QtListWidget: TQtCheckListBox;
begin
if not WSCheckHandleAllocated(ACheckListBox, 'GetState') then
Exit(cbUnchecked);
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
QtListWidget.AllowGrayed := ACheckListBox.AllowGrayed;
Result := QtCheckStateToLCLCheckStateMap[QtListWidget.ItemCheckState[AIndex]];
end;
class procedure TQtWSCustomCheckListBox.SetItemEnabled(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer;
const AEnabled: Boolean);
var
QtListWidget: TQtCheckListBox;
begin
if not WSCheckHandleAllocated(ACheckListBox, 'SetItemEnabled') then
Exit;
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
QtListWidget.BeginUpdate;
QtListWidget.Enabled[AIndex] := AEnabled;
QtListWidget.EndUpdate;
end;
class procedure TQtWSCustomCheckListBox.SetState(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer;
const AState: TCheckBoxState);
var
QtListWidget: TQtCheckListBox;
begin
if not WSCheckHandleAllocated(ACheckListBox, 'SetState') then
Exit;
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
QtListWidget.AllowGrayed := ACheckListBox.AllowGrayed;
QtListWidget.BeginUpdate;
QtListWidget.ItemCheckState[AIndex] := LCLCheckStateToQtCheckStateMap[AState];
QtListWidget.EndUpdate;
end;
end.
|