From b01341302fe6fee2dc0dc83df23fa4cccccc8db1 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 15 Jan 2023 17:18:52 +0000 Subject: [PATCH] ExCtrls: Fix CheckComboboxEx having a zero-height dropdown after Laz commit e4043024. Minor optimization in MeasureItem. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8679 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/exctrls/source/excheckcombo.pas | 36 ++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/components/exctrls/source/excheckcombo.pas b/components/exctrls/source/excheckcombo.pas index 4ebae80a1..9cc6d0abd 100644 --- a/components/exctrls/source/excheckcombo.pas +++ b/components/exctrls/source/excheckcombo.pas @@ -5,7 +5,8 @@ unit ExCheckCombo; interface uses - LCLIntf, LCLType, Classes, SysUtils, Controls, StdCtrls, ImgList, + LCLIntf, LCLType, + Classes, SysUtils, Controls, StdCtrls, ImgList, GroupedEdit, EditBtn, CheckLst, Forms; type @@ -215,6 +216,17 @@ implementation uses Buttons, Themes, WSForms; +type + TCustomListboxHelper = class helper for TCustomListbox + public + function CalculateStandardItemHeight: Integer; + end; + +function TCustomListboxHelper.CalculateStandardItemHeight: Integer; +begin + Result := inherited; +end; + { TCCBItem } // CCB = CheckComboBox type TCCBItem = class @@ -481,6 +493,7 @@ type FCaller: TControl; FCheckListBox: TCheckListBox; FDropDownCount: Integer; + FStdItemHeight: Integer; protected procedure ActivateDoubleBuffered; procedure DblClickHandler(Sender: TObject); @@ -503,6 +516,7 @@ begin FCheckListbox.OnDblClick := @DblClickHandler; FCheckListbox.OnKeyDown := @KeyDownHandler; FDropDownCount := 8; + FStdItemHeight := FCheckListbox.CalculateStandardItemHeight; end; procedure TCheckComboBoxForm.ActivateDoubleBuffered; @@ -578,16 +592,20 @@ end; procedure TCheckComboBoxForm.MeasureHeight(out AHeight: Integer); var - i: Integer; - h: Integer = 0; + i, h, n: Integer; begin AHeight := 0; - for i := 0 to FCheckListbox.Items.Count-1 do - if i < FDropDownCount then - begin - FCheckListbox.MeasureItem(i, h); - inc(AHeight,h); - end; + n := FCheckListbox.Items.Count; + if FDropDownCount < n then + n := FDropDownCount; + for i := 0 to n-1 do + begin + h := -1; + FCheckListbox.MeasureItem(i, h); + if h = -1 then + h := FStdItemHeight; + inc(AHeight, h); + end; inc(AHeight, 6); end;