protected override void AddAccessibleControlsToList(ArrayList list)
 {
     for (int i = 0; i < TabCount; i++)
     {
         TabEntry tabEntry = (TabEntry)tabEntryList[i];
         list.Add(tabEntry.TabSelectorLightweightControl);
     }
     base.AddAccessibleControlsToList(list);
 }
        /// <summary>
        /// Initializes a new instance of the TabSelectorLightweightControl class.
        /// </summary>
        public TabSelectorLightweightControl(TabEntry tabEntry)
        {
            /// <summary>
            /// Required for Windows.Forms Class Composition Designer support
            /// </summary>
            InitializeComponent();

            //	Set the tab entry.
            this.tabEntry = tabEntry;

            //	Initialize the object.
            InitializeObject();
        }
        private void DecrementTab()
        {
            int currentIndex = SelectedTabNumber - 1;

            if (currentIndex < 0)
            {
                currentIndex = tabEntryList.Count - 1;
            }
            TabEntry tabEntry = (TabEntry)tabEntryList[currentIndex];

            if (tabEntry != null)
            {
                SelectedTabEntry = tabEntry;
            }
        }
        private void IncrementTab()
        {
            int currentIndex = SelectedTabNumber + 1;

            if (currentIndex >= tabEntryList.Count)
            {
                currentIndex = 0;
            }
            TabEntry tabEntry = (TabEntry)tabEntryList[currentIndex];

            if (tabEntry != null)
            {
                SelectedTabEntry = tabEntry;
            }
        }
        /// <summary>
        /// Helper to remove a tab entry.
        /// </summary>
        /// <param name="tabNumber">The tab number of the tab entry to remove.</param>
        private void RemoveTabEntry(int tabNumber)
        {
            //	Locate the tab entry for the specified tab number.  It it's found, remove it.
            TabEntry tabEntry = (TabEntry)tabEntryList[tabNumber];

            if (tabEntry != null)
            {
                if (SelectedTabEntry == tabEntry)
                {
                    SelectedTabEntry = FirstTabEntry;
                }
                tabPageContainerControl.Controls.Remove(tabEntry.TabPageControl);
                LightweightControls.Remove(tabEntry.TabSelectorLightweightControl);
                tabEntryList.Remove(tabNumber);
            }
        }
        /// <summary>
        /// Sets a tab control.
        /// </summary>
        /// <param name="index">The tab index to set.</param>
        /// <param name="tabPageControl">The tab page control to set.</param>
        public void SetTab(int tabNumber, TabPageControl tabPageControl)
        {
            //	If there already is a tab entry for the specified tab number, remove it.
            RemoveTabEntry(tabNumber);

            //	Instantiate the new tab entry.
            TabEntry tabEntry = new TabEntry(this, tabPageControl);

            tabEntryList.Add(tabNumber, tabEntry);
            tabPageContainerControl.Controls.Add(tabEntry.TabPageControl);
            LightweightControls.Add(tabEntry.TabSelectorLightweightControl);
            tabEntry.TabSelectorLightweightControl.DragInside += new DragEventHandler(TabSelectorLightweightControl_DragInside);
            tabEntry.TabSelectorLightweightControl.DragOver   += new DragEventHandler(TabSelectorLightweightControl_DragOver);
            tabEntry.TabSelectorLightweightControl.Selected   += new EventHandler(TabSelectorLightweightControl_Selected);
            tabEntry.TabPageControl.VisibleChanged            += new EventHandler(TabPageControl_VisibleChanged);

            //	Layout and invalidate.
            PerformLayout();
            Invalidate();
        }
        /// <summary>
        /// Sets a tab control.
        /// </summary>
        /// <param name="index">The tab index to set.</param>
        /// <param name="tabPageControl">The tab page control to set.</param>
        public void SetTab(int tabNumber, TabPageControl tabPageControl)
        {
            //	If there already is a tab entry for the specified tab number, remove it.
            RemoveTabEntry(tabNumber);

            //	Instantiate the new tab entry.
            TabEntry tabEntry = new TabEntry(this, tabPageControl);
            tabEntryList.Add(tabNumber, tabEntry);
            tabPageContainerControl.Controls.Add(tabEntry.TabPageControl);
            LightweightControls.Add(tabEntry.TabSelectorLightweightControl);
            tabEntry.TabSelectorLightweightControl.DragInside += new DragEventHandler(TabSelectorLightweightControl_DragInside);
            tabEntry.TabSelectorLightweightControl.DragOver += new DragEventHandler(TabSelectorLightweightControl_DragOver);
            tabEntry.TabSelectorLightweightControl.Selected += new EventHandler(TabSelectorLightweightControl_Selected);
            tabEntry.TabPageControl.VisibleChanged += new EventHandler(TabPageControl_VisibleChanged);

            //	Layout and invalidate.
            PerformLayout();
            Invalidate();
        }
        /// <summary>
        /// Raises the Layout event.  The mother of all layout processing.
        /// </summary>
        /// <param name="e">An EventArgs that contains the event data.</param>
        protected override void OnLayout(EventArgs e)
        {
            //	Call the base class's method so registered delegates receive the event.
            base.OnLayout(e);

            //	No layout required if this control is not visible.
            if (Parent == null)
            {
                return;
            }

            //	If there are not tabs, layout processing is simple.
            if (tabEntryList.Count == 0)
            {
                HideTabScrollerInterface();
                tabSelectorAreaSize = new Size(0, 1);
                return;
            }

            //	Pre-process the layout of tab selectors.
            int width = (TAB_INSET * 2) + (PAD * 4) + (PAD * (tabEntryList.Count - 1)), height = 0;

            foreach (TabEntry tabEntry in tabEntryList.Values)
            {
                if (!tabEntry.Hidden)
                {
                    //	Reset the tab selector and have it perform its layout logic so that it is at
                    //	its natural size.
                    tabEntry.TabSelectorLightweightControl.SmallTabs     = SmallTabs;
                    tabEntry.TabSelectorLightweightControl.ShowTabBitmap = true;
                    tabEntry.TabSelectorLightweightControl.ShowTabText   = true;
                    tabEntry.TabSelectorLightweightControl.PerformLayout();

                    //	If this tab selector is the tallest one we've seen, it sets a new high-
                    //	water mark.
                    if (tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Height > height)
                    {
                        height = tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Height;
                    }

                    //	Adjust the width to account for this tab selector.
                    width += tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Width;

                    // Push the tabs closer together
                    width -= 6;
                }
            }
            width += 6;

            //	Pad height.
            height += PAD;

            //	If the tab selection area is scrollable, enable/disable the scroller interface.
            if (scrollableTabSelectorArea)
            {
                //	Set the tab selector area size.
                tabSelectorAreaSize = new Size(width, height);

                //	If the entire tab selector area is visible, hide the tab scroller interface.
                if (width <= VirtualWidth)
                {
                    HideTabScrollerInterface();
                }
                else
                {
                    //	If the tab scroller position is zero, the left tab scroller button is not
                    //	shown.
                    if (tabScrollerPosition == 0)
                    {
                        tabScrollerButtonLightweightControlLeft.Visible = false;
                    }
                    else
                    {
                        //	Layout the left tab scroller button.
                        tabScrollerButtonLightweightControlLeft.VirtualBounds = new Rectangle(0,
                                                                                              0,
                                                                                              tabScrollerButtonLightweightControlLeft.DefaultVirtualSize.Width,
                                                                                              tabSelectorAreaSize.Height);
                        tabScrollerButtonLightweightControlLeft.Visible = true;
                        tabScrollerButtonLightweightControlLeft.BringToFront();
                    }

                    //	Layout the right tab scroller button.
                    if (tabScrollerPosition == MaximumTabScrollerPosition)
                    {
                        tabScrollerButtonLightweightControlRight.Visible = false;
                    }
                    else
                    {
                        int rightScrollerButtonWidth = tabScrollerButtonLightweightControlRight.DefaultVirtualSize.Width;
                        tabScrollerButtonLightweightControlRight.VirtualBounds = new Rectangle(TabAreaRectangle.Right - rightScrollerButtonWidth,
                                                                                               0,
                                                                                               rightScrollerButtonWidth,
                                                                                               tabSelectorAreaSize.Height);
                        tabScrollerButtonLightweightControlRight.Visible = true;
                        tabScrollerButtonLightweightControlRight.BringToFront();
                    }
                }
            }
            else
            {
                //	Hide the tab scroller interface.
                HideTabScrollerInterface();

                if (!allowTabClipping)
                {
                    //	If the entire tab selector area is not visible, switch into "no bitmap" mode.
                    if (width > VirtualWidth)
                    {
                        //	Reset the width.
                        width = (TAB_INSET * 2) + (PAD * 4) + (PAD * (tabEntryList.Count - 1));

                        //	Re-process the layout of tab selectors.
                        foreach (TabEntry tabEntry in tabEntryList.Values)
                        {
                            if (!tabEntry.Hidden)
                            {
                                //	Hide tab bitmap.
                                tabEntry.TabSelectorLightweightControl.ShowTabBitmap = false;
                                tabEntry.TabSelectorLightweightControl.ShowTabText   = true;
                                tabEntry.TabSelectorLightweightControl.PerformLayout();

                                //	Adjust the width to account for this tab selector.
                                width += tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Width;
                            }
                        }
                    }

                    //	If the entire tab selector area is not visible, switch into "no text except selected" mode.
                    if (width > VirtualWidth)
                    {
                        //	Reset the width.
                        width = (TAB_INSET * 2) + (PAD * 4) + (PAD * (tabEntryList.Count - 1));

                        //	Re-process the layout of tab selectors.
                        foreach (TabEntry tabEntry in tabEntryList.Values)
                        {
                            if (!tabEntry.Hidden)
                            {
                                //	Hide tab text.
                                tabEntry.TabSelectorLightweightControl.ShowTabBitmap = true;
                                tabEntry.TabSelectorLightweightControl.ShowTabText   = tabEntry.IsSelected;
                                tabEntry.TabSelectorLightweightControl.PerformLayout();

                                //	Adjust the width to account for this tab selector.
                                width += tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Width;
                            }
                        }
                    }

                    //	If the entire tab selector area is not visible, switch into "no text" mode.
                    if (width > VirtualWidth)
                    {
                        //	Reset the width.
                        width = (TAB_INSET * 2) + (PAD * 4) + (PAD * (tabEntryList.Count - 1));

                        //	Re-process the layout of tab selectors.
                        foreach (TabEntry tabEntry in tabEntryList.Values)
                        {
                            if (!tabEntry.Hidden)
                            {
                                //	Hide tab text.
                                tabEntry.TabSelectorLightweightControl.ShowTabBitmap = true;
                                tabEntry.TabSelectorLightweightControl.ShowTabText   = false;
                                tabEntry.TabSelectorLightweightControl.PerformLayout();

                                //	Adjust the width to account for this tab selector.
                                width += tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Width;
                            }
                        }
                    }

                    //	If the entire tab selector area is not visible, hide it.
                    if (width > VirtualWidth)
                    {
                        //	Reset the width.
                        width = (TAB_INSET * 2) + (PAD * 4) + (PAD * (tabEntryList.Count - 1));

                        //	Re-process the layout of tab selectors.
                        foreach (TabEntry tabEntry in tabEntryList.Values)
                        {
                            if (!tabEntry.Hidden)
                            {
                                //	Hide tab text.
                                tabEntry.TabSelectorLightweightControl.ShowTabBitmap = false;
                                tabEntry.TabSelectorLightweightControl.PerformLayout();

                                //	Adjust the width to account for this tab selector.
                                width += tabEntry.TabSelectorLightweightControl.UnselectedVirtualSize.Width;
                            }
                        }

                        if (width > VirtualWidth)
                        {
                            height = 1;
                        }
                    }
                }

                //	Set the tab selector layout size.
                tabSelectorAreaSize = new Size(width, height);
            }

            //	Finally, actually layout the tab entries.
            int      x = TAB_INSET + (PAD * 2);
            TabEntry previousTabEntry = null;

            foreach (TabEntry tabEntry in tabEntryList.Values)
            {
                if (!tabEntry.Hidden)
                {
                    //	Adjust the x offset for proper positioning of this tab and set the y offset,
                    //	too.  Now we know WHERE the tab will be laid out in the tab area.
                    if (previousTabEntry != null)
                    {
                        x += previousTabEntry.IsSelected ? -PAD + 1 : -1;
                    }
                    int y = Math.Max(0, tabSelectorAreaSize.Height - tabEntry.TabSelectorLightweightControl.VirtualBounds.Height);

                    //	Latout the tab entry.
                    tabEntry.TabSelectorLightweightControl.VirtualLocation = new Point(x - tabScrollerPosition, y);

                    //	Adjust the x offset to account for the tab entry.
                    x += tabEntry.TabSelectorLightweightControl.VirtualBounds.Width;

                    //	Set the previous tab entry for the next loop iteration.
                    previousTabEntry = tabEntry;
                }
            }

            //	Set the bounds of the tab page control.
            Rectangle tabPageControlBounds = VirtualClientRectangleToParent(TabPageRectangle);

            if (tabPageContainerControl.Bounds != tabPageControlBounds)
            {
                tabPageContainerControl.Bounds = tabPageControlBounds;
            }

            //	Make sure the selected tab entry and its TabPageControl are visible and at the top
            //	of the Z order and that, if there is one, the previously selected tab entry's
            //	TabPageControl is not visible.
            if (SelectedTabEntry != null)
            {
                SelectedTabEntry.TabSelectorLightweightControl.BringToFront();
                SelectedTabEntry.TabPageControl.BringToFront();
            }

            RtlLayoutFixup(true);
        }
        /// <summary>
        /// Initializes a new instance of the TabSelectorLightweightControl class.
        /// </summary>
        public TabSelectorLightweightControl(TabEntry tabEntry)
        {
            /// <summary>
            /// Required for Windows.Forms Class Composition Designer support
            /// </summary>
            InitializeComponent();

            //	Set the tab entry.
            this.tabEntry = tabEntry;

            //	Initialize the object.
            InitializeObject();
        }