ComboBox: implement TComboBoxStyle.IsOwnerDrawn and .IsVariable and use them instead of the in [] syntax

git-svn-id: trunk@63228 -
This commit is contained in:
ondrej 2020-05-26 22:25:15 +00:00
parent a8d3315c24
commit ef8d6a825e
16 changed files with 80 additions and 89 deletions

View File

@ -92,8 +92,7 @@ begin
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
if (Style in [csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable])
and (FItemHeight > 0) then
if Style.IsOwnerDrawn and (FItemHeight > 0) then
ItemHeight := Round(ItemHeight * AYProportion);
end;
end;
@ -126,7 +125,7 @@ procedure TCustomComboBox.DoEnter;
begin
inherited DoEnter;
//AutoSelect when DoEnter is fired by keyboard
if (Style = csDropDownList) then Exit;//Non editable style
if not Style.HasEditBox then Exit;//Non editable style
if (FAutoSelect and not (csLButtonDown in ControlState)) then
begin
SelectAll;
@ -543,7 +542,7 @@ begin
//SelectAll when hitting return key for AutoSelect feature
if (Key = VK_RETURN) then
begin
if ((cbactEnabled in FAutoCompleteText) and (Style <> csDropDownList)) then
if ((cbactEnabled in FAutoCompleteText) and Style.HasEditBox) then
begin
// Only happens with alpha-numeric keys and return key and editable Style
SelectAll;
@ -555,7 +554,7 @@ begin
end;
end
else
if ((cbactEnabled in FAutoCompleteText) and (Style <> csDropDownList)) then
if ((cbactEnabled in FAutoCompleteText) and Style.HasEditBox) then
begin
//Only happens with alpha-numeric keys and return key and editable Style
//DebugLn(['TCustomComboBox.KeyUp ',Key,' ',IsEditableTextKey(Key)]);
@ -670,9 +669,7 @@ function TCustomComboBox.GetItemHeight: Integer;
begin
// FItemHeight is not initialized at class creating. we can, but with what value?
// so, if it still uninitialized (=0), then we ask widgetset
if (FStyle in [csOwnerDrawFixed, csOwnerDrawVariable,
csOwnerDrawEditableFixed, csOwnerDrawEditableVariable])
and (FItemHeight > 0) or not HandleAllocated then
if FStyle.IsOwnerDrawn and (FItemHeight > 0) or not HandleAllocated then
Result := FItemHeight
else
begin
@ -708,8 +705,7 @@ begin
FItemHeight := AValue;
if not HandleAllocated then
exit;
if Style in [csOwnerDrawFixed, csOwnerDrawVariable,
csOwnerDrawEditableFixed, csOwnerDrawEditableVariable] then
if Style.IsOwnerDrawn then
TWSCustomComboBoxClass(WidgetSetClass).SetItemHeight(Self, FItemHeight);
end;
@ -1040,7 +1036,7 @@ begin
AHeight := FItemHeight
else
AHeight := ItemHeight;
if FStyle in [csOwnerDrawVariable, csOwnerDrawEditableVariable] then
if FStyle.IsVariable then
MeasureItem(Integer(ItemId), AHeight);
if AHeight > 0 then
ItemHeight := AHeight;
@ -1133,4 +1129,34 @@ begin
Result := ArrHasEditBox[Self];
end;
function TComboBoxStyleHelper.IsOwnerDrawn: Boolean;
const
ArrIsOwnerDrawn: array[TComboBoxStyle] of Boolean = (
False, // csDropDown, // like an TEdit plus a button to drop down the list, default
False, // csSimple, // like an TEdit plus a TListBox
False, // csDropDownList, // like TLabel plus a button to drop down the list
True, // csOwnerDrawFixed, // like csDropDownList, but custom drawn
True, // 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 := ArrIsOwnerDrawn[Self];
end;
function TComboBoxStyleHelper.IsVariable: Boolean;
const
ArrIsVariable: array[TComboBoxStyle] of Boolean = (
False, // csDropDown, // like an TEdit plus a button to drop down the list, default
False, // 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
True, // csOwnerDrawVariable,// like csDropDownList, but custom drawn and with each item can have another height
False, // csOwnerDrawEditableFixed,// like csOwnerDrawFixed, but with TEdit
True // csOwnerDrawEditableVariable// like csOwnerDrawVariable, but with TEdit
);
begin
Result := ArrIsVariable[Self];
end;
// included by stdctrls.pp

View File

@ -31,7 +31,7 @@ var
i: Integer;
begin
// combo that has edit control may have unreliable itemindex like bug 20950
if Style <> csDropDownList then
if Style.HasEditBox then
ItemIndex := Items.IndexOf(Text);
i := ItemIndex;
if i <> -1 then
@ -87,7 +87,7 @@ end;
procedure TDBLookupComboBox.DoOnSelect;
begin
if Style=csDropDownList then
if not Style.HasEditBox then
UpdateRecord;
inherited DoOnSelect;
end;

View File

@ -496,13 +496,12 @@ end;
function ComboBoxIsOwnerDrawn(AStyle: TComboBoxStyle): Boolean;
begin
Result := AStyle in [csOwnerDrawFixed, csOwnerDrawVariable,
csOwnerDrawEditableFixed, csOwnerDrawEditableVariable];
Result := AStyle.IsOwnerDrawn;
end;
function ComboBoxIsVariable(AStyle: TComboBoxStyle): Boolean;
begin
Result := AStyle in [csOwnerDrawVariable, csOwnerDrawEditableVariable];
Result := AStyle.IsVariable;
end;
procedure ComboBoxSetBorderStyle(box: NSComboBox; astyle: TBorderStyle);

View File

@ -796,10 +796,8 @@ end;
class procedure TCDWSCustomComboBox.SetStyle(
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
begin
TQtComboBox(ACustomComboBox.Handle).setEditable(NewStyle = csDropDown);
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle in
[csOwnerDrawFixed,
csOwnerDrawVariable];
TQtComboBox(ACustomComboBox.Handle).setEditable(NewStyle.HasEditBox);
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle.IsOwnerDrawn;
// TODO: implement styles: csSimple
inherited SetStyle(ACustomComboBox, NewStyle);
end;

View File

@ -69,7 +69,7 @@ begin
if TCustomListbox(LCLList.Owner).Style = lbStandard then
exit;
if LclList.Owner is TCustomCombobox then
if TCustomCombobox(LclList.Owner).Style < csOwnerDrawFixed then
if not TCustomCombobox(LclList.Owner).Style.IsOwnerDrawn then
exit;
// get itemindex and area

View File

@ -1168,21 +1168,19 @@ var
GtkCombo: PGtkCombo;
begin
GtkCombo := GTK_COMBO(Pointer(ACustomComboBox.Handle));
case ACustomComboBox.Style of
csDropDownList :
begin
// do not set ok_if_empty = true, otherwise it can hang focus
gtk_combo_set_value_in_list(GtkCombo,GdkTrue,GdkTrue);
gtk_combo_set_use_arrows_always(GtkCombo,GdkTrue);
gtk_combo_set_case_sensitive(GtkCombo,GdkFalse);
end;
else
begin
// do not set ok_if_empty = true, otherwise it can hang focus
gtk_combo_set_value_in_list(GtkCombo,GdkFalse,GdkTrue);
gtk_combo_set_use_arrows_always(GtkCombo,GdkFalse);
gtk_combo_set_case_sensitive(GtkCombo,GdkTrue);
end;
if not ACustomComboBox.Style.HasEditBox then
begin
// do not set ok_if_empty = true, otherwise it can hang focus
gtk_combo_set_value_in_list(GtkCombo,GdkTrue,GdkTrue);
gtk_combo_set_use_arrows_always(GtkCombo,GdkTrue);
gtk_combo_set_case_sensitive(GtkCombo,GdkFalse);
end
else
begin
// do not set ok_if_empty = true, otherwise it can hang focus
gtk_combo_set_value_in_list(GtkCombo,GdkFalse,GdkTrue);
gtk_combo_set_use_arrows_always(GtkCombo,GdkFalse);
gtk_combo_set_case_sensitive(GtkCombo,GdkTrue);
end;
end;

View File

@ -120,7 +120,7 @@ begin
if TCustomListbox(AWinControl).Style < lbOwnerDrawFixed then
exit;
if AWinControl is TCustomCombobox then
if TCustomCombobox(AWinControl).Style < csOwnerDrawVariable then
if not TCustomCombobox(AWinControl).Style.IsVariable then
exit;
ItemIndex := GetItemIndex(PLCLIntfCellRenderer(cell), Widget);
@ -255,7 +255,7 @@ begin
if TCustomListbox(AWinControl).Style = lbStandard then
exit;
if AWinControl is TCustomCombobox then
if TCustomCombobox(AWinControl).Style < csOwnerDrawFixed then
if not TCustomCombobox(AWinControl).Style.IsOwnerDrawn then
exit;
// get itemindex and area
@ -438,7 +438,7 @@ begin
if (WidgetInfo <> nil) and
(WidgetInfo^.LCLObject is TCustomComboBox) and
(TCustomComboBox(WidgetInfo^.LCLObject).Style = csDropDownList) and
not (TCustomComboBox(WidgetInfo^.LCLObject).Style.HasEditBox) and
not (TCustomComboBox(WidgetInfo^.LCLObject).DroppedDown) then
begin
Value.g_type := G_TYPE_UINT;

View File

@ -69,7 +69,7 @@ begin
if TCustomListbox(LCLList.Owner).Style = lbStandard then
exit;
if LclList.Owner is TCustomCombobox then
if TCustomCombobox(LclList.Owner).Style < csOwnerDrawFixed then
if not TCustomCombobox(LclList.Owner).Style.IsOwnerDrawn then
exit;
// get itemindex and area

View File

@ -1559,7 +1559,7 @@ begin
g_object_set_data(G_OBJECT(renderer), 'widgetinfo', AWidgetInfo);
gtk_cell_layout_clear(PGtkCellLayout(AWidget));
gtk_cell_layout_pack_start(PGtkCellLayout(AWidget), renderer, True);
if not (ACustomComboBox.Style in [csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable]) then
if not ACustomComboBox.Style.IsOwnerDrawn then
gtk_cell_layout_set_attributes(PGtkCellLayout(AWidget), renderer, ['text', 0, nil]);
gtk_cell_layout_set_cell_data_func(PGtkCellLayout(AWidget), renderer,
@LCLIntfCellRenderer_CellDataFunc, AWidgetInfo, nil);
@ -2009,17 +2009,7 @@ var
begin
WidgetInfo := GetWidgetInfo({%H-}Pointer(ACustomComboBox.Handle));
p := WidgetInfo^.CoreWidget;
case NewStyle of
csDropDown,
csSimple,
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable:
NeedEntry := True;
csDropDownList,
csOwnerDrawFixed,
csOwnerDrawVariable:
NeedEntry := False;
end;
NeedEntry := NewStyle.HasEditBox;
if gtk_is_combo_box_entry(p) = NeedEntry then Exit;
ReCreateCombo(ACustomComboBox, NeedEntry, WidgetInfo);
end;
@ -2141,7 +2131,6 @@ var
ACustomComboBox: TCustomComboBox;
ItemList: TGtkListStoreStringList;
LCLIndex: PLongint;
NeedEntry: Boolean;
begin
ACustomComboBox := TCustomComboBox(AWinControl);
@ -2154,18 +2143,7 @@ begin
ListStore := gtk_list_store_new (2, [G_TYPE_STRING, G_TYPE_POINTER, nil]);
case ACustomComboBox.Style of
csDropDown,
csSimple,
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable:
NeedEntry := True;
csDropDownList,
csOwnerDrawFixed,
csOwnerDrawVariable:
NeedEntry := False;
end;
if NeedEntry then
if ACustomComboBox.Style.HasEditBox then
ComboWidget := gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL (ListStore), 0)
else
ComboWidget := gtk_combo_box_new_with_model(GTK_TREE_MODEL (ListStore));

View File

@ -168,7 +168,7 @@ begin
if TCustomListbox(AWinControl).Style < lbOwnerDrawFixed then
exit;
if AWinControl is TCustomCombobox then
if TCustomCombobox(AWinControl).Style < csOwnerDrawVariable then
if not TCustomCombobox(AWinControl).Style.IsVariable then
exit;
ItemIndex := GetItemIndex(PLCLIntfCellRenderer(cell), Widget);
@ -272,7 +272,7 @@ begin
if TCustomListbox(AWinControl).Style < lbOwnerDrawFixed then
exit;
if AWinControl is TCustomCombobox then
if TCustomCombobox(AWinControl).Style < csOwnerDrawVariable then
if not TCustomCombobox(AWinControl).Style.IsVariable then
exit;
ItemIndex := GetItemIndex(PLCLIntfCellRenderer(cell), Widget);
@ -322,7 +322,7 @@ begin
if TCustomListbox(AWinControl).Style < lbOwnerDrawFixed then
exit;
if AWinControl is TCustomCombobox then
if TCustomCombobox(AWinControl).Style < csOwnerDrawVariable then
if not TCustomCombobox(AWinControl).Style.IsVariable then
exit;
ItemIndex := GetItemIndex(PLCLIntfCellRenderer(cell), Widget);
@ -487,7 +487,7 @@ begin
if TCustomListbox(AWinControl).Style = lbStandard then
exit;
if AWinControl is TCustomCombobox then
if TCustomCombobox(AWinControl).Style < csOwnerDrawFixed then
if not TCustomCombobox(AWinControl).Style.IsOwnerDrawn then
exit;
ItemIndex := GetItemIndex(PLCLIntfCellRenderer(cell), Widget);
@ -673,7 +673,7 @@ begin
// DebugLn(['LCLIntfCellRenderer_CellDataFunc stamp=',iter^.stamp,' tree_model=',dbgs(tree_model),' cell=',dbgs(cell),' WidgetInfo=',WidgetInfo <> nil,' Time=',TimeToStr(Now)]);
if (wtComboBox in TGtk3Widget(Data).WidgetType) and
(TCustomComboBox(TGtk3Widget(Data).LCLObject).Style = csDropDownList) and
not (TCustomComboBox(TGtk3Widget(Data).LCLObject).Style.HasEditBox) and
not (TCustomComboBox(TGtk3Widget(Data).LCLObject).DroppedDown) then
begin
Value.g_type := G_TYPE_UINT;

View File

@ -6221,8 +6221,6 @@ begin
g_object_set_data(PGObject(Result), GtkListItemLCLListTag, ItemList);
PGtkComboBox(Result)^.set_entry_text_column(0);
if ACombo.Style = csDropDownList then
PGtkEditable(PGtkComboBox(Result)^.get_child)^.set_editable(False);
// do not allow combo button to get focus, entry should take focus
if PGtkComboBox(Result)^.priv3^.button <> nil then
PGtkComboBox(Result)^.priv3^.button^.set_can_focus(False);
@ -6250,7 +6248,7 @@ begin
gtk_cell_layout_clear(PGtkCellLayout(FCentralWidget));
gtk_cell_layout_pack_start(PGtkCellLayout(FCentralWidget), renderer, True);
if not (ACombo.Style in [csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable]) then
if not ACombo.Style.IsOwnerDrawn then
gtk_cell_layout_set_attributes(PGtkCellLayout(FCentralWidget), renderer, ['text', 0, nil]);
gtk_cell_layout_set_cell_data_func(PGtkCellLayout(FCentralWidget), renderer,
@LCLIntfCellRenderer_CellDataFunc, Self, nil);

View File

@ -1639,11 +1639,7 @@ class procedure TQtWSCustomComboBox.SetStyle(
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
begin
TQtComboBox(ACustomComboBox.Handle).setEditable(NewStyle.HasEditBox);
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle in
[csOwnerDrawFixed,
csOwnerDrawVariable,
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable];
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle.IsOwnerDrawn;
// TODO: implement styles: csSimple
inherited SetStyle(ACustomComboBox, NewStyle);
end;
@ -1718,12 +1714,12 @@ var
begin
if not WSCheckHandleAllocated(ACustomComboBox, 'SetItemHeight') then
Exit;
{only for csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable}
{only for OwnerDrawn}
ComboBox := TQtComboBox(ACustomComboBox.Handle);
if ComboBox.getDroppedDown then
begin
ComboBox.DropList.setUniformItemSizes(False);
ComboBox.DropList.setUniformItemSizes(ACustomComboBox.Style in [csOwnerDrawFixed, csOwnerDrawEditableFixed]);
ComboBox.DropList.setUniformItemSizes(ACustomComboBox.Style.IsOwnerDrawn);
end else
RecreateWnd(ACustomComboBox);
end;

View File

@ -1584,11 +1584,7 @@ class procedure TQtWSCustomComboBox.SetStyle(
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
begin
TQtComboBox(ACustomComboBox.Handle).setEditable(NewStyle.HasEditBox);
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle in
[csOwnerDrawFixed,
csOwnerDrawVariable,
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable];
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle.IsOwnerDrawn;
// TODO: implement styles: csSimple
inherited SetStyle(ACustomComboBox, NewStyle);
end;
@ -1663,12 +1659,12 @@ var
begin
if not WSCheckHandleAllocated(ACustomComboBox, 'SetItemHeight') then
Exit;
{only for csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable}
{only for OwnerDrawn}
ComboBox := TQtComboBox(ACustomComboBox.Handle);
if ComboBox.getDroppedDown then
begin
ComboBox.DropList.setUniformItemSizes(False);
ComboBox.DropList.setUniformItemSizes(ACustomComboBox.Style in [csOwnerDrawFixed, csOwnerDrawEditableFixed]);
ComboBox.DropList.setUniformItemSizes(ACustomComboBox.Style.IsOwnerDrawn);
end else
RecreateWnd(ACustomComboBox);
end;

View File

@ -1464,7 +1464,7 @@ begin
(((lWinControl is TCustomListbox) and
(TCustomListBox(lWinControl).Style <> lbStandard)) or
((lWinControl is TCustomCombobox) and
(TCustomCombobox(lWinControl).Style in [csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable])))
TCustomCombobox(lWinControl).Style.IsOwnerDrawn))
then
UpdateDrawListItem(LM_DRAWLISTITEM)
else if Assigned(WindowInfo^.DrawItemHandler) then begin

View File

@ -1372,7 +1372,7 @@ begin
if ((lWinControl is TCustomListbox) and
(TCustomListBox(lWinControl).Style <> lbStandard)) or
((lWinControl is TCustomCombobox) and
(TCustomCombobox(lWinControl).Style in [csOwnerDrawFixed, csOwnerDrawVariable, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable]))
TCustomCombobox(lWinControl).Style.IsOwnerDrawn)
then
begin
if PDrawItemStruct(LParam)^.itemID <> dword(-1) then

View File

@ -261,6 +261,8 @@ type
TComboBoxStyleHelper = type helper for TComboBoxStyle
public
function HasEditBox: Boolean;
function IsOwnerDrawn: Boolean;
function IsVariable: Boolean;
end;
TOwnerDrawState = LCLType.TOwnerDrawState;