Beispiel #1
0
        private static void WindowFocusChanging(object sender, FocusChangeEventArgs e)
        {
            Func <HwndHost, bool> func = null;

            foreach (DockingManager _manager in FocusElementManager._managers)
            {
                IEnumerable <HwndHost> hwndHosts = _manager.FindLogicalChildren <HwndHost>();
                Func <HwndHost, bool>  func1     = func;
                if (func1 == null)
                {
                    Func <HwndHost, bool> func2 = (HwndHost hw) => Win32Helper.IsChild(hw.Handle, e.GotFocusWinHandle);
                    Func <HwndHost, bool> func3 = func2;
                    func  = func2;
                    func1 = func3;
                }
                HwndHost hwndHost = hwndHosts.FirstOrDefault <HwndHost>(func1);
                if (hwndHost == null)
                {
                    continue;
                }
                LayoutAnchorableControl gotFocusWinHandle = hwndHost.FindVisualAncestor <LayoutAnchorableControl>();
                if (gotFocusWinHandle == null)
                {
                    LayoutDocumentControl layoutDocumentControl = hwndHost.FindVisualAncestor <LayoutDocumentControl>();
                    if (layoutDocumentControl == null)
                    {
                        continue;
                    }
                    FocusElementManager._modelFocusedWindowHandle[layoutDocumentControl.Model] = e.GotFocusWinHandle;
                    if (layoutDocumentControl.Model == null)
                    {
                        continue;
                    }
                    layoutDocumentControl.Model.IsActive = true;
                }
                else
                {
                    FocusElementManager._modelFocusedWindowHandle[gotFocusWinHandle.Model] = e.GotFocusWinHandle;
                    if (gotFocusWinHandle.Model == null)
                    {
                        continue;
                    }
                    gotFocusWinHandle.Model.IsActive = true;
                }
            }
        }
Beispiel #2
0
        private static void manager_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            Visual newFocus = e.NewFocus as Visual;

            if (newFocus != null && !(newFocus is LayoutAnchorableTabItem) && !(newFocus is LayoutDocumentTabItem))
            {
                LayoutAnchorableControl layoutAnchorableControl = newFocus.FindVisualAncestor <LayoutAnchorableControl>();
                if (layoutAnchorableControl != null)
                {
                    FocusElementManager._modelFocusedElement[layoutAnchorableControl.Model] = e.NewFocus;
                    return;
                }
                LayoutDocumentControl layoutDocumentControl = newFocus.FindVisualAncestor <LayoutDocumentControl>();
                if (layoutDocumentControl != null)
                {
                    FocusElementManager._modelFocusedElement[layoutDocumentControl.Model] = e.NewFocus;
                }
            }
        }
        internal UIElement CreateUIElementForModel(ILayoutElement model)
        {
            if (model is LayoutPanel)
                return new LayoutPanelControl(model as LayoutPanel);
            if (model is LayoutAnchorablePaneGroup)
                return new LayoutAnchorablePaneGroupControl(model as LayoutAnchorablePaneGroup);
            if (model is LayoutDocumentPaneGroup)
                return new LayoutDocumentPaneGroupControl(model as LayoutDocumentPaneGroup);

            if (model is LayoutAnchorSide)
            {
                var templateModelView = new LayoutAnchorSideControl(model as LayoutAnchorSide);
                templateModelView.SetBinding(LayoutAnchorSideControl.TemplateProperty, new Binding("AnchorSideTemplate") { Source = this });
                return templateModelView;
            }
            if (model is LayoutAnchorGroup)
            {
                var templateModelView = new LayoutAnchorGroupControl(model as LayoutAnchorGroup);
                templateModelView.SetBinding(LayoutAnchorGroupControl.TemplateProperty, new Binding("AnchorGroupTemplate") { Source = this });
                return templateModelView;
            }

            if (model is LayoutDocumentPane)
            {
                var templateModelView = new LayoutDocumentPaneControl(model as LayoutDocumentPane);
                templateModelView.SetBinding(LayoutDocumentPaneControl.StyleProperty, new Binding("DocumentPaneControlStyle") { Source = this });
                return templateModelView;
            }
            if (model is LayoutAnchorablePane)
            {
                var templateModelView = new LayoutAnchorablePaneControl(model as LayoutAnchorablePane);
                templateModelView.SetBinding(LayoutAnchorablePaneControl.StyleProperty, new Binding("AnchorablePaneControlStyle") { Source = this });
                return templateModelView;
            }

            if (model is LayoutAnchorableFloatingWindow)
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return null;
                var modelFW = model as LayoutAnchorableFloatingWindow;
                var newFW = new LayoutAnchorableFloatingWindowControl(modelFW)
                {
                    //Owner = Window.GetWindow(this)
                };
                newFW.SetParentToMainWindowOf(this);

                var paneForExtensions = modelFW.RootPanel.Children.OfType<LayoutAnchorablePane>().FirstOrDefault();
                if (paneForExtensions != null)
                {
                    //ensure that floating window position is inside current (or nearest) monitor
                    paneForExtensions.KeepInsideNearestMonitor();

                    newFW.Left = paneForExtensions.FloatingLeft;
                    newFW.Top = paneForExtensions.FloatingTop;
                    newFW.Width = paneForExtensions.FloatingWidth;
                    newFW.Height = paneForExtensions.FloatingHeight;
                }

                newFW.ShowInTaskbar = false;
                newFW.Show();
                // Do not set the WindowState before showing or it will be lost
                if( paneForExtensions != null && paneForExtensions.IsMaximized )
                {
                  newFW.WindowState = WindowState.Maximized;
                }
                return newFW;
            }

            if (model is LayoutDocumentFloatingWindow)
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return null;
                var modelFW = model as LayoutDocumentFloatingWindow;
                var newFW = new LayoutDocumentFloatingWindowControl(modelFW)
                {
                    //Owner = Window.GetWindow(this)
                };
                newFW.SetParentToMainWindowOf(this);

                var paneForExtensions = modelFW.RootDocument;
                if (paneForExtensions != null)
                {
                    //ensure that floating window position is inside current (or nearest) monitor
                    paneForExtensions.KeepInsideNearestMonitor();

                    newFW.Left = paneForExtensions.FloatingLeft;
                    newFW.Top = paneForExtensions.FloatingTop;
                    newFW.Width = paneForExtensions.FloatingWidth;
                    newFW.Height = paneForExtensions.FloatingHeight;
                }

                newFW.ShowInTaskbar = false;
                newFW.Show();
                // Do not set the WindowState before showing or it will be lost
                if( paneForExtensions != null && paneForExtensions.IsMaximized )
                {
                  newFW.WindowState = WindowState.Maximized;
                }
                return newFW;
            }

            if (model is LayoutDocument)
            {
                var templateModelView = new LayoutDocumentControl() { Model = model as LayoutDocument };
                return templateModelView;
            }

            return null;
        }