mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-14 12:40:02 +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;
|
NSUserInterfaceItemIdentifier = NSString;
|
||||||
|
|
||||||
|
NSTableViewAnimationOptions = NSUInteger;
|
||||||
|
|
||||||
NSTableViewFix = objccategory external (NSTableView)
|
NSTableViewFix = objccategory external (NSTableView)
|
||||||
// 10.7
|
// 10.7
|
||||||
function rowForView(AView: NSView): NSInteger; message 'rowForView:';
|
function rowForView(AView: NSView): NSInteger; message 'rowForView:';
|
||||||
function columnForView(AView: NSView): NSInteger; message 'columnForView:';
|
function columnForView(AView: NSView): NSInteger; message 'columnForView:';
|
||||||
function makeViewWithIdentifier_owner(identifier_: NSUserInterfaceItemIdentifier; owner: id): NSView ; message 'makeViewWithIdentifier:owner:';
|
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:';
|
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;
|
end;
|
||||||
|
|
||||||
{// private since 10.5, doesn't seam to do anything in 10.10
|
{// private since 10.5, doesn't seam to do anything in 10.10
|
||||||
@ -177,6 +183,27 @@ const
|
|||||||
const
|
const
|
||||||
NSKeyCodeTab = 48;
|
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
|
implementation
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -117,6 +117,8 @@ type
|
|||||||
function lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; message 'lclGetLabelRect:::';
|
function lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; message 'lclGetLabelRect:::';
|
||||||
function lclGetIconRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; message 'lclGetIconRect:::';
|
function lclGetIconRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; message 'lclGetIconRect:::';
|
||||||
|
|
||||||
|
procedure lclInsDelRow(Arow: Integer; inserted: Boolean); message 'lclInsDelRow::';
|
||||||
|
|
||||||
// NSTableViewDataSourceProtocol
|
// NSTableViewDataSourceProtocol
|
||||||
function numberOfRowsInTableView(tableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
|
function numberOfRowsInTableView(tableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
|
||||||
//procedure tableView_sortDescriptorsDidChange(tableView: NSTableView; oldDescriptors: NSArray); message 'tableView:sortDescriptorsDidChange:';
|
//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:';
|
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:';
|
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:';
|
function tableView_dataCellForTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): NSCell; message 'tableView:dataCellForTableColumn:row:';
|
||||||
|
procedure lclInsDelRow(Arow: Integer; inserted: Boolean); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// View based NSTableView
|
// View based NSTableView
|
||||||
@ -234,6 +237,7 @@ type
|
|||||||
procedure checkboxAction(sender: NSButton); message 'checkboxAction:';
|
procedure checkboxAction(sender: NSButton); message 'checkboxAction:';
|
||||||
|
|
||||||
function lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; override;
|
function lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; override;
|
||||||
|
procedure lclInsDelRow(Arow: Integer; inserted: Boolean); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AllocCocoaTableListView: TCocoaTableListView;
|
function AllocCocoaTableListView: TCocoaTableListView;
|
||||||
@ -434,6 +438,13 @@ begin
|
|||||||
Result := BoundsRect;
|
Result := BoundsRect;
|
||||||
end;
|
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;
|
function TCocoaTableListView.acceptsFirstResponder: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
@ -873,6 +884,11 @@ begin
|
|||||||
Result := btn;
|
Result := btn;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCellCocoaTableListView.lclInsDelRow(Arow: Integer; inserted: Boolean);
|
||||||
|
begin
|
||||||
|
noteNumberOfRowsChanged;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCellCocoaTableListView.tableView_objectValueForTableColumn_row(
|
function TCellCocoaTableListView.tableView_objectValueForTableColumn_row(
|
||||||
tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): id;
|
tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): id;
|
||||||
var
|
var
|
||||||
@ -1144,5 +1160,16 @@ begin
|
|||||||
Result.Width := Round(lTableItemLV.textFrame.size.width);
|
Result.Width := Round(lTableItemLV.textFrame.size.width);
|
||||||
end;
|
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.
|
end.
|
||||||
|
|
||||||
|
@ -1000,24 +1000,16 @@ var
|
|||||||
lCocoaLV: TCocoaListView;
|
lCocoaLV: TCocoaListView;
|
||||||
lTableLV: TCocoaTableListView;
|
lTableLV: TCocoaTableListView;
|
||||||
lclcb : TLCLListViewCallback;
|
lclcb : TLCLListViewCallback;
|
||||||
lStr: NSString;
|
|
||||||
cols, rows: NSIndexSet;
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
WriteLn(Format('[TCocoaWSCustomListView.ItemDelete] AIndex=%d', [AIndex]));
|
WriteLn(Format('[TCocoaWSCustomListView.ItemDelete] AIndex=%d', [AIndex]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if not CheckParamsCb(lCocoaLV, lTableLV, lclcb, ALV) then Exit;
|
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.tempItemsCountDelta := -1;
|
||||||
lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, -1);
|
lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, -1);
|
||||||
|
|
||||||
cols := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(0, lTableLV.numberOfColumns));
|
lTableLV.lclInsDelRow(AIndex, false);
|
||||||
rows := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(AIndex, lTableLV.numberOfRows - AIndex));
|
|
||||||
lTableLV.reloadDataForRowIndexes_columnIndexes(rows, cols);
|
|
||||||
|
|
||||||
lclcb.tempItemsCountDelta := 0;
|
lclcb.tempItemsCountDelta := 0;
|
||||||
end;
|
end;
|
||||||
@ -1082,39 +1074,16 @@ class procedure TCocoaWSCustomListView.ItemInsert(const ALV: TCustomListView;
|
|||||||
var
|
var
|
||||||
lCocoaLV: TCocoaListView;
|
lCocoaLV: TCocoaListView;
|
||||||
lTableLV: TCocoaTableListView;
|
lTableLV: TCocoaTableListView;
|
||||||
i, lColumnCount: Integer;
|
|
||||||
lColumn: NSTableColumn;
|
|
||||||
lStr: string;
|
|
||||||
lNSStr: NSString;
|
|
||||||
lclcb: TLCLListViewCallback;
|
lclcb: TLCLListViewCallback;
|
||||||
cols, rows: NSIndexSet;
|
|
||||||
begin
|
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 CheckParamsCb(lCocoaLV, lTableLV, lclcb, ALV) then Exit;
|
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);
|
lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, 1);
|
||||||
|
|
||||||
cols := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(0, lTableLV.numberOfColumns));
|
lTableLV.lclInsDelRow(AIndex, true);
|
||||||
rows := NSIndexSet.indexSetWithIndexesInRange(NSMakeRange(AIndex - 1, lTableLV.numberOfRows - AIndex));
|
|
||||||
lTableLV.reloadDataForRowIndexes_columnIndexes(rows, cols);
|
|
||||||
|
|
||||||
lTableLV.sizeToFit();
|
lTableLV.sizeToFit();
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user