Repository: nvaccess/nvda

Issue:
LibreOffice Calc: NVDA reports "not selected" for every cell
In NVDA 2018.4beta2, NVDA reports "not selected" for every cell in Calc.

### Steps to reproduce:
1. Open application Calc.
2. Press downArrow to move through cells.

#### Actual behavior:
NVDA reports "not selected" and Cell coordinates.

#### Expected behavior:
NVDA reports Cell coordinates only.

P.S. (If this is the default behavior that NVDA reports "not selected). Could we add an toggle option to turn it on / off?)

### System configuration:

#### NVDA Installed/portable/running from source:
Installed.

#### NVDA version:
2018.4beta2

#### Windows version:
6.1.7601 service pack 1

#### Name and version of other software in use when reproducing the issue:

LibreOffice 6.0.7.3

### Other questions:

#### Does the issue still occur after restarting your PC?
Yes.

#### Have you tried any other versions of NVDA?
Yes. This issue does not occur in NVDA 2018.3.2.



Discussion:
Most likely caused by #8898 

Cc @michaelDCurran 

Resolving patch:
diff --git a/source/NVDAObjects/IAccessible/__init__.py b/source/NVDAObjects/IAccessible/__init__.py
--- a/source/NVDAObjects/IAccessible/__init__.py
+++ b/source/NVDAObjects/IAccessible/__init__.py
@@ -1250,7 +1250,7 @@ def getSelectedItemsCount(self,maxCount):
 		except (COMError,NotImplementedError) as e:
 			log.debug("Cannot fetch selected items count using accSelection, %s"%e)
 			pass
-		if self.IAccessibleTable2Object:
+		if hasattr(self,'IAccessibleTable2Object'):
 			try:
 				return self.IAccessibleTable2Object.nSelectedCells
 			except COMError as e:
diff --git a/source/appModules/soffice.py b/source/appModules/soffice.py
--- a/source/appModules/soffice.py
+++ b/source/appModules/soffice.py
@@ -216,8 +216,20 @@ def _get_states(self):
 		states=super(SymphonyTableCell,self).states
 		states.discard(controlTypes.STATE_MULTILINE)
 		states.discard(controlTypes.STATE_EDITABLE)
+		if controlTypes.STATE_SELECTED not in states and {controlTypes.STATE_FOCUSED, controlTypes.STATE_SELECTABLE}.issubset(states):
+			# #8988: Cells in Libre Office do not have the selected state when a single cell is selected (i.e. has focus).
+			# Since #8898, the negative selected state is announced for table cells with the selectable state.
+			states.add(controlTypes.STATE_SELECTED)
 		return states
 
+class SymphonyTable(IAccessible):
+
+	def getSelectedItemsCount(self,maxCount=2):
+		# #8988: Neither accSelection nor IAccessibleTable2 is implemented on the LibreOffice tables.
+		# Returning 1 will suppress redundant selected announcements,
+		# while having the drawback of never announcing selected for selected cells.
+		return 1
+
 class SymphonyParagraph(SymphonyText):
 	"""Removes redundant information that can be retreaved in other ways."""
 	value=None
@@ -231,6 +243,8 @@ def chooseNVDAObjectOverlayClasses(self, obj, clsList):
 		if isinstance(obj, IAccessible) and windowClassName in ("SALTMPSUBFRAME", "SALSUBFRAME", "SALFRAME"):
 			if role==controlTypes.ROLE_TABLECELL:
 				clsList.insert(0, SymphonyTableCell)
+			elif role==controlTypes.ROLE_TABLE:
+				clsList.insert(0, SymphonyTable)
 			elif hasattr(obj, "IAccessibleTextObject"):
 				clsList.insert(0, SymphonyText)
 			if role==controlTypes.ROLE_PARAGRAPH:


Test patch: