From 71e85eb4d5db27f435ecebb5a43723c5ca56495c Mon Sep 17 00:00:00 2001 From: rich2014 Date: Tue, 12 Sep 2023 21:41:43 +0800 Subject: [PATCH] Cocoa/TabControl: #40050 Merge branch 'cocoa/tabcontrol', scrolling is supported when TabPosition:=tpBottom --- lcl/interfaces/cocoa/cocoatabcontrols.pas | 31 ++++++++++++++++++----- lcl/interfaces/cocoa/cocoawscomctrls.pas | 3 +-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoatabcontrols.pas b/lcl/interfaces/cocoa/cocoatabcontrols.pas index aaa1ec8826..8a084eb4d7 100644 --- a/lcl/interfaces/cocoa/cocoatabcontrols.pas +++ b/lcl/interfaces/cocoa/cocoatabcontrols.pas @@ -67,6 +67,7 @@ type class function alloc: id; override; procedure dealloc; override; procedure setFrame(aframe: NSRect); override; + procedure setTabViewType(newValue: NSTabViewType); override; // lcl function lclIsEnabled: Boolean; override; procedure lclSetEnabled(AEnabled: Boolean); override; @@ -191,8 +192,15 @@ var begin if not assigned(abtn) then Exit; - if isPrev then org:=NSMakePoint(arrow_hofs, arrow_vofs) - else org:=NSMakePoint(dst.frame.size.width - abtn.frame.size.width - arrow_hofs , arrow_vofs); + if dst.tabViewType = NSTopTabsBezelBorder then + org.y := arrow_vofs + else + org.y := dst.frame.size.height - abtn.frame.size.height - arrow_vofs; + + if isPrev then + org.x := arrow_hofs + else + org.x := dst.frame.size.width - abtn.frame.size.width - arrow_hofs; abtn.setFrameOrigin(org); end; @@ -208,10 +216,6 @@ begin aview.prevarr.setAction( ObjCSelector('extTabPrevButtonClick:')); aview.nextarr.setTarget(aview); aview.nextarr.setAction( ObjCSelector('extTabNextButtonClick:')); - - - PlaceButton(true, aview.prevarr, aview); - PlaceButton(false, aview.nextarr, aview); end; // only missing ViewItems inserted, RemoveAllTabs() is no longer needed, @@ -260,6 +264,9 @@ begin ShowPrev := false; ShowNext := false; + // ReviseTabs() supports tpTop and tpBottom only + if (aview.tabViewType=NSLeftTabsBezelBorder) or (aview.tabViewType=NSRightTabsBezelBorder) then exit; + if aview.fulltabs.count=0 then exit; // AttachAllTabs() has been modified to not remove the selectedTabViewItem first, @@ -330,17 +337,23 @@ var begin ReviseTabs(aview, showPrev, showNExt); if Assigned(aview.prevarr) then + begin + PlaceButton(true, aview.prevarr, aview); {$ifdef BOOLFIX} aview.prevarr.setHidden_(Ord(not showPrev)); {$else} aview.prevarr.setHidden(not showPrev); {$endif} + end; if Assigned(aview.nextarr) then + begin + PlaceButton(false, aview.nextarr, aview); {$ifdef BOOLFIX} aview.nextarr.setHidden_(Ord(not showNext)); {$else} aview.nextarr.setHidden(not showNext); {$endif} + end; end; function IndexOfTab(ahost: TCocoaTabControl; atab: NSTabViewItem): Integer; @@ -440,6 +453,12 @@ begin UpdateTabAndArrowVisibility(self); end; +procedure TCocoaTabControl.setTabViewType(newValue: NSTabViewType); +begin + Inherited; + UpdateTabAndArrowVisibility(self); +end; + procedure TCocoaTabControl.extselectTabViewItemAtIndex(index: NSInteger); var idx : integer; diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index 10525156e6..ad7549cd03 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -911,12 +911,11 @@ end; class procedure TCocoaWSCustomTabControl.SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition); var lTabControl: TCocoaTabControl = nil; - lOldTabStyle, lTabStyle: NSTabViewType; + lTabStyle: NSTabViewType; begin if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit; lTabControl := TCocoaTabControl(ATabControl.Handle); - lOldTabStyle := lTabControl.tabViewType(); lTabStyle := LCLTabPosToNSTabStyle(ATabControl.ShowTabs, ATabControl.BorderWidth, ATabPosition); lTabControl.setTabViewType(lTabStyle); end;