def findGroupboxObject(obj): prevWindow = winUser.getPreviousWindow(obj.windowHandle) while prevWindow: if (winUser.getClassName(prevWindow) == "Button" and winUser.getWindowStyle(prevWindow) & winUser.BS_GROUPBOX and winUser.isWindowVisible(prevWindow)): groupObj = NVDAObjects.IAccessible.getNVDAObjectFromEvent( prevWindow, winUser.OBJID_CLIENT, 0) try: (left, top, width, height) = obj.location (groupLeft, groupTop, groupWidth, groupHeight) = groupObj.location except: # noqa: E722 Bare except return if (groupObj.IAccessibleRole == oleacc.ROLE_SYSTEM_GROUPING and left >= groupLeft and (left + width) <= (groupLeft + groupWidth) and top >= groupTop and (top + height) <= (groupTop + groupHeight)): return groupObj tempWindow = winUser.getPreviousWindow(prevWindow) if tempWindow == prevWindow: # In rare cases (e.g. HWND 65554 "Message"), getPreviousWindow can return # the window passed to it, causing an infinite loop. break prevWindow = tempWindow
def __contains__(self, obj): #Special code to handle Mozilla combobox lists if obj.windowClassName.startswith( 'Mozilla') and winUser.getWindowStyle( obj.windowHandle) & winUser.WS_POPUP: parent = obj.parent while parent and parent.windowHandle == obj.windowHandle: parent = parent.parent if parent: obj = parent.parent if not (isinstance(obj, NVDAObjects.IAccessible.IAccessible) and isinstance(obj.IAccessibleObject, IAccessibleHandler.IAccessible2) ) or not obj.windowClassName.startswith( 'Mozilla') or not winUser.isDescendantWindow( self.rootNVDAObject.windowHandle, obj.windowHandle): return False if self.rootNVDAObject.windowHandle == obj.windowHandle: ID = obj.IA2UniqueID try: self.rootNVDAObject.IAccessibleObject.accChild(ID) except COMError: return ID == self.rootNVDAObject.IA2UniqueID return not self._isNVDAObjectInApplication(obj)
def maximizeWindow(hWnd): windowStyle = winUser.getWindowStyle(hWnd) maximized = windowStyle & WS_MAXIMIZE if not maximized and windowStyle & WS_MAXIMIZEBOX: try: winUser.PostMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0) except Exception: pass
def winEventCallback(handle,eventID,window,objectID,childID,threadID,timestamp): try: #Ignore all object IDs from alert onwards (sound, nativeom etc) as we don't support them if objectID<=winUser.OBJID_ALERT: return #Ignore all locationChange events except ones for the caret if eventID==winUser.EVENT_OBJECT_LOCATIONCHANGE and objectID!=winUser.OBJID_CARET: return if eventID==winUser.EVENT_OBJECT_DESTROY: processDestroyWinEvent(window,objectID,childID) return #Change window objIDs to client objIDs for better reporting of objects if (objectID==0) and (childID==0): objectID=winUser.OBJID_CLIENT #Ignore events with invalid window handles isWindow = winUser.isWindow(window) if window else 0 if window==0 or (not isWindow and eventID in (winUser.EVENT_SYSTEM_SWITCHSTART,winUser.EVENT_SYSTEM_SWITCHEND,winUser.EVENT_SYSTEM_MENUEND,winUser.EVENT_SYSTEM_MENUPOPUPEND)): window=winUser.getDesktopWindow() elif not isWindow: return if childID<0: tempWindow=window while tempWindow and not winUser.getWindowStyle(tempWindow)&winUser.WS_POPUP and winUser.getClassName(tempWindow)=="MozillaWindowClass": tempWindow=winUser.getAncestor(tempWindow,winUser.GA_PARENT) if tempWindow and winUser.getClassName(tempWindow).startswith('Mozilla'): window=tempWindow windowClassName=winUser.getClassName(window) # Modern IME candidate list windows fire menu events which confuse us # and can't be used properly in conjunction with input composition support. if windowClassName=="Microsoft.IME.UIManager.CandidateWindow.Host" and eventID in MENU_EVENTIDS: return #At the moment we can't handle show, hide or reorder events on Mozilla Firefox Location bar,as there are just too many of them #Ignore show, hide and reorder on MozillaDropShadowWindowClass windows. if windowClassName.startswith('Mozilla') and eventID in (winUser.EVENT_OBJECT_SHOW,winUser.EVENT_OBJECT_HIDE,winUser.EVENT_OBJECT_REORDER) and childID<0: #Mozilla Gecko can sometimes fire win events on a catch-all window which isn't really the real window #Move up the ancestry to find the real mozilla Window and use that if winUser.getClassName(window)=='MozillaDropShadowWindowClass': return if eventID==winUser.EVENT_SYSTEM_FOREGROUND: #We never want to see foreground events for the Program Manager or Shell (task bar) if windowClassName in ("Progman","Shell_TrayWnd"): return # #3831: Event handling can be deferred if Windows takes a while to change the foreground window. # See pumpAll for details. global _deferUntilForegroundWindow,_foregroundDefers _deferUntilForegroundWindow=window _foregroundDefers=0 if windowClassName=="MSNHiddenWindowClass": # HACK: Events get fired by this window in Windows Live Messenger 2009 when it starts. # If we send a WM_NULL to this window at this point (which happens in accessibleObjectFromEvent), Messenger will silently exit (#677). # Therefore, completely ignore these events, which is useless to us anyway. return if winEventLimiter.addEvent(eventID,window,objectID,childID,threadID): core.requestPump() except: log.error("winEventCallback", exc_info=True)
def maximizeWindow(hWnd): windowStyle = winUser.getWindowStyle(hWnd) maximized = windowStyle & WS_MAXIMIZE if not maximized and windowStyle & WS_MAXIMIZEBOX: try: winUser.PostMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0) log.warning("Window maximized: %s" % winUser.getWindowText(hWnd)) except: # noqa:E722 pass
def winEventCallback(handle,eventID,window,objectID,childID,threadID,timestamp): try: #Ignore all object IDs from alert onwards (sound, nativeom etc) as we don't support them if objectID<=winUser.OBJID_ALERT: return #Ignore all locationChange events except ones for the caret if eventID==winUser.EVENT_OBJECT_LOCATIONCHANGE and objectID!=winUser.OBJID_CARET: return if eventID==winUser.EVENT_OBJECT_DESTROY: processDestroyWinEvent(window,objectID,childID) return #Change window objIDs to client objIDs for better reporting of objects if (objectID==0) and (childID==0): objectID=winUser.OBJID_CLIENT #Ignore events with invalid window handles isWindow = winUser.isWindow(window) if window else 0 if window==0 or (not isWindow and eventID in (winUser.EVENT_SYSTEM_SWITCHSTART,winUser.EVENT_SYSTEM_SWITCHEND,winUser.EVENT_SYSTEM_MENUEND,winUser.EVENT_SYSTEM_MENUPOPUPEND)): window=winUser.getDesktopWindow() elif not isWindow: return if childID<0: tempWindow=window while tempWindow and not winUser.getWindowStyle(tempWindow)&winUser.WS_POPUP and winUser.getClassName(tempWindow)=="MozillaWindowClass": tempWindow=winUser.getAncestor(tempWindow,winUser.GA_PARENT) if tempWindow and winUser.getClassName(tempWindow).startswith('Mozilla'): window=tempWindow windowClassName=winUser.getClassName(window) #At the moment we can't handle show, hide or reorder events on Mozilla Firefox Location bar,as there are just too many of them #Ignore show, hide and reorder on MozillaDropShadowWindowClass windows. if windowClassName.startswith('Mozilla') and eventID in (winUser.EVENT_OBJECT_SHOW,winUser.EVENT_OBJECT_HIDE,winUser.EVENT_OBJECT_REORDER) and childID<0: #Mozilla Gecko can sometimes fire win events on a catch-all window which isn't really the real window #Move up the ancestry to find the real mozilla Window and use that if winUser.getClassName(window)=='MozillaDropShadowWindowClass': return if eventID==winUser.EVENT_SYSTEM_FOREGROUND: #We never want to see foreground events for the Program Manager or Shell (task bar) if windowClassName in ("Progman","Shell_TrayWnd"): return # #3831: Event handling can be deferred if Windows takes a while to change the foreground window. # See pumpAll for details. global _deferUntilForegroundWindow,_foregroundDefers _deferUntilForegroundWindow=window _foregroundDefers=0 if windowClassName=="MSNHiddenWindowClass": # HACK: Events get fired by this window in Windows Live Messenger 2009 when it starts. # If we send a WM_NULL to this window at this point (which happens in accessibleObjectFromEvent), Messenger will silently exit (#677). # Therefore, completely ignore these events, which is useless to us anyway. return if winEventLimiter.addEvent(eventID,window,objectID,childID,threadID): core.requestPump() except: log.error("winEventCallback", exc_info=True)
def findGroupboxObject(obj): prevWindow=winUser.getPreviousWindow(obj.windowHandle) while prevWindow: if winUser.getClassName(prevWindow)=="Button" and winUser.getWindowStyle(prevWindow)&winUser.BS_GROUPBOX and winUser.isWindowVisible(prevWindow): groupObj=NVDAObjects.IAccessible.getNVDAObjectFromEvent(prevWindow,winUser.OBJID_CLIENT,0) try: (left,top,width,height)=obj.location (groupLeft,groupTop,groupWidth,groupHeight)=groupObj.location except: return if groupObj.IAccessibleRole==oleacc.ROLE_SYSTEM_GROUPING and left>=groupLeft and (left+width)<=(groupLeft+groupWidth) and top>=groupTop and (top+height)<=(groupTop+groupHeight): return groupObj prevWindow=winUser.getPreviousWindow(prevWindow)
def processFocusWinEvent(window,objectID,childID,force=False): """checks to see if the focus win event is not the same as the existing focus, then converts the win event to an NVDA event (instanciating an NVDA Object) then calls processFocusNVDAEvent. If all is ok it returns True. @type window: integer @param objectID: a win event's object ID @type objectID: integer @param childID: a win event's child ID @type childID: integer @param force: If True, the shouldAllowIAccessibleFocusEvent property of the object is ignored. @type force: boolean @returns: True if the focus is valid and was handled, False otherwise. @rtype: boolean """ windowClassName=winUser.getClassName(window) # Generally, we must ignore focus on child windows of SDM windows as we only want the SDM MSAA events. # However, we don't want to ignore focus if the child ID isn't 0, # as this is a child control and the SDM MSAA events don't handle child controls. if childID==0 and not windowClassName.startswith('bosa_sdm') and winUser.getClassName(winUser.getAncestor(window,winUser.GA_PARENT)).startswith('bosa_sdm'): return False rootWindow=winUser.getAncestor(window,winUser.GA_ROOT) # If this window is not within the foreground window and this window or its root window is not a popup window, and this window's root window is not the highest in the z-order if not winUser.isDescendantWindow(winUser.getForegroundWindow(),window) and not (winUser.getWindowStyle(window) & winUser.WS_POPUP or winUser.getWindowStyle(rootWindow)&winUser.WS_POPUP) and winUser.getPreviousWindow(rootWindow)!=0: # This is a focus event from a background window, so ignore it. return False #Notify appModuleHandler of this new foreground window appModuleHandler.update(winUser.getWindowThreadProcessID(window)[0]) #If Java access bridge is running, and this is a java window, then pass it to java and forget about it if JABHandler.isRunning and JABHandler.isJavaWindow(window): JABHandler.event_enterJavaWindow(window) return True #Convert the win event to an NVDA event NVDAEvent=winEventToNVDAEvent(winUser.EVENT_OBJECT_FOCUS,window,objectID,childID,useCache=False) if not NVDAEvent: return False eventName,obj=NVDAEvent if (childID==0 and obj.IAccessibleRole==oleacc.ROLE_SYSTEM_LIST) or (objectID==winUser.OBJID_CLIENT and "SysListView32" in obj.windowClassName): # Some controls incorrectly fire focus on child ID 0, even when there is a child with focus. try: realChildID=obj.IAccessibleObject.accFocus except: realChildID=None if isinstance(realChildID,int) and realChildID>0 and realChildID!=childID: realObj=NVDAObjects.IAccessible.IAccessible(IAccessibleObject=obj.IAccessibleObject,IAccessibleChildID=realChildID,event_windowHandle=window,event_objectID=objectID,event_childID=realChildID) if realObj: obj=realObj return processFocusNVDAEvent(obj,force=force)
def __contains__(self,obj): #Special code to handle Mozilla combobox lists if obj.windowClassName.startswith('Mozilla') and winUser.getWindowStyle(obj.windowHandle)&winUser.WS_POPUP: parent=obj.parent while parent and parent.windowHandle==obj.windowHandle: parent=parent.parent if parent: obj=parent.parent if not (isinstance(obj,NVDAObjects.IAccessible.IAccessible) and isinstance(obj.IAccessibleObject,IAccessibleHandler.IAccessible2)) or not obj.windowClassName.startswith('Mozilla') or not winUser.isDescendantWindow(self.rootNVDAObject.windowHandle,obj.windowHandle): return False if self.rootNVDAObject.windowHandle==obj.windowHandle: ID=obj.IAccessibleObject.uniqueID try: self.rootNVDAObject.IAccessibleObject.accChild(ID) except: return False return self._isNVDAObjectInApplication(obj)
def _get_windowStyle(self): return winUser.getWindowStyle(self.windowHandle)
def isMaximized(hWnd): windowStyle = winUser.getWindowStyle(hWnd) return (windowStyle & WS_MAXIMIZE)