internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) { bool parentedByCombo = false; ProxyFragment parent = null; int item = 0; try { int style = Misc.GetWindowStyle(hwnd); // If can not get windows style the hwnd is bad so do not create a proxy for it. if (style == 0) { return(null); } if (Misc.IsBitSet(style, NativeMethods.LBS_COMBOBOX)) { // List portion of combo box NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize); if (WindowsComboBox.GetComboInfo(hwnd, ref cbInfo) && (cbInfo.hwndCombo != IntPtr.Zero)) { parent = (ProxyFragment)WindowsComboBox.Create(cbInfo.hwndCombo, 0); parentedByCombo = true; item = (int)WindowsComboBox.ComboChildren.List; } } } catch (ElementNotAvailableException) { return(null); } WindowsListBox listbox = new WindowsListBox(hwnd, parent, item, parentedByCombo); if (idChild == 0) { return(listbox); } else { return(listbox.CreateListboxItem(idChild - 1)); } }
private static void RaiseEventsOnClient(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { ProxySimple el = null; WindowsListBox wlb = (WindowsListBox)WindowsListBox.Create(hwnd, 0); // Upon creation, a single selection Listbox can have no selection to start with // however once an item has been selection, the selection cannot be removed. // This WinEvent can only be received once, on the first selection. // Once the notification is received the notification handler is removed to not get it a // second time. if ((eventId == NativeMethods.EventObjectSelection || eventId == NativeMethods.EventObjectSelectionAdd) && (idProp as AutomationProperty) == SelectionPattern.IsSelectionRequiredProperty) { // This array must be kept in sync with the array in PropertyToWinEvent WinEventTracker.EvtIdProperty[] aEvtIdProperties = new WinEventTracker.EvtIdProperty[] { new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectSelection, SelectionPattern.IsSelectionRequiredProperty) }; WinEventTracker.RemoveToNotificationList(hwnd, aEvtIdProperties, null, aEvtIdProperties.Length); el = wlb; } else if (eventId == NativeMethods.EventObjectSelection || eventId == NativeMethods.EventObjectSelectionRemove || eventId == NativeMethods.EventObjectSelectionAdd) { bool isMultipleSelection = wlb.IsMultipleSelection(); // User should send SelectionAdd for a Multiselect listbox but it sends instead // Selection. The code below fixes the if (eventId == NativeMethods.EventObjectSelection && isMultipleSelection && wlb.HasOtherSelections(idChild - 1)) { eventId = NativeMethods.EventObjectSelectionAdd; } // The spec says a ElementSelectionEvent should be fired when action causes only one // selection. if ((eventId == NativeMethods.EventObjectSelectionRemove || eventId == NativeMethods.EventObjectSelectionAdd) && isMultipleSelection && wlb.GetSelectionCount() == 1) { // The net result of the user action is that there is only one item selected in the // listbox, so change the event to an EventObjectSelected. idProp = SelectionItemPattern.ElementSelectedEvent; eventId = NativeMethods.EventObjectSelection; // Now need to find what item is selected. int selection = wlb.GetOtherSelection(idChild - 1); if (selection != NativeMethods.LB_ERR) { idChild = selection; } } el = wlb.CreateListboxItem(idChild - 1); } else { el = wlb; } // Special case for logical element change for listbox item if ((idProp as AutomationEvent) == AutomationElement.StructureChangedEvent && (eventId == NativeMethods.EventObjectDestroy || eventId == NativeMethods.EventObjectCreate)) { // Since children are referenced by position in the tree, addition and removal // of items leads to different results when asking properties for the same element // On removal, item + 1 is now item! // Use Children Invalidated to let the client knows that all the cached AutomationInteropProvider.RaiseStructureChangedEvent(wlb, new StructureChangedEventArgs(StructureChangeType.ChildrenInvalidated, wlb.MakeRuntimeId())); return; } if (el != null) { el.DispatchEvents(eventId, idProp, idObject, idChild); } }
internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild) { bool parentedByCombo = false; ProxyFragment parent = null; int item = 0; try { int style = Misc.GetWindowStyle(hwnd); // If can not get windows style the hwnd is bad so do not create a proxy for it. if (style == 0) { return null; } if (Misc.IsBitSet(style, NativeMethods.LBS_COMBOBOX)) { // List portion of combo box NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize); if (WindowsComboBox.GetComboInfo(hwnd, ref cbInfo) && (cbInfo.hwndCombo != IntPtr.Zero)) { parent = (ProxyFragment)WindowsComboBox.Create(cbInfo.hwndCombo, 0); parentedByCombo = true; item = (int)WindowsComboBox.ComboChildren.List; } } } catch (ElementNotAvailableException) { return null; } WindowsListBox listbox = new WindowsListBox (hwnd, parent, item, parentedByCombo); if (idChild == 0) { return listbox; } else { return listbox.CreateListboxItem(idChild - 1); } }