LCL: don't call LB_GETITEMRECT from LM_MEASUREITEM handler (issue #39653)

This commit is contained in:
Martok 2022-08-19 22:03:40 +02:00 committed by Maxim Ganetsky
parent e931147ff2
commit 1161c4a75a
2 changed files with 7 additions and 11 deletions

View File

@ -339,13 +339,15 @@ var
begin
with TheMessage.MeasureItemStruct^ do
begin
if Self.ItemHeight <> 0 then
AHeight := Self.ItemHeight
// don't call GetItemHeight: causes errors on Windows due to recursion on control creation
if FItemHeight <> 0 then
AHeight := FItemHeight
else begin
Canvas.Font := Font;
AHeight := Canvas.TextHeight('Hg');
end;
MeasureItem(Integer(ItemId), AHeight);
if FStyle = lbOwnerDrawVariable then
MeasureItem(Integer(ItemId), AHeight);
if AHeight > 0 then
ItemHeight := AHeight;
end;

View File

@ -853,15 +853,9 @@ begin
end;
class function TWin32WSCustomListBox.GetItemRect(
const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect
): boolean;
var
Handle: HWND;
const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean;
begin
Handle := ACustomListBox.Handle;
// The check for GetProp is required because of some division error which happens
// if call LB_GETITEMRECT on window initialization
Result := Assigned(GetProp(Handle, 'WinControl')) and (Windows.SendMessage(Handle, LB_GETITEMRECT, Index, LPARAM(@ARect)) <> LB_ERR);
Result := Windows.SendMessage(ACustomListBox.Handle, LB_GETITEMRECT, Index, LPARAM(@ARect)) <> LB_ERR;
end;
class function TWin32WSCustomListBox.GetScrollWidth(const ACustomListBox: TCustomListBox): Integer;