mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 10:39:09 +02:00
lcl-cocoa: Various fixes and improvements related to TPageControl, it can already show all tabs and the contents of the initially selected tab
git-svn-id: trunk@44774 -
This commit is contained in:
parent
103fe7fe69
commit
b50fcc983d
@ -1691,11 +1691,8 @@ begin
|
|||||||
p := nil;
|
p := nil;
|
||||||
if (AParams.WndParent <> 0) then
|
if (AParams.WndParent <> 0) then
|
||||||
begin
|
begin
|
||||||
|
p := CocoaUtils.GetNSObjectView(NSObject(AParams.WndParent));
|
||||||
if (NSObject(AParams.WndParent).isKindOfClass_(NSView)) then
|
if (NSObject(AParams.WndParent).isKindOfClass_(NSView)) then
|
||||||
p := NSView(AParams.WndParent)
|
|
||||||
else
|
|
||||||
if (NSObject(AParams.WndParent).isKindOfClass_(NSWindow)) then
|
|
||||||
p := NSWindow(AParams.WndParent).contentView;
|
|
||||||
end;
|
end;
|
||||||
with AParams do
|
with AParams do
|
||||||
if Assigned(p) then
|
if Assigned(p) then
|
||||||
|
@ -223,8 +223,12 @@ function GetNSObjectView(obj: NSObject): NSView;
|
|||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
if not Assigned(obj) then Exit;
|
if not Assigned(obj) then Exit;
|
||||||
if obj.isKindOfClass_(NSView) then Result:=NSView(obj)
|
if obj.isKindOfClass_(NSView) then
|
||||||
else if obj.isKindOfClass_(NSWindow) then Result:=NSWindow(obj).contentView;
|
Result:=NSView(obj)
|
||||||
|
else if obj.isKindOfClass_(NSWindow) then
|
||||||
|
Result:=NSWindow(obj).contentView
|
||||||
|
else if obj.isKindOfClass_(NSTabViewItem) then
|
||||||
|
Result := NSTabViewItem(obj).view;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetNSPoint(x, y: single): NSPoint;
|
function GetNSPoint(x, y: single): NSPoint;
|
||||||
|
@ -927,7 +927,7 @@ begin
|
|||||||
|
|
||||||
// Call on a window
|
// Call on a window
|
||||||
lView := NSView(Handle);
|
lView := NSView(Handle);
|
||||||
if lView.isKindOfClass(objc_getClass('TCocoaWindowContent')) then
|
if lView.isKindOfClass_(TCocoaWindowContent) then
|
||||||
begin
|
begin
|
||||||
if TCocoaWindowContent(handle).isembedded then
|
if TCocoaWindowContent(handle).isembedded then
|
||||||
r := TCocoaWindowContent(handle).lclFrame
|
r := TCocoaWindowContent(handle).lclFrame
|
||||||
|
@ -5,6 +5,8 @@ interface
|
|||||||
{$mode delphi}
|
{$mode delphi}
|
||||||
{$modeswitch objectivec1}
|
{$modeswitch objectivec1}
|
||||||
|
|
||||||
|
{.$DEFINE COCOA_DEBUG_TABCONTROL}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
// RTL, FCL, LCL
|
// RTL, FCL, LCL
|
||||||
CocoaAll,
|
CocoaAll,
|
||||||
@ -40,6 +42,7 @@ type
|
|||||||
published
|
published
|
||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
|
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
|
||||||
|
class procedure SetProperties(const ACustomPage: TCustomPage; ACocoaControl: NSTabViewItem);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomTabControl }
|
{ TCocoaWSCustomTabControl }
|
||||||
@ -196,17 +199,43 @@ class function TCocoaWSCustomPage.CreateHandle(const AWinControl: TWinControl; c
|
|||||||
var
|
var
|
||||||
lControl: TCocoaTabPage;
|
lControl: TCocoaTabPage;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn('[TCocoaWSCustomPage.CreateHandle]');
|
||||||
|
{$ENDIF}
|
||||||
lControl := TCocoaTabPage.alloc().init();
|
lControl := TCocoaTabPage.alloc().init();
|
||||||
Result := TLCLIntfHandle(lControl);
|
Result := TLCLIntfHandle(lControl);
|
||||||
if Result <> 0 then
|
if Result <> 0 then
|
||||||
begin
|
begin
|
||||||
//lControl.callback := TLCLCommonCallback.Create(Result, ATarget);
|
//lControl.callback := TLCLCommonCallback.Create(lControl, AWinControl);
|
||||||
lControl.LCLPage := TCustomPage(AWinControl);
|
lControl.LCLPage := TCustomPage(AWinControl);
|
||||||
|
SetProperties(TCustomPage(AWinControl), lControl);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
|
class procedure TCocoaWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
|
||||||
|
var
|
||||||
|
lTabPage: TCocoaTabPage;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn('[TCocoaWSCustomTabControl.UpdateProperties] ACustomPage='+IntToStr(PtrInt(ACustomPage)));
|
||||||
|
{$ENDIF}
|
||||||
|
if not Assigned(ACustomPage) or not ACustomPage.HandleAllocated then Exit;
|
||||||
|
lTabPage := TCocoaTabPage(ACustomPage.Handle);
|
||||||
|
SetProperties(ACustomPage, lTabPage);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCocoaWSCustomPage.SetProperties(
|
||||||
|
const ACustomPage: TCustomPage; ACocoaControl: NSTabViewItem);
|
||||||
|
var
|
||||||
|
lHintStr: string;
|
||||||
|
begin
|
||||||
|
// title
|
||||||
|
ACocoaControl.setLabel(NSStringUTF8(ACustomPage.Caption));
|
||||||
|
|
||||||
|
// hint
|
||||||
|
if ACustomPage.ShowHint then lHintStr := ACustomPage.Hint
|
||||||
|
else lHintStr := '';
|
||||||
|
ACocoaControl.setToolTip(NSStringUTF8(lHintStr));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomTabControl }
|
{ TCocoaWSCustomTabControl }
|
||||||
@ -219,7 +248,7 @@ begin
|
|||||||
Result := TLCLIntfHandle(lControl);
|
Result := TLCLIntfHandle(lControl);
|
||||||
if Result <> 0 then
|
if Result <> 0 then
|
||||||
begin
|
begin
|
||||||
//Result.callback := TLCLCommonCallback.Create(Result, ATarget);
|
//lControl.callback := TLCLCommonCallback.Create(lControl, AWinControl);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -228,12 +257,19 @@ var
|
|||||||
lTabControl: TCocoaTabControl;
|
lTabControl: TCocoaTabControl;
|
||||||
lTabPage: TCocoaTabPage;
|
lTabPage: TCocoaTabPage;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn('[TCocoaWSCustomTabControl.AddPage] AChild='+IntToStr(PtrInt(AChild)));
|
||||||
|
{$ENDIF}
|
||||||
if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit;
|
if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit;
|
||||||
lTabControl := TCocoaTabControl(ATabControl.Handle);
|
lTabControl := TCocoaTabControl(ATabControl.Handle);
|
||||||
|
AChild.HandleNeeded();
|
||||||
if not Assigned(AChild) or not AChild.HandleAllocated then Exit;
|
if not Assigned(AChild) or not AChild.HandleAllocated then Exit;
|
||||||
lTabPage := TCocoaTabPage(AChild.Handle);
|
lTabPage := TCocoaTabPage(AChild.Handle);
|
||||||
|
|
||||||
lTabControl.insertTabViewItem_atIndex(lTabPage, AIndex);
|
lTabControl.insertTabViewItem_atIndex(lTabPage, AIndex);
|
||||||
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn('[TCocoaWSCustomTabControl.AddPage] END');
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomTabControl.MovePage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const NewIndex: integer);
|
class procedure TCocoaWSCustomTabControl.MovePage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const NewIndex: integer);
|
||||||
@ -243,6 +279,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit;
|
if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit;
|
||||||
lTabControl := TCocoaTabControl(ATabControl.Handle);
|
lTabControl := TCocoaTabControl(ATabControl.Handle);
|
||||||
|
AChild.HandleNeeded();
|
||||||
if not Assigned(AChild) or not AChild.HandleAllocated then Exit;
|
if not Assigned(AChild) or not AChild.HandleAllocated then Exit;
|
||||||
lTabPage := TCocoaTabPage(AChild.Handle);
|
lTabPage := TCocoaTabPage(AChild.Handle);
|
||||||
|
|
||||||
@ -282,12 +319,18 @@ var
|
|||||||
lTabControl: TCocoaTabControl;
|
lTabControl: TCocoaTabControl;
|
||||||
lTabCount: NSInteger;
|
lTabCount: NSInteger;
|
||||||
begin
|
begin
|
||||||
//WriteLn('[TCocoaWSCustomTabControl.SetPageIndex]');
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn('[TCocoaWSCustomTabControl.SetPageIndex]');
|
||||||
|
{$ENDIF}
|
||||||
if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit;
|
if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit;
|
||||||
lTabControl := TCocoaTabControl(ATabControl.Handle);
|
lTabControl := TCocoaTabControl(ATabControl.Handle);
|
||||||
//WriteLn(Format('[TCocoaWSCustomTabControl.SetPageIndex] lTabControl=%d', [PtrUInt(lTabControl)]));
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn(Format('[TCocoaWSCustomTabControl.SetPageIndex] lTabControl=%d', [PtrUInt(lTabControl)]));
|
||||||
|
{$ENDIF}
|
||||||
lTabCount := lTabControl.numberOfTabViewItems();
|
lTabCount := lTabControl.numberOfTabViewItems();
|
||||||
//WriteLn(Format('[TCocoaWSCustomTabControl.SetPageIndex] lTabCount=%d', [lTabCount]));
|
{$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 >= lTabCount) then Exit;
|
||||||
|
|
||||||
lTabControl.selectTabViewItemAtIndex(AIndex);
|
lTabControl.selectTabViewItemAtIndex(AIndex);
|
||||||
|
@ -828,15 +828,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
if assigned(targetControl) and not FIsEventRouting then
|
if assigned(targetControl) and not FIsEventRouting then
|
||||||
begin
|
begin
|
||||||
FIsEventRouting:=true;
|
FIsEventRouting:=true;
|
||||||
// debugln(Target.name+' -> '+targetControl.Name+'- is parent:'+dbgs(targetControl=Target.Parent)+' Point: '+dbgs(mp)+' Rect'+dbgs(rect));
|
// debugln(Target.name+' -> '+targetControl.Name+'- is parent:'+dbgs(targetControl=Target.Parent)+' Point: '+dbgs(mp)+' Rect'+dbgs(rect));
|
||||||
obj:=NSView(targetControl.Handle);
|
obj := GetNSObjectView(NSObject(targetControl.Handle));
|
||||||
callback:=obj.lclGetCallback;
|
callback:=obj.lclGetCallback;
|
||||||
result:=callback.MouseMove(Event);
|
result:=callback.MouseMove(Event);
|
||||||
FIsEventRouting:=false;
|
FIsEventRouting:=false;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// debugln('Send to: '+Target.name+' Point: '+dbgs(mp));
|
// debugln('Send to: '+Target.name+' Point: '+dbgs(mp));
|
||||||
|
|
||||||
@ -1046,13 +1046,8 @@ var
|
|||||||
View: NSView;
|
View: NSView;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
if Owner.isKindOfClass_(NSWindow) then
|
View := CocoaUtils.GetNSObjectView(Owner);
|
||||||
View := NSwindow(Owner).contentView
|
if View = nil then Exit;
|
||||||
else
|
|
||||||
if Owner.isKindOfClass_(NSView) then
|
|
||||||
View := NSView(Owner)
|
|
||||||
else
|
|
||||||
Exit;
|
|
||||||
if not (csDesigning in Target.ComponentState) then
|
if not (csDesigning in Target.ComponentState) then
|
||||||
begin
|
begin
|
||||||
ACursor := Screen.Cursor;
|
ACursor := Screen.Cursor;
|
||||||
|
@ -165,8 +165,7 @@ end;
|
|||||||
|
|
||||||
function RegisterPageControl: Boolean; alias : 'WSRegisterPageControl';
|
function RegisterPageControl: Boolean; alias : 'WSRegisterPageControl';
|
||||||
begin
|
begin
|
||||||
RegisterWSComponent(TCustomTabControl, TCocoaWSCustomTabControl);
|
Result := False;
|
||||||
Result := True;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RegisterCustomListView: Boolean; alias : 'WSRegisterCustomListView';
|
function RegisterCustomListView: Boolean; alias : 'WSRegisterCustomListView';
|
||||||
@ -338,7 +337,8 @@ end;
|
|||||||
|
|
||||||
function RegisterCustomNotebook: Boolean; alias : 'WSRegisterCustomNotebook';
|
function RegisterCustomNotebook: Boolean; alias : 'WSRegisterCustomNotebook';
|
||||||
begin
|
begin
|
||||||
Result := False;
|
RegisterWSComponent(TCustomTabControl, TCocoaWSCustomTabControl);
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RegisterShape: Boolean; alias : 'WSRegisterShape';
|
function RegisterShape: Boolean; alias : 'WSRegisterShape';
|
||||||
|
Loading…
Reference in New Issue
Block a user