import ctypes import IAccessibleHandler import speech import textInfos.offsets import winKernel import winUser import globalVars import controlTypes import config from . import Window from .. import NVDAObjectTextInfo from ..behaviors import EditableTextWithAutoSelectDetection import locale import watchdog import eventHandler #Window messages SCI_POSITIONFROMPOINT=2022 SCI_POINTXFROMPOSITION=2164 SCI_POINTYFROMPOSITION=2165 SCI_GETTEXTRANGE=2162 SCI_GETTEXT=2182 SCI_GETTEXTLENGTH=2183 SCI_GETLENGTH=2006 SCI_GETCURRENTPOS=2008 SCI_GETANCHOR=2009 SCI_GOTOPOS=2025 SCI_SETCURRENTPOS=2141 SCI_GETSELECTIONSTART=2143 SCI_GETSELECTIONEND=2145 SCI_SETSEL=2160 SCI_GETLINEENDPOSITION=2136 SCI_GETLINECOUNT=2154 SCI_LINEFROMPOSITION=2166 SCI_POSITIONFROMLINE=2167 SCI_LINELENGTH=2350 SCI_GETSTYLEAT=2010 SCI_STYLEGETFONT=2486 SCI_STYLEGETSIZE=2485 SCI_STYLEGETBOLD=2483 SCI_STYLEGETITALIC=2484 SCI_STYLEGETUNDERLINE=2488 SCI_WORDSTARTPOSITION=2266 SCI_WORDENDPOSITION=2267 SC_WRAP_NONE=0 SCI_GETWRAPMODE=2269 SCI_GETCODEPAGE=2137 SCI_POSITIONAFTER=2418 #constants STYLE_DEFAULT=32 SC_CP_UTF8=65001 class CharacterRangeStruct(ctypes.Structure): _fields_=[ ('cpMin',ctypes.c_long), ('cpMax',ctypes.c_long), ] class TextRangeStruct(ctypes.Structure): _fields_=[ ('chrg',CharacterRangeStruct), ('lpstrText',ctypes.c_char_p), ] class ScintillaTextInfo(textInfos.offsets.OffsetsTextInfo): def _getOffsetFromPoint(self,x,y): return watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POSITIONFROMPOINT,x,y) def _getPointFromOffset(self,offset): point=textInfos.Point( watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTXFROMPOSITION,None,offset), watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POINTYFROMPOSITION,None,offset) ) if point.x and point.y: return point else: raise NotImplementedError def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True): style=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_GETSTYLEAT,offset,0) if calculateOffsets: #we need to manually see how far the style goes, limit to line lineStart,lineEnd=self._getLineOffsets(offset) startOffset=offset while startOffset>lineStart: curStyle=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_GETSTYLEAT,startOffset-1,0) if curStyle==style: startOffset-=1 else: break endOffset=offset+1 while endOffset=self._getStoryLength(): return offset,offset+1 end=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POSITIONAFTER,offset,0) start=offset tempOffset=offset-1 while True: start=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_POSITIONAFTER,tempOffset,0) if start