mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-07 18:00:23 +02:00
cocoa: update insertion and removal of rows in cocoa table (fix implementation from #34319)
git-svn-id: trunk@59206 -
This commit is contained in:
parent
5bb6685e21
commit
969020a44e
@ -108,12 +108,18 @@ type
|
||||
|
||||
NSUserInterfaceItemIdentifier = NSString;
|
||||
|
||||
NSTableViewAnimationOptions = NSUInteger;
|
||||
|
||||
NSTableViewFix = objccategory external (NSTableView)
|
||||
// 10.7
|
||||
function rowForView(AView: NSView): NSInteger; message 'rowForView:';
|
||||
function columnForView(AView: NSView): NSInteger; message 'columnForView:';
|
||||
function makeViewWithIdentifier_owner(identifier_: NSUserInterfaceItemIdentifier; owner: id): NSView ; message 'makeViewWithIdentifier:owner:';
|
||||
function viewAtColumn_row_makeIfNecessary(column, row: NSInteger; makeifNecessary: Boolean): NSview; message 'viewAtColumn:row:makeIfNecessary:';
|
||||
procedure insertRowsAtIndexes_withAnimation(indexes: NSIndexSet; withAnimation: NSTableViewAnimationOptions);
|
||||
message 'insertRowsAtIndexes:withAnimation:';
|
||||
procedure removeRowsAtIndexes_withAnimation(indexes: NSIndexSet; withAnimation: NSTableViewAnimationOptions);
|
||||
message 'removeRowsAtIndexes:withAnimation:';
|
||||
end;
|
||||
|
||||
{// private since 10.5, doesn't seam to do anything in 10.10
|
||||
@ -177,6 +183,27 @@ const
|
||||
const
|
||||
NSKeyCodeTab = 48;
|
||||
|
||||
{ NSTableView Animation Options }
|
||||
|
||||
const
|
||||
{ Use to not apply any animation effect (the default).
|
||||
Specifying any animation from the effect groups below
|
||||
negates this effect. }
|
||||
NSTableViewAnimationEffectNone = $0;
|
||||
|
||||
{ Row animation Effect (optional). The effect can be combined
|
||||
with other any NSTableViewRowAnimationSlide* option.
|
||||
}
|
||||
NSTableViewAnimationEffectFade = $1; // Fades in new rows.
|
||||
NSTableViewAnimationEffectGap = $2; // Creates a gap for newly inserted rows. This is useful for drag and drop animations that animate to a newly opened gap and should be used in -tableView:acceptDrop:row:dropOperation:.
|
||||
|
||||
{Row Animation Sliding (optional). Currently only one option from this group may be specified at a time.
|
||||
}
|
||||
NSTableViewAnimationSlideUp = $10; // Animates a row in or out by sliding upward.
|
||||
NSTableViewAnimationSlideDown = $20; // Animates a row in or out by sliding downward.
|
||||
NSTableViewAnimationSlideLeft = $30; // Animates a row in by sliding from the left. Animates a row out by sliding towards the left.
|
||||
NSTableViewAnimationSlideRight = $40; // Animates a row in by sliding from the right. Animates a row out by sliding towards the right.
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
@ -117,6 +117,8 @@ type
|
||||
function lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; message 'lclGetLabelRect:::';
|
||||
function lclGetIconRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; message 'lclGetIconRect:::';
|
||||
|
||||
procedure lclInsDelRow(Arow: Integer; inserted: Boolean); message 'lclInsDelRow::';
|
||||
|
||||
// NSTableViewDataSourceProtocol
|
||||
function numberOfRowsInTableView(tableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
|
||||
//procedure tableView_sortDescriptorsDidChange(tableView: NSTableView; oldDescriptors: NSArray); message 'tableView:sortDescriptorsDidChange:';
|
||||
@ -191,6 +193,7 @@ type
|
||||
function tableView_objectValueForTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): id; message 'tableView:objectValueForTableColumn:row:';
|
||||
procedure tableView_setObjectValue_forTableColumn_row(tableView: NSTableView; object_: id; tableColumn: NSTableColumn; row: NSInteger); message 'tableView:setObjectValue:forTableColumn:row:';
|
||||
function tableView_dataCellForTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): NSCell; message 'tableView:dataCellForTableColumn:row:';
|
||||
procedure lclInsDelRow(Arow: Integer; inserted: Boolean); override;
|
||||
end;
|
||||
|
||||
// View based NSTableView
|
||||
@ -234,6 +237,7 @@ type
|
||||
procedure checkboxAction(sender: NSButton); message 'checkboxAction:';
|
||||
|
||||
function lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; override;
|
||||
procedure lclInsDelRow(Arow: Integer; inserted: Boolean); override;
|
||||
end;
|
||||
|
||||
function AllocCocoaTableListView: TCocoaTableListView;
|
||||
@ -434,6 +438,13 @@ begin
|
||||
Result := BoundsRect;
|
||||
end;
|
||||
|
||||
procedure TCocoaTableListView.lclInsDelRow(Arow: Integer; inserted: Boolean);
|
||||
begin
|
||||
// a row has been inserted or removed
|
||||
// the following rows needs to be invalidated
|
||||
// as well as number of total items in the table should be marked as modified
|
||||
end;
|
||||
|
||||
function TCocoaTableListView.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -873,6 +884,11 @@ begin
|
||||
Result := btn;
|
||||
end;
|
||||
|
||||
procedure TCellCocoaTableListView.lclInsDelRow(Arow: Integer; inserted: Boolean);
|
||||
begin
|
||||
noteNumberOfRowsChanged;
|
||||
end;
|
||||
|
||||
function TCellCocoaTableListView.tableView_objectValueForTableColumn_row(
|
||||
tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): id;
|
||||
var
|
||||
@ -1144,5 +1160,16 @@ begin
|
||||
Result.Width := Round(lTableItemLV.textFrame.size.width);
|
||||
end;
|
||||
|
||||
procedure TViewCocoaTableListView.lclInsDelRow(Arow: Integer; inserted: Boolean);
|
||||
var
|
||||
rows: NSIndexSet;
|
||||
begin
|
||||
rows := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(Arow,1));
|
||||
if inserted then
|
||||
insertRowsAtIndexes_withAnimation(rows, 0)
|
||||
else
|
||||
removeRowsAtIndexes_withAnimation(rows, 0);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -1000,24 +1000,16 @@ var
|
||||
lCocoaLV: TCocoaListView;
|
||||
lTableLV: TCocoaTableListView;
|
||||
lclcb : TLCLListViewCallback;
|
||||
lStr: NSString;
|
||||
cols, rows: NSIndexSet;
|
||||
begin
|
||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||
WriteLn(Format('[TCocoaWSCustomListView.ItemDelete] AIndex=%d', [AIndex]));
|
||||
{$ENDIF}
|
||||
if not CheckParamsCb(lCocoaLV, lTableLV, lclcb, ALV) then Exit;
|
||||
//lTableLV.deleteItemForRow(AIndex);
|
||||
|
||||
// TListView item would actually be removed after call to ItemDelete()
|
||||
// thus have to decrease the count, as reloadDate might
|
||||
// request the updated itemCount immediately
|
||||
lclcb.tempItemsCountDelta := -1;
|
||||
lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, -1);
|
||||
|
||||
cols := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(0, lTableLV.numberOfColumns));
|
||||
rows := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(AIndex, lTableLV.numberOfRows - AIndex));
|
||||
lTableLV.reloadDataForRowIndexes_columnIndexes(rows, cols);
|
||||
lTableLV.lclInsDelRow(AIndex, false);
|
||||
|
||||
lclcb.tempItemsCountDelta := 0;
|
||||
end;
|
||||
@ -1082,39 +1074,16 @@ class procedure TCocoaWSCustomListView.ItemInsert(const ALV: TCustomListView;
|
||||
var
|
||||
lCocoaLV: TCocoaListView;
|
||||
lTableLV: TCocoaTableListView;
|
||||
i, lColumnCount: Integer;
|
||||
lColumn: NSTableColumn;
|
||||
lStr: string;
|
||||
lNSStr: NSString;
|
||||
lclcb: TLCLListViewCallback;
|
||||
cols, rows: NSIndexSet;
|
||||
begin
|
||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex]));
|
||||
{$ENDIF}
|
||||
if not CheckParamsCb(lCocoaLV, lTableLV, lclcb, ALV) then Exit;
|
||||
lColumnCount := lTableLV.tableColumns.count();
|
||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount]));
|
||||
{$ENDIF}
|
||||
{for i := 0 to lColumnCount-1 do
|
||||
begin
|
||||
lColumn := lTableLV.tableColumns.objectAtIndex(i);
|
||||
if i = 0 then
|
||||
lStr := AItem.Caption
|
||||
else if (i-1 < AItem.SubItems.Count) then
|
||||
lStr := AItem.SubItems.Strings[i-1]
|
||||
else
|
||||
lStr := '';
|
||||
lNSStr := NSStringUTF8(lStr);
|
||||
lTableLV.setStringValue_forCol_row(lNSStr, i, AIndex);
|
||||
lNSStr.release;
|
||||
end;}
|
||||
|
||||
lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, 1);
|
||||
|
||||
cols := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(0, lTableLV.numberOfColumns));
|
||||
rows := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(AIndex - 1, lTableLV.numberOfRows - AIndex));
|
||||
lTableLV.reloadDataForRowIndexes_columnIndexes(rows, cols);
|
||||
lTableLV.lclInsDelRow(AIndex, true);
|
||||
|
||||
lTableLV.sizeToFit();
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user