Esempio n. 1
0
		protected virtual int DrawTab (Graphics dc, System.Windows.Forms.TabPage page, System.Windows.Forms.TabControl tab, Rectangle bounds, bool is_selected)
		{
			Rectangle interior;
			int res = bounds.Width;

			dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);

			if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
				// Separators
				if (tab.Appearance == TabAppearance.FlatButtons) {
					int width = bounds.Width;
					bounds.Width += (flatButtonSpacing - 2);
					res = bounds.Width;
					if (tab.Alignment == TabAlignment.Top || tab.Alignment == TabAlignment.Bottom)
						ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
					else
						ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Top);
					bounds.Width = width;
				}

				if (is_selected) {
					ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
				} else if (tab.Appearance != TabAppearance.FlatButtons) {
					ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
				}


			} else {
				CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);

				Pen light = ResPool.GetPen (cpcolor.LightLight);

				switch (tab.Alignment) {

					case TabAlignment.Top:

						dc.DrawLine (light, bounds.Left, bounds.Bottom - 1, bounds.Left, bounds.Top + 3);
						dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 2, bounds.Top);
						dc.DrawLine (light, bounds.Left + 2, bounds.Top, bounds.Right - 3, bounds.Top);

						dc.DrawLine (SystemPens.ControlDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 2, bounds.Bottom - 1);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 2);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 1);
						break;

					case TabAlignment.Bottom:

						dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 2);
						dc.DrawLine (light, bounds.Left, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);
						
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
						dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);

						dc.DrawLine (SystemPens.ControlDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Top + 1);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 2);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Top + 1);

						break;

					case TabAlignment.Left:

						dc.DrawLine (light, bounds.Left - 2, bounds.Top, bounds.Right, bounds.Top);
						dc.DrawLine (light, bounds.Left, bounds.Top + 2, bounds.Left - 2, bounds.Top);
						dc.DrawLine (light, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);

						dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom - 1);

						dc.DrawLine (SystemPens.ControlDark, bounds.Left + 2, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Right, bounds.Bottom);

						break;

					default: // TabAlignment.Right

						dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
						dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);

						dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
						dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);

						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);

						break;
				}
			}

			Point padding = tab.Padding;
			interior = new Rectangle (bounds.Left + padding.X - 1, // substract a little offset
				bounds.Top + padding.Y,
				bounds.Width - (padding.X * 2), 
				bounds.Height - (padding.Y * 2));

			if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
				if (tab.Alignment == TabAlignment.Left) {
					dc.TranslateTransform (bounds.Left, bounds.Bottom);
					dc.RotateTransform (-90);
					dc.DrawString (page.Text, tab.Font,
						SystemBrushes.ControlText, 
						tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming
						tab.Padding.Y,
						defaultFormatting);
					dc.ResetTransform ();
				} else if (tab.Alignment == TabAlignment.Right) {
					dc.TranslateTransform (bounds.Right, bounds.Top);
					dc.RotateTransform (90);
					dc.DrawString (page.Text, tab.Font,
						SystemBrushes.ControlText, 
						tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming
						tab.Padding.Y,
						defaultFormatting);
					dc.ResetTransform ();
				} else {
					Rectangle str_rect = interior;

					if (is_selected) {
						// Reduce the interior size to match the inner size of non-selected tabs
						str_rect.X += selectedTabDelta.X;
						str_rect.Y += selectedTabDelta.Y;
						str_rect.Width -= selectedTabDelta.Width;
						str_rect.Height -= selectedTabDelta.Height;

						str_rect.Y -= selectedTabDelta.Y; // Move up the text / image of the selected tab
					}

					if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) {
						int image_x;
						if (tab.SizeMode != TabSizeMode.Fixed) {
							image_x = str_rect.X;
						}
						else {
							image_x = str_rect.X + (str_rect.Width - tab.ImageList.ImageSize.Width) / 2;
							if (page.Text != null) {
								SizeF textSize = dc.MeasureString(page.Text, page.Font, str_rect.Size);
								image_x -= (int)(textSize.Width / 2);
							}
						}
						int image_y = str_rect.Y + (str_rect.Height - tab.ImageList.ImageSize.Height) / 2;
						tab.ImageList.Draw (dc, new Point (image_x, image_y), page.ImageIndex);
						str_rect.X += tab.ImageList.ImageSize.Width + 2;
						str_rect.Width -= tab.ImageList.ImageSize.Width + 2;
					}
					dc.DrawString (page.Text, tab.Font,
						SystemBrushes.ControlText,
						str_rect, 
						defaultFormatting);

				}
			} else if (page.Text != null) {
				DrawItemState state = DrawItemState.None;
				if (page == tab.SelectedTab)
					state |= DrawItemState.Selected;
				DrawItemEventArgs e = new DrawItemEventArgs (dc,
					tab.Font, bounds, tab.IndexForTabPage (page),
					state, page.ForeColor, page.BackColor);
				tab.OnDrawItemInternal (e);
				return res;
			}

			// TabControl ignores the value of ShowFocusCues
			if (page.Parent.Focused && is_selected) {
				Rectangle focus_rect = bounds;
				focus_rect.Inflate (-2, -2);
				ThemeEngine.Current.CPDrawFocusRectangle (dc, focus_rect, tab.BackColor, tab.ForeColor);
			}

			return res;
		}
		protected virtual int DrawTab (Graphics dc, System.Windows.Forms.TabPage page, System.Windows.Forms.TabControl tab, Rectangle bounds, bool is_selected)
		{
			Rectangle interior;
			int res = bounds.Width;

			dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);

			if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
				// Separators
				if (tab.Appearance == TabAppearance.FlatButtons) {
					int width = bounds.Width;
					bounds.Width += (flatButtonSpacing - 2);
					res = bounds.Width;
					if (tab.Alignment == TabAlignment.Top || tab.Alignment == TabAlignment.Bottom)
						ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
					else
						ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Top);
					bounds.Width = width;
				}

				if (is_selected) {
					ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
				} else if (tab.Appearance != TabAppearance.FlatButtons) {
					ThemeEngine.Current.CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
				}


			} else {
				CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);

				Pen light = ResPool.GetPen (cpcolor.LightLight);

				switch (tab.Alignment) {

					case TabAlignment.Top:

						dc.DrawLine (light, bounds.Left, bounds.Bottom - 1, bounds.Left, bounds.Top + 3);
						dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 2, bounds.Top);
						dc.DrawLine (light, bounds.Left + 2, bounds.Top, bounds.Right - 3, bounds.Top);

						dc.DrawLine (SystemPens.ControlDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 2, bounds.Bottom - 1);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 2);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 1);
						break;

					case TabAlignment.Bottom:

						dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 2);
						dc.DrawLine (light, bounds.Left, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);
						
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
						dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);

						dc.DrawLine (SystemPens.ControlDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Top + 1);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 2);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Top + 1);

						break;

					case TabAlignment.Left:

						dc.DrawLine (light, bounds.Left - 2, bounds.Top, bounds.Right, bounds.Top);
						dc.DrawLine (light, bounds.Left, bounds.Top + 2, bounds.Left - 2, bounds.Top);
						dc.DrawLine (light, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);

						dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom - 1);

						dc.DrawLine (SystemPens.ControlDark, bounds.Left + 2, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Right, bounds.Bottom);

						break;

					default: // TabAlignment.Right

						dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
						dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);

						dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
						dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);

						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
						dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);

						break;
				}
			}

			interior = new Rectangle (bounds.Left + focusRectSpacing.X + borderThickness.Left, 
				bounds.Top + focusRectSpacing.Y +  + borderThickness.Top,
				bounds.Width - (focusRectSpacing.X * 2) - borderThickness.Width + 1, 
				bounds.Height - (focusRectSpacing.Y * 2) - borderThickness.Height);

			if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
				if (tab.Alignment == TabAlignment.Left) {
					dc.TranslateTransform (bounds.Left, bounds.Bottom);
					dc.RotateTransform (-90);
					dc.DrawString (page.Text, page.Font,
						SystemBrushes.ControlText, 
						tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming
						tab.Padding.Y,
						defaultFormatting);
					dc.ResetTransform ();
				} else if (tab.Alignment == TabAlignment.Right) {
					dc.TranslateTransform (bounds.Right, bounds.Top);
					dc.RotateTransform (90);
					dc.DrawString (page.Text, page.Font,
						SystemBrushes.ControlText, 
						tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming
						tab.Padding.Y,
						defaultFormatting);
					dc.ResetTransform ();
				} else {
					Rectangle str_rect = interior;

					if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) {
						int image_y = interior.Y + (interior.Height - tab.ImageList.ImageSize.Height) / 2;
						tab.ImageList.Draw (dc, new Point (interior.X, image_y), page.ImageIndex);
						str_rect.X += tab.ImageList.ImageSize.Width + 2;
						str_rect.Width -= tab.ImageList.ImageSize.Width + 2;
					}
					dc.DrawString (page.Text, page.Font,
						SystemBrushes.ControlText,
						str_rect, 
						defaultFormatting);

				}
			} else if (page.Text != null) {
				DrawItemState state = DrawItemState.None;
				if (page == tab.SelectedTab)
					state |= DrawItemState.Selected;
				DrawItemEventArgs e = new DrawItemEventArgs (dc,
					tab.Font, bounds, tab.IndexForTabPage (page),
					state, page.ForeColor, page.BackColor);
				tab.OnDrawItemInternal (e);
				return res;
			}

			if (page.Parent.Focused && is_selected && tab.ShowFocusCues) {
				interior.Width -= 1;
				ThemeEngine.Current.CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
			}

			return res;
		}