Cocoa/TabControl: improve Robustness

This commit is contained in:
rich2014 2023-12-16 18:09:06 +08:00
parent 917e9d3ae8
commit 1666b45e46
2 changed files with 14 additions and 4 deletions

View File

@ -281,6 +281,8 @@ begin
if aview.fulltabs.count=0 then exit;
tryToKeepIndex:= aview.currentIndex - aview.leftKeepAmount;
if tryToKeepIndex < 0 then
tryToKeepIndex:= 0;
// AttachAllTabs() has been modified to not remove the selectedTabViewItem first,
// and no longer trigger tabView_didSelectTabViewItem
@ -817,10 +819,13 @@ begin
if fulltabs.count=0 then
Exit;
OldIndex := exttabIndexOfTabViewItem( lTabPage );
if OldIndex < 0 then
Exit;
if NewIndex > fulltabs.count then
NewIndex:= fulltabs.count;
OldIndex := exttabIndexOfTabViewItem( lTabPage );
isMovingCurrentPage := (OldIndex=currentIndex);
fulltabs.removeObjectAtIndex( OldIndex );
@ -861,6 +866,8 @@ begin
triggeringByLCL:= true;
try
removedIndex := exttabIndexOfTabViewItem( removedTabPage );
if removedIndex < 0 then
Exit;
isRemovingCurrentPage:= (removedIndex=currentIndex);
fulltabs.removeObjectAtIndex( removedIndex );
@ -895,6 +902,8 @@ function TCocoaTabControl.exttabIndexOfTabViewItem(lTabPage: NSTabViewItem
): NSInteger;
begin
Result := fulltabs.indexOfObject(lTabPage);
if Result = NSNotFound then
Result:= -1;
end;
{ TCocoaTabControlArrow }

View File

@ -901,10 +901,11 @@ begin
tb := TCocoaTabPageView(ATabControl.Page[AIndex].Handle);
if not Assigned(tb) then Exit;
i := TCocoaTabControl(ATabControl.Handle).fulltabs.indexOfObject( tb.tabPage );
if (i = NSNotFound) then Exit;
i := TCocoaTabControl(ATabControl.Handle).exttabIndexOfTabViewItem(tb.tabPage);
if i < 0 then
Exit;
TCocoaTabControl(ATabControl.Handle).extselectTabViewItemAtIndex(NSInteger(i));
TCocoaTabControl(ATabControl.Handle).extselectTabViewItemAtIndex(i);
end;
class procedure TCocoaWSCustomTabControl.SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition);