From 31cf05f76ca9e9041143d04453fe5a41d460a6cc Mon Sep 17 00:00:00 2001 From: Sven Harazim Date: Sun, 29 Nov 2020 19:29:31 +0100 Subject: [PATCH] custom image lists added to TChromeTab --- Lib/ChromeTabs.pas | 2 +- Lib/ChromeTabsClasses.pas | 60 ++++++++++++++++++++++++++++++++++++++ Lib/ChromeTabsControls.pas | 54 +++++++++++++++++++++++++--------- 3 files changed, 101 insertions(+), 15 deletions(-) diff --git a/Lib/ChromeTabs.pas b/Lib/ChromeTabs.pas index 7ea6a5a..e777ca8 100644 --- a/Lib/ChromeTabs.pas +++ b/Lib/ChromeTabs.pas @@ -1199,7 +1199,7 @@ function TCustomChromeTabs.ControlReady: Boolean; procedure TCustomChromeTabs.DoOnChange(ATab: TChromeTab; TabChangeType: TTabChangeType); var - i: Integer; + //i: Integer; NewTabControl: TChromeTabControl; NewTabLeft, LastVisibleTabIndex: Integer; begin diff --git a/Lib/ChromeTabsClasses.pas b/Lib/ChromeTabsClasses.pas index 35cc442..16dc75a 100644 --- a/Lib/ChromeTabsClasses.pas +++ b/Lib/ChromeTabsClasses.pas @@ -61,6 +61,10 @@ TChromeTabsLookAndFeelStyle = class; function GetSpinnerState: TChromeTabSpinnerState; function GetHideCloseButton: Boolean; function GetData: Pointer; + function GetCustomImages: TCustomImageList; + function GetCustomImagesOverlay: TCustomImageList; + function GetCustomImagesSpinnerDownload: TCustomImageList; + function GetCustomImagesSpinnerUpload: TCustomImageList; procedure SetData(const Value: Pointer); property Data: Pointer read GetData write SetData; end; @@ -126,6 +130,10 @@ TChromeTab = class(TCollectionItem, IChromeTab) FMarkedForDeletion: Boolean; FSpinnerState: TChromeTabSpinnerState; FHideCloseButton: Boolean; + FCustomImages: TCustomImageList; + FCustomImagesOverlay: TCustomImageList; + FCustomImagesSpinnerDownload: TCustomImageList; + FCustomImagesSpinnerUpload: TCustomImageList; procedure SetActive(Value: boolean); procedure SetCaption(Value: TCaption); @@ -155,6 +163,14 @@ TChromeTab = class(TCollectionItem, IChromeTab) function GetSpinnerState: TChromeTabSpinnerState; function GetHideCloseButton: Boolean; function GetData: Pointer; + procedure SetCustomImages(const Value: TCustomImageList); + procedure SetCustomImagesOverlay(const Value: TCustomImageList); + procedure SetCustomImagesSpinnerDownload(const Value: TCustomImageList); + procedure SetCustomImagesSpinnerUpload(const Value: TCustomImageList); + function GetCustomImages: TCustomImageList; + function GetCustomImagesOverlay: TCustomImageList; + function GetCustomImagesSpinnerDownload: TCustomImageList; + function GetCustomImagesSpinnerUpload: TCustomImageList; protected procedure DoChanged(ChangeType: TTabChangeType = tcPropertyUpdated); virtual; function GetDisplayName: string; override; @@ -175,6 +191,10 @@ TChromeTab = class(TCollectionItem, IChromeTab) property Caption: TCaption read GetCaption write SetCaption; property Active: boolean read GetActive write SetActive; property Tag: integer read GetTag write SetTag; + property CustomImages: TCustomImageList read GetCustomImages write SetCustomImages; + property CustomImagesOverlay: TCustomImageList read GetCustomImagesOverlay write SetCustomImagesOverlay; + property CustomImagesSpinnerUpload: TCustomImageList read GetCustomImagesSpinnerUpload write SetCustomImagesSpinnerUpload; + property CustomImagesSpinnerDownload: TCustomImageList read GetCustomImagesSpinnerDownload write SetCustomImagesSpinnerDownload; property ImageIndex: {$IF CompilerVersion >= 23.0}System.UITypes.{$IFEND}TImageIndex read GetImageIndex write SetImageIndex; property ImageIndexOverlay: {$IF CompilerVersion >= 23.0}System.UITypes.{$IFEND}TImageIndex read GetImageIndexOverlay write SetImageIndexOverlay; property Pinned: Boolean read GetPinned write SetPinned; @@ -1239,6 +1259,46 @@ destructor TChromeTab.Destroy; FTabControl.Free; end; +procedure TChromeTab.SetCustomImages(const Value: TCustomImageList); +begin + FCustomImages := Value; +end; + +procedure TChromeTab.SetCustomImagesOverlay(const Value: TCustomImageList); +begin + FCustomImagesOverlay := Value; +end; + +procedure TChromeTab.SetCustomImagesSpinnerDownload(const Value: TCustomImageList); +begin + FCustomImagesSpinnerDownload := Value; +end; + +procedure TChromeTab.SetCustomImagesSpinnerUpload(const Value: TCustomImageList); +begin + FCustomImagesSpinnerUpload := Value; +end; + +function TChromeTab.GetCustomImages : TCustomImageList; +begin + Result := FCustomImages; +end; + +function TChromeTab.GetCustomImagesOverlay : TCustomImageList; +begin + Result := FCustomImagesOverlay; +end; + +function TChromeTab.GetCustomImagesSpinnerDownload : TCustomImageList; +begin + Result := FCustomImagesSpinnerDownload; +end; + +function TChromeTab.GetCustomImagesSpinnerUpload : TCustomImageList; +begin + Result := FCustomImagesSpinnerUpload; +end; + procedure TChromeTab.SetPinned(const Value: Boolean); var LastPinned: Integer; diff --git a/Lib/ChromeTabsControls.pas b/Lib/ChromeTabsControls.pas index da2f6e5..19aaf28 100644 --- a/Lib/ChromeTabsControls.pas +++ b/Lib/ChromeTabsControls.pas @@ -165,6 +165,8 @@ TChromeTabControl = class(TBaseChromeTabsControl) procedure CalculateRects(var ImageRect, TextRect, CloseButtonRect, CloseButtonCrossRect: TRect; var NormalImageVisible, OverlayImageVisible, SpinnerVisible, TextVisible: Boolean); + function GetImageList: TCustomImageList; + function GetImageListOverlay: TCustomImageList; function GetSpinnerImageList: TCustomImageList; protected procedure SetCloseButtonState(const Value: TDrawState); virtual; @@ -638,6 +640,20 @@ function TChromeTabControl.GetHitTestArea(MouseX, MouseY: Integer): THitTestArea end; end; +function TChromeTabControl.GetImageList: TCustomImageList; +begin + Result := ChromeTab.GetCustomImages; + if Result = nil then + Result := ChromeTabs.GetImages; +end; + +function TChromeTabControl.GetImageListOverlay: TCustomImageList; +begin + Result := ChromeTab.GetCustomImagesOverlay; + if Result = nil then + Result := ChromeTabs.GetImagesOverlay; +end; + function TChromeTabControl.AnimateModified: Boolean; var TickCount: Cardinal; @@ -685,8 +701,18 @@ function TChromeTabControl.AnimateModified: Boolean; function TChromeTabControl.GetSpinnerImageList: TCustomImageList; begin case ChromeTab.GetSpinnerState of - tssImageUpload: Result := ChromeTabs.GetImagesSpinnerUpload; - tssImageDownload: Result := ChromeTabs.GetImagesSpinnerDownload; + tssImageUpload: + begin + Result := ChromeTab.GetCustomImagesSpinnerUpload; + if Result = nil then + Result := ChromeTabs.GetImagesSpinnerUpload; + end; + tssImageDownload: + begin + Result := ChromeTab.GetCustomImagesSpinnerDownload; + if Result = nil then + Result := ChromeTabs.GetImagesSpinnerDownload; + end else Result := nil; end; @@ -971,8 +997,8 @@ procedure TChromeTabControl.CalculateRects(var ImageRect, TextRect, LeftOffset := ControlRect.Left + ChromeTabs.ScaledPixels(ChromeTabs.GetOptions.Display.Tabs.ContentOffsetLeft); - NormalImageVisible := ImageVisible(ChromeTabs.GetImages, ChromeTab.GetImageIndex); - OverlayImageVisible := ImageVisible(ChromeTabs.GetImagesOverlay, ChromeTab.GetImageIndexOverlay); + NormalImageVisible := ImageVisible(GetImageList, ChromeTab.GetImageIndex); + OverlayImageVisible := ImageVisible(GetImageListOverlay, ChromeTab.GetImageIndexOverlay); SpinnerVisible := (ChromeTab.GetSpinnerState <> tssNone) and (not (csDesigning in ChromeTabs.GetComponentState)); ImageWidth := 0; @@ -997,20 +1023,20 @@ procedure TChromeTabControl.CalculateRects(var ImageRect, TextRect, (NormalImageVisible) or (OverlayImageVisible) then begin - if ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Width) > ImageWidth then - ImageWidth := ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Width); + if ChromeTabs.ScaledPixels(GetImageList.Width) > ImageWidth then + ImageWidth := ChromeTabs.ScaledPixels(GetImageList.Width); - if ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Height) > ImageHeight then - ImageHeight := ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Height); + if ChromeTabs.ScaledPixels(GetImageList.Height) > ImageHeight then + ImageHeight := ChromeTabs.ScaledPixels(GetImageList.Height); end; if OverlayImageVisible then begin - if ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Width) > ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Width) then - ImageWidth := ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Width); + if ChromeTabs.ScaledPixels(GetImageListOverlay.Width) > ChromeTabs.ScaledPixels(GetImageList.Width) then + ImageWidth := ChromeTabs.ScaledPixels(GetImageListOverlay.Width); - if ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Height) > ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Height) then - ImageHeight := ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Height); + if ChromeTabs.ScaledPixels(GetImageListOverlay.Height) > ChromeTabs.ScaledPixels(GetImageList.Height) then + ImageHeight := ChromeTabs.ScaledPixels(GetImageListOverlay.Height); end; // Does the image fit between the left margin and the close button? @@ -1521,10 +1547,10 @@ procedure TChromeTabControl.DrawTo(TabCanvas: TGPGraphics; MouseX, MouseY: Integ (not ChromeTabs.GetOptions.Display.TabSpinners.HideImagesWhenSpinnerVisible) then begin if NormalImageVisible then - DrawImage(ChromeTabs.GetImages, ChromeTab.GetImageIndex, ImageRect, itTabImage); + DrawImage(GetImageList, ChromeTab.GetImageIndex, ImageRect, itTabImage); if OverlayImageVisible then - DrawImage(ChromeTabs.GetImagesOverlay, ChromeTab.GetImageIndexOverlay, ImageRect, itTabImageOverlay); + DrawImage(GetImageListOverlay, ChromeTab.GetImageIndexOverlay, ImageRect, itTabImageOverlay); end; // Draw the spinner image