Exemplo n.º 1
0
 static FocusElementManager()
 {
     FocusElementManager._managers                 = new List <DockingManager>();
     FocusElementManager._modelFocusedElement      = new FullWeakDictionary <ILayoutElement, IInputElement>();
     FocusElementManager._modelFocusedWindowHandle = new WeakDictionary <ILayoutElement, IntPtr>();
     FocusElementManager._windowHandler            = null;
     FocusElementManager._lastFocusedElementBeforeEnterMenuMode = null;
 }
Exemplo n.º 2
0
 private static void Current_Exit(object sender, ExitEventArgs e)
 {
     Application.Current.Exit -= new ExitEventHandler(FocusElementManager.Current_Exit);
     if (FocusElementManager._windowHandler != null)
     {
         FocusElementManager._windowHandler.FocusChanged -= new EventHandler <FocusChangeEventArgs>(FocusElementManager.WindowFocusChanging);
         FocusElementManager._windowHandler.Detach();
         FocusElementManager._windowHandler = null;
     }
 }
Exemplo n.º 3
0
 private static void Current_Exit(object sender, ExitEventArgs e)
 {
     Application.Current.Exit -= new ExitEventHandler(Current_Exit);
     if (_windowHandler != null)
     {
         _windowHandler.FocusChanged -= new EventHandler <FocusChangeEventArgs>(WindowFocusChanging);
         //_windowHandler.Activate -= new EventHandler<WindowActivateEventArgs>(WindowActivating);
         _windowHandler.Detach();
         _windowHandler = null;
     }
 }
Exemplo n.º 4
0
 internal static void FinalizeFocusManagement(DockingManager manager)
 {
     manager.PreviewGotKeyboardFocus -= new KeyboardFocusChangedEventHandler(FocusElementManager.manager_PreviewGotKeyboardFocus);
     FocusElementManager._managers.Remove(manager);
     if (FocusElementManager._managers.Count == 0 && FocusElementManager._windowHandler != null)
     {
         FocusElementManager._windowHandler.FocusChanged -= new EventHandler <FocusChangeEventArgs>(FocusElementManager.WindowFocusChanging);
         FocusElementManager._windowHandler.Detach();
         FocusElementManager._windowHandler = null;
     }
 }
Exemplo n.º 5
0
        internal static void SetupFocusManagement(DockingManager manager)
        {
            if (_managers.Count == 0)
            {
                //InputManager.Current.EnterMenuMode += new EventHandler(InputManager_EnterMenuMode);
                //InputManager.Current.LeaveMenuMode += new EventHandler(InputManager_LeaveMenuMode);
                _windowHandler = new WindowHookHandler();
                _windowHandler.FocusChanged += new EventHandler <FocusChangeEventArgs>(WindowFocusChanging);
                //_windowHandler.Activate += new EventHandler<WindowActivateEventArgs>(WindowActivating);
                _windowHandler.Attach();

                if (Application.Current != null)
                {
                    var currentDispatcher = Application.Current.Dispatcher;
                    if (currentDispatcher != null)
                    {
                        if (currentDispatcher.CheckAccess())
                        {
                            Application.Current.Exit += new ExitEventHandler(Current_Exit);
                        }
                        else
                        {
                            var disableProcessingCountFieldInfo = typeof(Dispatcher).GetField("_disableProcessingCount", BindingFlags.Instance | BindingFlags.NonPublic);
                            if (disableProcessingCountFieldInfo != null)
                            {
                                var disableProcessingCountFieldInfoValue = disableProcessingCountFieldInfo.GetValue(currentDispatcher);
                                if ((disableProcessingCountFieldInfoValue != null) && (disableProcessingCountFieldInfoValue is int))
                                {
                                    var action = new Action(() => Application.Current.Exit += new ExitEventHandler(Current_Exit));

                                    if (( int )disableProcessingCountFieldInfoValue == 0)
                                    {
                                        // in sync
                                        currentDispatcher.Invoke(DispatcherPriority.Normal, action);
                                    }
                                    else
                                    {
                                        // in async.
                                        currentDispatcher.BeginInvoke(DispatcherPriority.Normal, action);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            manager.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(manager_PreviewGotKeyboardFocus);
            _managers.Add(manager);
        }
Exemplo n.º 6
0
 internal static void SetupFocusManagement(DockingManager manager)
 {
     if (FocusElementManager._managers.Count == 0)
     {
         FocusElementManager._windowHandler = new WindowHookHandler();
         FocusElementManager._windowHandler.FocusChanged += new EventHandler <FocusChangeEventArgs>(FocusElementManager.WindowFocusChanging);
         FocusElementManager._windowHandler.Attach();
         if (Application.Current != null)
         {
             Application.Current.Exit += new ExitEventHandler(FocusElementManager.Current_Exit);
         }
     }
     manager.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(FocusElementManager.manager_PreviewGotKeyboardFocus);
     FocusElementManager._managers.Add(manager);
 }
        internal static void FinalizeFocusManagement(DockingManager manager)
        {
            manager.PreviewGotKeyboardFocus -= new KeyboardFocusChangedEventHandler(manager_PreviewGotKeyboardFocus);
            _managers.Remove(manager);

            if (_managers.Count == 0) {
                //InputManager.Current.EnterMenuMode -= new EventHandler(InputManager_EnterMenuMode);
                //InputManager.Current.LeaveMenuMode -= new EventHandler(InputManager_LeaveMenuMode);
                if (_windowHandler != null) {
                    _windowHandler.FocusChanged -= new EventHandler<FocusChangeEventArgs>(WindowFocusChanging);
                    //_windowHandler.Activate -= new EventHandler<WindowActivateEventArgs>(WindowActivating);
                    _windowHandler.Detach();
                    _windowHandler = null;
                }
            }
        }
Exemplo n.º 8
0
        internal static void FinalizeFocusManagement(DockingManager manager)
        {
            manager.PreviewGotKeyboardFocus -= new KeyboardFocusChangedEventHandler(manager_PreviewGotKeyboardFocus);
            _managers.Remove(manager);

            if (_managers.Count == 0)
            {
                //InputManager.Current.EnterMenuMode -= new EventHandler(InputManager_EnterMenuMode);
                //InputManager.Current.LeaveMenuMode -= new EventHandler(InputManager_LeaveMenuMode);
                if (_windowHandler != null)
                {
                    _windowHandler.FocusChanged -= new EventHandler <FocusChangeEventArgs>(WindowFocusChanging);
                    //_windowHandler.Activate -= new EventHandler<WindowActivateEventArgs>(WindowActivating);
                    _windowHandler.Detach();
                    _windowHandler = null;
                }
            }
        }
        internal static void SetupFocusManagement(DockingManager manager)
        {
            if (_managers.Count == 0)
            {
                //InputManager.Current.EnterMenuMode += new EventHandler(InputManager_EnterMenuMode);
                //InputManager.Current.LeaveMenuMode += new EventHandler(InputManager_LeaveMenuMode);
                _windowHandler = new WindowHookHandler();
                _windowHandler.FocusChanged += new EventHandler<FocusChangeEventArgs>(WindowFocusChanging);
                //_windowHandler.Activate += new EventHandler<WindowActivateEventArgs>(WindowActivating);
                _windowHandler.Attach();

                if (Application.Current != null)
                    Application.Current.Exit += new ExitEventHandler(Current_Exit);
            }

            manager.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(manager_PreviewGotKeyboardFocus);
            _managers.Add(manager);
        }
Exemplo n.º 10
0
        internal static void SetupFocusManagement(DockingManager manager)
        {
            if (_managers.Count == 0)
            {
                //InputManager.Current.EnterMenuMode += new EventHandler(InputManager_EnterMenuMode);
                //InputManager.Current.LeaveMenuMode += new EventHandler(InputManager_LeaveMenuMode);
                _windowHandler = new WindowHookHandler();
                _windowHandler.FocusChanged += new EventHandler <FocusChangeEventArgs>(WindowFocusChanging);
                //_windowHandler.Activate += new EventHandler<WindowActivateEventArgs>(WindowActivating);
                _windowHandler.Attach();

                if (Application.Current != null)
                {
                    Application.Current.Exit += new ExitEventHandler(Current_Exit);
                }
            }

            manager.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(manager_PreviewGotKeyboardFocus);
            _managers.Add(manager);
        }
Exemplo n.º 11
0
        internal static void SetupFocusManagement(DockingManager manager)
        {
            if (_managers.Count == 0)
            {
                //InputManager.Current.EnterMenuMode += new EventHandler(InputManager_EnterMenuMode);
                //InputManager.Current.LeaveMenuMode += new EventHandler(InputManager_LeaveMenuMode);
                _windowHandler = new WindowHookHandler();
                _windowHandler.FocusChanged += new EventHandler <FocusChangeEventArgs>(WindowFocusChanging);
                //_windowHandler.Activate += new EventHandler<WindowActivateEventArgs>(WindowActivating);
                _windowHandler.Attach();
                if (Application.Current != null)
                {
                    //Application.Current.Exit += new ExitEventHandler( Current_Exit );
                    //Application.Current.Dispatcher.Invoke(new Action(() => Application.Current.Exit += new ExitEventHandler(Current_Exit)));
                    var    disp = Application.Current.Dispatcher;
                    Action subscribeToExitAction = new Action(() => Application.Current.Exit += new ExitEventHandler(Current_Exit));
                    if (disp.CheckAccess())
                    {
                        // if we are already on the dispatcher thread we don't need to call Invoke/BeginInvoke
                        subscribeToExitAction();
                    }
                    else
                    {
                        // For resolve issue "System.InvalidOperationException: Cannot perform this operation while dispatcher processing is suspended." make async subscribing instead of sync subscribing.
                        int disableProcessingCount = (int?)typeof(Dispatcher).GetField("_disableProcessingCount", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(disp) ?? 0;

                        if (disableProcessingCount == 0)
                        {
                            disp.Invoke(subscribeToExitAction);
                        }
                        else
                        {
                            disp.BeginInvoke(subscribeToExitAction);
                        }
                    }
                }
            }

            manager.PreviewGotKeyboardFocus += new KeyboardFocusChangedEventHandler(manager_PreviewGotKeyboardFocus);
            _managers.Add(manager);
        }
 private static void Current_Exit(object sender, ExitEventArgs e)
 {
     Application.Current.Exit -= new ExitEventHandler(Current_Exit);
     if (_windowHandler != null) {
         _windowHandler.FocusChanged -= new EventHandler<FocusChangeEventArgs>(WindowFocusChanging);
         //_windowHandler.Activate -= new EventHandler<WindowActivateEventArgs>(WindowActivating);
         _windowHandler.Detach();
         _windowHandler = null;
     }
 }