void UpdateSelectedItem()
        {
            if (_hwndPopupList == IntPtr.Zero)
            {
                Logger.WindowWatcher.Verbose("PopupList UpdateSelectedItem ignored: PopupList is null");
                return;
            }

            if (!IsVisible)
            {
                if (_selectedItemIndex == -1 &&
                    SelectedItemText == string.Empty &&
                    SelectedItemBounds == Rect.Empty)
                {
                    // Don't change anything, or fire an updated event
                    return;
                }

                // Set to the way things should be when not visible, and fire an updated event
                _selectedItemIndex = -1;
                SelectedItemText   = string.Empty;
                SelectedItemBounds = Rect.Empty;
                ListBounds         = Rect.Empty;
            }
            else
            {
                string text;
                Rect   itemBounds;
                var    hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);
                ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);

                _selectedItemIndex = Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
                if (string.IsNullOrEmpty(text))
                {
                    // We (unexpectedly) failed to get information about the selected item - not sure this is a problem
                    Logger.WindowWatcher.Info("PopupList UpdateSelectedItem - IsVisible but GetListViewSelectedItemInfo failed ");
                    _selectedItemIndex = -1;
                    SelectedItemText   = string.Empty;
                    SelectedItemBounds = Rect.Empty;
                    ListBounds         = Rect.Empty;
                }
                else
                {
                    // Normal case - all is OK
                    itemBounds.Offset(ListBounds.Left, ListBounds.Top);
                    SelectedItemBounds = itemBounds;
                    SelectedItemText   = text;
                }
            }
            OnSelectedItemChanged();
        }
 // Runs on our automation thread
 void _windowWatcher_FormulaEditLocationChanged(object sender, EventArgs e)
 {
     if (IsVisible && _selectedItemIndex != -1 && _hwndPopupList != IntPtr.Zero)
     {
         string text;
         Rect   itemBounds;
         var    hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);
         ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);
         Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
         itemBounds.Offset(ListBounds.Left, ListBounds.Top);
         SelectedItemBounds = itemBounds;
         OnSelectedItemChanged();
     }
 }
        // Runs on our automation thread
        void InstallEventHandlers()
        {
            Logger.WindowWatcher.Verbose(string.Format("PopupList Installing event handlers on thread {0}", Thread.CurrentThread.ManagedThreadId));
            try
            {
                // TODO: Clean up
                var hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);

                _selectionChangeHook = new WinEventHook(WinEventHook.WinEvent.EVENT_OBJECT_SELECTION, WinEventHook.WinEvent.EVENT_OBJECT_SELECTION, _syncContextAuto, _syncContextMain, hwndListView);
                _selectionChangeHook.WinEventReceived += _selectionChangeHook_WinEventReceived;
                Logger.WindowWatcher.Verbose("PopupList selection event handler added");
            }
            catch (Exception ex)
            {
                // Probably no longer visible
                Logger.WindowWatcher.Warn(string.Format("PopupList event handler error {0}", ex));
                _hwndPopupList = IntPtr.Zero;
                IsVisible      = false;
            }
        }
예제 #4
0
        void UpdateSelectedItem()
        {
            if (_hwndPopupList == IntPtr.Zero)
            {
                Logger.WindowWatcher.Verbose($"PopupList UpdateSelectedItem ignored: PopupList is null");
                return;
            }

            if (!IsVisible)
            {
                if (_selectedItemIndex == -1 &&
                    SelectedItemText == string.Empty &&
                    SelectedItemBounds == Rect.Empty)
                {
                    // Don't change anything, or fire an updated event
                    return;
                }

                // Set to the way things should be when not visible, and fire an updated event
                _selectedItemIndex = -1;
                SelectedItemText   = string.Empty;
                SelectedItemBounds = Rect.Empty;
                ListBounds         = Rect.Empty;
            }
            else
            {
                string text;
                Rect   itemBounds;
                var    hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);
                ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);

                _selectedItemIndex = Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
                itemBounds.Offset(ListBounds.Left, ListBounds.Top);
                SelectedItemBounds = itemBounds;
                SelectedItemText   = text;
            }
            OnSelectedItemChanged();
        }