OSDN Git Service

These changes try to fix the issue where NVDA will not show a new blank line on a...
authorMichael Curran <mick@kulgan.net>
Mon, 7 Dec 2009 00:05:15 +0000 (11:05 +1100)
committerMichael Curran <mick@kulgan.net>
Mon, 7 Dec 2009 00:05:15 +0000 (11:05 +1100)
      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.

source/NVDAObjects/window/winword.py
source/braille.py

index 5ed8066..8f8d9f9 100755 (executable)
@@ -97,13 +97,16 @@ class WordDocumentTextInfo(textInfos.TextInfo):
 \r
 \r
 \r
-       def _expandToLine(self,rangeObj):\r
-               sel=self.obj.WinwordSelectionObject\r
-               oldSel=sel.range\r
-               sel.SetRange(rangeObj.start,rangeObj.end)\r
-               sel.Expand(wdLine)\r
-               rangeObj.SetRange(sel.Start,sel.End)\r
-               sel.SetRange(oldSel.Start,oldSel.End)\r
+       def _expandToLineFromCaret(self):\r
+               info=winUser.getGUIThreadInfo(self.obj.windowThreadID)\r
+               caretPoint=ctypes.wintypes.POINT(info.rcCaret.left,info.rcCaret.top)\r
+               ctypes.windll.user32.ClientToScreen(self.obj.windowHandle,ctypes.byref(caretPoint))\r
+               caretY=caretPoint.y\r
+               clientLeft,clientTop,clientWidth,clientHeight=self.obj.location\r
+               tempRange=self.obj.WinwordDocumentObject.application.activeWindow.rangeFromPoint(clientLeft,caretY)\r
+               self._rangeObj.Start=tempRange.Start\r
+               tempRange=self.obj.WinwordDocumentObject.application.activeWindow.rangeFromPoint(clientLeft+clientWidth,caretY)\r
+               self._rangeObj.End=tempRange.Start\r
 \r
        def _getFormatFieldAtRange(self,range,formatConfig):\r
                formatField=textInfos.FormatField()\r
@@ -221,7 +224,7 @@ class WordDocumentTextInfo(textInfos.TextInfo):
                if unit==textInfos.UNIT_LINE and self.basePosition not in (textInfos.POSITION_CARET,textInfos.POSITION_SELECTION):\r
                        unit=textInfos.UNIT_SENTENCE\r
                if unit==textInfos.UNIT_LINE:\r
-                       self._expandToLine(self._rangeObj)\r
+                       self._expandToLineFromCaret()\r
                elif unit==textInfos.UNIT_CHARACTER:\r
                        self._rangeObj.moveEnd(wdCharacter,1)\r
                elif unit in NVDAUnitsToWordUnits:\r
index 7470d19..5cf9cf2 100644 (file)
@@ -297,10 +297,12 @@ class TextInfoRegion(Region):
                        log.debugWarning("", exc_info=True)\r
 \r
        def update(self):\r
-               caret = self._getSelection()\r
-               caret.collapse()\r
+               # HACK: Some TextInfos only support UNIT_LINE properly if they are based on POSITION_CARET,\r
+               # so use the original caret TextInfo for line and copy for caret.\r
+               self._line = line = self._getSelection()\r
+               line.collapse()\r
+               caret = line.copy()\r
                # Get the line at the caret.\r
-               self._line = line = caret.copy()\r
                line.expand(textInfos.UNIT_LINE)\r
                # Not all text APIs support offsets, so we can't always get the offset of the caret relative to the start of the line.\r
                # Therefore, grab the line in two parts.\r