From d5d9f4c4d6c5e721400a9db745c37cb48444021d Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 16 Jun 2008 01:37:30 +0000 Subject: [PATCH] win32: update checklistbox itemheight in runtime on font change git-svn-id: trunk@15433 - --- lcl/checklst.pas | 31 +++++++++++++++++-------------- lcl/include/customlistbox.inc | 16 ++++++++++++++++ lcl/stdctrls.pp | 1 + 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lcl/checklst.pas b/lcl/checklst.pas index 7fc72158c2..5f8507347f 100644 --- a/lcl/checklst.pas +++ b/lcl/checklst.pas @@ -63,6 +63,8 @@ type procedure WriteData(Stream: TStream); procedure ClickCheck; dynamic; procedure ItemClick(const AIndex: Integer); dynamic; + procedure FontChanged(Sender: TObject); override; + procedure ParentFontChanged; override; public constructor Create(AOwner: TComponent); override; procedure MeasureItem(Index: Integer; var TheHeight: Integer); override; @@ -184,22 +186,9 @@ begin end; procedure TCustomCheckListBox.MeasureItem(Index: Integer; var TheHeight: Integer); -var - B: TBitmap; begin if (Style = lbStandard) then - begin - // Paul: This will happen only once if Style = lbStandard then CheckListBox is - // OwnerDrawFixed in real (under windows). Handle is not allocated and we - // cant use Canvas since it will cause recursion but we need correct font height - B := TBitmap.Create; - try - B.Canvas.Font := Font; - TheHeight := B.Canvas.TextHeight('Fj'); - finally - B.Free; - end; - end + TheHeight := CalculateStandardItemHeight else inherited MeasureItem(Index, TheHeight); end; @@ -327,6 +316,20 @@ begin if Assigned(OnItemClick) then OnItemClick(Self, AIndex); end; +procedure TCustomCheckListBox.FontChanged(Sender: TObject); +begin + inherited FontChanged(Sender); + if ([csLoading, csDestroying] * ComponentState = []) and (Style = lbStandard) then + ItemHeight := CalculateStandardItemHeight; +end; + +procedure TCustomCheckListBox.ParentFontChanged; +begin + inherited ParentFontChanged; + if ([csLoading, csDestroying] * ComponentState = []) and (Style = lbStandard) then + ItemHeight := CalculateStandardItemHeight; +end; + procedure TCustomCheckListBox.DefineProperties(Filer: TFiler); begin inherited DefineProperties(Filer); diff --git a/lcl/include/customlistbox.inc b/lcl/include/customlistbox.inc index 1bc05d30bb..d68829a133 100644 --- a/lcl/include/customlistbox.inc +++ b/lcl/include/customlistbox.inc @@ -45,6 +45,22 @@ begin BeginDrag(False); end; +function TCustomListBox.CalculateStandardItemHeight: Integer; +var + B: TBitmap; +begin + // Paul: This will happen only once if Style = lbStandard then CheckListBox is + // OwnerDrawFixed in real (under windows). Handle is not allocated and we + // cant use Canvas since it will cause recursion but we need correct font height + B := TBitmap.Create; + try + B.Canvas.Font := Font; + Result := B.Canvas.TextHeight('Fj'); + finally + B.Free; + end; +end; + procedure TCustomListBox.Loaded; begin inherited Loaded; diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 2e6e123a85..f1c4d4c84a 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -491,6 +491,7 @@ type procedure AssignItemDataToCache(const AIndex: Integer; const AData: Pointer); virtual; // called to store item data while the handle isn't created procedure AssignCacheToItemData(const AIndex: Integer; const AData: Pointer); virtual; // called to restore the itemdata after a handle is created procedure BeginAutoDrag; override; + function CalculateStandardItemHeight: Integer; procedure Loaded; override; procedure InitializeWnd; override; procedure FinalizeWnd; override;