cocoa: Reorganizes the TListView handle so that now scrolling and the header are working

git-svn-id: trunk@44878 -
This commit is contained in:
sekelsenmat 2014-05-01 23:29:12 +00:00
parent 90d7c92c6b
commit 6199957e3a
2 changed files with 34 additions and 13 deletions

View File

@ -555,7 +555,7 @@ type
tabview: TCocoaTabControl; tabview: TCocoaTabControl;
end; end;
{ TCocoaTableListView } { TListView }
TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol) TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol)
public public
@ -633,6 +633,16 @@ type
procedure tableViewSelectionIsChanging(notification: NSNotification); message 'tableViewSelectionIsChanging:';} procedure tableViewSelectionIsChanging(notification: NSNotification); message 'tableViewSelectionIsChanging:';}
end; 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 }
TCocoaGroupBox = objcclass(NSBox) TCocoaGroupBox = objcclass(NSBox)

View File

@ -349,18 +349,18 @@ end;
class function TCocoaWSCustomListView.CheckParams(out class function TCocoaWSCustomListView.CheckParams(out
ATableControl: TCocoaTableListView; const ALV: TCustomListView): Boolean; ATableControl: TCocoaTableListView; const ALV: TCustomListView): Boolean;
var var
lObject: NSObject; lCocoaListView: TCocoaListView;
begin begin
Result := False; Result := False;
ATableControl := nil; ATableControl := nil;
ALV.HandleNeeded(); ALV.HandleNeeded();
if not Assigned(ALV) or not ALV.HandleAllocated then Exit; if not Assigned(ALV) or not ALV.HandleAllocated then Exit;
lObject := NSObject(ALV.Handle); lCocoaListView := TCocoaListView(ALV.Handle);
// ToDo: Implement for other styles // ToDo: Implement for other styles
if lObject.isKindOfClass(TCocoaTableListView) then if lCocoaListView.TableListView <> nil then
begin begin
ATableControl := TCocoaTableListView(lObject); ATableControl := lCocoaListView.TableListView;
Result := True; Result := True;
end; end;
end; end;
@ -378,7 +378,7 @@ begin
lObject := NSObject(ALV.Handle); lObject := NSObject(ALV.Handle);
if not lObject.isKindOfClass(TCocoaTableListView) then Exit; // in styles other than Report, column have no meaning 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; if (AIndex < 0) or (AIndex >= ATableControl.tableColumns.count()) then Exit;
ANSColumn := NSTableColumn(ATableControl.tableColumns.objectAtIndex(AIndex)); ANSColumn := NSTableColumn(ATableControl.tableColumns.objectAtIndex(AIndex));
@ -391,21 +391,32 @@ end;
class function TCocoaWSCustomListView.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; class function TCocoaWSCustomListView.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
var var
lCocoaLV: TCocoaListView;
lTableLV: TCocoaTableListView; lTableLV: TCocoaTableListView;
ns: NSRect;
begin begin
{$IFDEF COCOA_DEBUG_LISTVIEW} {$IFDEF COCOA_DEBUG_LISTVIEW}
WriteLn('[TCocoaWSCustomListView.CreateHandle] AWinControl='+IntToStr(PtrInt(AWinControl))); WriteLn('[TCocoaWSCustomListView.CreateHandle] AWinControl='+IntToStr(PtrInt(AWinControl)));
{$ENDIF} {$ENDIF}
lTableLV := TCocoaTableListView.alloc.lclInitWithCreateParams(AParams); lCocoaLV := TCocoaListView.alloc.lclInitWithCreateParams(AParams);
Result := TLCLIntfHandle(lTableLV); ns := GetNSRect(0, 0, AParams.Width, AParams.Height);
lTableLV := TCocoaTableListView.alloc.initWithFrame(ns);
Result := TLCLIntfHandle(lCocoaLV);
if Result <> 0 then if Result <> 0 then
begin begin
lCocoaLV.TableListView := lTableLV;
lCocoaLV.ListView := TCustomListView(AWinControl);
lCocoaLV.setDocumentView(lTableLV);
lCocoaLV.setHasVerticalScroller(True);
lTableLV.callback := TLCLListViewCallback.Create(lTableLV, AWinControl); lTableLV.callback := TLCLListViewCallback.Create(lTableLV, AWinControl);
lTableLV.Items := TStringList.Create; lTableLV.Items := TStringList.Create;
lTableLV.ListView := TCustomListView(AWinControl); lTableLV.ListView := TCustomListView(AWinControl);
lTableLV.setDataSource(lTableLV); lTableLV.setDataSource(lTableLV);
lTableLV.setDelegate(lTableLV); lTableLV.setDelegate(lTableLV);
{$IFDEF COCOA_DEBUG_LISTVIEW}
WriteLn(Format('[TCocoaWSCustomListView.CreateHandle] headerView=%d', [PtrInt(lTableLV.headerView)]));
{$ENDIF}
end; end;
end; end;
@ -436,7 +447,7 @@ begin
WriteLn(Format('[TCocoaWSCustomListView.ColumnGetWidth] AIndex=%d', [AIndex])); WriteLn(Format('[TCocoaWSCustomListView.ColumnGetWidth] AIndex=%d', [AIndex]));
{$ENDIF} {$ENDIF}
if not Assigned(ALV) or not ALV.HandleAllocated then Exit; 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; if (AIndex < 0) or (AIndex >= lTableLV.tableColumns.count()) then Exit;
lColumn := lTableLV.tableColumns.objectAtIndex(AIndex); lColumn := lTableLV.tableColumns.objectAtIndex(AIndex);
@ -455,7 +466,7 @@ begin
{$ENDIF} {$ENDIF}
ALV.HandleNeeded(); ALV.HandleNeeded();
if not Assigned(ALV) or not ALV.HandleAllocated then Exit; if not Assigned(ALV) or not ALV.HandleAllocated then Exit;
lTableLV := TCocoaTableListView(ALV.Handle); lTableLV := TCocoaListView(ALV.Handle).TableListView;
{$IFDEF COCOA_DEBUG_LISTVIEW} {$IFDEF COCOA_DEBUG_LISTVIEW}
WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert]=> tableColumns.count=%d', [lTableLV.tableColumns.count()])); WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert]=> tableColumns.count=%d', [lTableLV.tableColumns.count()]));
{$ENDIF} {$ENDIF}
@ -626,8 +637,7 @@ begin
{$IFDEF COCOA_DEBUG_TABCONTROL} {$IFDEF COCOA_DEBUG_TABCONTROL}
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex])); WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex]));
{$ENDIF} {$ENDIF}
if not Assigned(ALV) or not ALV.HandleAllocated then Exit; CheckParams(lTableLV, ALV);
lTableLV := TCocoaTableListView(ALV.Handle);
lColumnCount := lTableLV.tableColumns.count(); lColumnCount := lTableLV.tableColumns.count();
{$IFDEF COCOA_DEBUG_TABCONTROL} {$IFDEF COCOA_DEBUG_TABCONTROL}
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount])); WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount]));
@ -646,6 +656,7 @@ begin
lNSStr.release; lNSStr.release;
end; end;
lTableLV.reloadData(); lTableLV.reloadData();
lTableLV.sizeToFit();
end; end;
class procedure TCocoaWSCustomListView.ItemSetText(const ALV: TCustomListView; class procedure TCocoaWSCustomListView.ItemSetText(const ALV: TCustomListView;