Example #1
0
        /// <summary>
        /// Invoked when the focus changes either in the active window or when the
        /// active window itself changes.
        /// </summary>
        /// <param name="monitorInfo">Info about focused element</param>
        /// <param name="handled">was this handled</param>
        public override void OnFocusChanged(WindowActivityMonitorInfo monitorInfo, ref bool handled)
        {
            Log.Debug("OnFocus: " + monitorInfo.ToString());

            base.OnFocusChanged(monitorInfo, ref handled);

            var handle = IntPtr.Zero;

            if (_form != null)
            {
                _form.Invoke(new MethodInvoker(delegate()
                {
                    handle = _form.Handle;
                }));
            }

            // if the abbreviations scanner is up, display the
            // alphabet scanner
            if (handle != IntPtr.Zero && monitorInfo.FgHwnd == handle)
            {
                if (!_scannerShown)
                {
                    var arg = new PanelRequestEventArgs(PanelClasses.AlphabetMinimal, monitorInfo)
                    {
                        RequestArg  = _form,
                        TargetPanel = _form,
                        UseCurrentScreenAsParent = true
                    };
                    showPanel(this, arg);
                    _scannerShown = true;
                }
            }

            handled = true;
        }
Example #2
0
        /// <summary>
        /// Invoked when the focus changes either in the active window or when the
        /// active window itself changes.
        /// </summary>
        /// <param name="monitorInfo">Info about focused element</param>
        /// <param name="handled">was this handled</param>
        public override void OnFocusChanged(WindowActivityMonitorInfo monitorInfo, ref bool handled)
        {
            Log.Debug("OnFocus: " + monitorInfo.ToString());

            base.OnFocusChanged(monitorInfo, ref handled);

            setTextInterface(textInterface);

            if (_menuShown)
            {
                return;
            }

            var arg = new PanelRequestEventArgs(PanelClasses.None, monitorInfo);

            handled = getLectureManagerPanel(arg);

            Log.Debug("handled: " + handled);

            if (handled)
            {
                _menuShown = true;
                Log.Debug("calling showpanel for : " + arg.PanelClass);

                showPanel(this, arg);
            }
        }
Example #3
0
        /// <summary>
        /// Invoked when the focus changes either in the active window or when the
        /// active window itself changes.
        /// </summary>
        /// <param name="monitorInfo">Info about focused element</param>
        /// <param name="handled">was this handled</param>
        public override void OnFocusChanged(WindowActivityMonitorInfo monitorInfo, ref bool handled)
        {
            Log.Debug("OnFocus: " + monitorInfo.ToString());

            base.OnFocusChanged(monitorInfo, ref handled);
            Log.Debug("menuShown: " + _scannerShown + ", title: " + monitorInfo.Title);
            if (!_scannerShown && monitorInfo.Title == "Create New File")
            {
                var arg = new PanelRequestEventArgs("Alphabet", monitorInfo);
                _scannerShown = true;
                showPanel(this, arg);
            }

            handled = true;
        }
Example #4
0
        /// <summary>
        /// Invoked when the focus changes either in the active window or when the
        /// active window itself changes.
        /// </summary>
        /// <param name="monitorInfo">Info about focused element</param>
        /// <param name="handled">was this handled</param>
        public override void OnFocusChanged(WindowActivityMonitorInfo monitorInfo, ref bool handled)
        {
            Log.Debug("OnFocus: " + monitorInfo.ToString() + ", menushown: " + _scannerShown);

            base.OnFocusChanged(monitorInfo, ref handled);

            if (!_scannerShown && _launchAppScanner != null)
            {
                var arg = new PanelRequestEventArgs(PanelClasses.AlphabetMinimal, monitorInfo)
                {
                    TargetPanel = _launchAppScanner,
                    RequestArg  = _launchAppScanner,
                    UseCurrentScreenAsParent = true
                };
                showPanel(this, arg);
                _scannerShown = true;
            }

            handled = true;
        }
Example #5
0
        public override void OnFocusChanged(WindowActivityMonitorInfo monitorInfo, ref bool handled)
        {
            Log.Debug("OnFocus: " + monitorInfo.ToString());

            base.OnFocusChanged(monitorInfo, ref handled);

            setTextInterface(textInterface);

            if (!_menuShown)
            {
                var arg = new PanelRequestEventArgs(PanelClasses.None, monitorInfo);
                handled = getPanel(arg);

                if (handled)
                {
                    _menuShown = true;
                    showPanel(this, arg);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Event triggered when the active foreground window changes
        /// or if focus changes within the foreground window
        /// </summary>
        /// <param name="monitorInfo">Info about focused element</param>
        private void onFocusChanged(WindowActivityMonitorInfo monitorInfo)
        {
            if (monitorInfo.FgHwnd == IntPtr.Zero)
            {
                Log.Debug("hWnd is null");
                return;
            }

            Log.Debug(monitorInfo.ToString());

            //Log.Debug(" hwnd: " + hWnd + " Title:  [" + title + "] process: " + process.ProcessName +
            //      ". focusedElement: [" +
            //  ((focusedElement != null) ? focusedElement.Current.ClassName : "null") + "]");

            bool handled = false;

            if (_currentAgent is IFunctionalAgent)
            {
                _currentAgent.OnFocusChanged(monitorInfo, ref handled);
            }
            else
            {
                activateAppAgent(monitorInfo);
            }

            if (_currentAgent != null)
            {
                Log.Debug("CurrentAgent is " + _currentAgent.GetType());
            }

            if (EvtFocusChanged != null)
            {
                EvtFocusChanged(this, new FocusChangedEventArgs(monitorInfo));
            }
            else
            {
                Log.Debug("EVTFocusChanged is null!");
            }
        }
Example #7
0
        public override void OnFocusChanged(WindowActivityMonitorInfo monitorInfo, ref bool handled)
        {
            Log.Debug("OnFocus: " + monitorInfo.ToString());

            base.OnFocusChanged(monitorInfo, ref handled);

            if (monitorInfo.IsNewWindow)
            {
                showPanelOnFocusChanged(this, new PanelRequestEventArgs(PanelClasses.Alphabet, monitorInfo));
                handled = true;
            }

#if abc
            String panel = PanelClasses.None;
            handled = getPanel(monitorInfo, false, ref panel);

            if (handled)
            {
                showPanelOnFocusChanged(this, new PanelRequestEventArgs(panel, "Explorer", monitorInfo));
            }
#endif
        }
Example #8
0
        /// <summary>
        /// Activates an application agent depending on the context.
        /// The monitorInfo parameter has all the information to make
        /// this decision. Depending on the active foreground process,
        /// the appropriate agent is activated.  if there is no dedicated
        /// agent for the process, the generic agent is used.
        /// If a dialog the foreground window, the dialog agent is activated.
        /// If a menu has been activated, the menu agent is activated
        /// </summary>
        /// <param name="monitorInfo">Foreground window/process info</param>
        private void activateAppAgent(WindowActivityMonitorInfo monitorInfo)
        {
            if (_inActivateAppAgent)
            {
                Log.Debug("Already inside. returning");
                return;
            }

            Log.Debug("Before syncsetagent");
            lock (_syncActivateAgent)
            {
                _inActivateAppAgent = true;
                Log.Debug("After syncsetagent");
                try
                {
                    bool handled = false;

                    Log.Debug(monitorInfo.ToString());

                    // did a request for displaying the contextual
                    // menu come in?  If so handle it.

                    bool getContextMenu = _getContextMenu;

                    Log.Debug("getContextMenu: " + getContextMenu);

                    _getContextMenu = false;

                    String processName = monitorInfo.FgProcess.ProcessName;

                    // first check if there is an ad-hoc agent, if so,
                    // activate it
                    Log.Debug("Looking for adhoc agent for " + monitorInfo.FgHwnd);
                    IApplicationAgent agent = _agentsCache.GetAgent(monitorInfo.FgHwnd);
                    if (agent == null)
                    {
                        // check if a dialog or menu is active
                        Log.Debug("Adhoc agent not present for " + monitorInfo.FgHwnd);

                        if (EnableContextualMenusForDialogs &&
                            (String.Compare(processName, _currentProcessName, true) != 0) &&
                            isDialog(monitorInfo))
                        {
                            Log.Debug("Fg window is a dialog.  Setting agent to dialog agent");

                            agent = _dialogAgent;
                        }
                        else if (EnableContextualMenusForMenus && isMenu(monitorInfo))
                        {
                            Log.Debug("Fg window is a menu.  Setting agent to menu agent");
                            agent = _menuControlAgent;
                        }
                        else
                        {
                            // check if there is a dedicated agent for
                            // this process
                            Log.Debug("Getting agent for " + processName);
                            agent = _agentsCache.GetAgent(monitorInfo.FgProcess);
                        }
                    }
                    else
                    {
                        Log.Debug("Adhoc agent IS present for " + monitorInfo.FgHwnd);
                    }

                    Log.Debug("Current agent: " + ((_currentAgent != null) ?
                                                   _currentAgent.Name : "null") +
                              ", agent:  " + ((agent != null) ? agent.Name : "null"));

                    // if there is an agent switch, query the current agent
                    // if it is OK to switch. Some agents may not allow
                    // the switch
                    if (_currentAgent != null && _currentAgent != agent)
                    {
                        bool allowSwitch = _currentAgent.QueryAgentSwitch(agent);
                        Log.Debug("CurrentAgent is " + _currentAgent.Name + ", queryAgentSwitch: " + allowSwitch);
                        if (!allowSwitch)
                        {
                            _currentAgent.OnFocusChanged(monitorInfo, ref handled);
                            _textControlAgent = _currentAgent.TextControlAgent;
                            return;
                        }

                        _currentAgent.OnFocusLost();
                    }

                    // if there was a request to display
                    // contextual menu, do so
                    if (getContextMenu)
                    {
                        if (agent == null)
                        {
                            agent = _genericAppAgent;
                        }

                        Log.Debug("agent : " + agent.Name);
                        agent.OnContextMenuRequest(monitorInfo);
                        return;
                    }

                    // Inform the new agent about the current
                    // focused element so it can display the scanner that
                    // is appropriated for the context.
                    if (agent != null)
                    {
                        Log.Debug("Trying agent " + agent.Name);
                        agent.OnFocusChanged(monitorInfo, ref handled);
                        Log.Debug("Returned from agent.OnFOcus");
                    }

                    // If we have reached here, it means there was no
                    // agent. Just use the default generic agent. See
                    // if it will handle it
                    if (!handled)
                    {
                        Log.Debug("Did not find agent for " + processName + ". trying generic app agent");
                        Log.Debug("_genericAppAgent is " + ((_genericAppAgent != null) ? "not null" : "null"));
                        agent = _genericAppAgent;
                        try
                        {
                            agent.OnFocusChanged(monitorInfo, ref handled);
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(ex);
                        }
                    }

                    // even the generic agent refused.  Use the null agent
                    // as the last resort
                    Log.Debug("handled " + handled);
                    if (!handled)
                    {
                        Log.Debug("generic app agent refused. Using null agent");
                        agent = _nullAgent;
                        agent.OnFocusChanged(monitorInfo, ref handled);
                    }

                    updateCurrentAgentAndNotify(agent);
                }
                catch (Exception ex)
                {
                    Log.Debug(ex.ToString());
                }
                finally
                {
                    _inActivateAppAgent = false;
                }
            }

            Log.Debug("Return");
        }