From: Michael Curran Date: Mon, 7 Dec 2009 00:05:15 +0000 (+1100) Subject: These changes try to fix the issue where NVDA will not show a new blank line on a... X-Git-Tag: jpdev130418~2847 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7f9d5600e50d19ea0b48044d17b00d2962642b1a;p=nvdajp%2Fnvdajp.git These changes try to fix the issue where NVDA will not show a new blank line on a braille display when pressing enter in a Microsoft Word document or MSHTML edit control. Specific changes: * braille.TextInfoRegion.update: TextInfo implementations such as for MS Word and MSHTML can only expand to line if dealing with the caret. So rather then making a copy of the caret TextInfo and then expanding to line, use the copy as the caret reference and expand the original TextInfo to line. * Microsoft Word document TextInfo: remove _expandToLine method and replace it with a better implementation (calling it _expandToLineFromCaret, for better readability). This method uses caret and window coordinates and sets it to the line containing the caret. I.e. from the left edge of the window at the height of the caret to the right side of the window at the height of the caret. The advantage of this new way is that we no longer fiddle with MS Word's actual selection, which means no flickering, and it also will stop possible typing errors if typing fast when using braille, due to the above braille change. The one disadvantage is that now when arrowing by line in a table, NVDA will report the line relative to the document, rather than relative to the current table cell (i.e. it will read the entire row). We may be able to fix this in the future by not allowing the use of this way when in a table, though finding this out is quite costly. Please test Microsoft Word cursoring a lot, and report any bugs created by this change. --- diff --git a/source/NVDAObjects/window/winword.py b/source/NVDAObjects/window/winword.py index 5ed8066da..8f8d9f99c 100755 --- a/source/NVDAObjects/window/winword.py +++ b/source/NVDAObjects/window/winword.py @@ -97,13 +97,16 @@ class WordDocumentTextInfo(textInfos.TextInfo): - def _expandToLine(self,rangeObj): - sel=self.obj.WinwordSelectionObject - oldSel=sel.range - sel.SetRange(rangeObj.start,rangeObj.end) - sel.Expand(wdLine) - rangeObj.SetRange(sel.Start,sel.End) - sel.SetRange(oldSel.Start,oldSel.End) + def _expandToLineFromCaret(self): + info=winUser.getGUIThreadInfo(self.obj.windowThreadID) + caretPoint=ctypes.wintypes.POINT(info.rcCaret.left,info.rcCaret.top) + ctypes.windll.user32.ClientToScreen(self.obj.windowHandle,ctypes.byref(caretPoint)) + caretY=caretPoint.y + clientLeft,clientTop,clientWidth,clientHeight=self.obj.location + tempRange=self.obj.WinwordDocumentObject.application.activeWindow.rangeFromPoint(clientLeft,caretY) + self._rangeObj.Start=tempRange.Start + tempRange=self.obj.WinwordDocumentObject.application.activeWindow.rangeFromPoint(clientLeft+clientWidth,caretY) + self._rangeObj.End=tempRange.Start def _getFormatFieldAtRange(self,range,formatConfig): formatField=textInfos.FormatField() @@ -221,7 +224,7 @@ class WordDocumentTextInfo(textInfos.TextInfo): if unit==textInfos.UNIT_LINE and self.basePosition not in (textInfos.POSITION_CARET,textInfos.POSITION_SELECTION): unit=textInfos.UNIT_SENTENCE if unit==textInfos.UNIT_LINE: - self._expandToLine(self._rangeObj) + self._expandToLineFromCaret() elif unit==textInfos.UNIT_CHARACTER: self._rangeObj.moveEnd(wdCharacter,1) elif unit in NVDAUnitsToWordUnits: diff --git a/source/braille.py b/source/braille.py index 7470d1906..5cf9cf2c4 100644 --- a/source/braille.py +++ b/source/braille.py @@ -297,10 +297,12 @@ class TextInfoRegion(Region): log.debugWarning("", exc_info=True) def update(self): - caret = self._getSelection() - caret.collapse() + # HACK: Some TextInfos only support UNIT_LINE properly if they are based on POSITION_CARET, + # so use the original caret TextInfo for line and copy for caret. + self._line = line = self._getSelection() + line.collapse() + caret = line.copy() # Get the line at the caret. - self._line = line = caret.copy() line.expand(textInfos.UNIT_LINE) # Not all text APIs support offsets, so we can't always get the offset of the caret relative to the start of the line. # Therefore, grab the line in two parts.