def screen_to_client(self, hWnd): """ Translates window screen coordinates to client coordinates. @see: L{client_to_screen}, L{translate} @type hWnd: int or L{HWND} or L{system.Window} @param hWnd: Window handle. @rtype: L{Rect} @return: New object containing the translated coordinates. """ topleft = winUser.ScreenToClient(hWnd, (self.left, self.top)) bottomright = winUser.ScreenToClient(hWnd, (self.bottom, self.right)) return Rect(topleft.x, topleft.y, bottomright.x, bottomright.y)
def _getOffsetFromPoint(self,x,y): x, y = winUser.ScreenToClient(self.obj.windowHandle, x, y) if self.obj.editAPIVersion>=1: processHandle=self.obj.processHandle internalP=winKernel.virtualAllocEx(processHandle,None,ctypes.sizeof(PointLStruct),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) try: p=PointLStruct(x,y) winKernel.writeProcessMemory(processHandle,internalP,ctypes.byref(p),ctypes.sizeof(p),None) offset=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_CHARFROMPOS,0,internalP) finally: winKernel.virtualFreeEx(processHandle,internalP,0,winKernel.MEM_RELEASE) else: p=x+(y<<16) res=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_CHARFROMPOS,0,p) offset=winUser.LOWORD(res) lineNum=winUser.HIWORD(res) if offset==0xFFFF and lineNum==0xFFFF: raise LookupError("Point outside client area") if self._getStoryLength() > 0xFFFF: # Returned offsets are 16 bits, therefore for large documents, we need to make sure that the correct offset is returned. # We can calculate this by using the start offset of the line with the retrieved line number. lineStart=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_LINEINDEX,lineNum,0) # Get the last 16 bits of the line number lineStart16=lineStart&0xFFFF if lineStart16 > offset: # There are cases where the last 16 bits of the line start are greater than the # 16 bits offset. For example, this happens when the line start offset is 65534 (0xFFFE) # and the offset we need ought to be 65537 (0x10001), which is a 17 bits number # In that case, add 0x10000 to the offset, which will make the eventual formula return the correct offset, # unless a line has more than 65535 characters, in which case we can't get a reliable offset. offset+=0x10000 offset = (offset - lineStart16) + lineStart return offset
def redraw(self): """Redraw the display for this object. """ left, top, width, height = self.location left, top = winUser.ScreenToClient(self.windowHandle, left, top) winUser.RedrawWindow(self.windowHandle, winUser.RECT(left, top, left + width, top + height), None, winUser.RDW_INVALIDATE | winUser.RDW_UPDATENOW)
def screen_to_client(self, hWnd): """ Translates window screen coordinates to client coordinates. @see: L{client_to_screen}, L{translate} @type hWnd: int or L{HWND} or L{system.Window} @param hWnd: Window handle. @rtype: L{Point} @return: New object containing the translated coordinates. """ return winUser.ScreenToClient(hWnd, self)
def _getOffsetFromPoint(self, x, y): x, y = winUser.ScreenToClient(self.obj.windowHandle, x, y) return watchdog.cancellableSendMessage(self.obj.windowHandle, SCI_POSITIONFROMPOINT, x, y)
def toClient(self, hwnd): """Converts self from screen to client coordinates and returns a new L{Point}""" return Point(*winUser.ScreenToClient(hwnd, *self))