From c78b33853a6ffabbc5cd81770bdd133356ac1591 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Sun, 21 Jul 2024 23:16:04 +0800 Subject: [PATCH 1/4] Cocoa/ListView: in vsReport, fix the issue of double-clicking to enter editing --- lcl/interfaces/cocoa/cocoatables.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lcl/interfaces/cocoa/cocoatables.pas b/lcl/interfaces/cocoa/cocoatables.pas index deeaee8843..b9a050cc5a 100644 --- a/lcl/interfaces/cocoa/cocoatables.pas +++ b/lcl/interfaces/cocoa/cocoatables.pas @@ -652,9 +652,10 @@ begin Result := 0; end; +// TListView in LCL already supports editing, return False to avoid conflicts function TCocoaTableListView.tableView_shouldEditTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): Boolean; begin - Result := not readOnly; + Result:= False; end; function TCocoaTableListView.selectionShouldChangeInTableView( From 16f03ef620690ee1a3474ec632d1db9fffd14553 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Wed, 24 Jul 2024 23:11:26 +0800 Subject: [PATCH 2/4] Cocoa/ListView: in vsReport, fix the issue RowHeight and Spacing related --- lcl/interfaces/cocoa/cocoawscomctrls.pas | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index f723d90301..610ad38600 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -895,23 +895,38 @@ procedure TCocoaWSListView_TableViewHandler.SetDefaultItemHeight( const AValue: Integer); begin if AValue > 0 then - _tableView.setRowHeight(AValue); + _tableView.CustomRowHeight:= AValue; // setRowSizeStyle could be used here but is available only in 10.7+ end; procedure TCocoaWSListView_TableViewHandler.SetImageList( const AList: TListViewImageList; const AValue: TCustomImageListResolution); var + lclcb: TLCLListViewCallback; + lvil: TListViewImageList; spacing: NSSize; begin + lclcb:= getCallback; + if NOT Assigned(lclcb) then + Exit; + + if NOT lclcb.GetImageListType(lvil) then + Exit; + + if AList <> lvil then + Exit; + _tableView.lclSetImagesInCell(Assigned(AValue)); if NOT Assigned(AValue) then Exit; - if AValue.Height < _tableView.rowHeight-2 then - Exit; + spacing:= _tableView.intercellSpacing; - spacing.height:= _tableView.rowHeight / 3 + 2; + spacing.height:= AValue.Height / 3 + 2; + if spacing.height < 6 then + spacing.height:= 6 + else if spacing.height > 12 then + spacing.height:= 12; _tableView.setIntercellSpacing( spacing ); end; From 74415b6056a80a6f15bbb07c1c2573e69586a2ba Mon Sep 17 00:00:00 2001 From: rich2014 Date: Wed, 24 Jul 2024 23:12:44 +0800 Subject: [PATCH 3/4] Cocoa/ListView: in vsReport, fix the issue in ItemDisplayRect() --- lcl/interfaces/cocoa/cocoatables.pas | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoatables.pas b/lcl/interfaces/cocoa/cocoatables.pas index b9a050cc5a..21db8b653f 100644 --- a/lcl/interfaces/cocoa/cocoatables.pas +++ b/lcl/interfaces/cocoa/cocoatables.pas @@ -475,13 +475,23 @@ end; function TCocoaTableListView.lclGetLabelRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; begin - Result := BoundsRect; + Result:= BoundsRect; + Result.Top:= Result.Top - 2; + Result.Height:= Result.Height + 4; + if self.isImagesInCell then begin + Result.Left:= Result.Left + BoundsRect.Height; + end; end; function TCocoaTableListView.lclGetIconRect(ARow, ACol: Integer; const BoundsRect: TRect): TRect; begin - Result := BoundsRect; + if self.isImagesInCell then begin + Result:= BoundsRect; + Result.Width:= Result.Height; + end else begin + Result:= TRect.Empty; + end; end; procedure TCocoaTableListView.lclInsDelRow(Arow: Integer; inserted: Boolean); From ad8dd1dba2a943320f59d51924d89c941a2331f7 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Sat, 27 Jul 2024 00:34:54 +0800 Subject: [PATCH 4/4] Cocoa/ListView: in vsReport, fix the issues related to Multi Selection --- lcl/interfaces/cocoa/cocoatables.pas | 45 +++++++++++++++++------ lcl/interfaces/cocoa/cocoawscomctrls.pas | 47 ++++++++++++++++-------- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoatables.pas b/lcl/interfaces/cocoa/cocoatables.pas index 21db8b653f..98db343a95 100644 --- a/lcl/interfaces/cocoa/cocoatables.pas +++ b/lcl/interfaces/cocoa/cocoatables.pas @@ -73,10 +73,9 @@ type public callback: IListViewCallback; + selectingByProgram: Boolean; readOnly: Boolean; - beforeSel : NSIndexSet; - isImagesInCell: Boolean; isFirstColumnCheckboxes: Boolean; isOwnerDraw : Boolean; @@ -93,6 +92,8 @@ type // Own methods, mostly convenience methods function getIndexOfColumn(ACol: NSTableColumn): Integer; message 'getIndexOfColumn:'; procedure reloadDataForRow_column(ARow, ACol: NSInteger); message 'reloadDataForRow:column:'; + procedure selectRowIndexesByProgram( indexes: NSIndexSet ); + message 'selectRowIndexesByProgram:'; function initWithFrame(frameRect: NSRect): id; override; procedure dealloc; override; @@ -525,7 +526,6 @@ end; procedure TCocoaTableListView.dealloc; begin //if Assigned(Items) then FreeAndNil(Items); - if Assigned(beforeSel) then beforeSel.release; if Assigned(smallimages) then smallimages.release; // all contents is released automatically inherited dealloc; end; @@ -585,6 +585,13 @@ begin reloadDataForRowIndexes_columnIndexes(lRowSet, lColSet); end; +procedure TCocoaTableListView.selectRowIndexesByProgram( indexes: NSIndexSet ); +begin + self.selectingByProgram:= True; + self.selectRowIndexes_byExtendingSelection( indexes, False ); + self.selectingByProgram:= False; +end; + function TCocoaTableListView.initWithFrame(frameRect: NSRect): id; begin Result:=inherited initWithFrame(frameRect); @@ -671,8 +678,6 @@ end; function TCocoaTableListView.selectionShouldChangeInTableView( tableView: NSTableView): Boolean; begin - if Assigned(beforeSel) then beforeSel.release; - beforeSel := (NSIndexSet.alloc).initWithIndexSet(selectedRowIndexes); Result := true; end; @@ -874,16 +879,26 @@ var Unsel : NSIndexSet; rm : NSIndexSet; ad : NSIndexSet; + selectionIndexSet: NSMutableIndexSet; + lclcb: TLCLListViewCallback; begin - if Assigned(callback) then - begin - CompareIndexSets(beforeSel, selectedRowIndexes, rm, ad); + if NOT Assigned(callback) then + Exit; - NewSel := Self.selectedRow(); - callback.selectionChanged(NewSel, ad, rm); + lclcb:= TLCLListViewCallback( callback.GetCallbackObject ); - beforeSel.release; - beforeSel := nil; + if TCocoaListView(lclcb.Owner).initializing then + Exit; + + selectionIndexSet:= lclcb.selectionIndexSet; + CompareIndexSets(selectionIndexSet, selectedRowIndexes, rm, ad); + + NewSel := Self.selectedRow(); + callback.selectionChanged(NewSel, ad, rm); + + if NOT self.selectingByProgram then begin + selectionIndexSet.removeAllIndexes; + selectionIndexSet.addIndexes( self.selectedRowIndexes ); end; end; @@ -1016,8 +1031,14 @@ begin end; procedure TCellCocoaTableListView.backend_reloadData; +var + lclcb: TLCLListViewCallback; begin self.reloadData; + if Assigned(self.callback) then begin + lclcb:= TLCLListViewCallback( self.callback.GetCallbackObject ); + self.selectRowIndexesByProgram( lclcb.selectionIndexSet ); + end; end; procedure TCellCocoaTableListView.backend_onInit; diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index 610ad38600..7d80bc4657 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -163,7 +163,6 @@ type TLCLListViewCallback = class(TLCLCommonCallback, IListViewCallback) public listView: TCustomListView; - tempItemsCountDelta : Integer; isSetTextFromWS: Integer; // allows to suppress the notifation about text change // when initiated by Cocoa itself. @@ -382,10 +381,12 @@ type private _listView: TCocoaListView; _tableView: TCocoaTableListView; + private + function getCallback: TLCLListViewCallback; + procedure doReloadDataAfterDelete( AIndex: PtrInt ); public constructor Create( listView: TCocoaListView ); function getColumnFromIndex( const AIndex: Integer ): NSTableColumn; - function getCallback: TLCLListViewCallback; public // Column procedure ColumnDelete( const AIndex: Integer ); override; @@ -439,7 +440,7 @@ type _collectionView: TCocoaCollectionView; private function getCallback: TLCLListViewCallback; - procedure doReloadDataAfterDelete( AIndex: PtrInt); + procedure doReloadDataAfterDelete( AIndex: PtrInt ); public constructor Create( listView: TCocoaListView ); public @@ -523,6 +524,20 @@ begin Result:= TLCLListViewCallback( _tableView.lclGetCallback.GetCallbackObject ); end; +procedure TCocoaWSListView_TableViewHandler.doReloadDataAfterDelete( AIndex: PtrInt); +var + lclcb : TLCLListViewCallback; +begin + lclcb:= getCallback; + if NOT Assigned(lclcb) then + Exit; + + lclcb.checkedIdx.shiftIndexesStartingAtIndex_by( AIndex+1, -1); + lclcb.selectionIndexSet.shiftIndexesStartingAtIndex_by( AIndex+1, -1 ); + _tableView.selectRowIndexesByProgram( lclcb.selectionIndexSet ); + _tableView.lclInsDelRow(AIndex, false); +end; + procedure TCocoaWSListView_TableViewHandler.ColumnDelete( const AIndex: Integer); var @@ -715,17 +730,8 @@ end; procedure TCocoaWSListView_TableViewHandler.ItemDelete(const AIndex: Integer ); -var - lclcb : TLCLListViewCallback; begin - lclcb:= getCallback; - if NOT Assigned(lclcb) then - Exit; - - lclcb.tempItemsCountDelta:= -1; - lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, -1); - _tableView.lclInsDelRow(AIndex, false); - lclcb.tempItemsCountDelta := 0; + Application.QueueAsyncCall( doReloadDataAfterDelete, AIndex ); end; function TCocoaWSListView_TableViewHandler.ItemDisplayRect(const AIndex, @@ -783,8 +789,13 @@ begin if NOT Assigned(lclcb) then Exit; + if TCocoaListView(lclcb.Owner).initializing then + Exit; + lclcb.checkedIdx.shiftIndexesStartingAtIndex_by(AIndex, 1); + lclcb.selectionIndexSet.shiftIndexesStartingAtIndex_by( AIndex, 1 ); _tableView.lclInsDelRow(AIndex, true); + _tableView.selectRowIndexesByProgram( lclcb.selectionIndexSet ); _tableView.sizeToFit(); end; @@ -828,7 +839,7 @@ begin begin isSel := _tableView.selectedRowIndexes.containsIndex(row); if AIsSet and not isSel then - _tableView.selectRowIndexes_byExtendingSelection(NSIndexSet.indexSetWithIndex(row),false) + _tableView.selectRowIndexesByProgram( NSIndexSet.indexSetWithIndex(row) ) else if not AIsSet and isSel then _tableView.deselectRow(row); end; @@ -996,8 +1007,12 @@ begin if NOT Assigned(lclcb) then Exit; + if TCocoaListView(lclcb.Owner).initializing then + Exit; + if Assigned(lclcb.checkedIdx) then lclcb.checkedIdx.removeAllIndexes; + lclcb.selectionIndexSet.removeAllIndexes; _tableView.reloadData(); { //todo: lNSColumn.setSortDescriptorPrototype( @@ -1094,7 +1109,7 @@ begin Application.QueueAsyncCall( doReloadDataAfterDelete, AIndex ); end; -procedure TCocoaWSListView_CollectionViewHandler.doReloadDataAfterDelete( AIndex: PtrInt); +procedure TCocoaWSListView_CollectionViewHandler.doReloadDataAfterDelete( AIndex: PtrInt ); var lclcb : TLCLListViewCallback; begin @@ -2733,7 +2748,7 @@ end; function TLCLListViewCallback.ItemsCount: Integer; begin - Result:=listView.Items.Count + tempItemsCountDelta; + Result:= listView.Items.Count; end; function TLCLListViewCallback.GetItemTextAt(ARow, ACol: Integer;