Package NVDAObjects :: Package window :: Module akelEdit
[hide private]
[frames] | no frames]

Source Code for Module NVDAObjects.window.akelEdit

  1  #A part of NonVisual Desktop Access (NVDA) 
  2  #Copyright (C) 2006-2008 NVDA Contributors <http://www.nvda-project.org/> 
  3  #This file is covered by the GNU General Public License. 
  4  #See the file COPYING for more details. 
  5   
  6  import edit 
  7  import winUser 
  8  import winKernel 
  9  import ctypes 
 10  import watchdog 
 11   
 12  # Messages 
 13  AEM_GETINDEX          =(winUser.WM_USER + 2106) 
 14  AEM_CHARFROMPOS       =(winUser.WM_USER + 2151) 
 15  AEM_POSFROMCHAR       =(winUser.WM_USER + 2152) 
 16  AEM_INDEXTORICHOFFSET =(winUser.WM_USER + 2112) 
 17  AEM_RICHOFFSETTOINDEX =(winUser.WM_USER + 2113) 
 18  AEM_CONTROLVERSION        =(winUser.WM_USER + 2200) 
 19   
 20  #AEM_GETINDEX flags 
 21  AEGI_LASTCHAR         =2 
 22  AEGI_CARETCHAR             =5 
 23  AEGI_NEXTLINE              =24 
 24   
 25   
 26  #Structures 
 27   
28 -class AELINEDATA(ctypes.Structure):
29 pass
30 31 AELINEDATA._fields_=[ 32 ('next',ctypes.POINTER(AELINEDATA)), 33 ('prev',ctypes.POINTER(AELINEDATA)), 34 ('wpLine',ctypes.c_wchar), 35 ('nLineLen',ctypes.c_int), 36 ('nLineBreak',ctypes.c_int), 37 ('nLineWidth',ctypes.c_int), 38 ('nSelStart',ctypes.c_int), 39 ('nSelEnd',ctypes.c_int), 40 ] 41
42 -class AECHARINDEX(ctypes.Structure):
43 _fields_=[ 44 ('nLine',ctypes.c_int), 45 ('lpLine',AELINEDATA), 46 ('nCharInLine',ctypes.c_int), 47 ]
48 49
50 -class AkelEditTextInfo(edit.EditTextInfo):
51
52 - def _getLineNumFromOffset(self,offset):
53 ciChar=AECHARINDEX() 54 processHandle=self.obj.processHandle 55 internalCiChar=winKernel.virtualAllocEx(processHandle,None,ctypes.sizeof(ciChar),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) 56 try: 57 watchdog.cancellableSendMessage(self.obj.windowHandle,AEM_RICHOFFSETTOINDEX,offset,internalCiChar) 58 winKernel.readProcessMemory(processHandle,internalCiChar,ctypes.byref(ciChar),ctypes.sizeof(ciChar),None) 59 finally: 60 winKernel.virtualFreeEx(processHandle,internalCiChar,0,winKernel.MEM_RELEASE) 61 return ciChar.nLine
62
63 - def _getStoryLength(self):
64 ciChar=AECHARINDEX() 65 processHandle=self.obj.processHandle 66 internalCiChar=winKernel.virtualAllocEx(processHandle,None,ctypes.sizeof(ciChar),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) 67 try: 68 watchdog.cancellableSendMessage(self.obj.windowHandle,AEM_GETINDEX,AEGI_LASTCHAR,internalCiChar) 69 end=watchdog.cancellableSendMessage(self.obj.windowHandle,AEM_INDEXTORICHOFFSET,0,internalCiChar) 70 finally: 71 winKernel.virtualFreeEx(processHandle,internalCiChar,0,winKernel.MEM_RELEASE) 72 return end+1
73
74 - def _getLineOffsets(self,offset):
75 (start,end)=super(AkelEditTextInfo,self)._getLineOffsets(offset) 76 if end == self._getStoryLength(): 77 return (start,end) 78 ciChar=AECHARINDEX() 79 processHandle=self.obj.processHandle 80 internalCiChar=winKernel.virtualAllocEx(processHandle,None,ctypes.sizeof(ciChar),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) 81 try: 82 watchdog.cancellableSendMessage(self.obj.windowHandle,AEM_RICHOFFSETTOINDEX,offset,internalCiChar) 83 watchdog.cancellableSendMessage(self.obj.windowHandle,AEM_GETINDEX,AEGI_NEXTLINE,internalCiChar) 84 end=watchdog.cancellableSendMessage(self.obj.windowHandle,AEM_INDEXTORICHOFFSET,0,internalCiChar) 85 finally: 86 winKernel.virtualFreeEx(processHandle,internalCiChar,0,winKernel.MEM_RELEASE) 87 return (start,end)
88 89
90 -class AkelEdit(edit.RichEdit20):
91 92 TextInfo=AkelEditTextInfo 93
94 - def initOverlayClass(self):
95 global AEGI_NEXTLINE 96 version=self._getControlVersion() 97 if version <1.6: 98 AEGI_NEXTLINE =8 99 else: 100 AEGI_NEXTLINE =24 101 102 for gesture in ("kb:control+upArrow", "kb:control+downArrow"): 103 self.bindGesture(gesture, "caret_moveByLine")
104
105 - def _getControlVersion(self):
106 res=watchdog.cancellableSendMessage(self.windowHandle,AEM_CONTROLVERSION,None,None) 107 major=winUser.LOBYTE(winUser.LOWORD(res)) 108 minor=winUser.HIBYTE(winUser.LOWORD(res)) 109 version=major+(0.1*minor) 110 return version
111