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;
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)

View File

@ -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;