private static IRawElementProviderSimple CreateSystemMenu(IntPtr hwnd) { NonClientArea nonClientArea = new NonClientArea(hwnd); WindowsTitleBar titleBar = (WindowsTitleBar)nonClientArea.CreateNonClientChild(NonClientItem.TitleBar); return(titleBar.CreateTitleBarChild(WindowsTitleBar._systemMenu)); }
//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxySimple Interface // Returns a pattern interface if supported. internal override object GetPatternProvider(AutomationPattern iid) { // selection is always supported if (iid == SelectionPattern.Pattern) { return(this); } // the scroll pattern is only supported when the list is scrollable. else if (iid == ScrollPattern.Pattern && WindowScroll.HasScrollableStyle(_hwnd)) { // delegate work to the NonClientArea implementation of IScrollProvider IScrollProvider scroll = NonClientArea.Create(_hwnd, 0) as IScrollProvider; if (scroll != null) { return(scroll); } } return(null); }
private static void RaiseEventsOnWindow(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { ProxyFragment elw = new NonClientArea(hwnd); if (eventId == NativeMethods.EventObjectNameChange) { int style = Misc.GetWindowStyle(hwnd); if (Misc.IsBitSet(style, NativeMethods.WS_CHILD)) { // Full control names do not change. They are named by the static label. return; } else { // But the title bar name does so allow title bar proxy to procees the event. WindowsTitleBar tb = new WindowsTitleBar(hwnd, elw, 0); tb.DispatchEvents(eventId, idProp, idObject, idChild); } } elw.DispatchEvents(eventId, idProp, idObject, idChild); }
private static IRawElementProviderSimple CreateMenuBarItem(IntPtr hwnd, int idChild) { IntPtr menu = UnsafeNativeMethods.GetMenu(hwnd); if (menu == IntPtr.Zero) { return(null); } NonClientArea nonClientArea = new NonClientArea(hwnd); WindowsMenu appMenu = new WindowsMenu(hwnd, nonClientArea, menu, WindowsMenu.MenuType.Toplevel, (int)NonClientItem.Menu); if (idChild == 0) { return(appMenu); } else { return(appMenu.CreateMenuItem(idChild - 1)); } }
// Return menuItem object which is a hierarchical parent of the given menu (specified via hwnd) // return NULL in the case when menu does not have a parent (e.g. Context menu) // NOTE: this method should not be called for the menuItem that lives on the System or Menubar internal static MenuItem GetHierarchyParent(IntPtr hwnd) { int ownerMenuItemPos = -1; IntPtr menuParent = IntPtr.Zero; IntPtr hwndParent = IntPtr.Zero; IntPtr menu = HmenuFromHwnd(hwnd); if (menu == IntPtr.Zero) { throw new ElementNotAvailableException(); } MenuType currentType = GetSubMenuType(hwnd, menu); MenuType parentType = MenuType.Toplevel; if (currentType == MenuType.Submenu) { if (!GetSubMenuParent(hwnd, out menuParent, out hwndParent, out ownerMenuItemPos, out parentType)) { return null; } ProxyFragment parent = null; if (parentType == MenuType.Toplevel) { // Top Level Menu. // We need to have the parenthood defined in the same way as if it was done // from the non client area code. NonClientArea nonClientArea = new NonClientArea(hwndParent); parent = nonClientArea.CreateNonClientChild(NonClientArea.NonClientItem.Menu); } else { parent = new WindowsMenu(hwndParent, null, menuParent, parentType, ownerMenuItemPos); } return new MenuItem(hwndParent, parent, ownerMenuItemPos, menuParent, parentType); } return null; }
// Return menuItem object which is a hierarchical parent of the given menu (specified via hwnd) // return NULL in the case when menu does not have a parent (e.g. Context menu) // NOTE: this method should not be called for the menuItem that lives on the System or Menubar private static ProxyFragment GetSystemPopupParent () { // Parent lives on menuBar or parent lives on another submenu // or parent lives on the context or parent lives on system popup menu ... // Start from menuBar NativeMethods.GUITHREADINFO gui; if (!Misc.ProxyGetGUIThreadInfo(0, out gui)) { return null; } NonClientArea nonClientArea = new NonClientArea (gui.hwndActive); WindowsTitleBar titleBar = (WindowsTitleBar) nonClientArea.CreateNonClientChild (NonClientArea.NonClientItem.TitleBar); ProxyFragment systemMenu = (ProxyFragment) titleBar.CreateTitleBarChild (WindowsTitleBar._systemMenu); return (ProxyFragment) systemMenu.GetFirstChild (); }
private static void RaiseEventsOnScroll(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if ((idProp == ScrollPattern.VerticalScrollPercentProperty && idObject != NativeMethods.OBJID_VSCROLL) || (idProp == ScrollPattern.HorizontalScrollPercentProperty && idObject != NativeMethods.OBJID_HSCROLL)) { return; } ProxyFragment el = new NonClientArea(hwnd); if (el == null) return; if (idProp == InvokePattern.InvokedEvent) { NonClientItem item = idObject == NativeMethods.OBJID_HSCROLL ? NonClientItem.HScrollBar : NonClientItem.VScrollBar; int sbFlag = idObject == NativeMethods.OBJID_HSCROLL ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT; ProxyFragment scrollBar = new WindowsScrollBar(hwnd, el, (int)item, sbFlag); if (scrollBar != null) { ProxySimple scrollBarBit = WindowsScrollBarBits.CreateFromChildId(hwnd, scrollBar, idChild, sbFlag); if (scrollBarBit != null) { scrollBarBit.DispatchEvents(eventId, idProp, idObject, idChild); } } return; } if (eventId == NativeMethods.EventObjectStateChange && idProp == ValuePattern.IsReadOnlyProperty) { if (idChild == 0) { // if (idObject == NativeMethods.OBJID_HSCROLL || idObject == NativeMethods.OBJID_VSCROLL) { idObject = NativeMethods.OBJID_WINDOW; } el.DispatchEvents(eventId, idProp, idObject, idChild); } return; } if (idProp == ValuePattern.ValueProperty && eventId == NativeMethods.EVENT_OBJECT_VALUECHANGE) { NonClientItem item = idObject == NativeMethods.OBJID_HSCROLL ? NonClientItem.HScrollBar : NonClientItem.VScrollBar; WindowsScrollBar scrollBar = new WindowsScrollBar(hwnd, el, (int)item, idObject == NativeMethods.OBJID_HSCROLL ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT); scrollBar.DispatchEvents(0, ValuePattern.ValueProperty, NativeMethods.OBJID_CLIENT, 0); return; } if (Misc.GetClassName(hwnd) == "ComboLBox") { el = (ProxyFragment)WindowsListBox.Create(hwnd, 0); } if (el != null) { el.DispatchEvents(eventId, idProp, idObject, idChild); } }
private static IRawElementProviderSimple CreateSystemMenu(IntPtr hwnd) { NonClientArea nonClientArea = new NonClientArea(hwnd); WindowsTitleBar titleBar = (WindowsTitleBar)nonClientArea.CreateNonClientChild(NonClientItem.TitleBar); return titleBar.CreateTitleBarChild(WindowsTitleBar._systemMenu); }
private static IRawElementProviderSimple CreateMenuBarItem(IntPtr hwnd, int idChild) { IntPtr menu = UnsafeNativeMethods.GetMenu(hwnd); if (menu == IntPtr.Zero) { return null; } NonClientArea nonClientArea = new NonClientArea( hwnd ); WindowsMenu appMenu = new WindowsMenu(hwnd, nonClientArea, menu, WindowsMenu.MenuType.Toplevel, (int) NonClientItem.Menu); if (idChild == 0) { return appMenu; } else { return appMenu.CreateMenuItem(idChild - 1); } }
private static void RaiseEventsOnScroll(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if ((idProp == ScrollPattern.VerticalScrollPercentProperty && idObject != NativeMethods.OBJID_VSCROLL) || (idProp == ScrollPattern.HorizontalScrollPercentProperty && idObject != NativeMethods.OBJID_HSCROLL)) { return; } ProxyFragment el = new NonClientArea(hwnd); if (el == null) { return; } if (idProp == InvokePattern.InvokedEvent) { NonClientItem item = idObject == NativeMethods.OBJID_HSCROLL ? NonClientItem.HScrollBar : NonClientItem.VScrollBar; int sbFlag = idObject == NativeMethods.OBJID_HSCROLL ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT; ProxyFragment scrollBar = new WindowsScrollBar(hwnd, el, (int)item, sbFlag); if (scrollBar != null) { ProxySimple scrollBarBit = WindowsScrollBarBits.CreateFromChildId(hwnd, scrollBar, idChild, sbFlag); if (scrollBarBit != null) { scrollBarBit.DispatchEvents(eventId, idProp, idObject, idChild); } } return; } if (eventId == NativeMethods.EventObjectStateChange && idProp == ValuePattern.IsReadOnlyProperty) { if (idChild == 0) { // if (idObject == NativeMethods.OBJID_HSCROLL || idObject == NativeMethods.OBJID_VSCROLL) { idObject = NativeMethods.OBJID_WINDOW; } el.DispatchEvents(eventId, idProp, idObject, idChild); } return; } if (idProp == ValuePattern.ValueProperty && eventId == NativeMethods.EVENT_OBJECT_VALUECHANGE) { NonClientItem item = idObject == NativeMethods.OBJID_HSCROLL ? NonClientItem.HScrollBar : NonClientItem.VScrollBar; WindowsScrollBar scrollBar = new WindowsScrollBar(hwnd, el, (int)item, idObject == NativeMethods.OBJID_HSCROLL ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT); scrollBar.DispatchEvents(0, ValuePattern.ValueProperty, NativeMethods.OBJID_CLIENT, 0); return; } if (Misc.GetClassName(hwnd) == "ComboLBox") { el = (ProxyFragment)WindowsListBox.Create(hwnd, 0); } if (el != null) { el.DispatchEvents(eventId, idProp, idObject, idChild); } }
private static void RaiseEventsOnScroll(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if ((idProp == ScrollPattern.VerticalScrollPercentProperty && idObject != NativeMethods.OBJID_VSCROLL) || (idProp == ScrollPattern.HorizontalScrollPercentProperty && idObject != NativeMethods.OBJID_HSCROLL)) { return; } ProxyFragment el = new NonClientArea(hwnd); if (el == null) { return; } if (idProp == InvokePattern.InvokedEvent) { NonClientItem item = idObject == NativeMethods.OBJID_HSCROLL ? NonClientItem.HScrollBar : NonClientItem.VScrollBar; int sbFlag = idObject == NativeMethods.OBJID_HSCROLL ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT; ProxyFragment scrollBar = new WindowsScrollBar(hwnd, el, (int)item, sbFlag); if (scrollBar != null) { ProxySimple scrollBarBit = WindowsScrollBarBits.CreateFromChildId(hwnd, scrollBar, idChild, sbFlag); if (scrollBarBit != null) { scrollBarBit.DispatchEvents(eventId, idProp, idObject, idChild); } } return; } if (eventId == NativeMethods.EventObjectStateChange && idProp == ValuePattern.IsReadOnlyProperty) { if (idChild == 0) { // This code is never exercised. The code in User needs to change to send // EventObjectStateChange with a client ID of zero // // UIA works differently than MSAA. Events are set for elements rather than hwnd // Scroll bar are processed the same way whatever they are part of the non client area // or stand alone hwnd. OBJID_HSCROLL and OBJID_VSCROLL are mapped to OBJID_WINDOW // so they behave the same for NC and hwnd SB. // Parameters are setup so that the dispatch will send the proper notification and // recursively will send notifications to all of the children if (idObject == NativeMethods.OBJID_HSCROLL || idObject == NativeMethods.OBJID_VSCROLL) { idObject = NativeMethods.OBJID_WINDOW; } el.DispatchEvents(eventId, idProp, idObject, idChild); } return; } if (idProp == ValuePattern.ValueProperty && eventId == NativeMethods.EVENT_OBJECT_VALUECHANGE) { NonClientItem item = idObject == NativeMethods.OBJID_HSCROLL ? NonClientItem.HScrollBar : NonClientItem.VScrollBar; WindowsScrollBar scrollBar = new WindowsScrollBar(hwnd, el, (int)item, idObject == NativeMethods.OBJID_HSCROLL ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT); scrollBar.DispatchEvents(0, ValuePattern.ValueProperty, NativeMethods.OBJID_CLIENT, 0); return; } if (Misc.GetClassName(hwnd) == "ComboLBox") { el = (ProxyFragment)WindowsListBox.Create(hwnd, 0); } if (el != null) { el.DispatchEvents(eventId, idProp, idObject, idChild); } }