From 16f6a8bc06da675e4318a7944780aea181e5d913 Mon Sep 17 00:00:00 2001 From: zeljan1 Date: Thu, 1 May 2025 11:51:48 +0200 Subject: [PATCH] Gtk3: fixed TPageControl with customized image index. Patch by Anton Kavalenka. issue #41579 --- lcl/interfaces/gtk3/gtk3widgets.pas | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lcl/interfaces/gtk3/gtk3widgets.pas b/lcl/interfaces/gtk3/gtk3widgets.pas index 17cf943421..7fa81fead3 100644 --- a/lcl/interfaces/gtk3/gtk3widgets.pas +++ b/lcl/interfaces/gtk3/gtk3widgets.pas @@ -5297,16 +5297,34 @@ var Gtk3Page: TGtk3Page; AMinSize, ANaturalSize: gint; Bmp: TBitmap; + ImageIndex:integer; + HasIcon: Boolean; + IconSize: Types.TSize; + TheNotebook:TCustomTabControl; + Appi:integer; begin if IsWidgetOK then begin Gtk3Page := TGtk3Page(ACustomPage.Handle); Gtk3Page.CloseButtonVisible := nboShowCloseButtons in TCustomTabControl(LCLObject).Options; - if Assigned(TCustomTabControl(LCLObject).Images) and (ACustomPage.ImageIndex >= 0) and - (ACustomPage.ImageIndex < TCustomTabControl(LCLObject).Images.Count) then + + TheNoteBook:=TCustomTabControl(LCLObject); + HasIcon:=false; + IconSize:=Size(0,0); + ImageIndex := TheNoteBook.GetImageIndex(AIndex); + Appi:=TheNoteBook.Font.PixelsPerInch; + if (TheNoteBook.Images<>nil) + and (ImageIndex >= 0) + and (ImageIndex < TheNoteBook.Images.Count) then + begin + // page has valid image + IconSize := TheNoteBook.Images.SizeForPPI[TheNoteBook.ImagesWidth, Appi]; + HasIcon := (IconSize.cx>0) and (IconSize.cy>0); + end; + if HasIcon then begin Bmp := TBitmap.Create; - TCustomTabControl(LCLObject).Images.GetBitmap(ACustomPage.ImageIndex, Bmp); + TCustomTabControl(LCLObject).Images.ResolutionForPPI[IconSize.cx,Appi,1].GetBitmap(ImageIndex, Bmp); Gtk3Page.setTabImage(Bmp); Bmp.Free; end else