mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-11-04 14:29:25 +01:00 
			
		
		
		
	Gtk3: implemented image (custompage.imageindex) in tabs for TCustomTabControl
This commit is contained in:
		
							parent
							
								
									cec0a1fdbb
								
							
						
					
					
						commit
						82df55c246
					
				@ -416,6 +416,7 @@ type
 | 
				
			|||||||
  TGtk3Page = class(TGtk3Container)
 | 
					  TGtk3Page = class(TGtk3Container)
 | 
				
			||||||
  private
 | 
					  private
 | 
				
			||||||
    FPageBox: PGtkBox;
 | 
					    FPageBox: PGtkBox;
 | 
				
			||||||
 | 
					    FImageWidget: PGtkImage;
 | 
				
			||||||
    FPageLabel: PGtkLabel;
 | 
					    FPageLabel: PGtkLabel;
 | 
				
			||||||
    FCloseButton: PGtkButton;
 | 
					    FCloseButton: PGtkButton;
 | 
				
			||||||
  strict private
 | 
					  strict private
 | 
				
			||||||
@ -432,6 +433,7 @@ type
 | 
				
			|||||||
    function ClientToScreen(var P:TPoint):boolean; override;
 | 
					    function ClientToScreen(var P:TPoint):boolean; override;
 | 
				
			||||||
    function getClientOffset:TPoint; override;
 | 
					    function getClientOffset:TPoint; override;
 | 
				
			||||||
    function getClientRect: TRect; override;
 | 
					    function getClientRect: TRect; override;
 | 
				
			||||||
 | 
					    procedure setTabImage(aBitmap: TBitmap);
 | 
				
			||||||
    property CloseButtonVisible: boolean read GetCloseButtonVisible write SetCloseButtonVisible;
 | 
					    property CloseButtonVisible: boolean read GetCloseButtonVisible write SetCloseButtonVisible;
 | 
				
			||||||
  end;
 | 
					  end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -5042,6 +5044,9 @@ var
 | 
				
			|||||||
begin
 | 
					begin
 | 
				
			||||||
  FWidgetType := FWidgetType + [wtLayout];
 | 
					  FWidgetType := FWidgetType + [wtLayout];
 | 
				
			||||||
  FPageBox := TGtkBox.new(GTK_ORIENTATION_HORIZONTAL, 4);
 | 
					  FPageBox := TGtkBox.new(GTK_ORIENTATION_HORIZONTAL, 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  FImageWidget := TGtkImage.new;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  FPageLabel:= TGtkLabel.new(PChar(Params.Caption));
 | 
					  FPageLabel:= TGtkLabel.new(PChar(Params.Caption));
 | 
				
			||||||
  FPageLabel^.set_use_underline(true);
 | 
					  FPageLabel^.set_use_underline(true);
 | 
				
			||||||
  image := gtk_image_new_from_icon_name('window-close', GTK_ICON_SIZE_MENU);
 | 
					  image := gtk_image_new_from_icon_name('window-close', GTK_ICON_SIZE_MENU);
 | 
				
			||||||
@ -5050,10 +5055,13 @@ begin
 | 
				
			|||||||
  gtk_container_add(PGtkContainer(FCloseButton), image);
 | 
					  gtk_container_add(PGtkContainer(FCloseButton), image);
 | 
				
			||||||
  gtk_widget_set_name(FCloseButton, 'tab-close-button'); // optional styling via css.
 | 
					  gtk_widget_set_name(FCloseButton, 'tab-close-button'); // optional styling via css.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  FPageBox^.pack_start(FImageWidget, False, False, 0);
 | 
				
			||||||
  FPageBox^.pack_start(FPageLabel, False, False, 0);
 | 
					  FPageBox^.pack_start(FPageLabel, False, False, 0);
 | 
				
			||||||
  FPageBox^.pack_start(FCloseButton, False, False, 0);
 | 
					  FPageBox^.pack_start(FCloseButton, False, False, 0);
 | 
				
			||||||
  FPageBox^.show_all;
 | 
					  FPageBox^.show_all;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  FImageWidget^.hide;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Self.FHasPaint:=true;
 | 
					  Self.FHasPaint:=true;
 | 
				
			||||||
  // ref it to save it in case TabVisible is set to false
 | 
					  // ref it to save it in case TabVisible is set to false
 | 
				
			||||||
  FPageBox^.ref;
 | 
					  FPageBox^.ref;
 | 
				
			||||||
@ -5129,6 +5137,26 @@ begin
 | 
				
			|||||||
  // DebugLn('TGtk3Page.GetClientRect Result=',dbgs(Result),' Realized ',dbgs(getContainerWidget^.get_realized));
 | 
					  // DebugLn('TGtk3Page.GetClientRect Result=',dbgs(Result),' Realized ',dbgs(getContainerWidget^.get_realized));
 | 
				
			||||||
end;
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					procedure TGtk3Page.setTabImage(aBitmap: TBitmap);
 | 
				
			||||||
 | 
					var
 | 
				
			||||||
 | 
					  APixBuf: PGdkPixbuf;
 | 
				
			||||||
 | 
					begin
 | 
				
			||||||
 | 
					  if Assigned(aBitmap) then
 | 
				
			||||||
 | 
					    APixBuf := TGtk3Image(aBitmap.Handle).Handle^.copy
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    aPixBuf := nil;
 | 
				
			||||||
 | 
					  if aPixBuf = nil then
 | 
				
			||||||
 | 
					  begin
 | 
				
			||||||
 | 
					    FImageWidget^.set_from_pixbuf(nil);
 | 
				
			||||||
 | 
					    FImageWidget^.set_visible(False);
 | 
				
			||||||
 | 
					  end else
 | 
				
			||||||
 | 
					  begin
 | 
				
			||||||
 | 
					    FImageWidget^.set_from_pixbuf(aPixBuf);
 | 
				
			||||||
 | 
					    FImageWidget^.set_visible(True);
 | 
				
			||||||
 | 
					    aPixbuf^.unref;
 | 
				
			||||||
 | 
					  end;
 | 
				
			||||||
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{ TGtk3NoteBook }
 | 
					{ TGtk3NoteBook }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function NotebookPageRealToLCLIndex(const ATabControl: TCustomTabControl; AIndex: integer): integer;
 | 
					function NotebookPageRealToLCLIndex(const ATabControl: TCustomTabControl; AIndex: integer): integer;
 | 
				
			||||||
@ -5371,11 +5399,21 @@ procedure TGtk3NoteBook.InsertPage(ACustomPage: TCustomPage; AIndex: Integer);
 | 
				
			|||||||
var
 | 
					var
 | 
				
			||||||
  Gtk3Page: TGtk3Page;
 | 
					  Gtk3Page: TGtk3Page;
 | 
				
			||||||
  AMinSize, ANaturalSize: gint;
 | 
					  AMinSize, ANaturalSize: gint;
 | 
				
			||||||
 | 
					  Bmp: TBitmap;
 | 
				
			||||||
begin
 | 
					begin
 | 
				
			||||||
  if IsWidgetOK then
 | 
					  if IsWidgetOK then
 | 
				
			||||||
  begin
 | 
					  begin
 | 
				
			||||||
    Gtk3Page := TGtk3Page(ACustomPage.Handle);
 | 
					    Gtk3Page := TGtk3Page(ACustomPage.Handle);
 | 
				
			||||||
    Gtk3Page.CloseButtonVisible := nboShowCloseButtons in TCustomTabControl(LCLObject).Options;
 | 
					    Gtk3Page.CloseButtonVisible := nboShowCloseButtons in TCustomTabControl(LCLObject).Options;
 | 
				
			||||||
 | 
					    if Assigned(TCustomTabControl(LCLObject).Images) and (ACustomPage.ImageIndex >= 0) and
 | 
				
			||||||
 | 
					      (ACustomPage.ImageIndex < TCustomTabControl(LCLObject).Images.Count) then
 | 
				
			||||||
 | 
					    begin
 | 
				
			||||||
 | 
					      Bmp := TBitmap.Create;
 | 
				
			||||||
 | 
					      TCustomTabControl(LCLObject).Images.GetBitmap(ACustomPage.ImageIndex, Bmp);
 | 
				
			||||||
 | 
					      Gtk3Page.setTabImage(Bmp);
 | 
				
			||||||
 | 
					      Bmp.Free;
 | 
				
			||||||
 | 
					    end else
 | 
				
			||||||
 | 
					      Gtk3Page.setTabImage(nil);
 | 
				
			||||||
    with PGtkNoteBook(GetContainerWidget)^ do
 | 
					    with PGtkNoteBook(GetContainerWidget)^ do
 | 
				
			||||||
      insert_page(Gtk3Page.Widget, Gtk3Page.FPageBox, AIndex);
 | 
					      insert_page(Gtk3Page.Widget, Gtk3Page.FPageBox, AIndex);
 | 
				
			||||||
  end;
 | 
					  end;
 | 
				
			||||||
 | 
				
			|||||||
@ -1595,15 +1595,16 @@ var
 | 
				
			|||||||
begin
 | 
					begin
 | 
				
			||||||
  if ATabControl is TTabControl then
 | 
					  if ATabControl is TTabControl then
 | 
				
			||||||
    exit;
 | 
					    exit;
 | 
				
			||||||
  // inherited UpdateProperties(ATabControl);
 | 
					 | 
				
			||||||
  if not WSCheckHandleAllocated(ATabControl, 'ATabControl') then
 | 
					 | 
				
			||||||
    Exit;
 | 
					 | 
				
			||||||
  for i := 0 to PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.get_n_pages - 1 do
 | 
					  for i := 0 to PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.get_n_pages - 1 do
 | 
				
			||||||
  begin
 | 
					  begin
 | 
				
			||||||
    aPage := PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.get_nth_page(i);
 | 
					    aPage := PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.get_nth_page(i);
 | 
				
			||||||
    aLCLPage := TGtk3Page(HwndFromGtkWidget(aPage));
 | 
					    aLCLPage := TGtk3Page(HwndFromGtkWidget(aPage));
 | 
				
			||||||
    if Assigned(aLCLPage) then
 | 
					    if Assigned(aLCLPage) then
 | 
				
			||||||
 | 
					    begin
 | 
				
			||||||
      aLCLPage.CloseButtonVisible := (nboShowCloseButtons in ATabControl.Options);
 | 
					      aLCLPage.CloseButtonVisible := (nboShowCloseButtons in ATabControl.Options);
 | 
				
			||||||
 | 
					      if Assigned(ATabControl.Images) then
 | 
				
			||||||
 | 
					        TGtk3WSCustomPage.UpdateProperties(TCustomPage(aLCLPage.LCLObject));
 | 
				
			||||||
 | 
					    end;
 | 
				
			||||||
  end;
 | 
					  end;
 | 
				
			||||||
  if (nboHidePageListPopup in ATabControl.Options) then
 | 
					  if (nboHidePageListPopup in ATabControl.Options) then
 | 
				
			||||||
    PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.popup_disable
 | 
					    PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.popup_disable
 | 
				
			||||||
@ -1664,9 +1665,38 @@ end;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class procedure TGtk3WSCustomPage.UpdateProperties(
 | 
					class procedure TGtk3WSCustomPage.UpdateProperties(
 | 
				
			||||||
  const ACustomPage: TCustomPage);
 | 
					  const ACustomPage: TCustomPage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var
 | 
				
			||||||
 | 
					  ImageList: TCustomImageList;
 | 
				
			||||||
 | 
					  ImageIndex: Integer;
 | 
				
			||||||
 | 
					  Bmp: TBitmap;
 | 
				
			||||||
 | 
					  Res: TScaledImageListResolution;
 | 
				
			||||||
begin
 | 
					begin
 | 
				
			||||||
  // inherited UpdateProperties(ACustomPage);
 | 
					  if not WSCheckHandleAllocated(ACustomPage, 'UpdateProperties') then
 | 
				
			||||||
  DebugLn('TGtk3WSCustomPage.UpdateProperties missing implementation ');
 | 
					    Exit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ImageList := TCustomTabControl(ACustomPage.Parent).Images;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if Assigned(ImageList) then
 | 
				
			||||||
 | 
					  begin
 | 
				
			||||||
 | 
					    Res := ImageList.ResolutionForPPI[
 | 
				
			||||||
 | 
					      TCustomTabControl(ACustomPage.Parent).ImagesWidth,
 | 
				
			||||||
 | 
					      TCustomTabControl(ACustomPage.Parent).Font.PixelsPerInch,
 | 
				
			||||||
 | 
					      TCustomTabControl(ACustomPage.Parent).GetCanvasScaleFactor];
 | 
				
			||||||
 | 
					    ImageIndex := TCustomTabControl(ACustomPage.Parent).GetImageIndex(ACustomPage.PageIndex);
 | 
				
			||||||
 | 
					    if (ImageIndex >= 0) and (ImageIndex < Res.Count) then
 | 
				
			||||||
 | 
					    begin
 | 
				
			||||||
 | 
					      Bmp := TBitmap.Create;
 | 
				
			||||||
 | 
					      try
 | 
				
			||||||
 | 
					        Res.GetBitmap(ACustomPage.ImageIndex, Bmp);
 | 
				
			||||||
 | 
					        TGtk3Page(ACustomPage.Handle).setTabImage(Bmp);
 | 
				
			||||||
 | 
					      finally
 | 
				
			||||||
 | 
					        Bmp.Free;
 | 
				
			||||||
 | 
					      end;
 | 
				
			||||||
 | 
					    end else
 | 
				
			||||||
 | 
					      TGtk3Page(ACustomPage.Handle).setTabImage(nil);
 | 
				
			||||||
 | 
					  end else
 | 
				
			||||||
 | 
					    TGtk3Page(ACustomPage.Handle).setTabImage(nil);
 | 
				
			||||||
end;
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
end.
 | 
					end.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user