Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS Word documents: report when headings are collapsed in both speech and braille. #17499

Merged
merged 10 commits into from
Jan 20, 2025
1 change: 1 addition & 0 deletions nvdaHelper/remote/WinWord/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ constexpr int wdDISPID_PAGESETUP_PAGEWIDTH = 105;
constexpr int wdDISPID_PAGESETUP_SECTIONSTART = 114;
constexpr int wdDISPID_PAGESETUP_TEXTCOLUMNS = 119;
constexpr int wdDISPID_PARAGRAPH_OUTLINELEVEL = 202;
constexpr int wdDISPID_PARAGRAPH_COLLAPSED_STATE = 1203;
constexpr int wdDISPID_PARAGRAPH_RANGE = 0;
constexpr int wdDISPID_PARAGRAPH_STYLE = 100;
constexpr int wdDISPID_PARAGRAPHFORMAT_ALIGNMENT = 101;
Expand Down
6 changes: 6 additions & 0 deletions nvdaHelper/remote/winword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ int generateHeadingXML(IDispatch* pDispatchParagraph, IDispatch* pDispatchParagr
int headingLevel=getHeadingLevelFromParagraph(pDispatchParagraph);
if(!headingLevel) return 0;
XMLStream<<L"<control role=\"heading\" level=\""<<headingLevel<<L"\" ";
// Expose the collapsed state of the heading
bool isCollapsed=false;
michaelDCurran marked this conversation as resolved.
Show resolved Hide resolved
_com_dispatch_raw_propget(pDispatchParagraph, wdDISPID_PARAGRAPH_COLLAPSED_STATE, VT_BOOL, &isCollapsed);
if(isCollapsed) {
XMLStream<<L"collapsedState=\"true\" ";
}
michaelDCurran marked this conversation as resolved.
Show resolved Hide resolved
if(pDispatchParagraphRange) {
long iVal=0;
if(_com_dispatch_raw_propget(pDispatchParagraphRange,wdDISPID_RANGE_START,VT_I4,&iVal)==S_OK&&iVal>=startOffset) {
Expand Down
18 changes: 9 additions & 9 deletions source/NVDAObjects/UIA/wordDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,15 @@ def _getFormatFieldAtRange(self, textRange, formatConfig, ignoreMixedValues=Fals
)
if isinstance(textColumnNumber, int):
formatField.field["text-column-number"] = textColumnNumber
expandCollapseState = UIARemote.msWord_getCustomAttributeValue(
docElement,
textRange,
UIACustomAttributeID.EXPAND_COLLAPSE_STATE,
)
if expandCollapseState == EXPAND_COLLAPSE_STATE.COLLAPSED:
formatField.field["collapsed"] = True
elif expandCollapseState == EXPAND_COLLAPSE_STATE.EXPANDED:
formatField.field["collapsed"] = False
expandCollapseState = UIARemote.msWord_getCustomAttributeValue(
docElement,
textRange,
UIACustomAttributeID.EXPAND_COLLAPSE_STATE,
)
if expandCollapseState == EXPAND_COLLAPSE_STATE.COLLAPSED:
formatField.field["collapsed"] = True
elif expandCollapseState == EXPAND_COLLAPSE_STATE.EXPANDED:
formatField.field["collapsed"] = False
return formatField

def _getIndentValueDisplayString(self, val: float) -> str:
Expand Down
5 changes: 5 additions & 0 deletions source/NVDAObjects/window/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@ def _normalizeControlField(self, field):
field["name"] = name
field["alwaysReportName"] = True
field["role"] = controlTypes.Role.FRAME
collapsedState = field.pop("collapsedState", None) == "true"
if collapsedState:
michaelDCurran marked this conversation as resolved.
Show resolved Hide resolved
if "states" not in field:
field["states"] = set()
field["states"].add(controlTypes.State.COLLAPSED)
newField = LazyControlField_RowAndColumnHeaderText(self)
newField.update(field)
return newField
Expand Down
3 changes: 1 addition & 2 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,7 @@ def getFormatFieldBraille(field, fieldCache, isAtStart, formatConfig):
textList.append(_("h%s") % headingLevel)
collapsed = field.get("collapsed")
if collapsed:
SaschaCowley marked this conversation as resolved.
Show resolved Hide resolved
# Translators: Displayed in braille for collapsed text
textList.append(_("+"))
textList.append(positiveStateLabels[controlTypes.State.COLLAPSED])
if formatConfig["reportLinks"]:
link = field.get("link")
oldLink = fieldCache.get("link")
Expand Down
4 changes: 1 addition & 3 deletions source/speech/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -2632,9 +2632,7 @@ def getFormatFieldSpeech( # noqa: C901
)
or collapsed != oldCollapsed
):
# Translators: collapsed text (E.g. a collapsed heading in MS Word)
text = _("collapsed")
textList.append(text)
textList.append(State.COLLAPSED.displayString)
if formatConfig["reportStyle"]:
style = attrs.get("style")
oldStyle = attrsCache.get("style") if attrsCache is not None else None
Expand Down
2 changes: 1 addition & 1 deletion user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To use this feature, "allow NVDA to control the volume of other applications" mu
* Automatic language switching is now supported when using Microsoft Speech API version 5 (SAPI5) and Microsoft Speech Platform voices. (#17146, @gexgd0419)
* NVDA can now be configured to speak the current line or paragraph when navigating with braille navigation keys. (#17053, @nvdaes)
* In Word, the selection update is now reported when using Word commands to extend or reduce the selection (`f8` or `shift+f8`). (#3293, @CyrilleB79)
* In Word 16.0.18226 and higher, NVDA will now report if a heading is collapsed in both speech and braille. (#17499)
* In Microsoft Word 16.0.18226 and higher, NVDA will now report if a heading is collapsed in both speech and braille. (#17499)
SaschaCowley marked this conversation as resolved.
Show resolved Hide resolved
michaelDCurran marked this conversation as resolved.
Show resolved Hide resolved

### Changes

Expand Down