# Patch created by root
# Date: Tue Dec 28 07:51:52 SAST 2004
# Repository: pnetlib
# Comments:
# 
#### End of Preamble ####

#### Patch data follows ####
Index: System.Windows.Forms/TabControl.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/TabControl.cs,v
retrieving revision 1.23
diff -c -r1.23 TabControl.cs
*** System.Windows.Forms/TabControl.cs	27 Dec 2004 15:35:11 -0000	1.23
--- System.Windows.Forms/TabControl.cs	27 Dec 2004 23:50:10 -0000
***************
*** 123,132 ****
  
  		protected virtual void OnSelectedIndexChanged(EventArgs e)
  		{
! 			if (selectedIndex == -1 || selectedIndex >= TabCount)
! 			{
! 				return;
! 			}
  			SuspendLayout();
  			if (prevSelectedIndex > -1)
  			{
--- 123,133 ----
  
  		protected virtual void OnSelectedIndexChanged(EventArgs e)
  		{
! 			//redundant check, is done is SelectedIndex already
! 			//if (selectedIndex == -1 || selectedIndex >= TabCount)
! 			//{
! 			//	return;
! 			//}
  			SuspendLayout();
  			if (prevSelectedIndex > -1)
  			{
***************
*** 281,287 ****
  			}
  			set
  			{
! 				SelectedIndex = tabPageCollection.IndexOf(value);
  			}
  		}
  
--- 282,288 ----
  			}
  			set
  			{
! 				selectedIndex = tabPageCollection.IndexOf(value);
  			}
  		}
  
***************
*** 357,370 ****
  
  			public override void Add(Control control)
  			{
- 				control.Visible = false;
  				base.Add(control);
  				tabOwner.InvalidateTabs	();
  				tabOwner.SetTabPageBounds();
- 				if (tabOwner.SelectedTab == control)
- 				{
- 					control.Visible = true;
- 				}
  			}
  
  			[TODO]
--- 358,366 ----
***************
*** 546,562 ****
  
  		protected override void OnPaint(PaintEventArgs e)
  		{
- 			// Work around to set the SelectedTab to the first
- 			// added TabPage.
- 			if(firstPaint)
- 			{
- 				if((selectedIndex > -1) &&
- 					(tabPageCollection.Count > 0))
- 				{
- 					SelectedTab = (TabPage)tabPageCollection[selectedIndex];
- 				}
- 				firstPaint = false;
- 			}
  
  			Draw(e.Graphics);
  			// Draw the visible TabPage (child controls)
--- 542,547 ----
***************
*** 618,624 ****
  			{
  				for( int i = 0; i < tabPageCollection.Count; i++ )
  				{
! 					if (row == PositionInfo.positions[i].row && i != selectedIndex)
  					{
  						Rectangle bounds = GetTabRect(i);
  						// Remove bottom line off bounds if not selected so border isnt covered
--- 603,609 ----
  			{
  				for( int i = 0; i < tabPageCollection.Count; i++ )
  				{
! 					if (row == PositionInfo.positions[i].row && i != SelectedIndex)
  					{
  						Rectangle bounds = GetTabRect(i);
  						// Remove bottom line off bounds if not selected so border isnt covered
***************
*** 628,644 ****
  					}
  				}
  			}
! 			if (selectedIndex > -1 && selectedIndex < TabPages.Count)
  			{
! 				Rectangle bounds = GetTabRect(selectedIndex);
  				g.SetClip(new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height), Drawing.Drawing2D.CombineMode.Intersect);
  				
  				DrawItemState state;
  				if (Focused)
! 					state = DrawItemState.Focus;
  				else
! 					state = DrawItemState.None;
! 				OnDrawItem( new DrawItemEventArgs(g, Font, bounds, selectedIndex, state, ForeColor, BackColor));
  			}
  
  		}
--- 613,629 ----
  					}
  				}
  			}
! 			if (SelectedIndex < TabPages.Count)
  			{
! 				Rectangle bounds = GetTabRect(SelectedIndex);
  				g.SetClip(new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height), Drawing.Drawing2D.CombineMode.Intersect);
  				
  				DrawItemState state;
  				if (Focused)
! 					state = DrawItemState.Focus;// | DrawItemState.Selected;
  				else
! 					state = DrawItemState.Default; //DrawItemState.Selected;
! 				OnDrawItem( new DrawItemEventArgs(g, Font, bounds, SelectedIndex, state, ForeColor, BackColor));
  			}
  
  		}
***************
*** 688,699 ****
  								SizeTabsFillRight ( ref tabs, graphics, rowWidth, out maxRow );
  						}
  						// Do we need to move the row that was selected to the bottom of the tabs?
! 						if (selectedIndex > -1 && selectedIndex < TabCount)
! 						{
  							// Check to see if we have selected a tab that isnt on the last row and move the tab row down
! 							if (tabs[selectedIndex].row != maxRow)
! 								RowToBottom(ref tabs, tabs[selectedIndex].row, maxRow);
! 						}
  
  						// Find the actual bounds
  						LayoutTabBounds( ref tabs, rowWidth );
--- 673,685 ----
  								SizeTabsFillRight ( ref tabs, graphics, rowWidth, out maxRow );
  						}
  						// Do we need to move the row that was selected to the bottom of the tabs?
! 						// why is bounds checked here again? its redundant.
! 						//if (SelectedIndex < TabCount)
! 						//{
  							// Check to see if we have selected a tab that isnt on the last row and move the tab row down
! 							if (tabs[SelectedIndex].row != maxRow)
! 								RowToBottom(ref tabs, tabs[SelectedIndex].row, maxRow);
! 						//}
  
  						// Find the actual bounds
  						LayoutTabBounds( ref tabs, rowWidth );
***************
*** 935,947 ****
  				{
  					// Move the tabs thats selected by 1
  					int selDelta = 0;
! 					if (i != selectedIndex)
  						selDelta = 1;
  
  					TabPosition tab = tabs[i];
  					int width = tab.bounds.Width + (1-selDelta)*2*indent;
  					// Draw the left edge of tabs that begin a row or are selected
! 					if (tab.bounds.Left - leftOffset == 0 || selectedIndex == i)
  						tab.leftExposed = true;
  					tab.bounds = new Rectangle(tab.bounds.Left + indent - (1-selDelta)*2 - leftOffset, yDirection *((tab.row + extraRow ) * down + selDelta) + top, width, down + 1 - selDelta );
  					tabs[i] = tab;
--- 921,933 ----
  				{
  					// Move the tabs thats selected by 1
  					int selDelta = 0;
! 					if (i != SelectedIndex)
  						selDelta = 1;
  
  					TabPosition tab = tabs[i];
  					int width = tab.bounds.Width + (1-selDelta)*2*indent;
  					// Draw the left edge of tabs that begin a row or are selected
! 					if (tab.bounds.Left - leftOffset == 0 || SelectedIndex == i)
  						tab.leftExposed = true;
  					tab.bounds = new Rectangle(tab.bounds.Left + indent - (1-selDelta)*2 - leftOffset, yDirection *((tab.row + extraRow ) * down + selDelta) + top, width, down + 1 - selDelta );
  					tabs[i] = tab;
***************
*** 1019,1024 ****
--- 1005,1014 ----
  			}
  			set
  			{
+ 				if (value < 0 || value >= tabPageCollection.Count)
+ 				{
+ 					throw new IndexOutOfRangeException(value.ToString());
+ 				}
  				if (value != selectedIndex)
  				{
  					prevSelectedIndex = selectedIndex;
#### End of Patch data ####
