mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 01:39:25 +02:00
Cocoa: TabControl: jumping to the First/Last tab supported, Merge branch 'cocoa/tabcontrol'
This commit is contained in:
commit
285b99cc42
@ -98,14 +98,24 @@ type
|
|||||||
message 'exttabRemoveTabViewItem:';
|
message 'exttabRemoveTabViewItem:';
|
||||||
function exttabIndexOfTabViewItem(lTabPage: NSTabViewItem): NSInteger;
|
function exttabIndexOfTabViewItem(lTabPage: NSTabViewItem): NSInteger;
|
||||||
message 'exttabIndexOfTabViewItem:';
|
message 'exttabIndexOfTabViewItem:';
|
||||||
procedure extTabPrevButtonClick(sender: id);
|
|
||||||
message 'extTabPrevButtonClick:';
|
|
||||||
procedure extTabNextButtonClick(sender: id);
|
|
||||||
message 'extTabNextButtonClick:';
|
|
||||||
procedure extselectTabViewItemAtIndex(index: NSInteger);
|
procedure extselectTabViewItemAtIndex(index: NSInteger);
|
||||||
message 'extselectTabViewItemAtIndex:';
|
message 'extselectTabViewItemAtIndex:';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaTabControlArrow }
|
||||||
|
|
||||||
|
TCocoaTabControlArrow = objcclass(NSButton)
|
||||||
|
private
|
||||||
|
_tabControl: TCocoaTabControl;
|
||||||
|
_lastMouseDownTime: NSDate;
|
||||||
|
private
|
||||||
|
function shouldSpeedUp(): Boolean; message 'shouldSpeedUp';
|
||||||
|
public
|
||||||
|
procedure mouseDown(theEvent: NSEvent); override;
|
||||||
|
procedure prevClick(sender: id); message 'prevClick:';
|
||||||
|
procedure nextClick(sender: id); message 'nextClick:';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaTabPageView }
|
{ TCocoaTabPageView }
|
||||||
|
|
||||||
TCocoaTabPageView = objcclass(TCocoaCustomControl)
|
TCocoaTabPageView = objcclass(TCocoaCustomControl)
|
||||||
@ -159,18 +169,19 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AllocArrowButton(isPrev: Boolean): NSButton;
|
function AllocArrowButton(tabControl:TCocoaTabControl; isPrev:Boolean): NSButton;
|
||||||
var
|
var
|
||||||
btn : NSButton;
|
btn : TCocoaTabControlArrow;
|
||||||
begin
|
begin
|
||||||
btn:=NSButton(NSButton.alloc).initWithFrame(NSZeroRect);
|
btn := TCocoaTabControlArrow.alloc.initWithFrame(NSZeroRect);
|
||||||
|
btn._tabControl := tabControl;
|
||||||
btn.setBezelStyle(NSRegularSquareBezelStyle);
|
btn.setBezelStyle(NSRegularSquareBezelStyle);
|
||||||
btn.setButtonType(NSMomentaryLightButton);
|
btn.setButtonType(NSMomentaryLightButton);
|
||||||
|
|
||||||
if isPrev then
|
if isPrev then
|
||||||
btn.setTitle( StrToNSString('◀') )
|
btn.setTitle( StrToNSString('◀') )
|
||||||
else
|
else
|
||||||
btn.setTitle( StrToNSString('▶') );
|
btn.setTitle( StrToNSString('▶') );
|
||||||
|
|
||||||
{$ifdef BOOLFIX}
|
{$ifdef BOOLFIX}
|
||||||
btn.setBordered_(Ord(false));
|
btn.setBordered_(Ord(false));
|
||||||
@ -208,14 +219,15 @@ end;
|
|||||||
|
|
||||||
procedure AllocPrevNext(aview: TCocoaTabControl);
|
procedure AllocPrevNext(aview: TCocoaTabControl);
|
||||||
begin
|
begin
|
||||||
aview.prevarr := AllocArrowButton(true);
|
aview.prevarr := AllocArrowButton(aview, true);
|
||||||
aview.addSubview(aview.prevarr);
|
aview.addSubview(aview.prevarr);
|
||||||
aview.nextarr := AllocArrowButton(false);
|
aview.prevarr.setTarget(aview.prevarr);
|
||||||
|
aview.prevarr.setAction( ObjCSelector('prevClick:') );
|
||||||
|
|
||||||
|
aview.nextarr := AllocArrowButton(aview, false);
|
||||||
aview.addSubview(aview.nextarr);
|
aview.addSubview(aview.nextarr);
|
||||||
aview.prevarr.setTarget(aview);
|
aview.nextarr.setTarget(aview.nextarr);
|
||||||
aview.prevarr.setAction( ObjCSelector('extTabPrevButtonClick:'));
|
aview.nextarr.setAction( ObjCSelector('nextClick:') );
|
||||||
aview.nextarr.setTarget(aview);
|
|
||||||
aview.nextarr.setAction( ObjCSelector('extTabNextButtonClick:'));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// only missing ViewItems inserted, RemoveAllTabs() is no longer needed,
|
// only missing ViewItems inserted, RemoveAllTabs() is no longer needed,
|
||||||
@ -771,18 +783,56 @@ begin
|
|||||||
Result := fulltabs.indexOfObject(lTabPage);
|
Result := fulltabs.indexOfObject(lTabPage);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaTabControl.extTabPrevButtonClick(sender: id);
|
{ TCocoaTabControlArrow }
|
||||||
|
|
||||||
|
procedure TCocoaTabControlArrow.mouseDown(theEvent: NSEvent);
|
||||||
begin
|
begin
|
||||||
if currentIndex = 0 then Exit;
|
_lastMouseDownTime := NSDate.date;
|
||||||
extselectTabViewItemAtIndex( currentIndex-1 );
|
inherited;
|
||||||
|
_lastMouseDownTime := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaTabControl.extTabNextButtonClick(sender: id);
|
function TCocoaTabControlArrow.shouldSpeedUp(): Boolean;
|
||||||
|
const
|
||||||
|
FOUR_MODIFIER_FLAGS = NSShiftKeyMask
|
||||||
|
or NSControlKeyMask
|
||||||
|
or NSAlternateKeyMask
|
||||||
|
or NSCommandKeyMask;
|
||||||
begin
|
begin
|
||||||
if currentIndex = fulltabs.count - 1 then Exit;
|
if (NSApp.currentEvent.modifierFlags and FOUR_MODIFIER_FLAGS)<>0 then
|
||||||
extselectTabViewItemAtIndex( currentIndex+1 );
|
exit(true);
|
||||||
|
if NSDate.date.timeIntervalSinceDate(_lastMouseDownTime) > NSEvent.doubleClickInterval then
|
||||||
|
exit(true);
|
||||||
|
Result := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTabControlArrow.prevClick(sender: id);
|
||||||
|
var
|
||||||
|
currentIndex: Integer;
|
||||||
|
begin
|
||||||
|
currentIndex := _tabControl.currentIndex;
|
||||||
|
if currentIndex = 0 then
|
||||||
|
Exit;
|
||||||
|
if shouldSpeedUp() then
|
||||||
|
currentIndex := 0
|
||||||
|
else
|
||||||
|
dec(currentIndex);
|
||||||
|
_tabControl.extselectTabViewItemAtIndex(currentIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTabControlArrow.nextClick(sender: id);
|
||||||
|
var
|
||||||
|
currentIndex: Integer;
|
||||||
|
begin
|
||||||
|
currentIndex := _tabControl.currentIndex;
|
||||||
|
if currentIndex = _tabControl.fulltabs.count - 1 then
|
||||||
|
Exit;
|
||||||
|
if shouldSpeedUp() then
|
||||||
|
currentIndex := _tabControl.fulltabs.count - 1
|
||||||
|
else
|
||||||
|
inc(currentIndex);
|
||||||
|
_tabControl.extselectTabViewItemAtIndex(currentIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user