Пример #1
0
        private static void StatusBarValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiContainer mdiContainer = (MdiContainer)sender;
            UIElement    menu         = (UIElement)e.NewValue;

            mdiContainer._statusbar.Child = menu;
        }
Пример #2
0
        /// <summary>
        /// Dependency property event once the theme value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void ThemeValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiContainer mdiContainer = (MdiContainer)sender;
            ThemeType    themeType    = (ThemeType)e.NewValue;

            if (currentResourceDictionary != null)
            {
                Application.Current.Resources.MergedDictionaries.Remove(currentResourceDictionary);
            }

            switch (themeType)
            {
            case ThemeType.Luna:
                Application.Current.Resources.MergedDictionaries.Add(currentResourceDictionary = new ResourceDictionary {
                    Source = new Uri(@"/WWPF.MDI;component/Themes/Luna.xaml", UriKind.Relative)
                });
                break;

            case ThemeType.Aero:
                Application.Current.Resources.MergedDictionaries.Add(currentResourceDictionary = new ResourceDictionary {
                    Source = new Uri(@"/WWPF.MDI;component/Themes/Aero.xaml", UriKind.Relative)
                });
                break;
            }
        }
Пример #3
0
        static void MdiContainer_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            MdiContainer mdiContainer = (MdiContainer)sender;

            if (mdiContainer.Children.Count < 2)
            {
                return;
            }
            switch (e.Key)
            {
            case Key.Tab:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    int minZindex = Panel.GetZIndex(mdiContainer.Children[0]);
                    foreach (MdiChild mdiChild in mdiContainer.Children)
                    {
                        if (Panel.GetZIndex(mdiChild) < minZindex)
                        {
                            minZindex = Panel.GetZIndex(mdiChild);
                        }
                    }
                    Panel.SetZIndex(mdiContainer.GetTopChild(), minZindex - 1);
                    mdiContainer.GetTopChild().Focus();
                    e.Handled = true;
                }
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// Handles the Loaded event of the MdiChild control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void MdiChild_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement currentControl = this;

            while (currentControl != null && currentControl.GetType() != typeof(MdiContainer))
            {
                currentControl = (FrameworkElement)currentControl.Parent;
            }

            if (currentControl != null)
            {
                Container = (MdiContainer)currentControl;
            }
            //else throw new Exception("Unable to find MdiContainer parent.");
        }
Пример #5
0
        /// <summary>
        /// Dependency property event once the windows state value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void WindowStateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiChild mdiChild = (MdiChild)sender;

            WindowState previousWindowState = (WindowState)e.OldValue;
            WindowState windowState         = (WindowState)e.NewValue;

            if (mdiChild.Container == null ||
                previousWindowState == windowState)
            {
                return;
            }

            if (previousWindowState == WindowState.Maximized)
            {
                for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                {
                    if (mdiChild.Container.Children[i] != mdiChild &&
                        mdiChild.Container.Children[i].WindowState == WindowState.Maximized &&
                        mdiChild.Container.Children[i].MaximizeBox)
                    {
                        mdiChild.Container.Children[i].WindowState = WindowState.Normal;
                    }
                }

                ScrollViewer sv = (ScrollViewer)((Grid)mdiChild.Container.Content).Children[1];
                sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

                mdiChild.Buttons.Children.Clear();
                mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton);
                mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton);
                mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton);
            }

            if (previousWindowState == WindowState.Minimized)
            {
                mdiChild.minimizedPosition = mdiChild.Position;
            }

            switch (windowState)
            {
            case WindowState.Normal:
            {
                mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y);

                mdiChild.Width  = mdiChild.originalDimension.Width;
                mdiChild.Height = mdiChild.originalDimension.Height;
            }
            break;

            case WindowState.Minimized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                double newLeft, newTop;
                if (mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0)
                {
                    newLeft = mdiChild.minimizedPosition.X;
                    newTop  = mdiChild.minimizedPosition.Y;
                }
                else
                {
                    #region Simple
                    int minimizedWindows = 0;
                    for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                    {
                        if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                        {
                            minimizedWindows++;
                        }
                    }
                    int capacity = Convert.ToInt32(mdiChild.Container.ActualWidth) / MdiChild.MinimizedWidth,
                        row      = minimizedWindows / capacity + 1,
                        col      = minimizedWindows % capacity;
                    newTop  = mdiChild.Container.InnerHeight - MdiChild.MinimizedHeight * row;
                    newLeft = MdiChild.MinimizedWidth * col;
                    #endregion
                    #region Complex
                    //List<MdiChild> minimizedWindows = new List<MdiChild>();
                    //for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                    //    if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                    //        minimizedWindows.Add(mdiChild.Container.Children[i]);

                    #endregion
                }

                mdiChild.Position = new Point(newLeft, newTop);

                mdiChild.Width  = MdiChild.MinimizedWidth;
                mdiChild.Height = MdiChild.MinimizedHeight;
            }
            break;

            case WindowState.Maximized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                mdiChild.buttonsPanel.Children.Clear();
                StackPanel sp = new StackPanel {
                    Orientation = Orientation.Horizontal
                };
                sp.Children.Add(mdiChild.minimizeButton);
                sp.Children.Add(mdiChild.maximizeButton);
                sp.Children.Add(mdiChild.closeButton);
                mdiChild.Buttons = sp;

                mdiChild.Position = new Point(0, 0);
                mdiChild.Width    = mdiChild.Container.ActualWidth;
                mdiChild.Height   = mdiChild.Container.InnerHeight - 2;                               // ContentBorder.BorderThickness="1" in template

                if (mdiChild.Container.AllowWindowStateMax)
                {
                    MdiContainer mdiContainer = mdiChild.Container;
                    mdiContainer.AllowWindowStateMax = false;

                    for (int i = 0; i < mdiContainer.Children.Count; i++)
                    {
                        if (mdiContainer.Children[i] != mdiChild)
                        {
                            if (mdiContainer.Children[i].WindowState == WindowState.Normal &&
                                mdiContainer.Children[i].MaximizeBox)
                            {
                                mdiContainer.Children[i].WindowState = WindowState.Maximized;
                            }
                            else if (mdiContainer.Children[i].WindowState == WindowState.Maximized)
                            {
                                mdiContainer.Children[i].Height = mdiContainer.InnerHeight;
                            }
                        }
                    }

                    ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];
                    sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                    sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;

                    mdiChild.Focus();
                    mdiContainer.InvalidateSize();
                    mdiContainer.AllowWindowStateMax = true;
                }
            }
            break;
            }
        }
Пример #6
0
 /// <summary>
 /// Set focus to the child window and brings into view.
 /// </summary>
 public new void Focus()
 {
     //Container.ReArrange(this);
     MdiContainer.Focus(this);
 }
Пример #7
0
        /// <summary>
        /// Dependency property event once the MDI layout value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void MdiLayoutValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiContainer mdiContainer = (MdiContainer)sender;
            MdiLayout    value        = (MdiLayout)e.NewValue;

            if (value == MdiLayout.ArrangeIcons ||
                mdiContainer.Children.Count < 1)
            {
                return;
            }

            // 1. WindowState.Maximized -> WindowState.Normal
            List <MdiChild> minimizedWindows = new List <MdiChild>(),
                            normalWindows    = new List <MdiChild>();

            foreach (MdiChild mdiChild in mdiContainer.Children)
            {
                switch (mdiChild.WindowState)
                {
                case WindowState.Minimized:
                    minimizedWindows.Add(mdiChild);
                    break;

                case WindowState.Maximized:
                    mdiChild.WindowState = WindowState.Normal;
                    normalWindows.Add(mdiChild);
                    break;

                default:
                    normalWindows.Add(mdiChild);
                    break;
                }
            }

            minimizedWindows.Sort(new MdiChildComparer());
            normalWindows.Sort(new MdiChildComparer());

            // 2. Arrange minimized windows
            double containerHeight = mdiContainer.InnerHeight;

            for (int i = 0; i < minimizedWindows.Count; i++)
            {
                MdiChild mdiChild = minimizedWindows[i];
                int      capacity = Convert.ToInt32(mdiContainer.ActualWidth) / MdiChild.MinimizedWidth,
                         row      = i / capacity + 1,
                         col      = i % capacity;
                containerHeight = mdiContainer.InnerHeight - MdiChild.MinimizedHeight * row;
                double newLeft = MdiChild.MinimizedWidth * col;
                mdiChild.Position = new Point(newLeft, containerHeight);
            }

            // 3. Resize & arrange normal windows
            switch (value)
            {
            case MdiLayout.Cascade:
            {
                double newWidth     = mdiContainer.ActualWidth * 0.58,                             // should be non-linear formula here
                       newHeight    = containerHeight * 0.67,
                       windowOffset = 0;
                foreach (MdiChild mdiChild in normalWindows)
                {
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(windowOffset, windowOffset);

                    windowOffset += WindowOffset;
                    if (windowOffset + mdiChild.Width > mdiContainer.ActualWidth)
                    {
                        windowOffset = 0;
                    }
                    if (windowOffset + mdiChild.Height > containerHeight)
                    {
                        windowOffset = 0;
                    }
                }
            }
            break;

            case MdiLayout.TileHorizontal:
            {
                int cols = (int)Math.Sqrt(normalWindows.Count),
                    rows = normalWindows.Count / cols;

                List <int> col_count = new List <int>();                               // windows per column
                for (int i = 0; i < cols; i++)
                {
                    if (normalWindows.Count % cols > cols - i - 1)
                    {
                        col_count.Add(rows + 1);
                    }
                    else
                    {
                        col_count.Add(rows);
                    }
                }

                double newWidth   = mdiContainer.ActualWidth / cols,
                       newHeight  = containerHeight / col_count[0],
                       offsetTop  = 0,
                       offsetLeft = 0;

                for (int i = 0, col_index = 0, prev_count = 0; i < normalWindows.Count; i++)
                {
                    if (i >= prev_count + col_count[col_index])
                    {
                        prev_count += col_count[col_index++];
                        offsetLeft += newWidth;
                        offsetTop   = 0;
                        newHeight   = containerHeight / col_count[col_index];
                    }

                    MdiChild mdiChild = normalWindows[i];
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(offsetLeft, offsetTop);
                    offsetTop        += newHeight;
                }
            }
            break;

            case MdiLayout.TileVertical:
            {
                int rows = (int)Math.Sqrt(normalWindows.Count),
                    cols = normalWindows.Count / rows;

                List <int> col_count = new List <int>();                               // windows per column
                for (int i = 0; i < cols; i++)
                {
                    if (normalWindows.Count % cols > cols - i - 1)
                    {
                        col_count.Add(rows + 1);
                    }
                    else
                    {
                        col_count.Add(rows);
                    }
                }

                double newWidth   = mdiContainer.ActualWidth / cols,
                       newHeight  = containerHeight / col_count[0],
                       offsetTop  = 0,
                       offsetLeft = 0;

                for (int i = 0, col_index = 0, prev_count = 0; i < normalWindows.Count; i++)
                {
                    if (i >= prev_count + col_count[col_index])
                    {
                        prev_count += col_count[col_index++];
                        offsetLeft += newWidth;
                        offsetTop   = 0;
                        newHeight   = containerHeight / col_count[col_index];
                    }

                    MdiChild mdiChild = normalWindows[i];
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(offsetLeft, offsetTop);
                    offsetTop        += newHeight;
                }
            }
            break;
            }
            mdiContainer.InvalidateSize();
            mdiContainer.MdiLayout = MdiLayout.ArrangeIcons;
        }