| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:VS2005DockPaneCaption.cs
- * 2.功能描述:类文件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/01 1.00 新建
- *******************************************************************************/
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace Dongke.IBOSS.PRD.Basics.DockPanel
- {
- internal class VS2005DockPaneCaption : DockPaneCaptionBase
- {
- private sealed class InertButton : InertButtonBase
- {
- private Bitmap m_image, m_imageAutoHide;
- public InertButton(VS2005DockPaneCaption dockPaneCaption, Bitmap image, Bitmap imageAutoHide)
- : base()
- {
- m_dockPaneCaption = dockPaneCaption;
- m_image = image;
- m_imageAutoHide = imageAutoHide;
- RefreshChanges();
- }
- private VS2005DockPaneCaption m_dockPaneCaption;
- private VS2005DockPaneCaption DockPaneCaption
- {
- get
- {
- return m_dockPaneCaption;
- }
- }
- public bool IsAutoHide
- {
- get
- {
- return DockPaneCaption.DockPane.IsAutoHide;
- }
- }
- public override Bitmap Image
- {
- get
- {
- return IsAutoHide ? m_imageAutoHide : m_image;
- }
- }
- protected override void OnRefreshChanges()
- {
- if (DockPaneCaption.DockPane.DockPanel != null)
- {
- if (DockPaneCaption.TextColor != ForeColor)
- {
- ForeColor = DockPaneCaption.TextColor;
- Invalidate();
- }
- }
- }
- }
- #region consts
- private const int _TextGapTop = 2;
- private const int _TextGapBottom = 0;
- private const int _TextGapLeft = 3;
- private const int _TextGapRight = 3;
- private const int _ButtonGapTop = 2;
- private const int _ButtonGapBottom = 1;
- private const int _ButtonGapBetween = 1;
- private const int _ButtonGapLeft = 1;
- private const int _ButtonGapRight = 2;
- #endregion
- private static Bitmap _imageButtonClose;
- private static Bitmap ImageButtonClose
- {
- get
- {
- if (_imageButtonClose == null)
- _imageButtonClose = Resources.DockPane_Close;
- return _imageButtonClose;
- }
- }
- private InertButton m_buttonClose;
- private InertButton ButtonClose
- {
- get
- {
- if (m_buttonClose == null)
- {
- m_buttonClose = new InertButton(this, ImageButtonClose, ImageButtonClose);
- m_toolTip.SetToolTip(m_buttonClose, ToolTipClose);
- m_buttonClose.Click += new EventHandler(Close_Click);
- Controls.Add(m_buttonClose);
- }
- return m_buttonClose;
- }
- }
- private static Bitmap _imageButtonAutoHide;
- private static Bitmap ImageButtonAutoHide
- {
- get
- {
- if (_imageButtonAutoHide == null)
- _imageButtonAutoHide = Resources.DockPane_AutoHide;
- return _imageButtonAutoHide;
- }
- }
- private static Bitmap _imageButtonDock;
- private static Bitmap ImageButtonDock
- {
- get
- {
- if (_imageButtonDock == null)
- _imageButtonDock = Resources.DockPane_Dock;
- return _imageButtonDock;
- }
- }
- private InertButton m_buttonAutoHide;
- private InertButton ButtonAutoHide
- {
- get
- {
- if (m_buttonAutoHide == null)
- {
- m_buttonAutoHide = new InertButton(this, ImageButtonDock, ImageButtonAutoHide);
- m_toolTip.SetToolTip(m_buttonAutoHide, ToolTipAutoHide);
- m_buttonAutoHide.Click += new EventHandler(AutoHide_Click);
- Controls.Add(m_buttonAutoHide);
- }
- return m_buttonAutoHide;
- }
- }
- private static Bitmap _imageButtonOptions;
- private static Bitmap ImageButtonOptions
- {
- get
- {
- if (_imageButtonOptions == null)
- _imageButtonOptions = Resources.DockPane_Option;
- return _imageButtonOptions;
- }
- }
- private InertButton m_buttonOptions;
- private InertButton ButtonOptions
- {
- get
- {
- if (m_buttonOptions == null)
- {
- m_buttonOptions = new InertButton(this, ImageButtonOptions, ImageButtonOptions);
- m_toolTip.SetToolTip(m_buttonOptions, ToolTipOptions);
- m_buttonOptions.Click += new EventHandler(Options_Click);
- Controls.Add(m_buttonOptions);
- }
- return m_buttonOptions;
- }
- }
- private IContainer m_components;
- private IContainer Components
- {
- get
- {
- return m_components;
- }
- }
- private ToolTip m_toolTip;
- public VS2005DockPaneCaption(DockPane pane)
- : base(pane)
- {
- SuspendLayout();
- m_components = new Container();
- m_toolTip = new ToolTip(Components);
- ResumeLayout();
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- Components.Dispose();
- base.Dispose(disposing);
- }
- private static int TextGapTop
- {
- get
- {
- return _TextGapTop;
- }
- }
- public Font TextFont
- {
- get
- {
- return DockPane.DockPanel.Skin.DockPaneStripSkin.TextFont;
- }
- }
- private static int TextGapBottom
- {
- get
- {
- return _TextGapBottom;
- }
- }
- private static int TextGapLeft
- {
- get
- {
- return _TextGapLeft;
- }
- }
- private static int TextGapRight
- {
- get
- {
- return _TextGapRight;
- }
- }
- private static int ButtonGapTop
- {
- get
- {
- return _ButtonGapTop;
- }
- }
- private static int ButtonGapBottom
- {
- get
- {
- return _ButtonGapBottom;
- }
- }
- private static int ButtonGapLeft
- {
- get
- {
- return _ButtonGapLeft;
- }
- }
- private static int ButtonGapRight
- {
- get
- {
- return _ButtonGapRight;
- }
- }
- private static int ButtonGapBetween
- {
- get
- {
- return _ButtonGapBetween;
- }
- }
- private static string _toolTipClose;
- private static string ToolTipClose
- {
- get
- {
- if (_toolTipClose == null)
- _toolTipClose = Strings.DockPaneCaption_ToolTipClose;
- return _toolTipClose;
- }
- }
- private static string _toolTipOptions;
- private static string ToolTipOptions
- {
- get
- {
- if (_toolTipOptions == null)
- _toolTipOptions = Strings.DockPaneCaption_ToolTipOptions;
- return _toolTipOptions;
- }
- }
- private static string _toolTipAutoHide;
- private static string ToolTipAutoHide
- {
- get
- {
- if (_toolTipAutoHide == null)
- _toolTipAutoHide = Strings.DockPaneCaption_ToolTipAutoHide;
- return _toolTipAutoHide;
- }
- }
- private static Blend _activeBackColorGradientBlend;
- private static Blend ActiveBackColorGradientBlend
- {
- get
- {
- if (_activeBackColorGradientBlend == null)
- {
- Blend blend = new Blend(2);
- blend.Factors = new float[] { 0.5F, 1.0F };
- blend.Positions = new float[] { 0.0F, 1.0F };
- _activeBackColorGradientBlend = blend;
- }
- return _activeBackColorGradientBlend;
- }
- }
- private Color TextColor
- {
- get
- {
- if (DockPane.IsActivated)
- return DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor;
- else
- return DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor;
- }
- }
- private static TextFormatFlags _textFormat =
- TextFormatFlags.SingleLine |
- TextFormatFlags.EndEllipsis |
- TextFormatFlags.VerticalCenter;
- private TextFormatFlags TextFormat
- {
- get
- {
- if (RightToLeft == RightToLeft.No)
- return _textFormat;
- else
- return _textFormat | TextFormatFlags.RightToLeft | TextFormatFlags.Right;
- }
- }
- protected internal override int MeasureHeight()
- {
- int height = TextFont.Height + TextGapTop + TextGapBottom;
- if (height < ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom)
- height = ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom;
- return height;
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- DrawCaption(e.Graphics);
- }
- private void DrawCaption(Graphics g)
- {
- if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
- return;
- if (DockPane.IsActivated)
- {
- Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.StartColor;
- Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.EndColor;
- LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.LinearGradientMode;
- using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode))
- {
- brush.Blend = ActiveBackColorGradientBlend;
- g.FillRectangle(brush, ClientRectangle);
- }
- }
- else
- {
- Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.StartColor;
- Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.EndColor;
- LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.LinearGradientMode;
- using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode))
- {
- g.FillRectangle(brush, ClientRectangle);
- }
- }
- Rectangle rectCaption = ClientRectangle;
- Rectangle rectCaptionText = rectCaption;
- rectCaptionText.X += TextGapLeft;
- rectCaptionText.Width -= TextGapLeft + TextGapRight;
- rectCaptionText.Width -= ButtonGapLeft + ButtonClose.Width + ButtonGapRight;
- if (ShouldShowAutoHideButton)
- rectCaptionText.Width -= ButtonAutoHide.Width + ButtonGapBetween;
- if (HasTabPageContextMenu)
- rectCaptionText.Width -= ButtonOptions.Width + ButtonGapBetween;
- rectCaptionText.Y += TextGapTop;
- rectCaptionText.Height -= TextGapTop + TextGapBottom;
- Color colorText;
- if (DockPane.IsActivated)
- colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor;
- else
- colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor;
- TextRenderer.DrawText(g, DockPane.CaptionText, TextFont, DrawHelper.RtlTransform(this, rectCaptionText), colorText, TextFormat);
- }
- protected override void OnLayout(LayoutEventArgs levent)
- {
- SetButtonsPosition();
- base.OnLayout(levent);
- }
- protected override void OnRefreshChanges()
- {
- SetButtons();
- Invalidate();
- }
- private bool CloseButtonEnabled
- {
- get
- {
- return (DockPane.ActiveContent != null) ? DockPane.ActiveContent.DockHandler.CloseButton : false;
- }
- }
- /// <summary>
- /// Determines whether the close button is visible on the content
- /// </summary>
- private bool CloseButtonVisible
- {
- get
- {
- return (DockPane.ActiveContent != null) ? DockPane.ActiveContent.DockHandler.CloseButtonVisible : false;
- }
- }
- private bool ShouldShowAutoHideButton
- {
- get
- {
- return !DockPane.IsFloat;
- }
- }
- private void SetButtons()
- {
- ButtonClose.Enabled = CloseButtonEnabled;
- ButtonClose.Visible = CloseButtonVisible;
- ButtonAutoHide.Visible = ShouldShowAutoHideButton;
- ButtonOptions.Visible = HasTabPageContextMenu;
- ButtonClose.RefreshChanges();
- ButtonAutoHide.RefreshChanges();
- ButtonOptions.RefreshChanges();
- SetButtonsPosition();
- }
- private void SetButtonsPosition()
- {
- // set the size and location for close and auto-hide buttons
- Rectangle rectCaption = ClientRectangle;
- int buttonWidth = ButtonClose.Image.Width;
- int buttonHeight = ButtonClose.Image.Height;
- int height = rectCaption.Height - ButtonGapTop - ButtonGapBottom;
- if (buttonHeight < height)
- {
- buttonWidth = buttonWidth * (height / buttonHeight);
- buttonHeight = height;
- }
- Size buttonSize = new Size(buttonWidth, buttonHeight);
- int x = rectCaption.X + rectCaption.Width - 1 - ButtonGapRight - m_buttonClose.Width;
- int y = rectCaption.Y + ButtonGapTop;
- Point point = new Point(x, y);
- ButtonClose.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
- // If the close button is not visible draw the auto hide button overtop.
- // Otherwise it is drawn to the left of the close button.
- if (CloseButtonVisible)
- point.Offset(-(buttonWidth + ButtonGapBetween), 0);
- ButtonAutoHide.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
- if (ShouldShowAutoHideButton)
- point.Offset(-(buttonWidth + ButtonGapBetween), 0);
- ButtonOptions.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
- }
- private void Close_Click(object sender, EventArgs e)
- {
- DockPane.CloseActiveContent();
- }
- private void AutoHide_Click(object sender, EventArgs e)
- {
- DockPane.DockState = DockHelper.ToggleAutoHideState(DockPane.DockState);
- if (DockHelper.IsDockStateAutoHide(DockPane.DockState))
- {
- DockPane.DockPanel.ActiveAutoHideContent = null;
- DockPane.NestedDockingStatus.NestedPanes.SwitchPaneWithFirstChild(DockPane);
- }
- }
- private void Options_Click(object sender, EventArgs e)
- {
- ShowTabPageContextMenu(PointToClient(Control.MousePosition));
- }
- protected override void OnRightToLeftChanged(EventArgs e)
- {
- base.OnRightToLeftChanged(e);
- PerformLayout();
- }
- }
- }
|