ComboBox: implement TComboBoxStyle.HasEditBox as a replacement for the old and removed TCustomComboBox.ReadOnly property

git-svn-id: trunk@63224 -
This commit is contained in:
ondrej 2020-05-26 21:30:13 +00:00
parent 18d6e48e90
commit 34e6f40639
5 changed files with 27 additions and 6 deletions

View File

@ -1116,4 +1116,21 @@ begin
inherited;
end;
{ TComboBoxStyleHelper }
function TComboBoxStyleHelper.HasEditBox: Boolean;
const
ArrHasEditBox: array[TComboBoxStyle] of Boolean = (
True, // csDropDown, // like an TEdit plus a button to drop down the list, default
True, // csSimple, // like an TEdit plus a TListBox
False, // csDropDownList, // like TLabel plus a button to drop down the list
False, // csOwnerDrawFixed, // like csDropDownList, but custom drawn
False, // csOwnerDrawVariable,// like csDropDownList, but custom drawn and with each item can have another height
True, // csOwnerDrawEditableFixed,// like csOwnerDrawFixed, but with TEdit
True // csOwnerDrawEditableVariable// like csOwnerDrawVariable, but with TEdit
);
begin
Result := ArrHasEditBox[Self];
end;
// included by stdctrls.pp

View File

@ -1699,8 +1699,7 @@ begin
ACombo := QComboBox_create(nil);
try
QWidget_setFont(ACombo, ComboBox.getFont);
QComboBox_setEditable(ACombo,
not (ACustomComboBox.Style in [csDropDownList,csOwnerDrawFixed,csOwnerDrawVariable]));
QComboBox_setEditable(ACombo, not ACustomComboBox.Style.HasEditBox);
AText := 'Mtjx';
AItems := QStringList_create(@AText);
QComboBox_addItems(ACombo, AItems);

View File

@ -1644,8 +1644,7 @@ begin
ACombo := QComboBox_create(nil);
try
QWidget_setFont(ACombo, ComboBox.getFont);
QComboBox_setEditable(ACombo,
not (ACustomComboBox.Style in [csDropDownList,csOwnerDrawFixed,csOwnerDrawVariable]));
QComboBox_setEditable(ACombo, not ACustomComboBox.Style.HasEditBox);
AText := 'Mtjx';
AItems := QStringList_create(PWideString(@AText));
QComboBox_addItems(ACombo, AItems);

View File

@ -364,11 +364,11 @@ procedure TWinCEComboBoxStringList.Clear;
var
SaveText: String;
begin
if TCustomComboBox(FSender).Style in [csSimple, csDropDown, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable] then
if not TCustomComboBox(FSender).Style.HasEditBox then
SaveText := TCustomComboBox(FSender).Text;
inherited;
UpdateComboHeight;
if TCustomComboBox(FSender).Style in [csSimple, csDropDown, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable] then
if not TCustomComboBox(FSender).Style.HasEditBox then
TCustomComboBox(FSender).Text := SaveText;
end;

View File

@ -19,6 +19,7 @@ unit StdCtrls;
{$mode objfpc}{$H+}
{$I lcl_defines.inc}
{$modeswitch typehelpers}
interface
@ -257,6 +258,11 @@ type
csOwnerDrawEditableVariable// like csOwnerDrawVariable, but with TEdit
);
TComboBoxStyleHelper = type helper for TComboBoxStyle
public
function HasEditBox: Boolean;
end;
TOwnerDrawState = LCLType.TOwnerDrawState;
TDrawItemEvent = procedure(Control: TWinControl; Index: Integer;