cocoa: initial separation of NSTableView based on Cells (pre 10.7) and Views (10.7 and later)

git-svn-id: trunk@58822 -
This commit is contained in:
dmitry 2018-09-02 20:33:34 +00:00
parent d35a69cd0c
commit 8f9eeedba6
4 changed files with 73 additions and 57 deletions

View File

@ -142,7 +142,6 @@ type
function tableView_shouldShowCellExpansionForTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): Boolean; message 'tableView:shouldShowCellExpansionForTableColumn:row:';
function tableView_shouldTrackCell_forTableColumn_row(tableView: NSTableView; cell: NSCell; tableColumn: NSTableColumn; row: NSInteger): Boolean; message 'tableView:shouldTrackCell:forTableColumn:row:';
}
function tableView_dataCellForTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): NSCell; message 'tableView:dataCellForTableColumn:row:';
{
function tableView_isGroupRow(tableView: NSTableView; row: NSInteger): Boolean; message 'tableView:isGroupRow:';
function tableView_sizeToFitWidthOfColumn(tableView: NSTableView; column: NSInteger): CGFloat; message 'tableView:sizeToFitWidthOfColumn:';
@ -184,8 +183,22 @@ type
procedure setButtonType(aType: NSButtonType); override;
end;
{ TCellCocoaTableListView }
TCellCocoaTableListView = objcclass(TCocoaTableListView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol)
public
function tableView_dataCellForTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): NSCell; message 'tableView:dataCellForTableColumn:row:';
end;
function AllocCocoaTableListView: TCocoaTableListView;
implementation
function AllocCocoaTableListView: TCocoaTableListView;
begin
Result := TCellCocoaTableListView.alloc; // init will happen outside
end;
{ NSTableButtonCell }
function NSTableButtonCell.hitTestForEvent_inRect_ofView(event: NSEvent;
@ -549,59 +562,6 @@ begin
callback.ColumnClicked(getIndexOfColumn(tableColumn));
end;
function TCocoaTableListView.tableView_dataCellForTableColumn_row(
tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): NSCell;
var
chk : Boolean;
txt : string;
col : Integer;
nstxt : NSString;
idx : Integer;
img : NSImage;
btn : NSTableButtonCell;
begin
Result:=nil;
if not isFirstColumnCheckboxes and not isImagesInCell then Exit;
col := getIndexOfColumn(tableColumn);
if (col <> 0) then Exit;
if not isFirstColumnCheckboxes and isImagesInCell then begin
idx := -1;
callback.GetItemImageAt(row, col, idx);
if idx>=0 then
begin
img := lclGetSmallImage(idx);
if not Assigned(img) then begin
img := callback.GetImageFromIndex(idx);
if Assigned(img) then lclRegisterSmallImage(idx, img);
end;
end else
img := nil;
Result := NSImageAndTextCell(NSImageAndTextCell.alloc).initTextCell(NSSTR(''));
NSImageAndTextCell(Result).drawImage := img; // if "image" is assigned, text won't be drawn :(
Exit;
end;
txt := '';
chk := false;
callback.GetItemTextAt(row, col, txt);
if txt = '' then nstxt := NSString.string_
else nstxt := NSString.stringWithUTF8String(@txt[1]);
btn := NSTableButtonCell.alloc.init.autorelease;
//Result.setAllowsMixedState(True);
btn.setButtonType(NSSwitchButton);
btn.setTitle(nstxt);
if chk then begin
btn.setIntValue(1);
btn.setCellAttribute_to(NSCellState, NSOnState);
end;
Result := btn;
end;
type
TCompareData = record
rmved : NSMutableIndexSet;
@ -798,5 +758,61 @@ begin
inherited Create;
end;
{ TCellCocoaTableListView }
function TCellCocoaTableListView.tableView_dataCellForTableColumn_row(
tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): NSCell;
var
chk : Boolean;
txt : string;
col : Integer;
nstxt : NSString;
idx : Integer;
img : NSImage;
btn : NSTableButtonCell;
begin
Result:=nil;
if not isFirstColumnCheckboxes and not isImagesInCell then Exit;
col := getIndexOfColumn(tableColumn);
if (col <> 0) then Exit;
if not isFirstColumnCheckboxes and isImagesInCell then begin
idx := -1;
callback.GetItemImageAt(row, col, idx);
if idx>=0 then
begin
img := lclGetSmallImage(idx);
if not Assigned(img) then begin
img := callback.GetImageFromIndex(idx);
if Assigned(img) then lclRegisterSmallImage(idx, img);
end;
end else
img := nil;
Result := NSImageAndTextCell(NSImageAndTextCell.alloc).initTextCell(NSSTR(''));
NSImageAndTextCell(Result).drawImage := img; // if "image" is assigned, text won't be drawn :(
Exit;
end;
txt := '';
chk := false;
callback.GetItemTextAt(row, col, txt);
if txt = '' then nstxt := NSString.string_
else nstxt := NSString.stringWithUTF8String(@txt[1]);
btn := NSTableButtonCell.alloc.init.autorelease;
//Result.setAllowsMixedState(True);
btn.setButtonType(NSSwitchButton);
btn.setTitle(nstxt);
if chk then begin
btn.setIntValue(1);
btn.setCellAttribute_to(NSCellState, NSOnState);
end;
Result := btn;
end;
end.

View File

@ -141,7 +141,7 @@ var
list: TCocoaTableListView;
scroll: TCocoaScrollView;
begin
list := TCocoaTableListView.alloc.lclInitWithCreateParams(AParams);
list := AllocCocoaTableListView.lclInitWithCreateParams(AParams);
if not Assigned(list) then
begin
Result := 0;

View File

@ -724,7 +724,7 @@ begin
if Result <> 0 then
begin
ns := GetNSRect(0, 0, AParams.Width, AParams.Height);
lTableLV := TCocoaTableListView.alloc.initWithFrame(ns);
lTableLV := AllocCocoaTableListView.initWithFrame(ns);
if lTableLV = nil then
begin
lCocoaLV.dealloc;

View File

@ -1697,7 +1697,7 @@ var
scroll : TCocoaScrollView;
lclListBox: TCustomListBox absolute AWinControl;
begin
list := TCocoaTableListView.alloc.lclInitWithCreateParams(AParams);
list := AllocCocoaTableListView.lclInitWithCreateParams(AParams);
if not Assigned(list) then
begin
Result := 0;