Пример #1
0
        protected override void OnMouseDown(MouseEventArgs args)
        {
            base.OnMouseDown(args);

            Focus();

            Rectangle tabBounds = GetTabBounds();

            if (tabBounds.Contains(args.X, args.Y))
            {
                if (args.X < ScrollerOffset)
                {
                    ScrollLeft();
                }
                else if (args.X > (tabBounds.Right - ScrollerOffset))
                {
                    ScrollRight();
                }
                else
                {
                    NotebookPage page = GetTabAt(new Point(args.X, args.Y));
                    if (page != null)
                    {
                        Selected = page;
                    }
                }
            }
        }
Пример #2
0
 internal void ControlAdd(NotebookPage page)
 {
     if (!_updatingControls)
     {
         InternalAdd(_count, page);
     }
 }
Пример #3
0
 protected virtual void SelectionChanging(NotebookPage page)
 {
     if (OnSelectionChanging != null)
     {
         OnSelectionChanging(this, page);
     }
 }
Пример #4
0
 internal void ControlRemove(NotebookPage page)
 {
     if (!_updatingControls)
     {
         InternalRemoveAt(IndexOf(page));
     }
 }
Пример #5
0
 public int IndexOf(NotebookPage page)
 {
     for (int i = 0; i < _count; i++)
     {
         if (_pages[i] == page)
         {
             return(i);
         }
     }
     return(-1);
 }
Пример #6
0
 public void Insert(int index, NotebookPage page)
 {
     _updatingControls = true;
     try
     {
         _notebook.Controls.Add(page);
     }
     finally
     {
         _updatingControls = false;
     }
     InternalAdd(index, page);
 }
Пример #7
0
 public void Remove(NotebookPage page)
 {
     InternalRemoveAt(IndexOf(page));
     _updatingControls = true;
     try
     {
         _notebook.Controls.Remove(page);
     }
     finally
     {
         _updatingControls = false;
     }
 }
Пример #8
0
 protected virtual void PaintTabText(Graphics graphics, Rectangle bounds, NotebookPage page, StringFormat format)
 {
     if (page.Enabled)
     {
         using (Brush textBrush = new SolidBrush(ForeColor))
         {
             graphics.DrawString(page.Text, Font, textBrush, bounds, format);
         }
     }
     else
     {
         ControlPaint.DrawStringDisabled(graphics, page.Text, Font, SystemColors.InactiveCaptionText, bounds, format);
     }
 }
Пример #9
0
            public void RemoveAt(int index)
            {
                NotebookPage result = InternalRemoveAt(index);

                _updatingControls = true;
                try
                {
                    _notebook.Controls.Remove(result);
                }
                finally
                {
                    _updatingControls = false;
                }
            }
Пример #10
0
 public int Add(NotebookPage page)
 {
     _updatingControls = true;
     try
     {
         _notebook.Controls.Add(page);
     }
     finally
     {
         _updatingControls = false;
     }
     InternalAdd(_count, page);
     return(_count - 1);
 }
Пример #11
0
 internal void UpdateSelection()
 {
     // Clear the selection if the selected control is no longer a child of this control
     if ((_selected != null) && (_selected.Parent != this))
     {
         Selected = null;
     }
     else
     {
         // Ensure that there is a selection if there is at least one tab
         if ((_selected == null) && (Pages.Count > 0))
         {
             Selected = (NotebookPage)Pages[0];
         }
     }
 }
Пример #12
0
 /// <summary> Makes the prior tab the selected one. </summary>
 /// <returns> True if the selection changed. </returns>
 public bool SelectPriorPage()
 {
     if (_selected != null)
     {
         int index = Pages.IndexOf(_selected);
         if (index > 0)
         {
             Selected = (NotebookPage)Pages[index - 1];
         }
         else
         {
             Selected = (NotebookPage)Pages[Pages.Count - 1];
         }
         return(true);
     }
     return(false);
 }
Пример #13
0
        protected virtual void PaintTab(Graphics graphics, int offset, NotebookPage page, int tabWidth, bool isActive)
        {
            Rectangle    bounds   = base.DisplayRectangle;
            StringFormat format   = GetStringFormat();
            int          rounding = GetRounding();

            if (_tabAlignment == TabAlignment.Top)
            {
                using (GraphicsPath path = new GraphicsPath())
                {
                    // Create path for tab fill
                    path.AddBezier(offset, _tabAreaHeight, offset + (_tabAreaHeight / 2), _tabAreaHeight / 2, offset + (_tabAreaHeight / 2), 0, offset + _tabAreaHeight, 0);
                    path.AddLine(offset + _tabAreaHeight, 0, offset + (tabWidth - rounding), 0);
                    path.AddBezier(offset + (tabWidth - rounding), 0, offset + tabWidth, 0, offset + tabWidth, 0, offset + tabWidth, rounding);
                    path.AddLine(offset + tabWidth, rounding, offset + tabWidth, _tabAreaHeight);
                    path.CloseFigure();

                    // Fill the tab
                    using (Brush brush = new LinearGradientBrush(new Rectangle(0, 0, bounds.Width, _tabAreaHeight), _tabOriginColor, _tabColor, 90f, true))
                    {
                        graphics.FillPath(brush, path);
                    }

                    using (Pen pen = new Pen(_lineColor))
                    {
                        // Draw the tab border line
                        graphics.DrawBezier(pen, offset, _tabAreaHeight, offset + (_tabAreaHeight / 2), _tabAreaHeight / 2, offset + (_tabAreaHeight / 2), 0, offset + _tabAreaHeight, 0);
                        graphics.DrawLine(pen, offset + _tabAreaHeight, 0, offset + (tabWidth - rounding), 0);
                        graphics.DrawBezier(pen, offset + (tabWidth - rounding), 0, offset + tabWidth, 0, offset + tabWidth, 0, offset + tabWidth, rounding);
                        graphics.DrawLine(pen, offset + tabWidth, rounding, offset + tabWidth, _tabAreaHeight);

                        // Draw the highlight
                        pen.Color = Color.White;
                        graphics.DrawBezier(pen, 1 + offset, _tabAreaHeight, 1 + offset + (_tabAreaHeight / 2), 1 + (_tabAreaHeight / 2), 1 + offset + (_tabAreaHeight / 2), 1, 1 + offset + _tabAreaHeight, 1);
                        graphics.DrawLine(pen, 1 + offset + _tabAreaHeight, 1, offset + (tabWidth - rounding), 1);
                        graphics.DrawBezier(pen, offset + (tabWidth - rounding), 1, (offset + tabWidth) - 1, 1, (offset + tabWidth) - 1, 1, (offset + tabWidth) - 1, rounding / 2);
                    }
                }

                PaintTabText(graphics, new Rectangle((offset + _tabAreaHeight) - (_tabPadding / 2), (_tabAreaHeight - Font.Height) / 2, tabWidth, Font.Height), page, format);
            }
            else
            {
                // TODO: Paint TabAlignment = Bottom
            }
        }
Пример #14
0
            private NotebookPage InternalRemoveAt(int index)
            {
                if (index >= _count)
                {
                    throw new ArgumentOutOfRangeException("AIndex");
                }

                NotebookPage result = _pages[index];

                _count--;
                Array.Copy(_pages, index + 1, _pages, index, _count - index);

                result.TextChanged    -= new EventHandler(PageTextChanged);
                result.EnabledChanged -= new EventHandler(PageEnabledChanged);

                UpdateNotebook();

                return(result);
            }
Пример #15
0
 /// <summary> Makes the next tab the selected one. </summary>
 /// <returns> True if the selection changed. </returns>
 public bool SelectNextPage()
 {
     if (_selected != null)
     {
         int index = Pages.IndexOf(_selected);
         if (index >= 0)
         {
             if ((index < (Pages.Count - 1)))
             {
                 Selected = (NotebookPage)Pages[index + 1];
             }
             else
             {
                 Selected = (NotebookPage)Pages[0];
             }
             return(true);
         }
     }
     return(false);
 }
Пример #16
0
        /// <summary> Attempts to scroll the specified page into view. </summary>
        /// <remarks> If the given page is not a valid child page, nothing happens. </remarks>
        public void ScrollIntoView(NotebookPage page)
        {
            int[] tabWidths = GetTabWidths();
            int   pageIndex = Pages.IndexOf(page);

            if (pageIndex >= 0)
            {
                int tabWidth    = GetTabBounds().Width - (ScrollerOffset * 2);
                int tabOverlap  = GetTabOverlap();
                int accumulated = tabWidths[pageIndex];

                // Don't scroll below LMin offset, doing so would hide the specified page
                int min;
                for (min = pageIndex; (min > 0) && ((accumulated + (tabWidths[min - 1] - tabOverlap)) <= tabWidth); min--)
                {
                    accumulated += tabWidths[min - 1] - tabOverlap;
                }

                ScrollOffset = Math.Min(pageIndex, Math.Max(ScrollOffset, min));
            }
        }
Пример #17
0
            private void InternalAdd(int index, NotebookPage page)
            {
                page.Visible         = false;
                page.TextChanged    += new EventHandler(PageTextChanged);
                page.EnabledChanged += new EventHandler(PageEnabledChanged);

                // Grow the capacity of FPages if necessary
                if (_count == _pages.Length)
                {
                    NotebookPage[] pages = new NotebookPage[Math.Min(_pages.Length * 2, _pages.Length + 512)];
                    Array.Copy(_pages, pages, _pages.Length);
                    _pages = pages;
                }

                // Shift the items
                Array.Copy(_pages, index, _pages, index + 1, _count - index);

                // Set the inserted item
                _pages[index] = page;
                _count++;

                UpdateNotebook();
            }
Пример #18
0
 public bool Contains(NotebookPage page)
 {
     return(IndexOf(page) >= 0);
 }
Пример #19
0
 protected virtual int GetTabWidth(Graphics graphics, NotebookPage page)
 {
     return((_tabAreaHeight / 4) + _tabAreaHeight + Size.Ceiling(graphics.MeasureString(page.Text, Font, PointF.Empty, GetStringFormat())).Width);
 }