cocoa: resolved the conflict between Cocoa Tab index, LCL tab index and notification tab index. Seems like WS code should take care of widget tab index conversion to LCL tab indexconversion. Resolves the problem with disappearing tabs after a tab removal

git-svn-id: trunk@58439 -
This commit is contained in:
dmitry 2018-07-04 19:32:26 +00:00
parent ec75584bad
commit be82b77199
2 changed files with 44 additions and 15 deletions

View File

@ -55,12 +55,12 @@ type
prevarr : NSButton;
nextarr : NSButton;
fulltabs : NSMutableArray; // the full list of NSTabViewItems
leftmost : Integer; // index of the left-most tab shown
public
callback: ITabControlCallback;
fulltabs : NSMutableArray; // the full list of NSTabViewItems
lclEnabled: Boolean;
// cocoa
class function alloc: id; override;
@ -106,9 +106,10 @@ type
public
tabView: TCocoaTabControl;
tabPage: TCocoaTabPage;
procedure setHidden(Ahidden: Boolean); override;
end;
function IndexOfTab(ahost: TCocoaTabControl; atab: NSTabViewItem): Integer;
implementation
function AllocArrowButton(isPrev: Boolean): NSButton;
@ -268,6 +269,7 @@ begin
// todo: automatic resizing still has its effect on the tabs.
// the content page fails to pick up the proper size and place
// and it seems that the content of the tab is shifted.
// Needs investiage and a fix.
finally
if (aview.indexOfTabViewItem(sel)<>NSNotFound) then
@ -287,16 +289,16 @@ begin
aview.nextarr.setHidden(not showNext);
end;
{ TCocoaTabPageView }
procedure TCocoaTabPageView.setHidden(Ahidden: Boolean);
function IndexOfTab(ahost: TCocoaTabControl; atab: NSTabViewItem): Integer;
var
idx : NSUInteger;
begin
// Should never be hidden. (The parent NSView would show/hide tabs)
// it seems, that lclSetVisible interferes with
// control visibility TCocoaCustomControl
// todo: there should be a cleaner solution than overriding this method
inherited setHidden(false);
idx := ahost.fulltabs.indexOfObject(atab);
if idx=NSUIntegerMax then Result:=-1
else begin
if idx>MaxInt then Result:=-1
else Result:=Integer(idx);
end;
end;
{ TCocoaTabPage }
@ -399,7 +401,7 @@ procedure TCocoaTabControl.tabView_willSelectTabViewItem(tabView: NSTabView;
tabViewItem: NSTabViewItem);
begin
if Assigned(callback) then
callback.willSelectTabViewItem( tabview.indexOfTabViewItem(tabViewItem) );
callback.willSelectTabViewItem( IndexOfTab( self, tabViewItem) );
end;
procedure TCocoaTabControl.tabView_didSelectTabViewItem(tabView: NSTabView;
@ -412,7 +414,9 @@ procedure TCocoaTabControl.tabView_didSelectTabViewItem(tabView: NSTabView;
//lCurCallback: ICommonCallback;
begin
if Assigned(callback) then
callback.didSelectTabViewItem( tabview.indexOfTabViewItem(tabViewItem) );
begin
callback.didSelectTabViewItem( IndexOfTab( self, tabViewItem) );
end;
// The recent clean up, drove the workaround below unnecessary
// (at least the problem is not observed)

View File

@ -227,6 +227,31 @@ type
implementation
function CocoaTabIndexToLCLIndex(trg: TObject; src: TCocoaTabControl; aTabIndex: Integer): Integer;
var
i : integer;
tb: TCustomTabControl;
hnd: HWND;
tbitem: TCocoaTabPage;
begin
Result:=aTabIndex;
if not Assigned(trg) or not (trg is TCustomTabControl) then Exit;
if (aTabIndex<0) or (atabIndex>=src.fulltabs.count) then begin
aTabIndex:=-1;
Exit;
end;
tbitem:=TCocoaTabPage(src.fulltabs.objectAtIndex(aTabIndex));
hnd := HWND(NSView(tbitem.view).subviews.objectAtIndex(0));
tb:=TCustomTabControl(trg);
for i:=0 to tb.PageCount-1 do
if tb.Page[i].Handle = hnd then begin
Result:=i;
Exit;
end;
end;
{ TLCLTabControlCallback }
procedure TLCLTabControlCallback.willSelectTabViewItem(aTabIndex: Integer);
@ -240,7 +265,7 @@ begin
Hdr.hwndFrom := FTarget.Handle;
Hdr.Code := TCN_SELCHANGING;
Hdr.idFrom := aTabIndex;
Hdr.idFrom := CocoaTabIndexToLCLIndex(Target, TCocoaTabControl(Owner), aTabIndex);
Msg.NMHdr := @Hdr;
Msg.Result := 0;
LCLMessageGlue.DeliverMessage(Target, Msg);
@ -257,7 +282,7 @@ begin
Hdr.hwndFrom := FTarget.Handle;
Hdr.Code := TCN_SELCHANGE;
Hdr.idFrom := PtrUInt(aTabIndex);
Hdr.idFrom := CocoaTabIndexToLCLIndex(Target, TCocoaTabControl(Owner), aTabIndex);
Msg.NMHdr := @Hdr;
Msg.Result := 0;
LCLMessageGlue.DeliverMessage(Target, Msg);