/*
         * DrawTabButton
         */

        /// <summary>
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// <para>
        ///		<paramref name="paintParams"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        public void DrawTabButton(NuGenTabButtonPaintParams paintParams)
        {
            if (paintParams == null)
            {
                throw new ArgumentNullException("paintParams");
            }

            Graphics g = paintParams.Graphics;

            Debug.Assert(g != null, "g != null");

            if (Application.RenderWithVisualStyles)
            {
                this.DrawTabButtonBackgroundUsingVisualStyles(g, paintParams.Bounds, paintParams.State);
            }
            else
            {
                this.DrawTabButtonBackground(g, paintParams.Bounds, paintParams.State);
            }

            Rectangle textBounds = paintParams.TextBounds;

            if (textBounds.Width > 10)
            {
                Debug.Assert(paintParams.Font != null, "tabItemParams.Font != null");
                this.DrawText(
                    g,
                    textBounds,
                    NuGenTabItemStateTranslator.ToControlState(paintParams.State),
                    paintParams.Text,
                    paintParams.Font,
                    paintParams.ForeColor,
                    System.Drawing.ContentAlignment.MiddleLeft
                    );
            }

            Image tabItemImage = paintParams.Image;

            if (tabItemImage != null)
            {
                this.DrawImage(
                    g,
                    paintParams.ImageBounds,
                    NuGenTabItemStateTranslator.ToControlState(paintParams.State),
                    tabItemImage
                    );
            }
        }
        /*
         * DrawTabButton
         */

        /// <summary>
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// <para>
        ///		<paramref name="paintParams"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        public void DrawTabButton(NuGenTabButtonPaintParams paintParams)
        {
            if (paintParams == null)
            {
                throw new ArgumentNullException("paintParams");
            }

            Graphics g = paintParams.Graphics;

            Debug.Assert(g != null, "g != null");

            if (Application.RenderWithVisualStyles)
            {
                this.DrawTabButtonBackgroundUsingVisualStyles(g, paintParams.Bounds, paintParams.State);
            }
            else
            {
                this.DrawTabButtonBackground(g, paintParams.Bounds, paintParams.State);
            }

            Rectangle textBounds = paintParams.TextBounds;

            if (textBounds.Width > 10)
            {
                Debug.Assert(paintParams.Font != null, "tabItemParams.Font != null");
                this.DrawTabButtonText(
                    g,
                    paintParams.Text,
                    textBounds,
                    paintParams.Font,
                    paintParams.ForeColor,
                    paintParams.State != TabItemState.Disabled
                    );
            }

            Image tabItemImage = paintParams.Image;

            if (tabItemImage != null)
            {
                this.DrawTabButtonImage(
                    g,
                    tabItemImage,
                    paintParams.ImageBounds,
                    paintParams.State != TabItemState.Disabled
                    );
            }
        }
		/*
		 * OnPaint
		 */

		/// <summary>
		/// Raises the <see cref="E:System.Windows.Forms.Control.Paint"></see> event.
		/// </summary>
		/// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data.</param>
		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;

			using (SolidBrush sb = new SolidBrush(this.BackColor))
			{
				g.FillRectangle(sb, this.ClientRectangle);
			}

			Rectangle closeButtonBounds = this.CloseButton.Visible ? this.CloseButton.Bounds : Rectangle.Empty;
			Rectangle bounds = this.LayoutManager.GetContentRectangle(this.ClientRectangle, closeButtonBounds);
			Image image = this.Image;
			System.Drawing.ContentAlignment imageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			Rectangle imageBounds = Rectangle.Empty;

			if (image != null)
			{
				imageBounds = this.LayoutManager.GetImageBounds(
					new NuGenBoundsParams(
						bounds
						, imageAlign
						, new Rectangle(Point.Empty, image.Size)
						, this.RightToLeft
					)
				);
			}

			Rectangle textBounds = this.LayoutManager.GetTextBounds(
				new NuGenBoundsParams(bounds, imageAlign, imageBounds, this.RightToLeft)
			);

			NuGenTabButtonPaintParams tabItemParams = new NuGenTabButtonPaintParams(g);
			tabItemParams.Bounds = this.ClientRectangle;
			tabItemParams.Font = this.Font;
			tabItemParams.Image = this.Image;
			tabItemParams.ImageBounds = imageBounds;
			tabItemParams.Text = this.Text;

			if (this.Text != null)
			{
				tabItemParams.TextBounds = textBounds;
			}

			tabItemParams.State = NuGenTabItemStateTranslator.FromControlState(this.TabStateTracker.GetControlState());

			Debug.Assert(this.TabRenderer != null, "this.TabRenderer != null");
			this.TabRenderer.DrawTabButton(tabItemParams);
		}
		/*
		 * DrawTabButton
		 */

		/// <summary>
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="paintParams"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public void DrawTabButton(NuGenTabButtonPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Debug.Assert(g != null, "g != null");

			if (Application.RenderWithVisualStyles)
			{
				this.DrawTabButtonBackgroundUsingVisualStyles(g, paintParams.Bounds, paintParams.State);
			}
			else
			{
				this.DrawTabButtonBackground(g, paintParams.Bounds, paintParams.State);
			}

			Rectangle textBounds = paintParams.TextBounds;

			if (textBounds.Width > 10)
			{
				Debug.Assert(paintParams.Font != null, "tabItemParams.Font != null");
				this.DrawText(
					g,
					textBounds,
					NuGenTabItemStateTranslator.ToControlState(paintParams.State),
					paintParams.Text,
					paintParams.Font,
					paintParams.ForeColor,
					System.Drawing.ContentAlignment.MiddleLeft
				);
			}

			Image tabItemImage = paintParams.Image;

			if (tabItemImage != null)
			{
				this.DrawImage(
					g,
					paintParams.ImageBounds,
					NuGenTabItemStateTranslator.ToControlState(paintParams.State),
					tabItemImage
				);
			}
		}
		/*
		 * DrawTabButton
		 */

		/// <summary>
		/// </summary>
		/// <param name="paintParams"></param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="paintParams"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public void DrawTabButton(NuGenTabButtonPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Rectangle bounds = paintParams.Bounds;
			NuGenControlState currentState = NuGenControlState.Normal;

			/* Helps to draw background properly if the BackColor property is set to Color.Transparent. */
			g.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, bounds.Width, 2));

			switch (paintParams.State)
			{
				case TabItemState.Disabled:
				{
					currentState = NuGenControlState.Disabled;
					break;
				}
				case TabItemState.Hot:
				{
					currentState = NuGenControlState.Hot;
					break;
				}
				case TabItemState.Selected:
				{
					currentState = NuGenControlState.Pressed;
					break;
				}
				default:
				{
					currentState = NuGenControlState.Normal;
					break;
				}
			}

			Rectangle tweakedRectangle = NuGenControlPaint.BorderRectangle(bounds);

			using (NuGenGrfxMode mode = new NuGenGrfxMode(g))
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				DrawRoundBackground(g, tweakedRectangle, currentState, NuGenRoundRectangleStyle.TopRound);
				DrawRoundBorder(g, tweakedRectangle, currentState, NuGenRoundRectangleStyle.TopRound);
			}

			this.DrawText(
				g, 
				paintParams.TextBounds, 
				currentState, 
				paintParams.Text, 
				paintParams.Font, 
				paintParams.ForeColor, 
				System.Drawing.ContentAlignment.MiddleLeft
			);

			if (paintParams.Image != null)
			{
				this.DrawImage(
					g, 
					paintParams.ImageBounds, 
					currentState, 
					paintParams.Image
				);
			}
		}
		/*
		 * OnPaint
		 */

		/// <summary>
		/// Raises the <see cref="E:System.Windows.Forms.Control.Paint"></see> event.
		/// </summary>
		/// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data.</param>
		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;

			using (SolidBrush sb = new SolidBrush(this.BackColor))
			{
				g.FillRectangle(sb, this.ClientRectangle);
			}

			Rectangle closeButtonBounds = this.CloseButton.Visible ? this.CloseButton.Bounds : Rectangle.Empty;
			Rectangle bounds = this.LayoutManager.GetContentRectangle(this.ClientRectangle, closeButtonBounds);
			Image image = this.Image;
			System.Drawing.ContentAlignment imageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			Rectangle imageBounds = this.LayoutManager.GetImageBounds(new NuGenImageBoundsParams(bounds, image, imageAlign));
			Rectangle textBounds = this.LayoutManager.GetTextBounds(new NuGenTextBoundsParams(bounds, imageBounds, imageAlign));

			NuGenTabButtonPaintParams tabItemParams = new NuGenTabButtonPaintParams(g, this.ClientRectangle);
			tabItemParams.Font = this.Font;
			tabItemParams.Image = this.Image;
			tabItemParams.ImageBounds = imageBounds;
			tabItemParams.IsRightToLeft = this.RightToLeft == RightToLeft.Yes;
			tabItemParams.Text = this.Text;

			if (this.Text != null)
			{
				tabItemParams.TextBounds = textBounds;
			}

			if (!this.Enabled)
			{
				tabItemParams.State = TabItemState.Disabled;
			}
			else
			{
				switch (this.TabStateTracker.GetControlState())
				{
					case NuGenControlState.Hot:
					{
						tabItemParams.State = TabItemState.Hot;
						break;
					}
					case NuGenControlState.Pressed:
					{
						tabItemParams.State = TabItemState.Selected;
						break;
					}
				}
			}

			Debug.Assert(this.TabRenderer != null, "this.TabRenderer != null");
			this.TabRenderer.DrawTabButton(tabItemParams);
		}
		/*
		 * DrawTabButton
		 */

		/// <summary>
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="paintParams"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public void DrawTabButton(NuGenTabButtonPaintParams paintParams)
		{
			if (paintParams == null)
			{
				throw new ArgumentNullException("paintParams");
			}

			Graphics g = paintParams.Graphics;
			Debug.Assert(g != null, "g != null");

			if (Application.RenderWithVisualStyles)
			{
				this.DrawTabButtonBackgroundUsingVisualStyles(g, paintParams.Bounds, paintParams.State);
			}
			else
			{
				this.DrawTabButtonBackground(g, paintParams.Bounds, paintParams.State);
			}

			Rectangle textBounds = paintParams.TextBounds;

			if (textBounds.Width > 10)
			{
				Debug.Assert(paintParams.Font != null, "tabItemParams.Font != null");
				this.DrawTabButtonText(
					g,
					paintParams.Text,
					textBounds,
					paintParams.Font,
					paintParams.ForeColor,
					paintParams.State != TabItemState.Disabled
				);
			}

			Image tabItemImage = paintParams.Image;

			if (tabItemImage != null)
			{
				this.DrawTabButtonImage(
					g,
					tabItemImage,
					paintParams.ImageBounds,
					paintParams.State != TabItemState.Disabled
				);
			}
		}