From 6199957e3ac4f8b7bd9590ebcf5dc6ab49518a5d Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Thu, 1 May 2014 23:29:12 +0000 Subject: [PATCH] cocoa: Reorganizes the TListView handle so that now scrolling and the header are working git-svn-id: trunk@44878 - --- lcl/interfaces/cocoa/cocoaprivate.pp | 12 +++++++- lcl/interfaces/cocoa/cocoawscomctrls.pas | 35 ++++++++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index fa5f7248d0..b31fbb271a 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -555,7 +555,7 @@ type tabview: TCocoaTabControl; end; - { TCocoaTableListView } + { TListView } TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol) public @@ -633,6 +633,16 @@ type procedure tableViewSelectionIsChanging(notification: NSNotification); message 'tableViewSelectionIsChanging:';} end; + TCocoaListView = objcclass(NSScrollView) + public + ListView: TCustomListView; // just reference, don't release + callback: ICommonCallback; + // For report style: + TableListView: TCocoaTableListView; + // For the other styles: + // ToDo + end; + { TCocoaGroupBox } TCocoaGroupBox = objcclass(NSBox) diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index 7ddfa48877..6acb7ac228 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -349,18 +349,18 @@ end; class function TCocoaWSCustomListView.CheckParams(out ATableControl: TCocoaTableListView; const ALV: TCustomListView): Boolean; var - lObject: NSObject; + lCocoaListView: TCocoaListView; begin Result := False; ATableControl := nil; ALV.HandleNeeded(); if not Assigned(ALV) or not ALV.HandleAllocated then Exit; - lObject := NSObject(ALV.Handle); + lCocoaListView := TCocoaListView(ALV.Handle); // ToDo: Implement for other styles - if lObject.isKindOfClass(TCocoaTableListView) then + if lCocoaListView.TableListView <> nil then begin - ATableControl := TCocoaTableListView(lObject); + ATableControl := lCocoaListView.TableListView; Result := True; end; end; @@ -378,7 +378,7 @@ begin lObject := NSObject(ALV.Handle); if not lObject.isKindOfClass(TCocoaTableListView) then Exit; // in styles other than Report, column have no meaning - ATableControl := TCocoaTableListView(lObject); + ATableControl := TCocoaListView(lObject).TableListView; if (AIndex < 0) or (AIndex >= ATableControl.tableColumns.count()) then Exit; ANSColumn := NSTableColumn(ATableControl.tableColumns.objectAtIndex(AIndex)); @@ -391,21 +391,32 @@ end; class function TCocoaWSCustomListView.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; var + lCocoaLV: TCocoaListView; lTableLV: TCocoaTableListView; + ns: NSRect; begin {$IFDEF COCOA_DEBUG_LISTVIEW} WriteLn('[TCocoaWSCustomListView.CreateHandle] AWinControl='+IntToStr(PtrInt(AWinControl))); {$ENDIF} - lTableLV := TCocoaTableListView.alloc.lclInitWithCreateParams(AParams); - Result := TLCLIntfHandle(lTableLV); + lCocoaLV := TCocoaListView.alloc.lclInitWithCreateParams(AParams); + ns := GetNSRect(0, 0, AParams.Width, AParams.Height); + lTableLV := TCocoaTableListView.alloc.initWithFrame(ns); + Result := TLCLIntfHandle(lCocoaLV); if Result <> 0 then begin + lCocoaLV.TableListView := lTableLV; + lCocoaLV.ListView := TCustomListView(AWinControl); + lCocoaLV.setDocumentView(lTableLV); + lCocoaLV.setHasVerticalScroller(True); + lTableLV.callback := TLCLListViewCallback.Create(lTableLV, AWinControl); lTableLV.Items := TStringList.Create; - lTableLV.ListView := TCustomListView(AWinControl); lTableLV.setDataSource(lTableLV); lTableLV.setDelegate(lTableLV); + {$IFDEF COCOA_DEBUG_LISTVIEW} + WriteLn(Format('[TCocoaWSCustomListView.CreateHandle] headerView=%d', [PtrInt(lTableLV.headerView)])); + {$ENDIF} end; end; @@ -436,7 +447,7 @@ begin WriteLn(Format('[TCocoaWSCustomListView.ColumnGetWidth] AIndex=%d', [AIndex])); {$ENDIF} if not Assigned(ALV) or not ALV.HandleAllocated then Exit; - lTableLV := TCocoaTableListView(ALV.Handle); + lTableLV := TCocoaListView(ALV.Handle).TableListView; if (AIndex < 0) or (AIndex >= lTableLV.tableColumns.count()) then Exit; lColumn := lTableLV.tableColumns.objectAtIndex(AIndex); @@ -455,7 +466,7 @@ begin {$ENDIF} ALV.HandleNeeded(); if not Assigned(ALV) or not ALV.HandleAllocated then Exit; - lTableLV := TCocoaTableListView(ALV.Handle); + lTableLV := TCocoaListView(ALV.Handle).TableListView; {$IFDEF COCOA_DEBUG_LISTVIEW} WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert]=> tableColumns.count=%d', [lTableLV.tableColumns.count()])); {$ENDIF} @@ -626,8 +637,7 @@ begin {$IFDEF COCOA_DEBUG_TABCONTROL} WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex])); {$ENDIF} - if not Assigned(ALV) or not ALV.HandleAllocated then Exit; - lTableLV := TCocoaTableListView(ALV.Handle); + CheckParams(lTableLV, ALV); lColumnCount := lTableLV.tableColumns.count(); {$IFDEF COCOA_DEBUG_TABCONTROL} WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount])); @@ -646,6 +656,7 @@ begin lNSStr.release; end; lTableLV.reloadData(); + lTableLV.sizeToFit(); end; class procedure TCocoaWSCustomListView.ItemSetText(const ALV: TCustomListView;