public void AddTab(TabStripItem item)
 {
     if (!Items.Contains(item))
     {
         Items.Add(item);
     }
 }
 protected override void WndProc(ref Message msg)
 {
     if (msg.Msg == 0x201)
     {
         var selectionService = (ISelectionService)GetService(typeof(ISelectionService));
         if (selectionService != null)
         {
             Point location = Control.PointToClient(Cursor.Position);
             var   tabStrip = Control as TabStrip;
             if (tabStrip != null)
             {
                 TabStripItem tabStripItem = tabStrip.FindTabStripItem(location);
                 if (tabStripItem != null)
                 {
                     tabStrip.SelectedItem = tabStripItem;
                     var selection = new ArrayList {
                         tabStripItem
                     };
                     selectionService.SetSelectedComponents(selection);
                 }
             }
         }
     }
     base.WndProc(ref msg);
 }
 public void CloseTab(TabStripItem item)
 {
     if (!Items.Contains(item))
     {
         throw new Exception("Item not in collection");
     }
     CloseInternal(item);
 }
        private void OnItemSelected(TabStripItem item)
        {
            EventHandler <TabStripEventArgs> temp = TabStripItemSelected;

            if (temp != null)
            {
                temp(this, new TabStripEventArgs(item));
            }
            item.OnSelected();
        }
        private void OnItemMouseDown(TabStripItem item, MouseEventArgs e)
        {
            EventHandler <TabStripMouseEventArgs> temp = TabStripItemMouseDown;

            if (temp == null)
            {
                return;
            }
            temp(this, new TabStripMouseEventArgs(item, e));
        }
        private bool IsItemSelectingCanceled(TabStripItem item)
        {
            EventHandler <TabStripCancelEventArgs> temp = TabStripItemSelecting;

            if (temp == null)
            {
                return(false);
            }
            var args = new TabStripCancelEventArgs(item);

            temp(this, args);
            return(args.Cancel || item.IsSelectingCanceled());
        }
 protected override void OnMouseLeave(EventArgs e)
 {
     MouseOverItem                = null;
     MouseDownOverItem            = null;
     MouseOverItemCloseButton     = false;
     MouseOverMenuButton          = false;
     MouseDownOverItemCloseButton = false;
     if (_toolTip != null)
     {
         _toolTip.Hide(this);
         _toolTip = null;
     }
     Invalidate();
     base.OnMouseLeave(e);
 }
        private bool MouseOverHandler(Point location, MouseButtons buttons)
        {
            TabStripItem mouseOverItem = FindTabStripItem(location);
            bool         invalidate    = false;

            if (!ReferenceEquals(MouseOverItem, mouseOverItem))
            {
                MouseOverItem = mouseOverItem;
                invalidate    = true;
            }
            if (MouseOverItem != null)
            {
                bool mouseOverItemCloseButton = MouseOverItem.CloseButtonTabStripBounds.Contains(location);
                if (MouseOverItemCloseButton != mouseOverItemCloseButton)
                {
                    MouseOverItemCloseButton = mouseOverItemCloseButton;
                    invalidate = true;
                }
                if (_toolTip != null)
                {
                    if (!ReferenceEquals(_toolTip.Tag, MouseOverItem))
                    {
                        _toolTip.Hide(this);
                        _toolTip = null;
                    }
                }
                if (_toolTip == null)
                {
                    _toolTip     = new ToolTip();
                    _toolTip.Tag = MouseOverItem;
                    _toolTip.Show(MouseOverItem.ToolTip, this, location.X, Convert.ToInt32(_tabStripHeight) + 1);
                }
            }
            else if (_toolTip != null)
            {
                _toolTip.Hide(this);
                _toolTip = null;
            }
            if (!MouseDownOverItemCloseButton && MouseOverItem != null && MouseOverItem != SelectedItem &&
                MouseDownOverItem == SelectedItem && IsLeftMouseButtonDown(buttons))
            {
                int selectedItemIndex  = Items.IndexOf(SelectedItem);
                int mouseOverItemIndex = Items.IndexOf(MouseOverItem);
                Items.Move(selectedItemIndex, mouseOverItemIndex);
                invalidate = true;
            }
            return(invalidate);
        }
 private bool CloseInternal(TabStripItem item)
 {
     if (!IsItemClosingCanceled(item))
     {
         bool selected = ReferenceEquals(SelectedItem, item);
         int  index    = Items.IndexOf(item);
         if (index >= 0)
         {
             Items.Remove(item);
         }
         OnItemClosed(item);
         if (selected && Items.Count > 0)
         {
             SelectedItem = Items.Count > index ? Items[index] : Items[Items.Count - 1];
         }
         return(true);
     }
     return(false);
 }
 private void SelectItemInternal(TabStripItem item)
 {
     if (item == null)
     {
         return;
     }
     item.SetFocus();
     if (SelectedItem == item)
     {
         return;
     }
     if (IsItemSelectingCanceled(item))
     {
         return;
     }
     SelectedItem = item;
     OnItemSelected(SelectedItem);
     Invalidate();
 }
        private void ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_collectionReArrangedInternaly)
            {
                return;
            }
            if (e.NewItems != null)
            {
                TabStripItem lastItem = null;
                foreach (TabStripItem item in e.NewItems)
                {
                    lastItem = item;
                    if (Controls.Contains(item))
                    {
                        continue;
                    }
                    item.Visible = false;
                    Controls.Add(item);
                    item.Dock    = DockStyle.Fill;
                    item.Visible = false;
                }
                if (lastItem != null)
                {
                    SelectedItem = lastItem;
                }
            }
            if (e.OldItems != null)
            {
                foreach (TabStripItem item in e.OldItems)
                {
                    if (Controls.Contains(item))
                    {
                        Controls.Remove(item);
                    }
                }
            }

            UpdateLayout();
            Invalidate();
        }
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     _focusControl.Focus();
     MouseDownOverItemCloseButton = false;
     if (MouseOverMenuButton && IsLeftMouseButtonDown(e.Button))
     {
         MouseDownOverMenuButton = true;
         Invalidate();
         ShowItemsMenu(e.Location);
         return;
     }
     if (MouseOverItem == null)
     {
         return;
     }
     if (e.Button == MouseButtons.Middle)
     {
         CloseInternal(MouseOverItem);
         MouseOverItem                = null;
         MouseDownOverItem            = null;
         MouseDownOverItemCloseButton = false;
         return;
     }
     OnItemMouseDown(MouseOverItem, e);
     MouseDownOverItem = MouseOverItem;
     if (!IsLeftMouseButtonDown(e.Button))
     {
         return;
     }
     if (MouseOverItemCloseButton)
     {
         MouseDownOverItemCloseButton = true;
         Invalidate();
     }
     else
     {
         SelectItemInternal(MouseOverItem);
     }
 }
        private void DrawTabStripItemCloseButton(Graphics g, TabStripItem item)
        {
            bool mouseOverCloseButton = false;
            bool selected             = ReferenceEquals(item, SelectedItem);
            bool mouseDownOverItem    = ReferenceEquals(item, MouseDownOverItem);

            if (ReferenceEquals(item, MouseOverItem))
            {
                mouseOverCloseButton = MouseOverItemCloseButton;
            }
            else if (!selected && !mouseDownOverItem && !MouseDownOverItemCloseButton)
            {
                return;
            }
            RectangleF rect = item.CloseButtonTabStripBounds;
            var        pen  = new Pen(ForeColor, 2);

            if ((mouseDownOverItem && MouseDownOverItemCloseButton) ||
                (mouseOverCloseButton && MouseDownOverItem == null))
            {
                g.FillRectangle(MouseDownOverItemCloseButton ? _backColorBrush : _glyphFillBrush, rect);
                g.DrawRectangle(_glyphBorderPen, rect.X, rect.Y, rect.Width, rect.Height);
            }
            else if (selected)
            {
                pen = _selectedCloseButtonPen;
            }
            else
            {
                pen = _inActiveCloseButtonPen;
            }
            float left   = rect.X + 4;
            float top    = rect.Y + 4;
            float rigth  = rect.X + rect.Width - 4;
            float bottom = rect.Y + rect.Height - 4;

            g.DrawLine(pen, left, top, rigth, bottom);
            g.DrawLine(pen, rigth, top, left, bottom);
        }
 protected override void OnMouseUp(MouseEventArgs e)
 {
     base.OnMouseUp(e);
     if (MouseOverItem != null)
     {
         OnItemMouseUp(MouseOverItem, e);
         if (IsLeftMouseButtonDown(e.Button))
         {
             if (ReferenceEquals(MouseDownOverItem, MouseOverItem) && MouseDownOverItemCloseButton &&
                 MouseOverItemCloseButton &&
                 IsLeftMouseButtonDown(e.Button))
             {
                 CloseInternal(MouseOverItem);
                 MouseOverItem = null;
             }
             else
             {
                 if (MouseOverHandler(e.Location, e.Button))
                 {
                     Invalidate();
                 }
             }
         }
         else if (IsRightMouseButtonDown(e.Button))
         {
             SelectItemInternal(MouseOverItem);
             if (ContextMenuStrip != null)
             {
                 ContextMenuStrip.Show(this, e.Location);
             }
         }
     }
     if (MouseDownOverItemCloseButton || MouseDownOverItem != null)
     {
         Invalidate();
     }
     MouseDownOverItemCloseButton = false;
     MouseDownOverItem            = null;
 }
 public TabStripMouseEventArgs(TabStripItem item, MouseEventArgs e)
     : this(item, e.Button, e.Clicks, e.X, e.Y, e.Delta)
 {
 }
 public override IProjectFile Open()
 {
     if (_projectPropertiesEditor == null)
     {
         _projectPropertiesEditor = new ProjectPropertiesEditor(this);
         if (_tabItem != null)
         {
             _tabItem.Close();
         }
         _tabItem = TabStripItemFactory.CreateTabStripItem(_projectPropertiesEditor, this);
         _tabItem.Closed += TabItemClosed;
     }
     return this;
 }
 public TabStripEventArgs(TabStripItem item)
 {
     Item = item;
 }
 public void Close()
 {
     try
     {
         _closing = true;
         if (_tabItem != null)
         {
             _tabItem.Close();
             _tabItem = null;
         }
         if (_solutionPropertiesEditor != null)
         {
             _solutionPropertiesEditor.Dispose();
             _solutionPropertiesEditor = null;
         }
     }
     finally
     {
         _closing = false;
     }
 }
 private void DrawTabStripItemCloseButton(Graphics g, TabStripItem item)
 {
     bool mouseOverCloseButton = false;
     bool selected = ReferenceEquals(item, SelectedItem);
     bool mouseDownOverItem = ReferenceEquals(item, MouseDownOverItem);
     if (ReferenceEquals(item, MouseOverItem))
     {
         mouseOverCloseButton = MouseOverItemCloseButton;
     }
     else if (!selected && !mouseDownOverItem && !MouseDownOverItemCloseButton)
     {
         return;
     }
     RectangleF rect = item.CloseButtonTabStripBounds;
     var pen = new Pen(ForeColor, 2);
     if ((mouseDownOverItem && MouseDownOverItemCloseButton) ||
         (mouseOverCloseButton && MouseDownOverItem == null))
     {
         g.FillRectangle(MouseDownOverItemCloseButton ? _backColorBrush : _glyphFillBrush, rect);
         g.DrawRectangle(_glyphBorderPen, rect.X, rect.Y, rect.Width, rect.Height);
     }
     else if (selected)
     {
         pen = _selectedCloseButtonPen;
     }
     else
     {
         pen = _inActiveCloseButtonPen;
     }
     float left = rect.X + 4;
     float top = rect.Y + 4;
     float rigth = rect.X + rect.Width - 4;
     float bottom = rect.Y + rect.Height - 4;
     g.DrawLine(pen, left, top, rigth, bottom);
     g.DrawLine(pen, rigth, top, left, bottom);
 }
 private bool IsItemSelectingCanceled(TabStripItem item)
 {
     EventHandler<TabStripCancelEventArgs> temp = TabStripItemSelecting;
     if (temp == null) return false;
     var args = new TabStripCancelEventArgs(item);
     temp(this, args);
     return args.Cancel || item.IsSelectingCanceled();
 }
 public IProjectFile Open()
 {
     if (_solutionPropertiesEditor == null)
     {
         _solutionPropertiesEditor = new SolutionPropertiesEditor(this);
         if (_tabItem != null)
         {
             _tabItem.Close();
         }
         _tabItem = TabStripItemFactory.CreateTabStripItem(_solutionPropertiesEditor, this);
         _tabItem.Closed += TabItemClosed;
     }
     return this;
 }
 private bool CloseInternal(TabStripItem item)
 {
     if (!IsItemClosingCanceled(item))
     {
         bool selected = ReferenceEquals(SelectedItem, item);
         int index = Items.IndexOf(item);
         if (index >= 0) Items.Remove(item);
         OnItemClosed(item);
         if (selected && Items.Count > 0)
         {
             SelectedItem = Items.Count > index ? Items[index] : Items[Items.Count - 1];
         }
         return true;
     }
     return false;
 }
 private void OnItemMouseUp(TabStripItem item, MouseEventArgs e)
 {
     EventHandler<TabStripMouseEventArgs> temp = TabStripItemMouseUp;
     if (temp == null) return;
     temp(this, new TabStripMouseEventArgs(item, e));
 }
 public override IProjectFile Open()
 {
     if (_textEditor == null)
     {
         _textEditor = new TextEditorContainer(FileSystemPath);
         if (_tabItem != null)
         {
             _tabItem.Close();
         }
         _tabItem = TabStripItemFactory.CreateTabStripItem(_textEditor, this);
         _tabItem.Closed += TabItemClosed;
     }
     return this;
 }
 private void OnItemSelected(TabStripItem item)
 {
     EventHandler<TabStripEventArgs> temp = TabStripItemSelected;
     if (temp != null)
     {
         temp(this, new TabStripEventArgs(item));
     }
     item.OnSelected();
 }
 public TabStripMouseEventArgs(TabStripItem item, MouseButtons button, int clicks, int x, int y, int delta)
     : base(button, clicks, x, y, delta)
 {
     Item = item;
 }
 private void SelectItemInternal(TabStripItem item)
 {
     if (item == null) return;
     item.SetFocus();
     if (SelectedItem == item) return;
     if (IsItemSelectingCanceled(item)) return;
     SelectedItem = item;
     OnItemSelected(SelectedItem);
     Invalidate();
 }
 public TabStripEventArgs(TabStripItem item)
 {
     Item = item;
 }
 public void AddTab(TabStripItem item)
 {
     if (!Items.Contains(item))
     {
         Items.Add(item);
     }
 }
 public TabStripMouseEventArgs(TabStripItem item, MouseEventArgs e)
     : this(item, e.Button, e.Clicks, e.X, e.Y, e.Delta)
 {
 }
 public void CloseTab(TabStripItem item)
 {
     if (!Items.Contains(item)) throw new Exception("Item not in collection");
     CloseInternal(item);
 }
Example #32
0
 public TabStripCancelEventArgs(TabStripItem item)
 {
     Item = item;
 }
 public TabStripCancelEventArgs(TabStripItem item)
 {
     Item = item;
 }
 public override void Close()
 {
     try
     {
         _closing = true;
         if (_tabItem != null)
         {
             _tabItem.Close();
             _tabItem = null;
         }
         if (_textEditor != null)
         {
             _textEditor.Dispose();
             _textEditor = null;
         }
     }
     finally
     {
         _closing = false;
     }
 }
 public TabStripMouseEventArgs(TabStripItem item, MouseButtons button, int clicks, int x, int y, int delta)
     : base(button, clicks, x, y, delta)
 {
     Item = item;
 }