예제 #1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            try
            {
                bool handled = this.HandleMenuGlipMouseUp(e);
                handled |= this.HandleCloseButtonMouseUp(e);
                handled |= this.HandleTabDetach(e);

                // It is highly important to call this method after the above ones
                // to avoid messing up the tab order.
                this.HandleTablItemMouseUpActions(e);

                if (!handled)
                {
                    base.OnMouseUp(e);
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
            finally
            {
                this.tabAtMouseDown        = null;
                this.mouseDownAtMenuGliph  = false;
                this.mouseDownAtCloseGliph = false;
                this.movePreview.Hide();
            }
        }
예제 #2
0
        private void OnCalcTabPage(Graphics g, TabControlItem currentItem)
        {
            Font currentFont = this.Font;

            if (currentItem == this.SelectedItem)
            {
                currentFont = new Font(this.Font, FontStyle.Bold);
            }

            SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), this.sf);

            textSize.Width += 20;

            if (this.RightToLeft == RightToLeft.No)
            {
                RectangleF buttonRect = new RectangleF(this.startPosition, 3, textSize.Width, 17);
                currentItem.StripRect = buttonRect;
                this.startPosition   += (int)textSize.Width;
            }
            else
            {
                RectangleF buttonRect = new RectangleF(this.startPosition - textSize.Width + 1, 3, textSize.Width - 1, 17);
                currentItem.StripRect = buttonRect;
                this.startPosition   -= (int)textSize.Width;
            }
        }
예제 #3
0
        private void HandleMouseInTitle(MouseEventArgs e)
        {
            TabControlItem item = this.GetTabItemByPoint(e.Location);

            if (item != null)
            {
                var inTitle = item.LocationIsInTitle(e.Location);
                TabControlMouseOnTitleEventArgs args = new TabControlMouseOnTitleEventArgs(item);

                if (inTitle)
                {
                    this.OnTabControlMouseOnTitle(args);

                    if (!this.mouseEnteredTitle)
                    {
                        this.mouseEnteredTitle = true;
                        this.OnTabControlMouseEnteredTitle(args);
                    }
                }
                else if (this.mouseEnteredTitle)
                {
                    this.mouseEnteredTitle = false;
                    this.OnTabControlMouseLeftTitle(args);
                }
            }
        }
        protected override void OnInsertComplete(int index, object item)
        {
            TabControlItem itm = item as TabControlItem;

            itm.Changed += new EventHandler(this.OnItem_Changed);
            this.OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, item));
        }
 public void Remove(TabControlItem item)
 {
     if (this.List.Contains(item))
     {
         this.List.Remove(item);
     }
 }
 public void Add(TabControlItem item)
 {
     if (!this.List.Contains(item))
     {
         this.List.Add(item);
     }
 }
예제 #7
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.mouseDownPoint = e.Location;
                this.tabAtMouseDown = this.GetTabItemByPoint(this.mouseDownPoint);

                // Show Tabs menu
                if (this.MouseIsOnMenuGliph(e))
                {
                    this.mouseDownAtMenuGliph = true;
                }

                // close by click on close button
                if (this.MouseIsOnCloseButton(e))
                {
                    this.mouseDownAtCloseGliph = true;
                }
            }

            // custom handling
            if (!this.mouseDownAtCloseGliph && !this.mouseDownAtMenuGliph && this.tabAtMouseDown == null)
            {
                base.OnMouseDown(e);
            }

            this.Invalidate();
        }
예제 #8
0
        private void SwapTabItems(int mouseX, TabControlItem upItem)
        {
            int downIndex = this.Items.IndexOf(this.tabAtMouseDown);
            int newIndex  = this.Items.IndexOf(upItem);

            int upCentre = 48 + newIndex * 87;

            if (downIndex < newIndex)
            {
                newIndex--;
                upCentre += 10;
            }

            if (mouseX >= upCentre)
            {
                newIndex++;
            }

            if (newIndex > this.Items.Count - 1)
            {
                newIndex = this.Items.Count - 1;
            }

            if (newIndex <= 0)
            {
                newIndex = 0;
            }

            this.Items.Remove(this.tabAtMouseDown);
            this.Items.Insert(newIndex, this.tabAtMouseDown);
        }
        protected override void OnRemove(int index, object item)
        {
            base.OnRemove(index, item);
            TabControlItem itm = item as TabControlItem;

            itm.Changed -= new EventHandler(this.OnItem_Changed);
            this.OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, item));
        }
 public void Insert(int index, TabControlItem item)
 {
     if (this.Contains(item))
     {
         return;
     }
     this.List.Insert(index, item);
 }
예제 #11
0
        private void UpdateAttachedTabTitle(KeyValuePair <string, FavoriteConfigurationElement> updated)
        {
            TabControlItem attachedTab = this.FindAttachedTab(updated);

            if (attachedTab != null)
            {
                attachedTab.Title = updated.Value.Name;
            }
        }
예제 #12
0
 private void UpdateSize(TabControlItem tabControlItem)
 {
     RectangleF tabRectangle = tabControlItem.StripRect;
     // two pixels to add right mergin
     // tab doesnt have to be first, so include all on left side
     int imageDistance = this.imageDetach.Width + 4;
     this.Width = (int)(tabRectangle.Width + tabRectangle.Left) + imageDistance;
     this.Height = (int)(tabRectangle.Height + tabRectangle.Top);
 }
예제 #13
0
        private void UpdateSize(TabControlItem tabControlItem)
        {
            RectangleF tabRectangle = tabControlItem.StripRect;
            // two pixels to add right mergin
            // tab doesnt have to be first, so include all on left side
            int imageDistance = this.imageDetach.Width + 4;

            this.Width  = (int)(tabRectangle.Width + tabRectangle.Left) + imageDistance;
            this.Height = (int)(tabRectangle.Height + tabRectangle.Top);
        }
예제 #14
0
        private void OnMenuItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            TabControlItem clickedItem = (TabControlItem)e.ClickedItem.Tag;

            if (clickedItem != null)
            {
                this.SelectedItem = clickedItem;
                this.Items.MoveTo(0, clickedItem);
            }
        }
예제 #15
0
 public void AddTab(TabControlItem tabItem)
 {
     // Add a tabpage to the first position
     if (Settings.InvertTabPageOrder)
         this.Items.Insert(0, tabItem);
     // Add a tabpage to the last position in the sequence
     else
         this.Items.Add(tabItem);
     
     tabItem.Dock = DockStyle.Fill;
 }
예제 #16
0
        internal void Show(TabControlItem tabControlItem)
        {
            this.selectedTabItem = tabControlItem;
            this.UpdateSize(tabControlItem);

            if (!this.Visible)
            {
                this.Show(); // this grabs the fucus, which we have to return
                Form parentForm = this.tabControl.FindForm();
                if (parentForm != null)
                    parentForm.Focus();
            }
        }
예제 #17
0
        private void SetDefaultSelected()
        {
            if (this.selectedItem == null && this.Items.Count > 0)
            {
                this.SelectedItem = this.Items[0];
            }

            for (int i = 0; i < this.Items.Count; i++)
            {
                TabControlItem itm = this.Items[i];
                itm.Dock = DockStyle.Fill;
            }
        }
        public TabControlItem MoveTo(int newIndex, TabControlItem item)
        {
            int currentIndex = this.List.IndexOf(item);

            if (currentIndex >= 0)
            {
                this.RemoveAt(currentIndex);
                this.Insert(newIndex, item);

                return(item);
            }

            return(null);
        }
예제 #19
0
        internal void Show(TabControlItem tabControlItem)
        {
            this.selectedTabItem = tabControlItem;
            this.UpdateSize(tabControlItem);

            if (!this.Visible)
            {
                this.Show(); // this grabs the fucus, which we have to return
                Form parentForm = this.tabControl.FindForm();
                if (parentForm != null)
                {
                    parentForm.Focus();
                }
            }
        }
예제 #20
0
 private void HandleTablItemMouseUpActions(MouseEventArgs e)
 {
     if (this.tabAtMouseDown != null)
     {
         TabControlItem upItem = this.GetTabItemByPoint(e.Location);
         if (upItem != null && upItem == this.tabAtMouseDown)
         {
             this.SelectedItem = upItem;
         }
         else
         {
             this.SwapTabItems(e.X, upItem);
         }
     }
 }
예제 #21
0
        public void CloseTab(TabControlItem tabItem)
        {
            if (tabItem != null)
            {
                this.SelectedItem = tabItem;
                TabControlItemClosingEventArgs args = new TabControlItemClosingEventArgs();
                this.OnTabControlItemClosing(args);

                if (this.SelectedItem != null && !args.Cancel && this.SelectedItem.CanClose)
                {
                    this.RemoveTab(this.SelectedItem);
                    this.OnTabControlItemClosed(EventArgs.Empty);
                }
            }
        }
예제 #22
0
        public void AddTab(TabControlItem tabItem)
        {
            // Add a tabpage to the first position
            if (Settings.InvertTabPageOrder)
            {
                this.Items.Insert(0, tabItem);
            }
            // Add a tabpage to the last position in the sequence
            else
            {
                this.Items.Add(tabItem);
            }

            tabItem.Dock = DockStyle.Fill;
        }
예제 #23
0
        public TabControlItem GetTabItemByPoint(Point pt)
        {
            TabControlItem item = null;

            for (int i = 0; i < this.Items.Count; i++)
            {
                TabControlItem current = this.Items[i];

                if (current.StripRect.Contains(pt))
                {
                    item = current;
                }
            }

            return(item);
        }
예제 #24
0
        public void RemoveTab(TabControlItem tabItem)
        {
            int  tabIndex    = this.Items.IndexOf(tabItem);
            bool wasSelected = tabItem.Selected;

            if (tabIndex >= 0)
            {
                this.UnSelectItem(tabItem);
                this.Items.Remove(tabItem);
            }

            if (wasSelected)
            {
                if (this.Items.Count > 0)
                {
                    if (this.RightToLeft == RightToLeft.No)
                    {
                        if (this.Items[tabIndex - 1] != null)
                        {
                            this.SelectedItem = this.Items[tabIndex - 1];
                        }
                        else
                        {
                            this.SelectedItem = this.Items.FirstVisible;
                        }
                    }
                    else
                    {
                        if (this.Items[tabIndex + 1] != null)
                        {
                            this.SelectedItem = this.Items[tabIndex + 1];
                        }
                        else
                        {
                            this.SelectedItem = this.Items.LastVisible;
                        }
                    }
                }
                else
                {
                    this.SelectedItem = null;
                }
            }
        }
예제 #25
0
        public void RemoveTab(TabControlItem tabItem)
        {
            int tabIndex = this.Items.IndexOf(tabItem);
            bool wasSelected = tabItem.Selected;

            if (tabIndex >= 0)
            {
                this.UnSelectItem(tabItem);
                this.Items.Remove(tabItem);
            }

            if (wasSelected)
            {
                if (this.Items.Count > 0)
                {
                    if (this.RightToLeft == RightToLeft.No)
                    {
                        if (this.Items[tabIndex - 1] != null)
                        {
                            this.SelectedItem = this.Items[tabIndex - 1];
                        }
                        else
                        {
                            this.SelectedItem = this.Items.FirstVisible;
                        }
                    }
                    else
                    {
                        if (this.Items[tabIndex + 1] != null)
                        {
                            this.SelectedItem = this.Items[tabIndex + 1];
                        }
                        else
                        {
                            this.SelectedItem = this.Items.LastVisible;
                        }
                    }
                }
                else
                    this.SelectedItem = null;
            }
        }
예제 #26
0
        private bool AllowDraw(TabControlItem item)
        {
            bool result = true;

            if (this.RightToLeft == RightToLeft.No)
            {
                if (item.StripRect.Right >= this.stripButtonRect.Width)
                {
                    result = false;
                }
            }
            else
            {
                if (item.StripRect.Left <= this.stripButtonRect.Left)
                {
                    return(false);
                }
            }

            return(result);
        }
예제 #27
0
        private void OnCollectionChanged(object sender, CollectionChangeEventArgs e)
        {
            TabControlItem itm = (TabControlItem)e.Element;

            if (e.Action == CollectionChangeAction.Add)
            {
                this.Controls.Add(itm);
                this.OnTabControlItemChanged(new TabControlItemChangedEventArgs(itm));
            }
            else if (e.Action == CollectionChangeAction.Remove)
            {
                this.Controls.Remove(itm);
                this.OnTabControlItemChanged(new TabControlItemChangedEventArgs(itm));
            }
            else
            {
                this.OnTabControlItemChanged(new TabControlItemChangedEventArgs(itm));
            }

            this.UpdateLayout();
            this.Invalidate();
        }
예제 #28
0
        private void OnMenuItemsLoad(EventArgs e)
        {
            this.Menu.RightToLeft = this.RightToLeft;
            this.Menu.Items.Clear();

            List <ToolStripMenuItem> list = new List <ToolStripMenuItem>();

            for (int i = 0; i < this.Items.Count; i++)
            {
                TabControlItem item = this.Items[i];

                if (!item.Visible)
                {
                    continue;
                }

                ToolStripMenuItem tItem = new ToolStripMenuItem(item.Title);

                tItem.Tag = item;

                if (item.Selected)
                {
                    tItem.Select();
                }

                list.Add(tItem);
            }

            // Sort by caption, else do nothing i.e. sorted by call sequence not by caption!!!!!
            if (Terminals.Configuration.Files.Main.Settings.Settings.SortTabPagesByCaption)
            {
                list.Sort(CompareSortText);
            }

            this.Menu.Items.AddRange(list.ToArray());
            this.OnMenuItemsLoaded(EventArgs.Empty);
        }
예제 #29
0
        public void CloseTab(TabControlItem tabItem)
        {
            if (tabItem != null)
            {
                this.SelectedItem = tabItem;
                TabControlItemClosingEventArgs args = new TabControlItemClosingEventArgs();
                this.OnTabControlItemClosing(args);

                if (this.SelectedItem != null && !args.Cancel && this.SelectedItem.CanClose)
                {
                    this.RemoveTab(this.SelectedItem);
                    this.OnTabControlItemClosed(EventArgs.Empty);
                }
            }
        }
예제 #30
0
        internal void OnDrawTabPage(Graphics g, TabControlItem currentItem)
        {
            bool isFirstTab = this.Items.IndexOf(currentItem) == 0;
            Font currentFont = this.Font;

            if (currentItem == this.SelectedItem)
                currentFont = new Font(this.Font, FontStyle.Bold);

            SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), this.sf);
            textSize.Width += 20;

            RectangleF buttonRect = currentItem.StripRect;
            GraphicsPath path = new GraphicsPath();
            LinearGradientBrush brush = null;
            const int mtop = 3;

            #region Draw Not Right-To-Left Tab
            if (this.RightToLeft == RightToLeft.No)
            {
                if (currentItem == this.SelectedItem || isFirstTab)
                {
                    path.AddLine(buttonRect.Left - 10, buttonRect.Bottom - 1, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 4);
                }
                else
                {
                    path.AddLine(buttonRect.Left, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 2);
                    path.AddLine(buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 3);
                }

                path.AddLine(buttonRect.Left + (buttonRect.Height / 2) + 2, mtop, buttonRect.Right - 3, mtop);
                path.AddLine(buttonRect.Right, mtop + 2, buttonRect.Right, buttonRect.Bottom - 1);
                path.AddLine(buttonRect.Right - 4, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - 1);
                path.CloseFigure();
                try
                {
                    if (currentItem == this.SelectedItem)
                    {
                        brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                    }
                    else
                    {
                        brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                    }
                }
                catch (Exception)
                {

                }
                g.FillPath(brush, path);
                Pen pen = SystemPens.ControlDark;
                if (currentItem == this.SelectedItem)
                {
                    pen = new Pen(this.ToolStripRenderer.ColorTable.MenuStripGradientBegin);
                }
                g.DrawPath(pen, path);
                if (currentItem == this.SelectedItem)
                {
                    pen.Dispose();
                }

                if (currentItem == this.SelectedItem)
                {
                    g.DrawLine(new Pen(brush), buttonRect.Left - 9, buttonRect.Height + 2, buttonRect.Left + buttonRect.Width - 1, buttonRect.Height + 2);
                }

                PointF textLoc = new PointF(buttonRect.Left + buttonRect.Height - 4, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 3);
                RectangleF textRect = buttonRect;
                textRect.Location = textLoc;
                textRect.Width = (float)buttonRect.Width - (textRect.Left - buttonRect.Left) - 4;
                textRect.Height = textSize.Height + currentFont.Size / 2;

                HeaderHeight = Convert.ToInt32(buttonRect.Height + buttonRect.Location.Y);

                if (currentItem == this.SelectedItem)
                {
                    //textRect.Y -= 2;
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }
                else
                {
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }
            }
            #endregion

            #region Draw Right-To-Left Tab
            if (this.RightToLeft == RightToLeft.Yes)
            {
                if (currentItem == this.SelectedItem || isFirstTab)
                {
                    path.AddLine(buttonRect.Right + 10, buttonRect.Bottom - 1, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 4);
                }
                else
                {
                    path.AddLine(buttonRect.Right, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 2);
                    path.AddLine(buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 3);
                }

                path.AddLine(buttonRect.Right - (buttonRect.Height / 2) - 2, mtop, buttonRect.Left + 3, mtop);
                path.AddLine(buttonRect.Left, mtop + 2, buttonRect.Left, buttonRect.Bottom - 1);
                path.AddLine(buttonRect.Left + 4, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - 1);
                path.CloseFigure();

                if (currentItem == this.SelectedItem)
                {
                    brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                }
                else
                {
                    brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                }

                g.FillPath(brush, path);
                g.DrawPath(SystemPens.ControlDark, path);

                if (currentItem == this.SelectedItem)
                {
                    g.DrawLine(new Pen(brush), buttonRect.Right + 9, buttonRect.Height + 2, buttonRect.Right - buttonRect.Width + 1, buttonRect.Height + 2);
                }

                PointF textLoc = new PointF(buttonRect.Left + 2, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2);
                RectangleF textRect = buttonRect;
                textRect.Location = textLoc;
                textRect.Width = (float)buttonRect.Width - (textRect.Left - buttonRect.Left) - 10;
                textRect.Height = textSize.Height + currentFont.Size / 2;

                HeaderHeight = Convert.ToInt32(buttonRect.Height + buttonRect.Location.Y);

                if (currentItem == this.SelectedItem)
                {
                    textRect.Y -= 1;
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }
                else
                {
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }

                //g.FillRectangle(Brushes.Red, textRect);
            }
            #endregion

            currentItem.IsDrawn = true;
        }
예제 #31
0
        internal void OnDrawTabPage(Graphics g, TabControlItem currentItem)
        {
            bool isFirstTab  = this.Items.IndexOf(currentItem) == 0;
            Font currentFont = this.Font;

            if (currentItem == this.SelectedItem)
            {
                currentFont = new Font(this.Font, FontStyle.Bold);
            }

            SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), this.sf);

            textSize.Width += 20;

            RectangleF          buttonRect = currentItem.StripRect;
            GraphicsPath        path       = new GraphicsPath();
            LinearGradientBrush brush      = null;
            const int           mtop       = 3;

            #region Draw Not Right-To-Left Tab
            if (this.RightToLeft == RightToLeft.No)
            {
                if (currentItem == this.SelectedItem || isFirstTab)
                {
                    path.AddLine(buttonRect.Left - 10, buttonRect.Bottom - 1, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 4);
                }
                else
                {
                    path.AddLine(buttonRect.Left, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 2);
                    path.AddLine(buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 3);
                }

                path.AddLine(buttonRect.Left + (buttonRect.Height / 2) + 2, mtop, buttonRect.Right - 3, mtop);
                path.AddLine(buttonRect.Right, mtop + 2, buttonRect.Right, buttonRect.Bottom - 1);
                path.AddLine(buttonRect.Right - 4, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - 1);
                path.CloseFigure();
                try
                {
                    if (currentItem == this.SelectedItem)
                    {
                        brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                    }
                    else
                    {
                        brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                    }
                }
                catch (Exception)
                {
                }
                g.FillPath(brush, path);
                Pen pen = SystemPens.ControlDark;
                if (currentItem == this.SelectedItem)
                {
                    pen = new Pen(this.ToolStripRenderer.ColorTable.MenuStripGradientBegin);
                }
                g.DrawPath(pen, path);
                if (currentItem == this.SelectedItem)
                {
                    pen.Dispose();
                }

                if (currentItem == this.SelectedItem)
                {
                    g.DrawLine(new Pen(brush), buttonRect.Left - 9, buttonRect.Height + 2, buttonRect.Left + buttonRect.Width - 1, buttonRect.Height + 2);
                }

                PointF     textLoc  = new PointF(buttonRect.Left + buttonRect.Height - 4, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 3);
                RectangleF textRect = buttonRect;
                textRect.Location = textLoc;
                textRect.Width    = (float)buttonRect.Width - (textRect.Left - buttonRect.Left) - 4;
                textRect.Height   = textSize.Height + currentFont.Size / 2;

                HeaderHeight = Convert.ToInt32(buttonRect.Height + buttonRect.Location.Y);

                if (currentItem == this.SelectedItem)
                {
                    //textRect.Y -= 2;
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }
                else
                {
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }
            }
            #endregion

            #region Draw Right-To-Left Tab
            if (this.RightToLeft == RightToLeft.Yes)
            {
                if (currentItem == this.SelectedItem || isFirstTab)
                {
                    path.AddLine(buttonRect.Right + 10, buttonRect.Bottom - 1, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 4);
                }
                else
                {
                    path.AddLine(buttonRect.Right, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 2);
                    path.AddLine(buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 3);
                }

                path.AddLine(buttonRect.Right - (buttonRect.Height / 2) - 2, mtop, buttonRect.Left + 3, mtop);
                path.AddLine(buttonRect.Left, mtop + 2, buttonRect.Left, buttonRect.Bottom - 1);
                path.AddLine(buttonRect.Left + 4, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - 1);
                path.CloseFigure();

                if (currentItem == this.SelectedItem)
                {
                    brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                }
                else
                {
                    brush = new LinearGradientBrush(buttonRect, currentItem.TabColor, SystemColors.Window, LinearGradientMode.Vertical);
                }

                g.FillPath(brush, path);
                g.DrawPath(SystemPens.ControlDark, path);

                if (currentItem == this.SelectedItem)
                {
                    g.DrawLine(new Pen(brush), buttonRect.Right + 9, buttonRect.Height + 2, buttonRect.Right - buttonRect.Width + 1, buttonRect.Height + 2);
                }

                PointF     textLoc  = new PointF(buttonRect.Left + 2, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2);
                RectangleF textRect = buttonRect;
                textRect.Location = textLoc;
                textRect.Width    = (float)buttonRect.Width - (textRect.Left - buttonRect.Left) - 10;
                textRect.Height   = textSize.Height + currentFont.Size / 2;

                HeaderHeight = Convert.ToInt32(buttonRect.Height + buttonRect.Location.Y);

                if (currentItem == this.SelectedItem)
                {
                    textRect.Y -= 1;
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }
                else
                {
                    g.DrawString(currentItem.Title, currentFont, new SolidBrush(this.ForeColor), textRect, this.sf);
                }

                //g.FillRectangle(Brushes.Red, textRect);
            }
            #endregion

            currentItem.IsDrawn = true;
        }
예제 #32
0
 private void UnSelectItem(TabControlItem tabItem)
 {
     tabItem.Selected = false;
 }
 public void Add(TabControlItem item)
 {
     if (!this.List.Contains(item))
         this.List.Add(item);
 }
 public int IndexOf(TabControlItem item)
 {
     return this.List.IndexOf(item);
 }
예제 #35
0
        private void SwapTabItems(int mouseX, TabControlItem upItem)
        {
            int downIndex = this.Items.IndexOf(this.tabAtMouseDown);
            int newIndex = this.Items.IndexOf(upItem);

            int upCentre = 48 + newIndex * 87;
            if (downIndex < newIndex)
            {
                newIndex--;
                upCentre += 10;
            }

            if (mouseX >= upCentre)
            {
                newIndex++;
            }

            if (newIndex > this.Items.Count - 1)
            {
                newIndex = this.Items.Count - 1;
            }

            if (newIndex <= 0)
            {
                newIndex = 0;
            }

            this.Items.Remove(this.tabAtMouseDown);
            this.Items.Insert(newIndex, this.tabAtMouseDown);
        }
예제 #36
0
        private bool AllowDraw(TabControlItem item)
        {
            bool result = true;

            if (this.RightToLeft == RightToLeft.No)
            {
                if (item.StripRect.Right >= this.stripButtonRect.Width)
                    result = false;
            }
            else
            {
                if (item.StripRect.Left <= this.stripButtonRect.Left)
                    return false;
            }

            return result;
        }
예제 #37
0
 private void SelectItem(TabControlItem tabItem)
 {
     tabItem.Dock = DockStyle.Fill;
     tabItem.Visible = true;
     tabItem.Selected = true;
 }
예제 #38
0
        private void CloseTabAtCurrentCursor()
        {
            TabControlItem selectedTab = this.GetTabItemByPoint(this.PointToClient(Cursor.Position));

            this.CloseTab(selectedTab);
        }
예제 #39
0
 private void UnSelectItem(TabControlItem tabItem)
 {
     tabItem.Selected = false;
 }
예제 #40
0
        private void OnCalcTabPage(Graphics g, TabControlItem currentItem)
        {
            Font currentFont = this.Font;

            if (currentItem == this.SelectedItem)
                currentFont = new Font(this.Font, FontStyle.Bold);

            SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), this.sf);
            textSize.Width += 20;

            if (this.RightToLeft == RightToLeft.No)
            {
                RectangleF buttonRect = new RectangleF(this.startPosition, 3, textSize.Width, 17);
                currentItem.StripRect = buttonRect;
                this.startPosition += (int)textSize.Width;
            }
            else
            {
                RectangleF buttonRect = new RectangleF(this.startPosition - textSize.Width + 1, 3, textSize.Width - 1, 17);
                currentItem.StripRect = buttonRect;
                this.startPosition -= (int)textSize.Width;
            }
        }
예제 #41
0
        protected override void OnPaint(PaintEventArgs e)
        {
            this.SetDefaultSelected();

            if (this.showBorder)
            {
                Rectangle borderRc = base.ClientRectangle;
                borderRc.Width--;
                borderRc.Height--;
                e.Graphics.DrawRectangle(SystemPens.ControlDark, borderRc);
            }

            this.startPosition = this.RightToLeft == RightToLeft.No ? 10 : this.stripButtonRect.Right;

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            #region Draw Pages
            if (this.showTabs)
            {
                TabControlItem selectedTabItem = this.SelectedItem;

                // todo bug 32353 - first calculate all, then identify ragne of tabs to draw, and finally paint them
                for (int i = 0; i < this.Items.Count; i++)
                {
                    TabControlItem currentItem = this.Items[i];
                    if (!currentItem.Visible && !this.DesignMode)
                    {
                        continue;
                    }

                    this.OnCalcTabPage(e.Graphics, currentItem);
                    currentItem.IsDrawn = false;

                    // delay drawing active item to the end
                    if (currentItem == selectedTabItem)
                    {
                        continue;
                    }

                    if (!this.AllowDraw(currentItem))
                    {
                        continue;
                    }

                    this.OnDrawTabPage(e.Graphics, currentItem);
                }
                if (selectedTabItem != null && this.AllowDraw(selectedTabItem))
                {
                    try
                    {
                        this.OnDrawTabPage(e.Graphics, selectedTabItem);
                    }
                    catch (Exception)
                    {
                        //black hole this for now
                    }
                }
            }
            #endregion

            #region Draw UnderPage Line
            if (this.showTabs && this.showBorder)
            {
                using (Pen pen = new Pen(this.ToolStripRenderer.ColorTable.MenuStripGradientBegin))
                {
                    if (this.RightToLeft == RightToLeft.No)
                    {
                        if (this.Items.DrawnCount == 0 || this.Items.VisibleCount == 0)
                        {
                            e.Graphics.DrawLine(pen, new Point(0, DEF_HEADER_HEIGHT), new Point(this.ClientRectangle.Width, DEF_HEADER_HEIGHT));
                        }
                        else if (this.SelectedItem != null && this.SelectedItem.IsDrawn)
                        {
                            Point end = new Point((int)this.SelectedItem.StripRect.Left - 9, DEF_HEADER_HEIGHT);
                            e.Graphics.DrawLine(pen, new Point(0, DEF_HEADER_HEIGHT), end);
                            end.X += (int)this.SelectedItem.StripRect.Width + 10;
                            e.Graphics.DrawLine(pen, end, new Point(this.ClientRectangle.Width, DEF_HEADER_HEIGHT));
                        }
                    }
                    else
                    {
                        if (this.Items.DrawnCount == 0 || this.Items.VisibleCount == 0)
                        {
                            e.Graphics.DrawLine(SystemPens.ControlDark, new Point(0, DEF_HEADER_HEIGHT), new Point(this.ClientRectangle.Width, DEF_HEADER_HEIGHT));
                        }
                        else if (this.SelectedItem != null && this.SelectedItem.IsDrawn)
                        {
                            Point end = new Point((int)this.SelectedItem.StripRect.Left, DEF_HEADER_HEIGHT);
                            e.Graphics.DrawLine(pen, new Point(0, DEF_HEADER_HEIGHT), end);
                            end.X += (int)this.SelectedItem.StripRect.Width + 20;
                            e.Graphics.DrawLine(pen, end, new Point(this.ClientRectangle.Width, DEF_HEADER_HEIGHT));
                        }
                    }
                }
            }
            #endregion

            #region Draw Menu and Close Glyphs
            if (this.showTabs)
            {
                if ((this.AlwaysShowMenuGlyph && this.Items.VisibleCount > 0) || this.Items.DrawnCount > this.Items.VisibleCount)
                {
                    this.menuGlyph.DrawGlyph(e.Graphics);
                }

                if (this.AlwaysShowClose || (this.SelectedItem != null && this.SelectedItem.CanClose))
                {
                    this.closeButton.DrawCross(e.Graphics);
                }
            }
            #endregion
        }
예제 #42
0
 public TabControlMouseOnTitleEventArgs(TabControlItem item)
 {
     this.item = item;
 }
예제 #43
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.mouseDownPoint = e.Location;
                this.tabAtMouseDown = this.GetTabItemByPoint(this.mouseDownPoint);

                // Show Tabs menu
                if (this.MouseIsOnMenuGliph(e))
                    this.mouseDownAtMenuGliph = true;

                // close by click on close button
                if (this.MouseIsOnCloseButton(e))
                    this.mouseDownAtCloseGliph = true;
            }

            // custom handling
            if (!this.mouseDownAtCloseGliph && !this.mouseDownAtMenuGliph && this.tabAtMouseDown == null)
                base.OnMouseDown(e);

            this.Invalidate();
        }
 public TabControlMouseOnTitleEventArgs(TabControlItem item)
 {
     this.item = item;
 }
예제 #45
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            try
            {
                bool handled = this.HandleMenuGlipMouseUp(e);
                handled |= this.HandleCloseButtonMouseUp(e);
                handled |= this.HandleTabDetach(e);

                // It is highly important to call this method after the above ones
                // to avoid messing up the tab order.
                this.HandleTablItemMouseUpActions(e);

                if (!handled)
                    base.OnMouseUp(e);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
            finally
            {
                this.tabAtMouseDown = null;
                this.mouseDownAtMenuGliph = false;
                this.mouseDownAtCloseGliph = false;
                this.movePreview.Hide();
            }
        }
 public void Remove(TabControlItem item)
 {
     if (this.List.Contains(item))
         this.List.Remove(item);
 }
예제 #47
0
 private void SelectItem(TabControlItem tabItem)
 {
     tabItem.Dock     = DockStyle.Fill;
     tabItem.Visible  = true;
     tabItem.Selected = true;
 }
 public bool Contains(TabControlItem item)
 {
     return this.List.Contains(item);
 }
 public void Insert(int index, TabControlItem item)
 {
     if (this.Contains(item)) return;
     this.List.Insert(index, item);
 }
        public TabControlItem MoveTo(int newIndex, TabControlItem item)
        {
            int currentIndex = this.List.IndexOf(item);
            if (currentIndex >= 0)
            {
                this.RemoveAt(currentIndex);
                this.Insert(newIndex, item);

                return item;
            }

            return null;
        }
 public TabControlItemChangedEventArgs(TabControlItem item)
 {
     this.item = item;
 }