예제 #1
0
        private void ShowScreen(ApplicationScreen screen)
        {
            #region Pre-conditions
            Debug.Assert(screen != null);
            #endregion

            var cancelRemove = false;

            // notify current view for permission to remove
            ActiveScreen?.NotifyHideScreen(ref cancelRemove);

            // remove if current view granted permission
            if (!cancelRemove)
            {
                _splitContainer.Panel2.SuspendLayout();

                // remove the view toolbar items if any
                if (ActiveScreen != null)
                {
                    UnregisterScreenFromMenu(ActiveScreen);
                    // put the tool buttons back into the screen toolbar
                    ActiveScreen.ToolBar?.Items.AddRange(ActiveViewButtons.ToArray());
                    ActiveViewButtons.Clear();

                    // remove the view control
                    if (_splitContainer.Panel2.Controls.Contains(ActiveScreen))
                    {
                        _splitContainer.Panel2.Controls.Remove(ActiveScreen);
                    }
                    // dispose view and release its resources
                    if (ActiveScreen.ActivationMode == ScreenActivationMode.AlwaysCreate)
                    {
                        ActiveScreen.Dispose();
                    }
                }

                // collapse menu if new screen demands it
                bool collapseMenu =
                    screen.DisplayMode == ScreenDisplayMode.Filled ||
                    screen.DisplayMode == ScreenDisplayMode.FilledAndMaximized;
                _splitContainer.Panel1Collapsed = collapseMenu;

                // maximize if new screen demands it
                bool maximize =
                    screen.DisplayMode == ScreenDisplayMode.FilledAndMaximized ||
                    screen.DisplayMode == ScreenDisplayMode.Maximized;
                if (maximize)
                {
                    base.WindowState = FormWindowState.Maximized;
                }

                // place the new view in the content panel
                screen.Dock     = DockStyle.Fill;
                screen.Location = new Point(0, 0);
                screen.Name     = "VIEW";
                screen.TabIndex = 0;
                screen.Location = new Point(
                    _splitContainer.Panel2.Padding.Left,
                    _splitContainer.Panel2.Padding.Top
                    );
                Size newSize = new Size(
                    _splitContainer.Width -
                    (_splitContainer.SplitterDistance + _splitContainer.SplitterWidth) -
                    (_splitContainer.Panel2.Padding.Left + _splitContainer.Panel2.Padding.Right),
                    _splitContainer.Height -
                    (_splitContainer.Panel2.Padding.Top + _splitContainer.Panel2.Padding.Bottom)
                    );
                if (collapseMenu)
                {
                    newSize.Width = newSize.Width + _splitContainer.SplitterDistance;
                }
                ;
                screen.Size = newSize;
                screen.PerformLayout();
                _splitContainer.Panel2.Controls.Add(screen);
                _splitContainer.Panel2.ResumeLayout(false);

                // set current view sa the active view
                ActiveScreen = screen;

                // place new tool strip items
                if (ActiveScreen.ShowInApplicationMenuStrip)
                {
                    RegisterScreenInMenu(ActiveScreen);
                }
                RebuildToolBar();

                // let view know that it has begun
                ActiveScreen.NotifyShow();
            }
        }
예제 #2
0
        private void RebuildToolBar()
        {
            ToolStrip.SuspendLayout();
            ToolStrip.Items.Clear();

            #region Add standard buttons

            #endregion

            #region Add screen list buttons

            foreach (IApplicationBlock block in Plugins)
            {
                if (block.ShowInToolStrip)
                {
                    if (ToolStrip.Items.Count > 0)
                    {
                        ToolStrip.Items.Add(new ToolStripSeparator());
                    }
                    foreach (IMenu menu in block.Menus)
                    {
                        foreach (IMenuItem item in menu.Items)
                        {
                            if (item is ILinkMenuItem)
                            {
                                ILinkMenuItem linkItem = item as ILinkMenuItem;
                                if (linkItem.ShowOnToolStrip)
                                {
                                    ToolStripButton button = new ToolStripButton(
                                        string.Empty,
                                        item.Image16x16 != null ? item.Image16x16 : Sphere10.Framework.Windows.Forms.Properties.Resources.DefaultToolStripImage,
                                        ToolStripItemActivate
                                        );
                                    button.ToolTipText = linkItem.Text;
                                    ToolStrip.Items.Add(button);
                                    ToolStripBindings.Add(
                                        button,
                                        item
                                        );
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            #region Add active screen buttons
            if (ActiveScreen != null)
            {
                if (ActiveScreen.ToolBar != null)
                {
                    if (ToolStrip.Items.Count > 0)
                    {
                        ToolStrip.Items.Add(new ToolStripSeparator());
                    }

                    int buttonCount = ActiveScreen.ToolBar.Items.Count;
                    ActiveViewButtons.Clear();
                    for (int i = 0; i < buttonCount; i++)
                    {
                        ActiveViewButtons.Add(
                            ActiveScreen.ToolBar.Items[i]
                            );
                    }
                    if (ActiveScreen.ToolBar.Tag == null)
                    {
                        foreach (Control ctrl in ActiveScreen.Controls)
                        {
                            ctrl.Location = new Point(
                                ctrl.Location.X,
                                ctrl.Location.Y - ActiveScreen.ToolBar.Height
                                );
                        }
                        ActiveScreen.ToolBar.Visible = false;
                        ActiveScreen.ToolBar.Tag     = "Removed";
                    }
                    ToolStrip.Items.AddRange(ActiveViewButtons.ToArray());
                }
            }


            #endregion

            #region Add help buttons

            ToolStrip.Items.Add(new ToolStripSeparator());

            ToolStripItem contextHelpButton = ToolStrip.Items.Add(
                string.Empty,
                Sphere10.Framework.Windows.Forms.Properties.Resources.Help_16x16x32,
                ContextHelp_Click
                );
            contextHelpButton.ToolTipText = "Get help for currently opened screen";

            #endregion

            ToolStrip.ResumeLayout();
        }