From 1780f9b8701bf5a883acc13e1ec510046bdb02de Mon Sep 17 00:00:00 2001 From: dmitry Date: Fri, 6 Jul 2018 04:00:28 +0000 Subject: [PATCH] cocoa: update tab selection for CocoaTabControl git-svn-id: trunk@58445 - --- lcl/interfaces/cocoa/cocoatabcontrols.pas | 24 +++++++++++++++++++++++ lcl/interfaces/cocoa/cocoawscomctrls.pas | 20 +++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoatabcontrols.pas b/lcl/interfaces/cocoa/cocoatabcontrols.pas index 99b428542f..9e7b7a0f8e 100644 --- a/lcl/interfaces/cocoa/cocoatabcontrols.pas +++ b/lcl/interfaces/cocoa/cocoatabcontrols.pas @@ -98,6 +98,8 @@ type message 'extTabPrevButtonClick:'; procedure extTabNextButtonClick(sender: id); message 'extTabNextButtonClick:'; + procedure extselectTabViewItemAtIndex(index: NSInteger); + message 'extselectTabViewItemAtIndex:'; end; { TCocoaTabPageView } @@ -363,6 +365,28 @@ begin UpdateTabAndArrowVisibility(self); end; +procedure TCocoaTabControl.extselectTabViewItemAtIndex(index: NSInteger); +var + idx : integer; + itm : NSTabViewItem; + i : NSUInteger; +begin + if (index<0) or (index>=fulltabs.count) then Exit; + itm := NSTabViewItem(fulltabs.objectAtIndex(index)); + + i := tabViewItems.indexOfObject(itm); + if i <> NSNotFound then + begin + inherited selectTabViewItemAtIndex(NSInteger(i)); + end + else begin + leftmost := index; + UpdateTabAndArrowVisibility(self); + i := tabViewItems.indexOfObject(itm); + inherited selectTabViewItemAtIndex(NSInteger(i)); + end; +end; + function TCocoaTabControl.lclIsEnabled: Boolean; begin Result:=lclEnabled and ((Assigned(superview) and superview.lclIsEnabled) or not Assigned(superview)); diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index 1b513ffded..922a347745 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -584,22 +584,22 @@ class procedure TCocoaWSCustomTabControl.SetPageIndex(const ATabControl: TCustom var lTabControl: TCocoaTabControl; lTabCount: NSInteger; + h : id; + i : NSUInteger; + tb : TCocoaTabPageView; begin {$IFDEF COCOA_DEBUG_TABCONTROL} WriteLn('[TCocoaWSCustomTabControl.SetPageIndex]'); {$ENDIF} if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit; - lTabControl := TCocoaTabControl(ATabControl.Handle); - {$IFDEF COCOA_DEBUG_TABCONTROL} - WriteLn(Format('[TCocoaWSCustomTabControl.SetPageIndex] lTabControl=%d', [PtrUInt(lTabControl)])); - {$ENDIF} - lTabCount := lTabControl.numberOfTabViewItems(); - {$IFDEF COCOA_DEBUG_TABCONTROL} - WriteLn(Format('[TCocoaWSCustomTabControl.SetPageIndex] lTabCount=%d', [lTabCount])); - {$ENDIF} - if (AIndex < 0) or (AIndex >= lTabCount) then Exit; + if (AIndex<0) or (AIndex>=ATabControl.PageCount) then Exit; + tb := TCocoaTabPageView(ATabControl.Page[AIndex].Handle); + if not Assigned(tb) then Exit; - lTabControl.selectTabViewItemAtIndex(AIndex); + i := TCocoaTabControl(ATabControl.Handle).fulltabs.indexOfObject( tb.tabPage ); + if (i = NSNotFound) then Exit; + + TCocoaTabControl(ATabControl.Handle).extselectTabViewItemAtIndex(NSInteger(i)); end; class procedure TCocoaWSCustomTabControl.SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition);