~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/NVDAObjects/window/winword.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from comtypes import COMError, GUID
9
9
import comtypes.client
10
10
import comtypes.automation
 
11
import NVDAHelper
11
12
from logHandler import log
12
13
import winUser
13
14
import oleacc
14
15
import globalVars
15
16
import speech
16
 
from keyUtils import sendKey, key
17
17
import config
18
18
import textInfos
19
19
import textInfos.offsets
23
23
 
24
24
#Word constants
25
25
 
 
26
wdCollapseEnd=0
 
27
wdCollapseStart=1
26
28
#Indexing
27
29
wdActiveEndAdjustedPageNumber=1
28
30
wdActiveEndPageNumber=3
56
58
wdGoToAbsolute=1
57
59
wdGoToRelative=2
58
60
wdGoToNext=2
 
61
wdGoToPrevious=3
59
62
#GoTo - units
60
63
wdGoToPage=1
61
64
wdGoToLine=3
62
65
 
63
66
winwordWindowIid=GUID('{00020962-0000-0000-C000-000000000046}')
64
67
 
 
68
wm_winword_expandToLine=ctypes.windll.user32.RegisterWindowMessageW(u"wm_winword_expandToLine")
 
69
 
65
70
NVDAUnitsToWordUnits={
66
71
        textInfos.UNIT_CHARACTER:wdCharacter,
67
72
        textInfos.UNIT_WORD:wdWord,
99
104
                return True
100
105
 
101
106
        def _expandToLineAtCaret(self):
102
 
                sel=self.obj.WinwordSelectionObject
103
 
                oldSel=sel.range
104
 
                app=sel.application
105
 
                app.ScreenUpdating=False
106
 
                self._rangeObj.select()
107
 
                sel.Expand(wdLine)
108
 
                self._rangeObj=sel.range
109
 
                oldSel.Select()
110
 
                app.ScreenUpdating=True
 
107
                lineStart=ctypes.c_int()
 
108
                lineEnd=ctypes.c_int()
 
109
                res=NVDAHelper.localLib.nvdaInProcUtils_winword_expandToLine(self.obj.appModule.helperLocalBindingHandle,self.obj.windowHandle,self._rangeObj.start,ctypes.byref(lineStart),ctypes.byref(lineEnd))
 
110
                if res!=0:
 
111
                        raise ctypes.WinError(res)
 
112
                self._rangeObj.setRange(lineStart.value,lineEnd.value)
111
113
 
112
114
        def _getFormatFieldAtRange(self,range,formatConfig):
113
115
                formatField=textInfos.FormatField()
114
116
                fontObj=None
115
117
                paraFormatObj=None
 
118
                listString=range.ListFormat.ListString
 
119
                if listString and range.Paragraphs[1].range.start==range.start:
 
120
                        formatField['line-prefix']=listString
116
121
                if formatConfig["reportSpellingErrors"] and range.spellingErrors.count>0: 
117
122
                        formatField["invalid-spelling"]=True
118
123
                if formatConfig["reportLineNumber"]:
269
274
                        return False
270
275
 
271
276
        def collapse(self,end=False):
272
 
                a=self._rangeObj.Start
273
 
                b=self._rangeObj.end
274
 
                startOffset=min(a,b)
275
 
                endOffset=max(a,b)
276
 
                if not end:
277
 
                        offset=startOffset
278
 
                else:
279
 
                        offset=endOffset
280
 
                self._rangeObj.SetRange(offset,offset)
 
277
                if end:
 
278
                        oldEndOffset=self._rangeObj.end
 
279
                self._rangeObj.collapse(wdCollapseEnd if end else wdCollapseStart)
 
280
                if end and self._rangeObj.end<oldEndOffset:
 
281
                        raise RuntimeError
281
282
 
282
283
        def copy(self):
283
284
                return WordDocumentTextInfo(self.obj,None,_rangeObj=self._rangeObj)
302
303
                else:
303
304
                        moveFunc=self._rangeObj.Move
304
305
                res=moveFunc(unit,direction)
 
306
                #units higher than character and word expand to contain the last text plus the insertion point offset in the document
 
307
                #However move from a character before will incorrectly move to this offset which makes move/expand contridictory to each other
 
308
                #Make sure that move fails if it lands on the final offset but the unit is bigger than character/word
 
309
                if direction>0 and endPoint!="end" and unit not in (wdCharacter,wdWord)  and (self._rangeObj.start+1)==self.obj.WinwordDocumentObject.characters.count:
 
310
                        return 0
305
311
                return res
306
312
 
307
313
        def _get_bookmark(self):
325
331
        def _get_role(self):
326
332
                return controlTypes.ROLE_EDITABLETEXT
327
333
 
 
334
        def _get_WinwordVersion(self):
 
335
                if not hasattr(self,'_WinwordVersion'):
 
336
                        self._WinwordVersion=float(self.WinwordWindowObject.application.version)
 
337
                return self._WinwordVersion
 
338
 
328
339
        def _get_WinwordWindowObject(self):
329
340
                if not getattr(self,'_WinwordWindowObject',None): 
330
341
                        try:
342
353
                        self._WinwordDocumentObject=windowObject.document
343
354
                return self._WinwordDocumentObject
344
355
 
 
356
        def _get_WinwordApplicationObject(self):
 
357
                if not getattr(self,'_WinwordApplicationObject',None): 
 
358
                        self._WinwordApplicationObject=self.WinwordWindowObject.application
 
359
                return self._WinwordApplicationObject
 
360
 
345
361
        def _get_WinwordSelectionObject(self):
346
362
                if not getattr(self,'_WinwordSelectionObject',None):
347
363
                        windowObject=self.WinwordWindowObject
349
365
                        self._WinwordSelectionObject=windowObject.selection
350
366
                return self._WinwordSelectionObject
351
367
 
352
 
        def script_nextRow(self,keyPress):
 
368
        def script_tab(self,gesture):
 
369
                gesture.send()
 
370
                info=self.makeTextInfo(textInfos.POSITION_CARET)
 
371
                if info._rangeObj.tables.count>0:
 
372
                        info.expand(textInfos.UNIT_LINE)
 
373
                        speech.speakTextInfo(info,reason=speech.REASON_CARET)
 
374
 
 
375
        def script_nextRow(self,gesture):
353
376
                info=self.makeTextInfo("caret")
354
377
                if not info._rangeObj.Information(wdWithInTable):
355
378
                        speech.speakMessage(_("not in table"))
 
379
                        return
356
380
                if info._moveInTable(0,1):
357
381
                        info.updateCaret()
358
382
                        info.expand(textInfos.UNIT_CELL)
359
383
                        speech.speakTextInfo(info,reason=speech.REASON_CARET)
360
384
                else:
361
 
                        speech.speakMessage("edge of table")
 
385
                        speech.speakMessage(_("edge of table"))
362
386
 
363
 
        def script_previousRow(self,keyPress):
 
387
        def script_previousRow(self,gesture):
364
388
                info=self.makeTextInfo("caret")
365
389
                if not info._rangeObj.Information(wdWithInTable):
366
390
                        speech.speakMessage(_("not in table"))
 
391
                        return
367
392
                if info._moveInTable(0,-1):
368
393
                        info.updateCaret()
369
394
                        info.expand(textInfos.UNIT_CELL)
370
395
                        speech.speakTextInfo(info,reason=speech.REASON_CARET)
371
396
                else:
372
 
                        speech.speakMessage("edge of table")
 
397
                        speech.speakMessage(_("edge of table"))
373
398
 
374
 
        def script_nextColumn(self,keyPress):
 
399
        def script_nextColumn(self,gesture):
375
400
                info=self.makeTextInfo("caret")
376
401
                if not info._rangeObj.Information(wdWithInTable):
377
402
                        speech.speakMessage(_("not in table"))
 
403
                        return
378
404
                if info._moveInTable(1,0):
379
405
                        info.updateCaret()
380
406
                        info.expand(textInfos.UNIT_CELL)
381
407
                        speech.speakTextInfo(info,reason=speech.REASON_CARET)
382
408
                else:
383
 
                        speech.speakMessage("edge of table")
 
409
                        speech.speakMessage(_("edge of table"))
384
410
 
385
 
        def script_previousColumn(self,keyPress):
 
411
        def script_previousColumn(self,gesture):
386
412
                info=self.makeTextInfo("caret")
387
413
                if not info._rangeObj.Information(wdWithInTable):
388
414
                        speech.speakMessage(_("not in table"))
 
415
                        return
389
416
                if info._moveInTable(-1,0):
390
417
                        info.updateCaret()
391
418
                        info.expand(textInfos.UNIT_CELL)
392
419
                        speech.speakTextInfo(info,reason=speech.REASON_CARET)
393
420
                else:
394
 
                        speech.speakMessage("edge of table")
395
 
 
396
 
[WordDocument.bindKey(keyName,scriptName) for keyName,scriptName in [
397
 
        ("control+alt+extendedUp","previousRow"),
398
 
        ("control+alt+extendedDown","nextRow"),
399
 
        ("control+alt+extendedLeft","previousColumn"),
400
 
        ("control+alt+extendedRight","nextColumn"),
401
 
        ("Control+ExtendedPrior","caret_moveByLine"),
402
 
        ("Control+ExtendedNext","caret_moveByLine"),
403
 
]]
404
 
 
 
421
                        speech.speakMessage(_("edge of table"))
 
422
 
 
423
        __gestures = {
 
424
                "kb:tab": "tab",
 
425
                "kb:shift+tab": "tab",
 
426
                "kb:control+alt+upArrow": "previousRow",
 
427
                "kb:control+alt+downArrow": "nextRow",
 
428
                "kb:control+alt+leftArrow": "previousColumn",
 
429
                "kb:control+alt+rightArrow": "nextColumn",
 
430
                "kb:control+pageUp": "caret_moveByLine",
 
431
                "kb:control+pageDown": "caret_moveByLine",
 
432
        }