Skip to content

Commit

Permalink
Report section numbers in MS word.
Browse files Browse the repository at this point in the history
Fixes #5946. When reading through a document, report when the section
number changes. This is tied to the report page number setting
(available in document formatting settings dialog)
  • Loading branch information
feerrenrut committed Oct 24, 2016
1 parent a1cbaf7 commit ff2841e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nvdaHelper/remote/WinWord/Constants.h
@@ -1,7 +1,7 @@
/*
This file is a part of the NVDA project.
URL: http://www.nvda-project.org/
Copyright 2006-2010 NVDA contributers.
Copyright 2016 NVDA contributers.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2.0, as published by
the Free Software Foundation.
Expand All @@ -12,6 +12,8 @@ This license can be found at:
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/

#pragma once

// See https://github.com/nvaccess/nvda/wiki/Using-COM-with-NVDA-and-Microsoft-Word
constexpr int wdDISPID_APPLICATION_ISSANDBOX = 492;
constexpr int wdDISPID_APPLICATION_SCREENUPDATING = 26;
Expand Down Expand Up @@ -145,6 +147,7 @@ constexpr int wdCollapseEnd = 0;
constexpr int wdCollapseStart = 1;

constexpr int wdActiveEndAdjustedPageNumber = 1;
constexpr int wdActiveEndSectionNumber = 2;
constexpr int wdFirstCharacterLineNumber = 10;
constexpr int wdWithInTable = 12;
constexpr int wdStartOfRangeRowNumber = 13;
Expand Down
10 changes: 10 additions & 0 deletions nvdaHelper/remote/winword.cpp
Expand Up @@ -781,6 +781,15 @@ void winword_getTextInRange_helper(HWND hwnd, winword_getTextInRange_args* args)
}
}

const auto shouldReportSections = (initialFormatConfig&formatConfig_reportPage);
if(shouldReportSections) {
int sectionNumber = -1;
auto res = _com_dispatch_raw_method( pDispatchRange, wdDISPID_RANGE_INFORMATION, DISPATCH_PROPERTYGET, VT_I4, &sectionNumber, L"\x0003", wdActiveEndSectionNumber);
if( S_OK == res && sectionNumber >= 0) {
initialFormatAttribsStream << L"section-number=\""<<sectionNumber << "\" ";
}
}

bool firstLoop=true;
//Walk the range from the given start to end by characterFormatting or word units
//And grab any text and formatting and generate appropriate xml
Expand Down Expand Up @@ -860,6 +869,7 @@ void winword_getTextInRange_helper(HWND hwnd, winword_getTextInRange_args* args)

{ // scope for xmlAttribsFormatConfig
const auto xmlAttribsFormatConfig = formatConfig&(~curDisabledFormatConfig);

generateXMLAttribsForFormatting(pDispatchRange,chunkStartOffset,chunkEndOffset,xmlAttribsFormatConfig,XMLStream);
const auto shouldReportLinks = (xmlAttribsFormatConfig&formatConfig_reportLinks);
if( shouldReportLinks && currentFields.hasLinks(chunkStartOffset, chunkEndOffset) ) {
Expand Down
7 changes: 7 additions & 0 deletions source/speech.py
Expand Up @@ -1139,6 +1139,13 @@ def getFormatFieldSpeech(attrs,attrsCache=None,formatConfig=None,unit=None,extra
# %s will be replaced with the page number.
text=_("page %s")%pageNumber
textList.append(text)
sectionNumber=attrs.get("section-number")
oldSectionNumber=attrsCache.get("section-number") if attrsCache is not None else None
if sectionNumber and sectionNumber!=oldSectionNumber:
# Translators: Indicates the section number in a document.
# %s will be replaced with the section number.
text=_("section %s")%sectionNumber
textList.append(text)
if formatConfig["reportHeadings"]:
headingLevel=attrs.get("heading-level")
oldHeadingLevel=attrsCache.get("heading-level") if attrsCache is not None else None
Expand Down

0 comments on commit ff2841e

Please sign in to comment.