Exemplo n.º 1
0
        /// <summary>
        /// Select the given tab.
        /// </summary>
        /// <param name="tab">Tab to select.</param>
        private void SelectTab(WhidbeyTabPage tab)
        {
            // Ignore if disabled
            if ((tab.State == TabState.Disabled) ||
                (tab.Enabled == false))
            {
                return;
            }

            // Unselect previous
            UnselectTab();
            Unhover();

            // Set selected
            tab.State   = TabState.Selected;
            m_oSelected = tab;

            // Add new control to panel
            tab.ShowNotifty(true);
            tab.Visible = true;
            tab.Focus();

            // Force redraw
            this.Invalidate(tab.ItemBounds);

            // Fire event
            EventHandler <WhidbeyTabEventArgs> ev = this.m_eSelected;

            if (ev != null)
            {
                ev(this, new WhidbeyTabEventArgs(tab));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fired when a component is removed.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Information about component.</param>
        private void OnComponentRemoving(object sender, ComponentEventArgs e)
        {
            IDesignerHost host = this.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (e.Component is WhidbeyTabControl)
            {
                while (m_oControl.TabPages.Count > 0)
                {
                    m_oChangeSvc.OnComponentChanging(m_oControl, null);
                    WhidbeyTabPage tab = m_oControl.TabPages[0];

                    m_oControl.TabPages.RemoveAt(0);
                    host.DestroyComponent(tab);

                    m_oChangeSvc.OnComponentChanged(m_oControl, null, null, null);
                }
            }
            else if (e.Component is WhidbeyTabPage)
            {
                WhidbeyTabPage tab = e.Component as WhidbeyTabPage;
                if (m_oControl.TabPages.Contains(tab) == true)
                {
                    m_oChangeSvc.OnComponentChanging(m_oControl, null);
                    m_oControl.TabPages.Remove(tab);
                    m_oChangeSvc.OnComponentChanged(m_oControl, null, null, null);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove the given tab from the control.
        /// </summary>
        /// <param name="control">Tab to remove.</param>
        internal void RemoveTab(WhidbeyTabPage tab)
        {
            // Validate
            if ((tab == null) ||
                (tab == null))
            {
                return;
            }

            // Remove label/from panel
            this.Controls.Remove(tab.Label);
            this.panelContainer.Controls.Remove(tab);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Unhover the currently hovered tab.
        /// </summary>
        private void Unhover()
        {
            if (m_oHovered != null)
            {
                WhidbeyTabPage tab = m_oHovered;
                m_oHovered = null;

                tab.State = TabState.Normal;

                // Force redraw
                this.Invalidate(tab.ItemBounds);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Select the currently selected tab.
        /// </summary>
        private void UnselectTab()
        {
            if (m_oSelected != null)
            {
                WhidbeyTabPage tab = m_oSelected;
                m_oSelected = null;

                tab.State = TabState.Normal;

                // Drop old control from the panel
                tab.ShowNotifty(false);
                tab.Visible = false;

                // Force redraw
                this.Invalidate(tab.ItemBounds);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called whenever enable state changes on a tab.
        /// </summary>
        /// <param name="tab">Tab to inspect.</param>
        internal void SetTabEnabled(WhidbeyTabPage tab)
        {
            if (tab.Enabled == false)
            {
                // -- Tab is being disabled --

                // If it's selected, deselect
                if (tab == m_oSelected)
                {
                    // Find another tab
                    bool subFound = false;
                    foreach (WhidbeyTabPage page in m_aControls)
                    {
                        if ((page != tab) &&
                            (page.Enabled == true))
                        {
                            SelectTab(page);
                            subFound = true;
                            break;
                        }
                    }

                    // Check to make sure a substitute was found
                    if (subFound == false)
                    {
                        throw new InvalidOperationException("No valid page was found to replace disabled page; cannot disable the only page.");
                    }
                }

                // Set stuff
                tab.Label.ForeColor = Color.Gray;
                tab.State           = TabState.Disabled;
            }
            else
            {
                // -- Tab is being enabled --

                // Set stuff
                tab.Label.ForeColor = Color.Black;
                tab.State           = TabState.Normal;
            }

            // Force redraw
            this.Invalidate(tab.ItemBounds);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add a new tab and set selection.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void OnAddTab(object sender, EventArgs e)
        {
            // Begin transaction
            IDesignerHost       host        = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
            DesignerTransaction transaction = host.CreateTransaction("Add tab");

            // Create new tab
            WhidbeyTabPage tab = host.CreateComponent(typeof(WhidbeyTabPage)) as WhidbeyTabPage;

            m_oChangeSvc.OnComponentChanging(m_oControl, null);
            m_oControl.TabPages.Add(tab);
            m_oChangeSvc.OnComponentChanged(m_oControl, null, null, null);

            // End transaction
            transaction.Commit();

            m_oControl.SelectedTab = tab;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Hover the given tab.
        /// </summary>
        /// <param name="tab">Tab to hover.</param>
        private void Hover(WhidbeyTabPage tab)
        {
            // Ignore if disabled
            if ((tab.State == TabState.Disabled) ||
                (tab.Enabled == false))
            {
                return;
            }

            if (tab.State != TabState.Selected)
            {
                tab.State = TabState.Hovered;
            }
            m_oHovered = tab;

            // Force redraw
            this.Invalidate(tab.ItemBounds);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Insert the given tab into the control.
        /// </summary>
        /// <param name="control">Tab to add.</param>
        internal void InsertTab(WhidbeyTabPage tab)
        {
            // Create label for tab
            Label label = new Label();

            label.Text      = tab.Text;
            label.TextAlign = ContentAlignment.MiddleLeft;
            label.BackColor = Color.Transparent;
            if (tab.State == TabState.Disabled)
            {
                label.ForeColor = Color.Gray;
            }
            else
            {
                label.ForeColor = Color.Black;
            }
            label.Left        = 12;
            label.MouseMove  += new MouseEventHandler(Label_MouseMove);
            label.MouseLeave += new EventHandler(Label_MouseLeave);
            label.MouseUp    += new MouseEventHandler(Label_MouseUp);
            this.Controls.Add(label);
            tab.Label = label;

            // Add tab control to container
            this.panelContainer.Controls.Add(tab);
            tab.Dock    = DockStyle.Fill;
            tab.Visible = false;

            // Rebuild the tab bounds
            this.RebuildTabs();

            // Invalidate everything (a lot can change)
            this.Invalidate();

            // Always set the first to selected
            if (this.m_aControls.IndexOf(tab) == 0)
            {
                SelectTab(tab);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Rebuild tab bounding rectangles.
        /// </summary>
        private void RebuildTabs()
        {
            // Basic setup of bounds
            m_nBounds.X      = 0;
            m_nBounds.Y      = 6;
            m_nBounds.Width  = 107;
            m_nBounds.Height = 0;

            // Start tabs
            for (int n = 0; n < m_aControls.Count; n++)
            {
                WhidbeyTabPage tab = m_aControls[n];

                tab.ItemBounds = new Rectangle(m_nBounds.X, m_nBounds.Bottom, m_nBounds.Width + 1, 33);

                tab.Label.Top    = tab.ItemBounds.Top;
                tab.Label.Width  = tab.ItemBounds.Width - 12;
                tab.Label.Height = tab.ItemBounds.Height;

                m_nBounds.Height += 33;
            }

            m_nBounds.Height += 6;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="tab">Tab this event is about.</param>
 internal WhidbeyTabEventArgs(WhidbeyTabPage tab)
 {
     m_oTab = tab;
 }
Exemplo n.º 12
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="tab">Tab this event is about.</param>
		internal WhidbeyTabEventArgs(WhidbeyTabPage tab)
		{
			m_oTab = tab;
		}
Exemplo n.º 13
0
        /// <summary>
        /// Paint the given tab to the given graphics context.
        /// </summary>
        /// <param name="g">Destination graphics context.</param>
        /// <param name="tab">Tab to paint.</param>
        private void PaintTab(Graphics g, WhidbeyTabPage tab)
        {
            int borderWidth;    // Only used with Selected and Hovered

            // Hide the label if there is an icon
            tab.Label.Visible = (tab.Image == null);

            if (tab.State == TabState.Selected)
            {
                // Fill background white
                g.FillRectangle(Brushes.White, 3, tab.ItemBounds.Top + 1, 104, tab.ItemBounds.Height - 2);

                // Draw right border
                using (Pen p_selectedBorder = new Pen(Color.FromArgb(173, 190, 204), 1.0f))
                    g.DrawLine(p_selectedBorder, tab.ItemBounds.Right - 1, tab.ItemBounds.Top + 1, tab.ItemBounds.Right - 1, tab.ItemBounds.Bottom - 1);

                // We are selected, so width goes full
                borderWidth = 107;
            }
            else
            {
                // Hovered, so width goes one short
                borderWidth = 106;
            }

            if ((tab.State == TabState.Hovered) ||
                (tab.State == TabState.Selected))
            {
                // -- Draw fancy border --
                // Top
                g.DrawLine(p_darkBorderPen, 3, tab.ItemBounds.Top, borderWidth, tab.ItemBounds.Top);
                // Bottom
                g.DrawLine(p_darkBorderPen, 3, tab.ItemBounds.Bottom - 1, borderWidth, tab.ItemBounds.Bottom - 1);

                // -- Draw left side orange element --
                // Inside
                g.DrawRectangle(p_orangeInner, 1, tab.ItemBounds.Top + 1, 1, tab.ItemBounds.Height - 3);
                // Border
                g.DrawLines(p_orangeOuter, new Point[] {
                    new Point(2, tab.ItemBounds.Top),
                    new Point(0, tab.ItemBounds.Top + 2),
                    new Point(0, tab.ItemBounds.Bottom - 3),
                    new Point(2, tab.ItemBounds.Bottom - 1)
                });
            }
            else
            {
                // Top line
                g.DrawLine(p_itemBottom, 6, tab.ItemBounds.Top, 101, tab.ItemBounds.Top);
                // Bottom line
                g.DrawLine(Pens.White, 6, tab.ItemBounds.Bottom - 1, 101, tab.ItemBounds.Bottom - 1);
            }

            if (tab.Image != null)
            {
                Rectangle rect    = tab.ItemBounds;
                int       centerX = rect.X + (rect.Width / 2);
                int       centerY = rect.Y + (rect.Height / 2);
                centerX -= (tab.Image.Width / 2);
                centerY -= (tab.Image.Height / 2);
                g.DrawImageUnscaled(tab.Image, centerX, centerY);
            }
        }