From b50fcc983dca12c7ad04fcf6b191dd93d679179b Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Mon, 21 Apr 2014 10:56:41 +0000 Subject: [PATCH] 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 - --- lcl/interfaces/cocoa/cocoaprivate.pp | 5 +-- lcl/interfaces/cocoa/cocoautils.pas | 8 +++- lcl/interfaces/cocoa/cocoawinapi.inc | 2 +- lcl/interfaces/cocoa/cocoawscomctrls.pas | 53 +++++++++++++++++++++--- lcl/interfaces/cocoa/cocoawscommon.pas | 27 +++++------- lcl/interfaces/cocoa/cocoawsfactory.pas | 6 +-- 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index e6e45f46b8..da672bbbf7 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -1691,11 +1691,8 @@ begin p := nil; if (AParams.WndParent <> 0) then begin + p := CocoaUtils.GetNSObjectView(NSObject(AParams.WndParent)); 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; with AParams do if Assigned(p) then diff --git a/lcl/interfaces/cocoa/cocoautils.pas b/lcl/interfaces/cocoa/cocoautils.pas index b45ebff698..e7acb8fe70 100644 --- a/lcl/interfaces/cocoa/cocoautils.pas +++ b/lcl/interfaces/cocoa/cocoautils.pas @@ -223,8 +223,12 @@ function GetNSObjectView(obj: NSObject): NSView; begin Result := nil; if not Assigned(obj) then Exit; - if obj.isKindOfClass_(NSView) then Result:=NSView(obj) - else if obj.isKindOfClass_(NSWindow) then Result:=NSWindow(obj).contentView; + if obj.isKindOfClass_(NSView) then + Result:=NSView(obj) + else if obj.isKindOfClass_(NSWindow) then + Result:=NSWindow(obj).contentView + else if obj.isKindOfClass_(NSTabViewItem) then + Result := NSTabViewItem(obj).view; end; function GetNSPoint(x, y: single): NSPoint; diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index 336b556cea..6c3dccd90f 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -927,7 +927,7 @@ begin // Call on a window lView := NSView(Handle); - if lView.isKindOfClass(objc_getClass('TCocoaWindowContent')) then + if lView.isKindOfClass_(TCocoaWindowContent) then begin if TCocoaWindowContent(handle).isembedded then r := TCocoaWindowContent(handle).lclFrame diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index 249d0914c1..71d2dc4a9c 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -5,6 +5,8 @@ interface {$mode delphi} {$modeswitch objectivec1} +{.$DEFINE COCOA_DEBUG_TABCONTROL} + uses // RTL, FCL, LCL CocoaAll, @@ -40,6 +42,7 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class procedure UpdateProperties(const ACustomPage: TCustomPage); override; + class procedure SetProperties(const ACustomPage: TCustomPage; ACocoaControl: NSTabViewItem); end; { TCocoaWSCustomTabControl } @@ -196,17 +199,43 @@ class function TCocoaWSCustomPage.CreateHandle(const AWinControl: TWinControl; c var lControl: TCocoaTabPage; begin + {$IFDEF COCOA_DEBUG_TABCONTROL} + WriteLn('[TCocoaWSCustomPage.CreateHandle]'); + {$ENDIF} lControl := TCocoaTabPage.alloc().init(); Result := TLCLIntfHandle(lControl); if Result <> 0 then begin - //lControl.callback := TLCLCommonCallback.Create(Result, ATarget); + //lControl.callback := TLCLCommonCallback.Create(lControl, AWinControl); lControl.LCLPage := TCustomPage(AWinControl); + SetProperties(TCustomPage(AWinControl), lControl); end; end; class procedure TCocoaWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage); +var + lTabPage: TCocoaTabPage; 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; { TCocoaWSCustomTabControl } @@ -219,7 +248,7 @@ begin Result := TLCLIntfHandle(lControl); if Result <> 0 then begin - //Result.callback := TLCLCommonCallback.Create(Result, ATarget); + //lControl.callback := TLCLCommonCallback.Create(lControl, AWinControl); end; end; @@ -228,12 +257,19 @@ var lTabControl: TCocoaTabControl; lTabPage: TCocoaTabPage; begin + {$IFDEF COCOA_DEBUG_TABCONTROL} + WriteLn('[TCocoaWSCustomTabControl.AddPage] AChild='+IntToStr(PtrInt(AChild))); + {$ENDIF} if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit; lTabControl := TCocoaTabControl(ATabControl.Handle); + AChild.HandleNeeded(); if not Assigned(AChild) or not AChild.HandleAllocated then Exit; lTabPage := TCocoaTabPage(AChild.Handle); lTabControl.insertTabViewItem_atIndex(lTabPage, AIndex); + {$IFDEF COCOA_DEBUG_TABCONTROL} + WriteLn('[TCocoaWSCustomTabControl.AddPage] END'); + {$ENDIF} end; class procedure TCocoaWSCustomTabControl.MovePage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const NewIndex: integer); @@ -243,6 +279,7 @@ var begin if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit; lTabControl := TCocoaTabControl(ATabControl.Handle); + AChild.HandleNeeded(); if not Assigned(AChild) or not AChild.HandleAllocated then Exit; lTabPage := TCocoaTabPage(AChild.Handle); @@ -282,12 +319,18 @@ var lTabControl: TCocoaTabControl; lTabCount: NSInteger; begin - //WriteLn('[TCocoaWSCustomTabControl.SetPageIndex]'); + {$IFDEF COCOA_DEBUG_TABCONTROL} + WriteLn('[TCocoaWSCustomTabControl.SetPageIndex]'); + {$ENDIF} if not Assigned(ATabControl) or not ATabControl.HandleAllocated then Exit; 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(); - //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; lTabControl.selectTabViewItemAtIndex(AIndex); diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 036f25db3b..fb11d11bc3 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -828,15 +828,15 @@ begin end; if assigned(targetControl) and not FIsEventRouting then - begin - FIsEventRouting:=true; - // debugln(Target.name+' -> '+targetControl.Name+'- is parent:'+dbgs(targetControl=Target.Parent)+' Point: '+dbgs(mp)+' Rect'+dbgs(rect)); - obj:=NSView(targetControl.Handle); - callback:=obj.lclGetCallback; - result:=callback.MouseMove(Event); - FIsEventRouting:=false; - exit; - end; + begin + FIsEventRouting:=true; + // debugln(Target.name+' -> '+targetControl.Name+'- is parent:'+dbgs(targetControl=Target.Parent)+' Point: '+dbgs(mp)+' Rect'+dbgs(rect)); + obj := GetNSObjectView(NSObject(targetControl.Handle)); + callback:=obj.lclGetCallback; + result:=callback.MouseMove(Event); + FIsEventRouting:=false; + exit; + end; // debugln('Send to: '+Target.name+' Point: '+dbgs(mp)); @@ -1046,13 +1046,8 @@ var View: NSView; begin Result := False; - if Owner.isKindOfClass_(NSWindow) then - View := NSwindow(Owner).contentView - else - if Owner.isKindOfClass_(NSView) then - View := NSView(Owner) - else - Exit; + View := CocoaUtils.GetNSObjectView(Owner); + if View = nil then Exit; if not (csDesigning in Target.ComponentState) then begin ACursor := Screen.Cursor; diff --git a/lcl/interfaces/cocoa/cocoawsfactory.pas b/lcl/interfaces/cocoa/cocoawsfactory.pas index 6571e229ba..43e6288d6e 100644 --- a/lcl/interfaces/cocoa/cocoawsfactory.pas +++ b/lcl/interfaces/cocoa/cocoawsfactory.pas @@ -165,8 +165,7 @@ end; function RegisterPageControl: Boolean; alias : 'WSRegisterPageControl'; begin - RegisterWSComponent(TCustomTabControl, TCocoaWSCustomTabControl); - Result := True; + Result := False; end; function RegisterCustomListView: Boolean; alias : 'WSRegisterCustomListView'; @@ -338,7 +337,8 @@ end; function RegisterCustomNotebook: Boolean; alias : 'WSRegisterCustomNotebook'; begin - Result := False; + RegisterWSComponent(TCustomTabControl, TCocoaWSCustomTabControl); + Result := True; end; function RegisterShape: Boolean; alias : 'WSRegisterShape';