sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx | 41 +++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-)
New commits: commit 623c8502a5af5c0061f5285e8c0c4ac973990b7c Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Mar 28 15:54:52 2022 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Mar 29 06:53:17 2022 +0200 sc a11y: Fix + port events for row/col ins/del Previously, incorrect indices were sent when inserting or deleting rows or columns from a Calc spreadsheet, e.g. when deleting rows 4 to 12 (i.e. rows with indices 3 to 11), the pyatspi script from Change-Id I30821a5acafa4f3d1dafdfc219f3b4568d9a6e89, "a11y: Add new table model change types for row/col insertion/del" would have this output: > object:row-deleted(12, 10, 0) > source: [table | Sheet Sheet1] > host_application: [application | soffice] > sender: [application | soffice] > object:column-deleted(0, 16384, 0) > source: [table | Sheet Sheet1] > host_application: [application | soffice] > sender: [application | soffice] i.e. LO would announce the deletion of all columns and the deletion of 10 rows, starting at index 12, which is obviously wrong. For the case where rows or columns have been deleted, the range in the update hint passed to `ScAccessibleSpreadsheet::Notify` is the spreadhseet range after the removed rows/columns; for the case where rows or columns have been inserted, the range in the update hint is from the first inserted row/column to the last row/column in the spreadsheet. So, calculate the indices of the actually inserted/deleted rows/columns from that. Also, switch to using the table model change event types introduced in the change mentioned above. With this in place, output of the Python script for the above case now is as expected (9 rows, starting at row index 3, have been deleted): > object:row-deleted(3, 9, 0) > source: [table | Sheet Sheet1] > host_application: [application | soffice] > sender: [application | soffice] Deletion of non-contiguous row/column ranges (e.g. deleting columns A to C and F to H) also results in the correct events getting sent, since `ScAccessibleSpreadsheet::Notify` gets called multiple times, once for each contiguous cell range. Change-Id: I6e61eb45f255741661b29efb72394029109d682e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132220 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx index 1f6d899c9db5..09d8ad605043 100644 --- a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx +++ b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx @@ -418,6 +418,11 @@ void ScAccessibleSpreadsheet::Notify( SfxBroadcaster& rBC, const SfxHint& rHint // ignore next SfxHintId::ScDataChanged notification mbDelIns = true; + SCROW nFirstRow = -1; + SCROW nLastRow = -1; + SCCOL nFirstCol = -1; + SCCOL nLastCol = -1; + sal_Int16 nId(0); SCCOL nX(pRefHint->GetDx()); SCROW nY(pRefHint->GetDy()); @@ -425,33 +430,47 @@ void ScAccessibleSpreadsheet::Notify( SfxBroadcaster& rBC, const SfxHint& rHint if ((nX < 0) || (nY < 0)) { assert(!((nX < 0) && (nY < 0)) && "should not be possible to remove row and column at the same time"); - nId = AccessibleTableModelChangeType::DELETE; + + // Range in the update hint is the range after the removed rows/columns; + // calculate indices for the removed ones from that if (nX < 0) { - nX = -nX; - nY = aRange.aEnd.Row() - aRange.aStart.Row(); + nId = AccessibleTableModelChangeType::COLUMNS_REMOVED; + nFirstCol = aRange.aStart.Col() + nX; + nLastCol = aRange.aStart.Col() - 1; } else { - nY = -nY; - nX = aRange.aEnd.Col() - aRange.aStart.Col(); + nId = AccessibleTableModelChangeType::ROWS_REMOVED; + nFirstRow = aRange.aStart.Row() + nY; + nLastRow = aRange.aStart.Row() - 1; } } else if ((nX > 0) || (nY > 0)) { assert(!((nX > 0) && (nY > 0)) && "should not be possible to add row and column at the same time"); - nId = AccessibleTableModelChangeType::INSERT; - nX = aRange.aEnd.Col() - aRange.aStart.Col(); + + // Range in the update hint is from first inserted row/column to last one in spreadsheet; + // calculate indices for the inserted ones from that + if (nX > 0) + { + nId = AccessibleTableModelChangeType::COLUMNS_INSERTED; + nFirstCol = aRange.aStart.Col(); + nLastCol = aRange.aStart.Col() + nX - 1; + } + else + { + nId = AccessibleTableModelChangeType::ROWS_INSERTED; + nFirstRow = aRange.aStart.Row(); + nLastRow = aRange.aStart.Row() + nY -1; + } } else { assert(false && "is it a deletion or an insertion?"); } - CommitTableModelChange(pRefHint->GetRange().aStart.Row(), - pRefHint->GetRange().aStart.Col(), - pRefHint->GetRange().aStart.Row() + nY, - pRefHint->GetRange().aStart.Col() + nX, nId); + CommitTableModelChange(nFirstRow, nFirstCol, nLastRow, nLastCol, nId); AccessibleEventObject aEvent; aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;