Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/10 00:44:01 (14 years ago)
Author:
swagner
Message:

Sorted usings and removed unused usings in entire solution (#1094)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/VS2005DockPaneCaption.cs

    r2645 r4068  
    11using System;
     2using System.ComponentModel;
    23using System.Drawing;
    34using System.Drawing.Drawing2D;
    45using System.Windows.Forms;
    5 using System.ComponentModel;
    6 using System.Windows.Forms.VisualStyles;
    7 
    8 namespace WeifenLuo.WinFormsUI.Docking
    9 {
    10   internal class VS2005DockPaneCaption : DockPaneCaptionBase
    11   {
    12         private sealed class InertButton : InertButtonBase
    13         {
    14             private Bitmap m_image, m_imageAutoHide;
    15 
    16             public InertButton(VS2005DockPaneCaption dockPaneCaption, Bitmap image, Bitmap imageAutoHide)
    17                 : base()
    18             {
    19                 m_dockPaneCaption = dockPaneCaption;
    20                 m_image = image;
    21                 m_imageAutoHide = imageAutoHide;
    22                 RefreshChanges();
    23             }
    24 
    25             private VS2005DockPaneCaption m_dockPaneCaption;
    26             private VS2005DockPaneCaption DockPaneCaption
    27             {
    28                 get { return m_dockPaneCaption; }
    29             }
    30 
    31             public bool IsAutoHide
    32             {
    33                 get { return DockPaneCaption.DockPane.IsAutoHide; }
    34             }
    35 
    36             public override Bitmap Image
    37             {
    38                 get { return IsAutoHide ? m_imageAutoHide : m_image; }
    39             }
    40 
    41             protected override void OnRefreshChanges()
    42             {
    43                 if (DockPaneCaption.DockPane.DockPanel != null)
    44                 {
    45                     if (DockPaneCaption.TextColor != ForeColor)
    46                     {
    47                         ForeColor = DockPaneCaption.TextColor;
    48                         Invalidate();
    49                     }
    50                 }
    51             }
    52         }
    53 
    54     #region consts
    55     private const int _TextGapTop = 2;
    56     private const int _TextGapBottom = 0;
    57     private const int _TextGapLeft = 3;
    58     private const int _TextGapRight = 3;
    59     private const int _ButtonGapTop = 2;
    60     private const int _ButtonGapBottom = 1;
    61     private const int _ButtonGapBetween = 1;
    62     private const int _ButtonGapLeft = 1;
    63     private const int _ButtonGapRight = 2;
    64     #endregion
    65 
    66         private static Bitmap _imageButtonClose;
    67         private static Bitmap ImageButtonClose
    68         {
    69             get
    70             {
    71                 if (_imageButtonClose == null)
    72                     _imageButtonClose = Resources.DockPane_Close;
    73 
    74                 return _imageButtonClose;
    75             }
    76         }
    77 
    78     private InertButton m_buttonClose;
    79         private InertButton ButtonClose
    80         {
    81             get
    82             {
    83                 if (m_buttonClose == null)
    84                 {
    85                     m_buttonClose = new InertButton(this, ImageButtonClose, ImageButtonClose);
    86                     m_toolTip.SetToolTip(m_buttonClose, ToolTipClose);
    87                     m_buttonClose.Click += new EventHandler(Close_Click);
    88                     Controls.Add(m_buttonClose);
    89                 }
    90 
    91                 return m_buttonClose;
    92             }
    93         }
    94 
    95         private static Bitmap _imageButtonAutoHide;
    96         private static Bitmap ImageButtonAutoHide
    97         {
    98             get
    99             {
    100                 if (_imageButtonAutoHide == null)
    101                     _imageButtonAutoHide = Resources.DockPane_AutoHide;
    102 
    103                 return _imageButtonAutoHide;
    104             }
    105         }
    106 
    107         private static Bitmap _imageButtonDock;
    108         private static Bitmap ImageButtonDock
    109         {
    110             get
    111             {
    112                 if (_imageButtonDock == null)
    113                     _imageButtonDock = Resources.DockPane_Dock;
    114 
    115                 return _imageButtonDock;
    116             }
    117         }
    118 
    119         private InertButton m_buttonAutoHide;
    120         private InertButton ButtonAutoHide
    121         {
    122             get
    123             {
    124                 if (m_buttonAutoHide == null)
    125                 {
    126                     m_buttonAutoHide = new InertButton(this, ImageButtonDock, ImageButtonAutoHide);
    127                     m_toolTip.SetToolTip(m_buttonAutoHide, ToolTipAutoHide);
    128                     m_buttonAutoHide.Click += new EventHandler(AutoHide_Click);
    129                     Controls.Add(m_buttonAutoHide);
    130                 }
    131 
    132                 return m_buttonAutoHide;
    133             }
    134         }
    135 
    136         private static Bitmap _imageButtonOptions;
    137         private static Bitmap ImageButtonOptions
    138         {
    139             get
    140             {
    141                 if (_imageButtonOptions == null)
    142                     _imageButtonOptions = Resources.DockPane_Option;
    143 
    144                 return _imageButtonOptions;
    145             }
    146         }
    147 
    148         private InertButton m_buttonOptions;
    149         private InertButton ButtonOptions
    150         {
    151             get
    152             {
    153                 if (m_buttonOptions == null)
    154                 {
    155                     m_buttonOptions = new InertButton(this, ImageButtonOptions, ImageButtonOptions);
    156                     m_toolTip.SetToolTip(m_buttonOptions, ToolTipOptions);
    157                     m_buttonOptions.Click += new EventHandler(Options_Click);
    158                     Controls.Add(m_buttonOptions);
    159                 }
    160                 return m_buttonOptions;
    161             }
    162         }
    163 
    164         private IContainer m_components;
    165         private IContainer Components
    166         {
    167             get { return m_components; }
    168         }
    169 
    170     private ToolTip m_toolTip;
    171 
    172     public VS2005DockPaneCaption(DockPane pane) : base(pane)
    173     {
    174       SuspendLayout();
    175 
    176             m_components = new Container();
    177             m_toolTip = new ToolTip(Components);
    178 
    179       ResumeLayout();
    180     }
    181 
    182         protected override void Dispose(bool disposing)
    183         {
    184             if (disposing)
    185                 Components.Dispose();
    186             base.Dispose(disposing);
    187         }
    188 
    189     private static int TextGapTop
    190     {
    191       get { return _TextGapTop; }
    192     }
    193 
    194         private static Font TextFont
    195         {
    196             get { return SystemInformation.MenuFont; }
    197         }
    198 
    199     private static int TextGapBottom
    200     {
    201       get { return _TextGapBottom;  }
    202     }
    203 
    204     private static int TextGapLeft
    205     {
    206       get { return _TextGapLeft;  }
    207     }
    208 
    209     private static int TextGapRight
    210     {
    211       get { return _TextGapRight; }
    212     }
    213 
    214     private static int ButtonGapTop
    215     {
    216       get { return _ButtonGapTop; }
    217     }
    218 
    219     private static int ButtonGapBottom
    220     {
    221       get { return _ButtonGapBottom;  }
    222     }
    223 
    224     private static int ButtonGapLeft
    225     {
    226       get { return _ButtonGapLeft;  }
    227     }
    228 
    229     private static int ButtonGapRight
    230     {
    231       get { return _ButtonGapRight; }
    232     }
    233 
    234     private static int ButtonGapBetween
    235     {
    236       get { return _ButtonGapBetween; }
    237     }
    238 
    239     private static string _toolTipClose;
    240     private static string ToolTipClose
    241     {
    242       get
    243       {
    244         if (_toolTipClose == null)
    245           _toolTipClose = Strings.DockPaneCaption_ToolTipClose;
    246         return _toolTipClose;
    247       }
    248     }
    249 
    250         private static string _toolTipOptions;
    251         private static string ToolTipOptions
    252         {
    253             get
    254             {
    255                 if (_toolTipOptions == null)
    256                     _toolTipOptions = Strings.DockPaneCaption_ToolTipOptions;
    257 
    258                 return _toolTipOptions;
    259             }
    260         }
    261 
    262     private static string _toolTipAutoHide;
    263     private static string ToolTipAutoHide
    264     {
    265       get
    266       {
    267         if (_toolTipAutoHide == null)
    268           _toolTipAutoHide = Strings.DockPaneCaption_ToolTipAutoHide;
    269         return _toolTipAutoHide;
    270       }
    271     }
    272 
    273         private static Blend _activeBackColorGradientBlend;
    274         private static Blend ActiveBackColorGradientBlend
    275         {
    276             get
    277             {
    278                 if (_activeBackColorGradientBlend == null)
    279                 {
    280                     Blend blend = new Blend(2);
    281 
    282                     blend.Factors = new float[]{0.5F, 1.0F};
    283                     blend.Positions = new float[]{0.0F, 1.0F};
    284                     _activeBackColorGradientBlend = blend;
    285                 }
    286 
    287                 return _activeBackColorGradientBlend;
    288             }
    289         }
    290 
    291         private Color TextColor
    292         {
    293             get
    294             {
    295                 if (DockPane.IsActivated)
    296                     return DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor;
    297                 else
    298                     return DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor;
    299             }
    300         }
    301 
    302     private static TextFormatFlags _textFormat =
     6
     7namespace WeifenLuo.WinFormsUI.Docking {
     8  internal class VS2005DockPaneCaption : DockPaneCaptionBase {
     9    private sealed class InertButton : InertButtonBase {
     10      private Bitmap m_image, m_imageAutoHide;
     11
     12      public InertButton(VS2005DockPaneCaption dockPaneCaption, Bitmap image, Bitmap imageAutoHide)
     13        : base() {
     14        m_dockPaneCaption = dockPaneCaption;
     15        m_image = image;
     16        m_imageAutoHide = imageAutoHide;
     17        RefreshChanges();
     18      }
     19
     20      private VS2005DockPaneCaption m_dockPaneCaption;
     21      private VS2005DockPaneCaption DockPaneCaption {
     22        get { return m_dockPaneCaption; }
     23      }
     24
     25      public bool IsAutoHide {
     26        get { return DockPaneCaption.DockPane.IsAutoHide; }
     27      }
     28
     29      public override Bitmap Image {
     30        get { return IsAutoHide ? m_imageAutoHide : m_image; }
     31      }
     32
     33      protected override void OnRefreshChanges() {
     34        if (DockPaneCaption.DockPane.DockPanel != null) {
     35          if (DockPaneCaption.TextColor != ForeColor) {
     36            ForeColor = DockPaneCaption.TextColor;
     37            Invalidate();
     38          }
     39        }
     40      }
     41    }
     42
     43    #region consts
     44    private const int _TextGapTop = 2;
     45    private const int _TextGapBottom = 0;
     46    private const int _TextGapLeft = 3;
     47    private const int _TextGapRight = 3;
     48    private const int _ButtonGapTop = 2;
     49    private const int _ButtonGapBottom = 1;
     50    private const int _ButtonGapBetween = 1;
     51    private const int _ButtonGapLeft = 1;
     52    private const int _ButtonGapRight = 2;
     53    #endregion
     54
     55    private static Bitmap _imageButtonClose;
     56    private static Bitmap ImageButtonClose {
     57      get {
     58        if (_imageButtonClose == null)
     59          _imageButtonClose = Resources.DockPane_Close;
     60
     61        return _imageButtonClose;
     62      }
     63    }
     64
     65    private InertButton m_buttonClose;
     66    private InertButton ButtonClose {
     67      get {
     68        if (m_buttonClose == null) {
     69          m_buttonClose = new InertButton(this, ImageButtonClose, ImageButtonClose);
     70          m_toolTip.SetToolTip(m_buttonClose, ToolTipClose);
     71          m_buttonClose.Click += new EventHandler(Close_Click);
     72          Controls.Add(m_buttonClose);
     73        }
     74
     75        return m_buttonClose;
     76      }
     77    }
     78
     79    private static Bitmap _imageButtonAutoHide;
     80    private static Bitmap ImageButtonAutoHide {
     81      get {
     82        if (_imageButtonAutoHide == null)
     83          _imageButtonAutoHide = Resources.DockPane_AutoHide;
     84
     85        return _imageButtonAutoHide;
     86      }
     87    }
     88
     89    private static Bitmap _imageButtonDock;
     90    private static Bitmap ImageButtonDock {
     91      get {
     92        if (_imageButtonDock == null)
     93          _imageButtonDock = Resources.DockPane_Dock;
     94
     95        return _imageButtonDock;
     96      }
     97    }
     98
     99    private InertButton m_buttonAutoHide;
     100    private InertButton ButtonAutoHide {
     101      get {
     102        if (m_buttonAutoHide == null) {
     103          m_buttonAutoHide = new InertButton(this, ImageButtonDock, ImageButtonAutoHide);
     104          m_toolTip.SetToolTip(m_buttonAutoHide, ToolTipAutoHide);
     105          m_buttonAutoHide.Click += new EventHandler(AutoHide_Click);
     106          Controls.Add(m_buttonAutoHide);
     107        }
     108
     109        return m_buttonAutoHide;
     110      }
     111    }
     112
     113    private static Bitmap _imageButtonOptions;
     114    private static Bitmap ImageButtonOptions {
     115      get {
     116        if (_imageButtonOptions == null)
     117          _imageButtonOptions = Resources.DockPane_Option;
     118
     119        return _imageButtonOptions;
     120      }
     121    }
     122
     123    private InertButton m_buttonOptions;
     124    private InertButton ButtonOptions {
     125      get {
     126        if (m_buttonOptions == null) {
     127          m_buttonOptions = new InertButton(this, ImageButtonOptions, ImageButtonOptions);
     128          m_toolTip.SetToolTip(m_buttonOptions, ToolTipOptions);
     129          m_buttonOptions.Click += new EventHandler(Options_Click);
     130          Controls.Add(m_buttonOptions);
     131        }
     132        return m_buttonOptions;
     133      }
     134    }
     135
     136    private IContainer m_components;
     137    private IContainer Components {
     138      get { return m_components; }
     139    }
     140
     141    private ToolTip m_toolTip;
     142
     143    public VS2005DockPaneCaption(DockPane pane)
     144      : base(pane) {
     145      SuspendLayout();
     146
     147      m_components = new Container();
     148      m_toolTip = new ToolTip(Components);
     149
     150      ResumeLayout();
     151    }
     152
     153    protected override void Dispose(bool disposing) {
     154      if (disposing)
     155        Components.Dispose();
     156      base.Dispose(disposing);
     157    }
     158
     159    private static int TextGapTop {
     160      get { return _TextGapTop; }
     161    }
     162
     163    private static Font TextFont {
     164      get { return SystemInformation.MenuFont; }
     165    }
     166
     167    private static int TextGapBottom {
     168      get { return _TextGapBottom; }
     169    }
     170
     171    private static int TextGapLeft {
     172      get { return _TextGapLeft; }
     173    }
     174
     175    private static int TextGapRight {
     176      get { return _TextGapRight; }
     177    }
     178
     179    private static int ButtonGapTop {
     180      get { return _ButtonGapTop; }
     181    }
     182
     183    private static int ButtonGapBottom {
     184      get { return _ButtonGapBottom; }
     185    }
     186
     187    private static int ButtonGapLeft {
     188      get { return _ButtonGapLeft; }
     189    }
     190
     191    private static int ButtonGapRight {
     192      get { return _ButtonGapRight; }
     193    }
     194
     195    private static int ButtonGapBetween {
     196      get { return _ButtonGapBetween; }
     197    }
     198
     199    private static string _toolTipClose;
     200    private static string ToolTipClose {
     201      get {
     202        if (_toolTipClose == null)
     203          _toolTipClose = Strings.DockPaneCaption_ToolTipClose;
     204        return _toolTipClose;
     205      }
     206    }
     207
     208    private static string _toolTipOptions;
     209    private static string ToolTipOptions {
     210      get {
     211        if (_toolTipOptions == null)
     212          _toolTipOptions = Strings.DockPaneCaption_ToolTipOptions;
     213
     214        return _toolTipOptions;
     215      }
     216    }
     217
     218    private static string _toolTipAutoHide;
     219    private static string ToolTipAutoHide {
     220      get {
     221        if (_toolTipAutoHide == null)
     222          _toolTipAutoHide = Strings.DockPaneCaption_ToolTipAutoHide;
     223        return _toolTipAutoHide;
     224      }
     225    }
     226
     227    private static Blend _activeBackColorGradientBlend;
     228    private static Blend ActiveBackColorGradientBlend {
     229      get {
     230        if (_activeBackColorGradientBlend == null) {
     231          Blend blend = new Blend(2);
     232
     233          blend.Factors = new float[] { 0.5F, 1.0F };
     234          blend.Positions = new float[] { 0.0F, 1.0F };
     235          _activeBackColorGradientBlend = blend;
     236        }
     237
     238        return _activeBackColorGradientBlend;
     239      }
     240    }
     241
     242    private Color TextColor {
     243      get {
     244        if (DockPane.IsActivated)
     245          return DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor;
     246        else
     247          return DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor;
     248      }
     249    }
     250
     251    private static TextFormatFlags _textFormat =
    303252            TextFormatFlags.SingleLine |
    304253            TextFormatFlags.EndEllipsis |
    305254            TextFormatFlags.VerticalCenter;
    306     private TextFormatFlags TextFormat
    307     {
    308             get
    309             {
    310                 if (RightToLeft == RightToLeft.No)
    311                     return _textFormat;
    312                 else
    313                     return _textFormat | TextFormatFlags.RightToLeft | TextFormatFlags.Right;
    314             }
    315     }
    316 
    317     protected internal override int MeasureHeight()
    318     {
    319       int height = TextFont.Height + TextGapTop + TextGapBottom;
    320 
    321       if (height < ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom)
    322         height = ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom;
    323 
    324       return height;
    325     }
    326 
    327     protected override void OnPaint(PaintEventArgs e)
    328     {
    329       base.OnPaint (e);
    330       DrawCaption(e.Graphics);
    331     }
    332 
    333     private void DrawCaption(Graphics g)
    334     {
    335             if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
    336                 return;
    337 
    338             if (DockPane.IsActivated)
    339             {
    340                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.StartColor;
    341                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.EndColor;
    342                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.LinearGradientMode;
    343                 using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode))
    344                 {
    345                     brush.Blend = ActiveBackColorGradientBlend;
    346                     g.FillRectangle(brush, ClientRectangle);
    347                 }
    348             }
    349             else
    350             {
    351                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.StartColor;
    352                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.EndColor;
    353                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.LinearGradientMode;
    354                 using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode))
    355                 {
    356                     g.FillRectangle(brush, ClientRectangle);
    357                 }
    358             }
    359 
    360       Rectangle rectCaption = ClientRectangle;
    361 
    362       Rectangle rectCaptionText = rectCaption;
    363             rectCaptionText.X += TextGapLeft;
    364             rectCaptionText.Width -= TextGapLeft + TextGapRight;
    365             rectCaptionText.Width -= ButtonGapLeft + ButtonClose.Width + ButtonGapRight;
    366             if (ShouldShowAutoHideButton)
    367                 rectCaptionText.Width -= ButtonAutoHide.Width + ButtonGapBetween;
    368             if (HasTabPageContextMenu)
    369                 rectCaptionText.Width -= ButtonOptions.Width + ButtonGapBetween;
    370       rectCaptionText.Y += TextGapTop;
    371       rectCaptionText.Height -= TextGapTop + TextGapBottom;
    372 
    373             Color colorText;
    374             if (DockPane.IsActivated)
    375                 colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor;
    376             else
    377                 colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor;
    378 
    379             TextRenderer.DrawText(g, DockPane.CaptionText, TextFont, DrawHelper.RtlTransform(this, rectCaptionText), colorText, TextFormat);
    380     }
    381 
    382     protected override void OnLayout(LayoutEventArgs levent)
    383     {
    384       SetButtonsPosition();
    385       base.OnLayout (levent);
    386     }
    387 
    388     protected override void OnRefreshChanges()
    389     {
    390       SetButtons();
    391       Invalidate();
    392     }
    393 
    394     private bool CloseButtonEnabled
    395     {
    396       get { return (DockPane.ActiveContent != null)? DockPane.ActiveContent.DockHandler.CloseButton : false;  }
    397     }
    398 
    399         /// <summary>
    400         /// Determines whether the close button is visible on the content
    401         /// </summary>
    402         private bool CloseButtonVisible
    403         {
    404             get { return (DockPane.ActiveContent != null) ? DockPane.ActiveContent.DockHandler.CloseButtonVisible : false; }
    405         }
    406 
    407     private bool ShouldShowAutoHideButton
    408     {
    409       get { return !DockPane.IsFloat; }
    410     }
    411 
    412     private void SetButtons()
    413     {
    414       ButtonClose.Enabled = CloseButtonEnabled;
    415             ButtonClose.Visible = CloseButtonVisible;
    416       ButtonAutoHide.Visible = ShouldShowAutoHideButton;
    417             ButtonOptions.Visible = HasTabPageContextMenu;
    418             ButtonClose.RefreshChanges();
    419             ButtonAutoHide.RefreshChanges();
    420             ButtonOptions.RefreshChanges();
    421      
    422       SetButtonsPosition();
    423     }
    424 
    425     private void SetButtonsPosition()
    426     {
    427       // set the size and location for close and auto-hide buttons
    428       Rectangle rectCaption = ClientRectangle;
    429       int buttonWidth = ButtonClose.Image.Width;
    430       int buttonHeight = ButtonClose.Image.Height;
    431       int height = rectCaption.Height - ButtonGapTop - ButtonGapBottom;
    432       if (buttonHeight < height)
    433       {
    434         buttonWidth = buttonWidth * (height / buttonHeight);
    435         buttonHeight = height;
    436       }
    437       Size buttonSize = new Size(buttonWidth, buttonHeight);
    438       int x = rectCaption.X + rectCaption.Width - 1 - ButtonGapRight - m_buttonClose.Width;
    439       int y = rectCaption.Y + ButtonGapTop;
    440       Point point = new Point(x, y);
    441             ButtonClose.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
    442 
    443             // If the close button is not visible draw the auto hide button overtop.
    444             // Otherwise it is drawn to the left of the close button.
    445             if (CloseButtonVisible)
    446           point.Offset(-(buttonWidth + ButtonGapBetween), 0);
    447            
    448             ButtonAutoHide.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
    449             if (ShouldShowAutoHideButton)
    450                 point.Offset(-(buttonWidth + ButtonGapBetween), 0);
    451             ButtonOptions.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
    452     }
    453 
    454     private void Close_Click(object sender, EventArgs e)
    455     {
    456       DockPane.CloseActiveContent();
    457     }
    458 
    459     private void AutoHide_Click(object sender, EventArgs e)
    460     {
    461       DockPane.DockState = DockHelper.ToggleAutoHideState(DockPane.DockState);
    462             if (DockHelper.IsDockStateAutoHide(DockPane.DockState))
    463                 DockPane.DockPanel.ActiveAutoHideContent = null;
    464 
    465     }
    466 
    467         private void Options_Click(object sender, EventArgs e)
    468         {
    469             ShowTabPageContextMenu(PointToClient(Control.MousePosition));
    470         }
    471 
    472         protected override void OnRightToLeftChanged(EventArgs e)
    473         {
    474             base.OnRightToLeftChanged(e);
    475             PerformLayout();
    476         }
    477   }
     255    private TextFormatFlags TextFormat {
     256      get {
     257        if (RightToLeft == RightToLeft.No)
     258          return _textFormat;
     259        else
     260          return _textFormat | TextFormatFlags.RightToLeft | TextFormatFlags.Right;
     261      }
     262    }
     263
     264    protected internal override int MeasureHeight() {
     265      int height = TextFont.Height + TextGapTop + TextGapBottom;
     266
     267      if (height < ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom)
     268        height = ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom;
     269
     270      return height;
     271    }
     272
     273    protected override void OnPaint(PaintEventArgs e) {
     274      base.OnPaint(e);
     275      DrawCaption(e.Graphics);
     276    }
     277
     278    private void DrawCaption(Graphics g) {
     279      if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
     280        return;
     281
     282      if (DockPane.IsActivated) {
     283        Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.StartColor;
     284        Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.EndColor;
     285        LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.LinearGradientMode;
     286        using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) {
     287          brush.Blend = ActiveBackColorGradientBlend;
     288          g.FillRectangle(brush, ClientRectangle);
     289        }
     290      } else {
     291        Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.StartColor;
     292        Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.EndColor;
     293        LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.LinearGradientMode;
     294        using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) {
     295          g.FillRectangle(brush, ClientRectangle);
     296        }
     297      }
     298
     299      Rectangle rectCaption = ClientRectangle;
     300
     301      Rectangle rectCaptionText = rectCaption;
     302      rectCaptionText.X += TextGapLeft;
     303      rectCaptionText.Width -= TextGapLeft + TextGapRight;
     304      rectCaptionText.Width -= ButtonGapLeft + ButtonClose.Width + ButtonGapRight;
     305      if (ShouldShowAutoHideButton)
     306        rectCaptionText.Width -= ButtonAutoHide.Width + ButtonGapBetween;
     307      if (HasTabPageContextMenu)
     308        rectCaptionText.Width -= ButtonOptions.Width + ButtonGapBetween;
     309      rectCaptionText.Y += TextGapTop;
     310      rectCaptionText.Height -= TextGapTop + TextGapBottom;
     311
     312      Color colorText;
     313      if (DockPane.IsActivated)
     314        colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor;
     315      else
     316        colorText = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor;
     317
     318      TextRenderer.DrawText(g, DockPane.CaptionText, TextFont, DrawHelper.RtlTransform(this, rectCaptionText), colorText, TextFormat);
     319    }
     320
     321    protected override void OnLayout(LayoutEventArgs levent) {
     322      SetButtonsPosition();
     323      base.OnLayout(levent);
     324    }
     325
     326    protected override void OnRefreshChanges() {
     327      SetButtons();
     328      Invalidate();
     329    }
     330
     331    private bool CloseButtonEnabled {
     332      get { return (DockPane.ActiveContent != null) ? DockPane.ActiveContent.DockHandler.CloseButton : false; }
     333    }
     334
     335    /// <summary>
     336    /// Determines whether the close button is visible on the content
     337    /// </summary>
     338    private bool CloseButtonVisible {
     339      get { return (DockPane.ActiveContent != null) ? DockPane.ActiveContent.DockHandler.CloseButtonVisible : false; }
     340    }
     341
     342    private bool ShouldShowAutoHideButton {
     343      get { return !DockPane.IsFloat; }
     344    }
     345
     346    private void SetButtons() {
     347      ButtonClose.Enabled = CloseButtonEnabled;
     348      ButtonClose.Visible = CloseButtonVisible;
     349      ButtonAutoHide.Visible = ShouldShowAutoHideButton;
     350      ButtonOptions.Visible = HasTabPageContextMenu;
     351      ButtonClose.RefreshChanges();
     352      ButtonAutoHide.RefreshChanges();
     353      ButtonOptions.RefreshChanges();
     354
     355      SetButtonsPosition();
     356    }
     357
     358    private void SetButtonsPosition() {
     359      // set the size and location for close and auto-hide buttons
     360      Rectangle rectCaption = ClientRectangle;
     361      int buttonWidth = ButtonClose.Image.Width;
     362      int buttonHeight = ButtonClose.Image.Height;
     363      int height = rectCaption.Height - ButtonGapTop - ButtonGapBottom;
     364      if (buttonHeight < height) {
     365        buttonWidth = buttonWidth * (height / buttonHeight);
     366        buttonHeight = height;
     367      }
     368      Size buttonSize = new Size(buttonWidth, buttonHeight);
     369      int x = rectCaption.X + rectCaption.Width - 1 - ButtonGapRight - m_buttonClose.Width;
     370      int y = rectCaption.Y + ButtonGapTop;
     371      Point point = new Point(x, y);
     372      ButtonClose.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
     373
     374      // If the close button is not visible draw the auto hide button overtop.
     375      // Otherwise it is drawn to the left of the close button.
     376      if (CloseButtonVisible)
     377        point.Offset(-(buttonWidth + ButtonGapBetween), 0);
     378
     379      ButtonAutoHide.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
     380      if (ShouldShowAutoHideButton)
     381        point.Offset(-(buttonWidth + ButtonGapBetween), 0);
     382      ButtonOptions.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
     383    }
     384
     385    private void Close_Click(object sender, EventArgs e) {
     386      DockPane.CloseActiveContent();
     387    }
     388
     389    private void AutoHide_Click(object sender, EventArgs e) {
     390      DockPane.DockState = DockHelper.ToggleAutoHideState(DockPane.DockState);
     391      if (DockHelper.IsDockStateAutoHide(DockPane.DockState))
     392        DockPane.DockPanel.ActiveAutoHideContent = null;
     393
     394    }
     395
     396    private void Options_Click(object sender, EventArgs e) {
     397      ShowTabPageContextMenu(PointToClient(Control.MousePosition));
     398    }
     399
     400    protected override void OnRightToLeftChanged(EventArgs e) {
     401      base.OnRightToLeftChanged(e);
     402      PerformLayout();
     403    }
     404  }
    478405}
Note: See TracChangeset for help on using the changeset viewer.