Exemplo n.º 1
0
        // Runs on the Automation thread
        void _windowWatcher_InCellEditWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
        {
            switch (e.Type)
            {
            case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
                // CONSIDER: Is this too soon to set up the AutomationElement ??
                // TODO: Yes - need to do AutomationElement later (new Window does not have TextPattern ready)
                SetEditWindow(e.WindowHandle, ref _hwndInCellEdit, ref _inCellEdit);
                UpdateEditState();
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
                //if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
                //{
                //    _formulaEditFocus = FormulaEditFocus.None;
                //    UpdateEditState();
                //}
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
                if (_formulaEditFocus != FormulaEditFocus.InCellEdit)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Focus");
                    _formulaEditFocus = FormulaEditFocus.InCellEdit;
                    UpdateFormulaPolling();
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
                if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Unfocus");
                    _formulaEditFocus = FormulaEditFocus.None;
                    UpdateFormulaPolling();
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
                Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Show");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
                Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Hide");
                break;

            default:
                throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
            }
        }
Exemplo n.º 2
0
        // Runs on the Automation thread
        void _windowWatcher_FormulaBarWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
        {
            switch (e.Type)
            {
            case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
                // CONSIDER: Is this too soon to set up the AutomationElement ??
                SetEditWindow(e.WindowHandle, ref _hwndFormulaBar, ref _formulaBar);
                UpdateEditState();
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
                //if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
                //{
                //    _formulaEditFocus = FormulaEditFocus.None;
                //    UpdateEditState();
                //}
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
                if (_formulaEditFocus != FormulaEditFocus.FormulaBar)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Focus");
                    _formulaEditFocus = FormulaEditFocus.FormulaBar;
                    UpdateFormulaPolling();
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
                if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Unfocus");
                    _formulaEditFocus = FormulaEditFocus.None;
                    UpdateFormulaPolling();
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
                Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Show");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
                Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Hide");
                break;

            default:
                throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
            }
        }
Exemplo n.º 3
0
        // Runs on the Automation thread
        void _windowWatcher_InCellEditWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
        {
            // Debug.Print($"\r\n%%% InCellEditWindowChanged: {e.ObjectId} - {e.Type}\r\n");
            switch (e.Type)
            {
            case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
                if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Self)
                {
                    SetEditWindow(e.WindowHandle, ref _hwndInCellEdit);
                    _updateEditStateAfterTimeout.Signal();
                }
                else if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Caret)
                {
                    // We expect this on every text change
                    // NOTE: Not anymore after some Excel / Windows update
                    Debug.Print($"-#-#-#- Text Changed ... ");
                    _updateEditStateAfterTimeout.Signal();
                }
                else
                {
                    Debug.Print($"### Unexpected WindowsChanged object id: {e.ObjectId}");
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
                // Not expecting this anymore - Destroy is no longer routed from the WinEvents.
                Debug.Fail("Unexpected ChangeType");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
                if (_formulaEditFocus != FormulaEditFocus.InCellEdit)
                {
                    if (e.WindowHandle != _hwndInCellEdit)
                    {
                        // We never saw the Create...
                        SetEditWindow(e.WindowHandle, ref _hwndInCellEdit);
                    }

                    Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Focus");

                    _formulaEditFocus = FormulaEditFocus.InCellEdit;
                    _updateEditStateAfterTimeout.Signal();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
                if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Unfocus");
                    _formulaEditFocus = FormulaEditFocus.None;
                    _updateEditStateAfterTimeout.Signal();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
                Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Show");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
                Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Hide");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.LocationChange:
                if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Caret)
                {
                    // We expect this on every text change in newer Excel versions
                    Debug.Print($"-#-#-#- Text Changed ... ");
                    _updateEditStateAfterTimeout.Signal();
                }
                else
                {
                    Debug.Print($"-#-#-#- Unexpected WindowsChanged object id: {e.ObjectId}");
                }
                break;

            default:
                //throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
                Logger.WindowWatcher.Verbose($"FormulaEdit - Unexpected Window Change Type: {e.Type}");
                break;
            }
        }
Exemplo n.º 4
0
        // Runs on the Automation thread
        void _windowWatcher_InCellEditWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
        {
            // Debug.Print(string.Format("\r\n%%% InCellEditWindowChanged: {e.ObjectId} - {e.Type}\r\n");
            switch (e.Type)
            {
            case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
                if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Self)
                {
                    SetEditWindow(e.WindowHandle, ref _hwndInCellEdit);
                    UpdateEditState();
                }
                else if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Caret)
                {
                    // We expect this on every text change
                    // NOTE: Not anymore after some Excel / Windows update
                    Debug.Print("-#-#-#- Text Changed ... ");
                    UpdateEditStateDelayed();
                }
                else
                {
                    Debug.Print(string.Format("### Unexpected WindowsChanged object id: {0}", e.ObjectId));
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
                // We expect this for every text change, but ignore since we react to the Create event
                //if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
                //{
                //    _formulaEditFocus = FormulaEditFocus.None;
                //    UpdateEditState();
                //}
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
                if (_formulaEditFocus != FormulaEditFocus.InCellEdit)
                {
                    if (e.WindowHandle != _hwndInCellEdit)
                    {
                        // We never saw the Create...
                        SetEditWindow(e.WindowHandle, ref _hwndInCellEdit);
                    }

                    Logger.WindowWatcher.Verbose("FormulaEdit - InCellEdit Focus");

                    _formulaEditFocus = FormulaEditFocus.InCellEdit;
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
                if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
                {
                    Logger.WindowWatcher.Verbose("FormulaEdit - InCellEdit Unfocus");
                    _formulaEditFocus = FormulaEditFocus.None;
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
                Logger.WindowWatcher.Verbose("FormulaEdit - InCellEdit Show");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
                Logger.WindowWatcher.Verbose("FormulaEdit - InCellEdit Hide");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.LocationChange:
                if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Caret)
                {
                    // We expect this on every text change in newer Excel versions
                    Debug.Print("-#-#-#- Text Changed ... ");
                    UpdateEditStateDelayed();
                }
                else
                {
                    Debug.Print(string.Format("-#-#-#- Unexpected WindowsChanged object id: {0}", e.ObjectId));
                }
                break;

            default:
                //throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
                Logger.WindowWatcher.Verbose(string.Format("FormulaEdit - Unexpected Window Change Type: {0}", e.Type));
                break;
            }
        }
Exemplo n.º 5
0
 // Runs on the Automation thread
 void _windowWatcher_InCellEditWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
 {
     switch (e.Type)
     {
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
             // CONSIDER: Is this too soon to set up the AutomationElement ??
             // TODO: Yes - need to do AutomationElement later (new Window does not have TextPattern ready)
             SetEditWindow(e.WindowHandle, ref _hwndInCellEdit, ref _inCellEdit);
             UpdateEditState();
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
             //if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
             //{
             //    _formulaEditFocus = FormulaEditFocus.None;
             //    UpdateEditState();
             //}
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
             if (_formulaEditFocus != FormulaEditFocus.InCellEdit)
             {
                 Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Focus");
                 _formulaEditFocus = FormulaEditFocus.InCellEdit;
                 UpdateFormulaPolling();
                 UpdateEditState();
             }
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
             if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
             {
                 Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Unfocus");
                 _formulaEditFocus = FormulaEditFocus.None;
                 UpdateFormulaPolling();
                 UpdateEditState();
             }
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
             Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Show");
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
             Logger.WindowWatcher.Verbose($"FormulaEdit - InCellEdit Hide");
             break;
         default:
             throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
     }
 }
Exemplo n.º 6
0
 // Runs on the Automation thread
 void _windowWatcher_FormulaBarWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
 {
     switch (e.Type)
     {
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
             // CONSIDER: Is this too soon to set up the AutomationElement ??
             SetEditWindow(e.WindowHandle, ref _hwndFormulaBar, ref _formulaBar);
             UpdateEditState();
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
             //if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
             //{
             //    _formulaEditFocus = FormulaEditFocus.None;
             //    UpdateEditState();
             //}
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
             if (_formulaEditFocus != FormulaEditFocus.FormulaBar)
             {
                 Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Focus");
                 _formulaEditFocus = FormulaEditFocus.FormulaBar;
                 UpdateFormulaPolling();
                 UpdateEditState();
             }
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
             if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
             {
                 Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Unfocus");
                 _formulaEditFocus = FormulaEditFocus.None;
                 UpdateFormulaPolling();
                 UpdateEditState();
             }
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
                 Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Show");
             break;
         case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
                 Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Hide");
             break;
         default:
             throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
     }
 }
Exemplo n.º 7
0
        // Runs on the Automation thread
        void _windowWatcher_FormulaBarWindowChanged(object sender, WindowWatcher.WindowChangedEventArgs e)
        {
            switch (e.Type)
            {
            case WindowWatcher.WindowChangedEventArgs.ChangeType.Create:
                if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Self)
                {
                    SetEditWindow(e.WindowHandle, ref _hwndFormulaBar);
                    UpdateEditState();
                }
                else if (e.ObjectId == WindowWatcher.WindowChangedEventArgs.ChangeObjectId.Caret)
                {
                    // We expect this on every text change (and it is our only detection of text changes)
                    UpdateEditStateDelayed();
                }
                else
                {
                    Debug.Print($"### Unexpected WindowsChanged object id: {e.ObjectId}");
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:
                // We expect this for every text change, but ignore since we react to the Create event
                //if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
                //{
                //    _formulaEditFocus = FormulaEditFocus.None;
                //    UpdateEditState();
                //}
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Focus:
                if (_formulaEditFocus != FormulaEditFocus.FormulaBar)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Focus");
                    if (e.WindowHandle != _hwndFormulaBar)
                    {
                        // We never saw the Create...
                        SetEditWindow(e.WindowHandle, ref _hwndFormulaBar);
                    }
                    _formulaEditFocus = FormulaEditFocus.FormulaBar;
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Unfocus:
                if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
                {
                    Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Unfocus");
                    _formulaEditFocus = FormulaEditFocus.None;
                    UpdateEditState();
                }
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
                Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Show");
                break;

            case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
                Logger.WindowWatcher.Verbose($"FormulaEdit - FormulaBar Hide");
                break;

            default:
                throw new ArgumentOutOfRangeException("Unexpected Window Change Type", "e.Type");
            }
        }