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/DockPanel.AutoHideWindow.cs

    r2645 r4068  
    11using System;
     2using System.Drawing;
    23using System.Windows.Forms;
    3 using System.Drawing;
    4 using System.Runtime.InteropServices;
    5 
    6 namespace WeifenLuo.WinFormsUI.Docking
    7 {
    8     partial class DockPanel
    9     {
    10         private class AutoHideWindowControl : Panel, ISplitterDragSource
    11         {
    12             private class SplitterControl : SplitterBase
    13             {
    14                 public SplitterControl(AutoHideWindowControl autoHideWindow)
    15                 {
    16                     m_autoHideWindow = autoHideWindow;
    17                 }
    18 
    19                 private AutoHideWindowControl m_autoHideWindow;
    20                 private AutoHideWindowControl AutoHideWindow
    21                 {
    22                     get { return m_autoHideWindow; }
    23                 }
    24 
    25                 protected override int SplitterSize
    26                 {
    27                     get { return Measures.SplitterSize; }
    28                 }
    29 
    30                 protected override void StartDrag()
    31                 {
    32               AutoHideWindow.DockPanel.BeginDrag(AutoHideWindow, AutoHideWindow.RectangleToScreen(Bounds));
    33                 }
    34             }
    35 
    36             #region consts
    37             private const int ANIMATE_TIME = 100; // in mini-seconds
    38             #endregion
    39 
    40             private Timer m_timerMouseTrack;
    41             private SplitterControl m_splitter;
    42 
    43             public AutoHideWindowControl(DockPanel dockPanel)
    44             {
    45                 m_dockPanel = dockPanel;
    46 
    47                 m_timerMouseTrack = new Timer();
    48                 m_timerMouseTrack.Tick += new EventHandler(TimerMouseTrack_Tick);
    49 
    50                 Visible = false;
    51                 m_splitter = new SplitterControl(this);
    52                 Controls.Add(m_splitter);
    53             }
    54 
    55             protected override void Dispose(bool disposing)
    56             {
    57                 if (disposing)
    58                 {
    59                     m_timerMouseTrack.Dispose();
    60                 }
    61                 base.Dispose(disposing);
    62             }
    63 
    64             private DockPanel m_dockPanel = null;
    65             public DockPanel DockPanel
    66             {
    67                 get { return m_dockPanel; }
    68             }
    69 
    70             private DockPane m_activePane = null;
    71             public DockPane ActivePane
    72             {
    73                 get { return m_activePane; }
    74             }
    75             private void SetActivePane()
    76             {
    77                 DockPane value = (ActiveContent == null ? null : ActiveContent.DockHandler.Pane);
    78 
    79                 if (value == m_activePane)
    80                     return;
    81 
    82                 m_activePane = value;
    83             }
    84 
    85             private IDockContent m_activeContent = null;
    86             public IDockContent ActiveContent
    87             {
    88                 get { return m_activeContent; }
    89                 set
    90                 {
    91                     if (value == m_activeContent)
    92                         return;
    93 
    94                     if (value != null)
    95                     {
    96                         if (!DockHelper.IsDockStateAutoHide(value.DockHandler.DockState) || value.DockHandler.DockPanel != DockPanel)
    97                             throw (new InvalidOperationException(Strings.DockPanel_ActiveAutoHideContent_InvalidValue));
    98                     }
    99 
    100                     DockPanel.SuspendLayout();
    101 
    102                     if (m_activeContent != null)
    103                     {
    104                         if (m_activeContent.DockHandler.Form.ContainsFocus)
    105                             DockPanel.ContentFocusManager.GiveUpFocus(m_activeContent);
    106                         AnimateWindow(false);
    107                     }
    108 
    109                     m_activeContent = value;
    110                     SetActivePane();
    111                     if (ActivePane != null)
    112                         ActivePane.ActiveContent = m_activeContent;
    113 
    114                     if (m_activeContent != null)
    115                         AnimateWindow(true);
    116 
    117                     DockPanel.ResumeLayout();
    118                     DockPanel.RefreshAutoHideStrip();
    119 
    120                     SetTimerMouseTrack();
    121                 }
    122             }
    123 
    124             public DockState DockState
    125             {
    126                 get { return ActiveContent == null ? DockState.Unknown : ActiveContent.DockHandler.DockState; }
    127             }
    128 
    129             private bool m_flagAnimate = true;
    130             private bool FlagAnimate
    131             {
    132                 get { return m_flagAnimate; }
    133                 set { m_flagAnimate = value; }
    134             }
    135 
    136             private bool m_flagDragging = false;
    137             internal bool FlagDragging
    138             {
    139                 get { return m_flagDragging; }
    140                 set
    141                 {
    142                     if (m_flagDragging == value)
    143                         return;
    144 
    145                     m_flagDragging = value;
    146                     SetTimerMouseTrack();
    147                 }
    148             }
    149 
    150             private void AnimateWindow(bool show)
    151             {
    152                 if (!FlagAnimate && Visible != show)
    153                 {
    154                     Visible = show;
    155                     return;
    156                 }
    157 
    158                 Parent.SuspendLayout();
    159 
    160                 Rectangle rectSource = GetRectangle(!show);
    161                 Rectangle rectTarget = GetRectangle(show);
    162                 int dxLoc, dyLoc;
    163                 int dWidth, dHeight;
    164                 dxLoc = dyLoc = dWidth = dHeight = 0;
    165                 if (DockState == DockState.DockTopAutoHide)
    166                     dHeight = show ? 1 : -1;
    167                 else if (DockState == DockState.DockLeftAutoHide)
    168                     dWidth = show ? 1 : -1;
    169                 else if (DockState == DockState.DockRightAutoHide)
    170                 {
    171                     dxLoc = show ? -1 : 1;
    172                     dWidth = show ? 1 : -1;
    173                 }
    174                 else if (DockState == DockState.DockBottomAutoHide)
    175                 {
    176                     dyLoc = (show ? -1 : 1);
    177                     dHeight = (show ? 1 : -1);
    178                 }
    179 
    180                 if (show)
    181                 {
    182                     Bounds = DockPanel.GetAutoHideWindowBounds(new Rectangle(-rectTarget.Width, -rectTarget.Height, rectTarget.Width, rectTarget.Height));
    183                     if (Visible == false)
    184                         Visible = true;
    185                     PerformLayout();
    186                 }
    187 
    188                 SuspendLayout();
    189 
    190                 LayoutAnimateWindow(rectSource);
    191                 if (Visible == false)
    192                     Visible = true;
    193 
    194                 int speedFactor = 1;
    195                 int totalPixels = (rectSource.Width != rectTarget.Width) ?
    196                     Math.Abs(rectSource.Width - rectTarget.Width) :
    197                     Math.Abs(rectSource.Height - rectTarget.Height);
    198                 int remainPixels = totalPixels;
    199                 DateTime startingTime = DateTime.Now;
    200                 while (rectSource != rectTarget)
    201                 {
    202                     DateTime startPerMove = DateTime.Now;
    203 
    204                     rectSource.X += dxLoc * speedFactor;
    205                     rectSource.Y += dyLoc * speedFactor;
    206                     rectSource.Width += dWidth * speedFactor;
    207                     rectSource.Height += dHeight * speedFactor;
    208                     if (Math.Sign(rectTarget.X - rectSource.X) != Math.Sign(dxLoc))
    209                         rectSource.X = rectTarget.X;
    210                     if (Math.Sign(rectTarget.Y - rectSource.Y) != Math.Sign(dyLoc))
    211                         rectSource.Y = rectTarget.Y;
    212                     if (Math.Sign(rectTarget.Width - rectSource.Width) != Math.Sign(dWidth))
    213                         rectSource.Width = rectTarget.Width;
    214                     if (Math.Sign(rectTarget.Height - rectSource.Height) != Math.Sign(dHeight))
    215                         rectSource.Height = rectTarget.Height;
    216 
    217                     LayoutAnimateWindow(rectSource);
    218                     if (Parent != null)
    219                         Parent.Update();
    220 
    221                     remainPixels -= speedFactor;
    222 
    223                     while (true)
    224                     {
    225                         TimeSpan time = new TimeSpan(0, 0, 0, 0, ANIMATE_TIME);
    226                         TimeSpan elapsedPerMove = DateTime.Now - startPerMove;
    227                         TimeSpan elapsedTime = DateTime.Now - startingTime;
    228                         if (((int)((time - elapsedTime).TotalMilliseconds)) <= 0)
    229                         {
    230                             speedFactor = remainPixels;
    231                             break;
    232                         }
    233                         else
    234                             speedFactor = remainPixels * (int)elapsedPerMove.TotalMilliseconds / (int)((time - elapsedTime).TotalMilliseconds);
    235                         if (speedFactor >= 1)
    236                             break;
    237                     }
    238                 }
    239                 ResumeLayout();
    240                 Parent.ResumeLayout();
    241             }
    242 
    243             private void LayoutAnimateWindow(Rectangle rect)
    244             {
    245                 Bounds = DockPanel.GetAutoHideWindowBounds(rect);
    246 
    247                 Rectangle rectClient = ClientRectangle;
    248 
    249                 if (DockState == DockState.DockLeftAutoHide)
    250                     ActivePane.Location = new Point(rectClient.Right - 2 - Measures.SplitterSize - ActivePane.Width, ActivePane.Location.Y);
    251                 else if (DockState == DockState.DockTopAutoHide)
    252                     ActivePane.Location = new Point(ActivePane.Location.X, rectClient.Bottom - 2 - Measures.SplitterSize - ActivePane.Height);
    253             }
    254 
    255             private Rectangle GetRectangle(bool show)
    256             {
    257                 if (DockState == DockState.Unknown)
    258                     return Rectangle.Empty;
    259 
    260                 Rectangle rect = DockPanel.AutoHideWindowRectangle;
    261 
    262                 if (show)
    263                     return rect;
    264 
    265                 if (DockState == DockState.DockLeftAutoHide)
    266                     rect.Width = 0;
    267                 else if (DockState == DockState.DockRightAutoHide)
    268                 {
    269                     rect.X += rect.Width;
    270                     rect.Width = 0;
    271                 }
    272                 else if (DockState == DockState.DockTopAutoHide)
    273                     rect.Height = 0;
    274                 else
    275                 {
    276                     rect.Y += rect.Height;
    277                     rect.Height = 0;
    278                 }
    279 
    280                 return rect;
    281             }
    282 
    283             private void SetTimerMouseTrack()
    284             {
    285                 if (ActivePane == null || ActivePane.IsActivated || FlagDragging)
    286                 {
    287                     m_timerMouseTrack.Enabled = false;
    288                     return;
    289                 }
    290 
    291                 // start the timer
    292                 int hovertime = SystemInformation.MouseHoverTime ;
    293 
    294                 // assign a default value 400 in case of setting Timer.Interval invalid value exception
    295                 if (hovertime <= 0)
    296                     hovertime = 400;
    297 
    298                 m_timerMouseTrack.Interval = 2 * (int)hovertime;
    299                 m_timerMouseTrack.Enabled = true;
    300             }
    301 
    302             protected virtual Rectangle DisplayingRectangle
    303             {
    304                 get
    305                 {
    306                     Rectangle rect = ClientRectangle;
    307 
    308                     // exclude the border and the splitter
    309                     if (DockState == DockState.DockBottomAutoHide)
    310                     {
    311                         rect.Y += 2 + Measures.SplitterSize;
    312                         rect.Height -= 2 + Measures.SplitterSize;
    313                     }
    314                     else if (DockState == DockState.DockRightAutoHide)
    315                     {
    316                         rect.X += 2 + Measures.SplitterSize;
    317                         rect.Width -= 2 + Measures.SplitterSize;
    318                     }
    319                     else if (DockState == DockState.DockTopAutoHide)
    320                         rect.Height -= 2 + Measures.SplitterSize;
    321                     else if (DockState == DockState.DockLeftAutoHide)
    322                         rect.Width -= 2 + Measures.SplitterSize;
    323 
    324                     return rect;
    325                 }
    326             }
    327 
    328             protected override void OnLayout(LayoutEventArgs levent)
    329             {
    330                 DockPadding.All = 0;
    331                 if (DockState == DockState.DockLeftAutoHide)
    332                 {
    333                     DockPadding.Right = 2;
    334                     m_splitter.Dock = DockStyle.Right;
    335                 }
    336                 else if (DockState == DockState.DockRightAutoHide)
    337                 {
    338                     DockPadding.Left = 2;
    339                     m_splitter.Dock = DockStyle.Left;
    340                 }
    341                 else if (DockState == DockState.DockTopAutoHide)
    342                 {
    343                     DockPadding.Bottom = 2;
    344                     m_splitter.Dock = DockStyle.Bottom;
    345                 }
    346                 else if (DockState == DockState.DockBottomAutoHide)
    347                 {
    348                     DockPadding.Top = 2;
    349                     m_splitter.Dock = DockStyle.Top;
    350                 }
    351 
    352                 Rectangle rectDisplaying = DisplayingRectangle;
    353                 Rectangle rectHidden = new Rectangle(-rectDisplaying.Width, rectDisplaying.Y, rectDisplaying.Width, rectDisplaying.Height);
    354                 foreach (Control c in Controls)
    355                 {
    356                     DockPane pane = c as DockPane;
    357                     if (pane == null)
    358                         continue;
    359                    
    360                    
    361                     if (pane == ActivePane)
    362                         pane.Bounds = rectDisplaying;
    363                     else
    364                         pane.Bounds = rectHidden;
    365                 }
    366 
    367                 base.OnLayout(levent);
    368             }
    369 
    370             protected override void OnPaint(PaintEventArgs e)
    371             {
    372                 // Draw the border
    373                 Graphics g = e.Graphics;
    374 
    375                 if (DockState == DockState.DockBottomAutoHide)
    376                     g.DrawLine(SystemPens.ControlLightLight, 0, 1, ClientRectangle.Right, 1);
    377                 else if (DockState == DockState.DockRightAutoHide)
    378                     g.DrawLine(SystemPens.ControlLightLight, 1, 0, 1, ClientRectangle.Bottom);
    379                 else if (DockState == DockState.DockTopAutoHide)
    380                 {
    381                     g.DrawLine(SystemPens.ControlDark, 0, ClientRectangle.Height - 2, ClientRectangle.Right, ClientRectangle.Height - 2);
    382                     g.DrawLine(SystemPens.ControlDarkDark, 0, ClientRectangle.Height - 1, ClientRectangle.Right, ClientRectangle.Height - 1);
    383                 }
    384                 else if (DockState == DockState.DockLeftAutoHide)
    385                 {
    386                     g.DrawLine(SystemPens.ControlDark, ClientRectangle.Width - 2, 0, ClientRectangle.Width - 2, ClientRectangle.Bottom);
    387                     g.DrawLine(SystemPens.ControlDarkDark, ClientRectangle.Width - 1, 0, ClientRectangle.Width - 1, ClientRectangle.Bottom);
    388                 }
    389 
    390                 base.OnPaint(e);
    391             }
    392 
    393             public void RefreshActiveContent()
    394             {
    395                 if (ActiveContent == null)
    396                     return;
    397 
    398                 if (!DockHelper.IsDockStateAutoHide(ActiveContent.DockHandler.DockState))
    399                 {
    400                     FlagAnimate = false;
    401                     ActiveContent = null;
    402                     FlagAnimate = true;
    403                 }
    404             }
    405 
    406             public void RefreshActivePane()
    407             {
    408                 SetTimerMouseTrack();
    409             }
    410 
    411             private void TimerMouseTrack_Tick(object sender, EventArgs e)
    412             {
    413                 if (IsDisposed)
    414                     return;
    415 
    416                 if (ActivePane == null || ActivePane.IsActivated)
    417                 {
    418                     m_timerMouseTrack.Enabled = false;
    419                     return;
    420                 }
    421 
    422                 DockPane pane = ActivePane;
    423                 Point ptMouseInAutoHideWindow = PointToClient(Control.MousePosition);
    424                 Point ptMouseInDockPanel = DockPanel.PointToClient(Control.MousePosition);
    425 
    426                 Rectangle rectTabStrip = DockPanel.GetTabStripRectangle(pane.DockState);
    427 
    428                 if (!ClientRectangle.Contains(ptMouseInAutoHideWindow) && !rectTabStrip.Contains(ptMouseInDockPanel))
    429                 {
    430                     ActiveContent = null;
    431                     m_timerMouseTrack.Enabled = false;
    432                 }
    433             }
    434 
    435             #region ISplitterDragSource Members
    436 
    437             void ISplitterDragSource.BeginDrag(Rectangle rectSplitter)
    438             {
    439                 FlagDragging = true;
    440             }
    441 
    442             void ISplitterDragSource.EndDrag()
    443             {
    444                 FlagDragging = false;
    445             }
    446 
    447             bool ISplitterDragSource.IsVertical
    448             {
    449                 get { return (DockState == DockState.DockLeftAutoHide || DockState == DockState.DockRightAutoHide); }
    450             }
    451 
    452             Rectangle ISplitterDragSource.DragLimitBounds
    453             {
    454                 get
    455                 {
    456                     Rectangle rectLimit = DockPanel.DockArea;
    457 
    458                     if ((this as ISplitterDragSource).IsVertical)
    459                     {
    460                         rectLimit.X += MeasurePane.MinSize;
    461                         rectLimit.Width -= 2 * MeasurePane.MinSize;
    462                     }
    463                     else
    464                     {
    465                         rectLimit.Y += MeasurePane.MinSize;
    466                         rectLimit.Height -= 2 * MeasurePane.MinSize;
    467                     }
    468 
    469                     return DockPanel.RectangleToScreen(rectLimit);
    470                 }
    471             }
    472 
    473             void ISplitterDragSource.MoveSplitter(int offset)
    474             {
    475                 Rectangle rectDockArea = DockPanel.DockArea;
    476                 IDockContent content = ActiveContent;
    477                 if (DockState == DockState.DockLeftAutoHide && rectDockArea.Width > 0)
    478                 {
    479                     if (content.DockHandler.AutoHidePortion < 1)
    480                         content.DockHandler.AutoHidePortion += ((double)offset) / (double)rectDockArea.Width;
    481                     else
    482                         content.DockHandler.AutoHidePortion = Width + offset;
    483                 }
    484                 else if (DockState == DockState.DockRightAutoHide && rectDockArea.Width > 0)
    485                 {
    486                     if (content.DockHandler.AutoHidePortion < 1)
    487                         content.DockHandler.AutoHidePortion -= ((double)offset) / (double)rectDockArea.Width;
    488                     else
    489                         content.DockHandler.AutoHidePortion = Width - offset;
    490                 }
    491                 else if (DockState == DockState.DockBottomAutoHide && rectDockArea.Height > 0)
    492                 {
    493                     if (content.DockHandler.AutoHidePortion < 1)
    494                         content.DockHandler.AutoHidePortion -= ((double)offset) / (double)rectDockArea.Height;
    495                     else
    496                         content.DockHandler.AutoHidePortion = Height - offset;
    497                 }
    498                 else if (DockState == DockState.DockTopAutoHide && rectDockArea.Height > 0)
    499                 {
    500                     if (content.DockHandler.AutoHidePortion < 1)
    501                         content.DockHandler.AutoHidePortion += ((double)offset) / (double)rectDockArea.Height;
    502                     else
    503                         content.DockHandler.AutoHidePortion = Height + offset;
    504                 }
    505             }
    506 
    507             #region IDragSource Members
    508 
    509             Control IDragSource.DragControl
    510             {
    511                 get { return this; }
    512             }
    513 
    514             #endregion
    515 
    516             #endregion
    517         }
    518 
    519         private AutoHideWindowControl AutoHideWindow
    520         {
    521             get { return m_autoHideWindow; }
    522         }
    523 
    524         internal Control AutoHideControl
    525         {
    526             get { return m_autoHideWindow; }
    527         }
    528 
    529         internal void RefreshActiveAutoHideContent()
    530         {
    531             AutoHideWindow.RefreshActiveContent();
    532         }
    533 
    534         internal Rectangle AutoHideWindowRectangle
    535         {
    536             get
    537             {
    538                 DockState state = AutoHideWindow.DockState;
    539                 Rectangle rectDockArea = DockArea;
    540                 if (ActiveAutoHideContent == null)
    541                     return Rectangle.Empty;
    542 
    543                 if (Parent == null)
    544                     return Rectangle.Empty;
    545 
    546                 Rectangle rect = Rectangle.Empty;
    547                 double autoHideSize = ActiveAutoHideContent.DockHandler.AutoHidePortion;
    548                 if (state == DockState.DockLeftAutoHide)
    549                 {
    550                     if (autoHideSize < 1)
    551                         autoHideSize = rectDockArea.Width * autoHideSize;
    552                     if (autoHideSize > rectDockArea.Width - MeasurePane.MinSize)
    553                         autoHideSize = rectDockArea.Width - MeasurePane.MinSize;
    554                     rect.X = rectDockArea.X;
    555                     rect.Y = rectDockArea.Y;
    556                     rect.Width = (int)autoHideSize;
    557                     rect.Height = rectDockArea.Height;
    558                 }
    559                 else if (state == DockState.DockRightAutoHide)
    560                 {
    561                     if (autoHideSize < 1)
    562                         autoHideSize = rectDockArea.Width * autoHideSize;
    563                     if (autoHideSize > rectDockArea.Width - MeasurePane.MinSize)
    564                         autoHideSize = rectDockArea.Width - MeasurePane.MinSize;
    565                     rect.X = rectDockArea.X + rectDockArea.Width - (int)autoHideSize;
    566                     rect.Y = rectDockArea.Y;
    567                     rect.Width = (int)autoHideSize;
    568                     rect.Height = rectDockArea.Height;
    569                 }
    570                 else if (state == DockState.DockTopAutoHide)
    571                 {
    572                     if (autoHideSize < 1)
    573                         autoHideSize = rectDockArea.Height * autoHideSize;
    574                     if (autoHideSize > rectDockArea.Height - MeasurePane.MinSize)
    575                         autoHideSize = rectDockArea.Height - MeasurePane.MinSize;
    576                     rect.X = rectDockArea.X;
    577                     rect.Y = rectDockArea.Y;
    578                     rect.Width = rectDockArea.Width;
    579                     rect.Height = (int)autoHideSize;
    580                 }
    581                 else if (state == DockState.DockBottomAutoHide)
    582                 {
    583                     if (autoHideSize < 1)
    584                         autoHideSize = rectDockArea.Height * autoHideSize;
    585                     if (autoHideSize > rectDockArea.Height - MeasurePane.MinSize)
    586                         autoHideSize = rectDockArea.Height - MeasurePane.MinSize;
    587                     rect.X = rectDockArea.X;
    588                     rect.Y = rectDockArea.Y + rectDockArea.Height - (int)autoHideSize;
    589                     rect.Width = rectDockArea.Width;
    590                     rect.Height = (int)autoHideSize;
    591                 }
    592 
    593                 return rect;
    594             }
    595         }
    596 
    597         internal Rectangle GetAutoHideWindowBounds(Rectangle rectAutoHideWindow)
    598         {
    599             if (DocumentStyle == DocumentStyle.SystemMdi ||
    600                 DocumentStyle == DocumentStyle.DockingMdi)
    601                 return (Parent == null) ? Rectangle.Empty : Parent.RectangleToClient(RectangleToScreen(rectAutoHideWindow));
    602             else
    603                 return rectAutoHideWindow;
    604         }
    605 
    606         internal void RefreshAutoHideStrip()
    607         {
    608             AutoHideStripControl.RefreshChanges();
    609         }
    610 
    611     }
     4
     5namespace WeifenLuo.WinFormsUI.Docking {
     6  partial class DockPanel {
     7    private class AutoHideWindowControl : Panel, ISplitterDragSource {
     8      private class SplitterControl : SplitterBase {
     9        public SplitterControl(AutoHideWindowControl autoHideWindow) {
     10          m_autoHideWindow = autoHideWindow;
     11        }
     12
     13        private AutoHideWindowControl m_autoHideWindow;
     14        private AutoHideWindowControl AutoHideWindow {
     15          get { return m_autoHideWindow; }
     16        }
     17
     18        protected override int SplitterSize {
     19          get { return Measures.SplitterSize; }
     20        }
     21
     22        protected override void StartDrag() {
     23          AutoHideWindow.DockPanel.BeginDrag(AutoHideWindow, AutoHideWindow.RectangleToScreen(Bounds));
     24        }
     25      }
     26
     27      #region consts
     28      private const int ANIMATE_TIME = 100; // in mini-seconds
     29      #endregion
     30
     31      private Timer m_timerMouseTrack;
     32      private SplitterControl m_splitter;
     33
     34      public AutoHideWindowControl(DockPanel dockPanel) {
     35        m_dockPanel = dockPanel;
     36
     37        m_timerMouseTrack = new Timer();
     38        m_timerMouseTrack.Tick += new EventHandler(TimerMouseTrack_Tick);
     39
     40        Visible = false;
     41        m_splitter = new SplitterControl(this);
     42        Controls.Add(m_splitter);
     43      }
     44
     45      protected override void Dispose(bool disposing) {
     46        if (disposing) {
     47          m_timerMouseTrack.Dispose();
     48        }
     49        base.Dispose(disposing);
     50      }
     51
     52      private DockPanel m_dockPanel = null;
     53      public DockPanel DockPanel {
     54        get { return m_dockPanel; }
     55      }
     56
     57      private DockPane m_activePane = null;
     58      public DockPane ActivePane {
     59        get { return m_activePane; }
     60      }
     61      private void SetActivePane() {
     62        DockPane value = (ActiveContent == null ? null : ActiveContent.DockHandler.Pane);
     63
     64        if (value == m_activePane)
     65          return;
     66
     67        m_activePane = value;
     68      }
     69
     70      private IDockContent m_activeContent = null;
     71      public IDockContent ActiveContent {
     72        get { return m_activeContent; }
     73        set {
     74          if (value == m_activeContent)
     75            return;
     76
     77          if (value != null) {
     78            if (!DockHelper.IsDockStateAutoHide(value.DockHandler.DockState) || value.DockHandler.DockPanel != DockPanel)
     79              throw (new InvalidOperationException(Strings.DockPanel_ActiveAutoHideContent_InvalidValue));
     80          }
     81
     82          DockPanel.SuspendLayout();
     83
     84          if (m_activeContent != null) {
     85            if (m_activeContent.DockHandler.Form.ContainsFocus)
     86              DockPanel.ContentFocusManager.GiveUpFocus(m_activeContent);
     87            AnimateWindow(false);
     88          }
     89
     90          m_activeContent = value;
     91          SetActivePane();
     92          if (ActivePane != null)
     93            ActivePane.ActiveContent = m_activeContent;
     94
     95          if (m_activeContent != null)
     96            AnimateWindow(true);
     97
     98          DockPanel.ResumeLayout();
     99          DockPanel.RefreshAutoHideStrip();
     100
     101          SetTimerMouseTrack();
     102        }
     103      }
     104
     105      public DockState DockState {
     106        get { return ActiveContent == null ? DockState.Unknown : ActiveContent.DockHandler.DockState; }
     107      }
     108
     109      private bool m_flagAnimate = true;
     110      private bool FlagAnimate {
     111        get { return m_flagAnimate; }
     112        set { m_flagAnimate = value; }
     113      }
     114
     115      private bool m_flagDragging = false;
     116      internal bool FlagDragging {
     117        get { return m_flagDragging; }
     118        set {
     119          if (m_flagDragging == value)
     120            return;
     121
     122          m_flagDragging = value;
     123          SetTimerMouseTrack();
     124        }
     125      }
     126
     127      private void AnimateWindow(bool show) {
     128        if (!FlagAnimate && Visible != show) {
     129          Visible = show;
     130          return;
     131        }
     132
     133        Parent.SuspendLayout();
     134
     135        Rectangle rectSource = GetRectangle(!show);
     136        Rectangle rectTarget = GetRectangle(show);
     137        int dxLoc, dyLoc;
     138        int dWidth, dHeight;
     139        dxLoc = dyLoc = dWidth = dHeight = 0;
     140        if (DockState == DockState.DockTopAutoHide)
     141          dHeight = show ? 1 : -1;
     142        else if (DockState == DockState.DockLeftAutoHide)
     143          dWidth = show ? 1 : -1;
     144        else if (DockState == DockState.DockRightAutoHide) {
     145          dxLoc = show ? -1 : 1;
     146          dWidth = show ? 1 : -1;
     147        } else if (DockState == DockState.DockBottomAutoHide) {
     148          dyLoc = (show ? -1 : 1);
     149          dHeight = (show ? 1 : -1);
     150        }
     151
     152        if (show) {
     153          Bounds = DockPanel.GetAutoHideWindowBounds(new Rectangle(-rectTarget.Width, -rectTarget.Height, rectTarget.Width, rectTarget.Height));
     154          if (Visible == false)
     155            Visible = true;
     156          PerformLayout();
     157        }
     158
     159        SuspendLayout();
     160
     161        LayoutAnimateWindow(rectSource);
     162        if (Visible == false)
     163          Visible = true;
     164
     165        int speedFactor = 1;
     166        int totalPixels = (rectSource.Width != rectTarget.Width) ?
     167            Math.Abs(rectSource.Width - rectTarget.Width) :
     168            Math.Abs(rectSource.Height - rectTarget.Height);
     169        int remainPixels = totalPixels;
     170        DateTime startingTime = DateTime.Now;
     171        while (rectSource != rectTarget) {
     172          DateTime startPerMove = DateTime.Now;
     173
     174          rectSource.X += dxLoc * speedFactor;
     175          rectSource.Y += dyLoc * speedFactor;
     176          rectSource.Width += dWidth * speedFactor;
     177          rectSource.Height += dHeight * speedFactor;
     178          if (Math.Sign(rectTarget.X - rectSource.X) != Math.Sign(dxLoc))
     179            rectSource.X = rectTarget.X;
     180          if (Math.Sign(rectTarget.Y - rectSource.Y) != Math.Sign(dyLoc))
     181            rectSource.Y = rectTarget.Y;
     182          if (Math.Sign(rectTarget.Width - rectSource.Width) != Math.Sign(dWidth))
     183            rectSource.Width = rectTarget.Width;
     184          if (Math.Sign(rectTarget.Height - rectSource.Height) != Math.Sign(dHeight))
     185            rectSource.Height = rectTarget.Height;
     186
     187          LayoutAnimateWindow(rectSource);
     188          if (Parent != null)
     189            Parent.Update();
     190
     191          remainPixels -= speedFactor;
     192
     193          while (true) {
     194            TimeSpan time = new TimeSpan(0, 0, 0, 0, ANIMATE_TIME);
     195            TimeSpan elapsedPerMove = DateTime.Now - startPerMove;
     196            TimeSpan elapsedTime = DateTime.Now - startingTime;
     197            if (((int)((time - elapsedTime).TotalMilliseconds)) <= 0) {
     198              speedFactor = remainPixels;
     199              break;
     200            } else
     201              speedFactor = remainPixels * (int)elapsedPerMove.TotalMilliseconds / (int)((time - elapsedTime).TotalMilliseconds);
     202            if (speedFactor >= 1)
     203              break;
     204          }
     205        }
     206        ResumeLayout();
     207        Parent.ResumeLayout();
     208      }
     209
     210      private void LayoutAnimateWindow(Rectangle rect) {
     211        Bounds = DockPanel.GetAutoHideWindowBounds(rect);
     212
     213        Rectangle rectClient = ClientRectangle;
     214
     215        if (DockState == DockState.DockLeftAutoHide)
     216          ActivePane.Location = new Point(rectClient.Right - 2 - Measures.SplitterSize - ActivePane.Width, ActivePane.Location.Y);
     217        else if (DockState == DockState.DockTopAutoHide)
     218          ActivePane.Location = new Point(ActivePane.Location.X, rectClient.Bottom - 2 - Measures.SplitterSize - ActivePane.Height);
     219      }
     220
     221      private Rectangle GetRectangle(bool show) {
     222        if (DockState == DockState.Unknown)
     223          return Rectangle.Empty;
     224
     225        Rectangle rect = DockPanel.AutoHideWindowRectangle;
     226
     227        if (show)
     228          return rect;
     229
     230        if (DockState == DockState.DockLeftAutoHide)
     231          rect.Width = 0;
     232        else if (DockState == DockState.DockRightAutoHide) {
     233          rect.X += rect.Width;
     234          rect.Width = 0;
     235        } else if (DockState == DockState.DockTopAutoHide)
     236          rect.Height = 0;
     237        else {
     238          rect.Y += rect.Height;
     239          rect.Height = 0;
     240        }
     241
     242        return rect;
     243      }
     244
     245      private void SetTimerMouseTrack() {
     246        if (ActivePane == null || ActivePane.IsActivated || FlagDragging) {
     247          m_timerMouseTrack.Enabled = false;
     248          return;
     249        }
     250
     251        // start the timer
     252        int hovertime = SystemInformation.MouseHoverTime;
     253
     254        // assign a default value 400 in case of setting Timer.Interval invalid value exception
     255        if (hovertime <= 0)
     256          hovertime = 400;
     257
     258        m_timerMouseTrack.Interval = 2 * (int)hovertime;
     259        m_timerMouseTrack.Enabled = true;
     260      }
     261
     262      protected virtual Rectangle DisplayingRectangle {
     263        get {
     264          Rectangle rect = ClientRectangle;
     265
     266          // exclude the border and the splitter
     267          if (DockState == DockState.DockBottomAutoHide) {
     268            rect.Y += 2 + Measures.SplitterSize;
     269            rect.Height -= 2 + Measures.SplitterSize;
     270          } else if (DockState == DockState.DockRightAutoHide) {
     271            rect.X += 2 + Measures.SplitterSize;
     272            rect.Width -= 2 + Measures.SplitterSize;
     273          } else if (DockState == DockState.DockTopAutoHide)
     274            rect.Height -= 2 + Measures.SplitterSize;
     275          else if (DockState == DockState.DockLeftAutoHide)
     276            rect.Width -= 2 + Measures.SplitterSize;
     277
     278          return rect;
     279        }
     280      }
     281
     282      protected override void OnLayout(LayoutEventArgs levent) {
     283        DockPadding.All = 0;
     284        if (DockState == DockState.DockLeftAutoHide) {
     285          DockPadding.Right = 2;
     286          m_splitter.Dock = DockStyle.Right;
     287        } else if (DockState == DockState.DockRightAutoHide) {
     288          DockPadding.Left = 2;
     289          m_splitter.Dock = DockStyle.Left;
     290        } else if (DockState == DockState.DockTopAutoHide) {
     291          DockPadding.Bottom = 2;
     292          m_splitter.Dock = DockStyle.Bottom;
     293        } else if (DockState == DockState.DockBottomAutoHide) {
     294          DockPadding.Top = 2;
     295          m_splitter.Dock = DockStyle.Top;
     296        }
     297
     298        Rectangle rectDisplaying = DisplayingRectangle;
     299        Rectangle rectHidden = new Rectangle(-rectDisplaying.Width, rectDisplaying.Y, rectDisplaying.Width, rectDisplaying.Height);
     300        foreach (Control c in Controls) {
     301          DockPane pane = c as DockPane;
     302          if (pane == null)
     303            continue;
     304
     305
     306          if (pane == ActivePane)
     307            pane.Bounds = rectDisplaying;
     308          else
     309            pane.Bounds = rectHidden;
     310        }
     311
     312        base.OnLayout(levent);
     313      }
     314
     315      protected override void OnPaint(PaintEventArgs e) {
     316        // Draw the border
     317        Graphics g = e.Graphics;
     318
     319        if (DockState == DockState.DockBottomAutoHide)
     320          g.DrawLine(SystemPens.ControlLightLight, 0, 1, ClientRectangle.Right, 1);
     321        else if (DockState == DockState.DockRightAutoHide)
     322          g.DrawLine(SystemPens.ControlLightLight, 1, 0, 1, ClientRectangle.Bottom);
     323        else if (DockState == DockState.DockTopAutoHide) {
     324          g.DrawLine(SystemPens.ControlDark, 0, ClientRectangle.Height - 2, ClientRectangle.Right, ClientRectangle.Height - 2);
     325          g.DrawLine(SystemPens.ControlDarkDark, 0, ClientRectangle.Height - 1, ClientRectangle.Right, ClientRectangle.Height - 1);
     326        } else if (DockState == DockState.DockLeftAutoHide) {
     327          g.DrawLine(SystemPens.ControlDark, ClientRectangle.Width - 2, 0, ClientRectangle.Width - 2, ClientRectangle.Bottom);
     328          g.DrawLine(SystemPens.ControlDarkDark, ClientRectangle.Width - 1, 0, ClientRectangle.Width - 1, ClientRectangle.Bottom);
     329        }
     330
     331        base.OnPaint(e);
     332      }
     333
     334      public void RefreshActiveContent() {
     335        if (ActiveContent == null)
     336          return;
     337
     338        if (!DockHelper.IsDockStateAutoHide(ActiveContent.DockHandler.DockState)) {
     339          FlagAnimate = false;
     340          ActiveContent = null;
     341          FlagAnimate = true;
     342        }
     343      }
     344
     345      public void RefreshActivePane() {
     346        SetTimerMouseTrack();
     347      }
     348
     349      private void TimerMouseTrack_Tick(object sender, EventArgs e) {
     350        if (IsDisposed)
     351          return;
     352
     353        if (ActivePane == null || ActivePane.IsActivated) {
     354          m_timerMouseTrack.Enabled = false;
     355          return;
     356        }
     357
     358        DockPane pane = ActivePane;
     359        Point ptMouseInAutoHideWindow = PointToClient(Control.MousePosition);
     360        Point ptMouseInDockPanel = DockPanel.PointToClient(Control.MousePosition);
     361
     362        Rectangle rectTabStrip = DockPanel.GetTabStripRectangle(pane.DockState);
     363
     364        if (!ClientRectangle.Contains(ptMouseInAutoHideWindow) && !rectTabStrip.Contains(ptMouseInDockPanel)) {
     365          ActiveContent = null;
     366          m_timerMouseTrack.Enabled = false;
     367        }
     368      }
     369
     370      #region ISplitterDragSource Members
     371
     372      void ISplitterDragSource.BeginDrag(Rectangle rectSplitter) {
     373        FlagDragging = true;
     374      }
     375
     376      void ISplitterDragSource.EndDrag() {
     377        FlagDragging = false;
     378      }
     379
     380      bool ISplitterDragSource.IsVertical {
     381        get { return (DockState == DockState.DockLeftAutoHide || DockState == DockState.DockRightAutoHide); }
     382      }
     383
     384      Rectangle ISplitterDragSource.DragLimitBounds {
     385        get {
     386          Rectangle rectLimit = DockPanel.DockArea;
     387
     388          if ((this as ISplitterDragSource).IsVertical) {
     389            rectLimit.X += MeasurePane.MinSize;
     390            rectLimit.Width -= 2 * MeasurePane.MinSize;
     391          } else {
     392            rectLimit.Y += MeasurePane.MinSize;
     393            rectLimit.Height -= 2 * MeasurePane.MinSize;
     394          }
     395
     396          return DockPanel.RectangleToScreen(rectLimit);
     397        }
     398      }
     399
     400      void ISplitterDragSource.MoveSplitter(int offset) {
     401        Rectangle rectDockArea = DockPanel.DockArea;
     402        IDockContent content = ActiveContent;
     403        if (DockState == DockState.DockLeftAutoHide && rectDockArea.Width > 0) {
     404          if (content.DockHandler.AutoHidePortion < 1)
     405            content.DockHandler.AutoHidePortion += ((double)offset) / (double)rectDockArea.Width;
     406          else
     407            content.DockHandler.AutoHidePortion = Width + offset;
     408        } else if (DockState == DockState.DockRightAutoHide && rectDockArea.Width > 0) {
     409          if (content.DockHandler.AutoHidePortion < 1)
     410            content.DockHandler.AutoHidePortion -= ((double)offset) / (double)rectDockArea.Width;
     411          else
     412            content.DockHandler.AutoHidePortion = Width - offset;
     413        } else if (DockState == DockState.DockBottomAutoHide && rectDockArea.Height > 0) {
     414          if (content.DockHandler.AutoHidePortion < 1)
     415            content.DockHandler.AutoHidePortion -= ((double)offset) / (double)rectDockArea.Height;
     416          else
     417            content.DockHandler.AutoHidePortion = Height - offset;
     418        } else if (DockState == DockState.DockTopAutoHide && rectDockArea.Height > 0) {
     419          if (content.DockHandler.AutoHidePortion < 1)
     420            content.DockHandler.AutoHidePortion += ((double)offset) / (double)rectDockArea.Height;
     421          else
     422            content.DockHandler.AutoHidePortion = Height + offset;
     423        }
     424      }
     425
     426      #region IDragSource Members
     427
     428      Control IDragSource.DragControl {
     429        get { return this; }
     430      }
     431
     432      #endregion
     433
     434      #endregion
     435    }
     436
     437    private AutoHideWindowControl AutoHideWindow {
     438      get { return m_autoHideWindow; }
     439    }
     440
     441    internal Control AutoHideControl {
     442      get { return m_autoHideWindow; }
     443    }
     444
     445    internal void RefreshActiveAutoHideContent() {
     446      AutoHideWindow.RefreshActiveContent();
     447    }
     448
     449    internal Rectangle AutoHideWindowRectangle {
     450      get {
     451        DockState state = AutoHideWindow.DockState;
     452        Rectangle rectDockArea = DockArea;
     453        if (ActiveAutoHideContent == null)
     454          return Rectangle.Empty;
     455
     456        if (Parent == null)
     457          return Rectangle.Empty;
     458
     459        Rectangle rect = Rectangle.Empty;
     460        double autoHideSize = ActiveAutoHideContent.DockHandler.AutoHidePortion;
     461        if (state == DockState.DockLeftAutoHide) {
     462          if (autoHideSize < 1)
     463            autoHideSize = rectDockArea.Width * autoHideSize;
     464          if (autoHideSize > rectDockArea.Width - MeasurePane.MinSize)
     465            autoHideSize = rectDockArea.Width - MeasurePane.MinSize;
     466          rect.X = rectDockArea.X;
     467          rect.Y = rectDockArea.Y;
     468          rect.Width = (int)autoHideSize;
     469          rect.Height = rectDockArea.Height;
     470        } else if (state == DockState.DockRightAutoHide) {
     471          if (autoHideSize < 1)
     472            autoHideSize = rectDockArea.Width * autoHideSize;
     473          if (autoHideSize > rectDockArea.Width - MeasurePane.MinSize)
     474            autoHideSize = rectDockArea.Width - MeasurePane.MinSize;
     475          rect.X = rectDockArea.X + rectDockArea.Width - (int)autoHideSize;
     476          rect.Y = rectDockArea.Y;
     477          rect.Width = (int)autoHideSize;
     478          rect.Height = rectDockArea.Height;
     479        } else if (state == DockState.DockTopAutoHide) {
     480          if (autoHideSize < 1)
     481            autoHideSize = rectDockArea.Height * autoHideSize;
     482          if (autoHideSize > rectDockArea.Height - MeasurePane.MinSize)
     483            autoHideSize = rectDockArea.Height - MeasurePane.MinSize;
     484          rect.X = rectDockArea.X;
     485          rect.Y = rectDockArea.Y;
     486          rect.Width = rectDockArea.Width;
     487          rect.Height = (int)autoHideSize;
     488        } else if (state == DockState.DockBottomAutoHide) {
     489          if (autoHideSize < 1)
     490            autoHideSize = rectDockArea.Height * autoHideSize;
     491          if (autoHideSize > rectDockArea.Height - MeasurePane.MinSize)
     492            autoHideSize = rectDockArea.Height - MeasurePane.MinSize;
     493          rect.X = rectDockArea.X;
     494          rect.Y = rectDockArea.Y + rectDockArea.Height - (int)autoHideSize;
     495          rect.Width = rectDockArea.Width;
     496          rect.Height = (int)autoHideSize;
     497        }
     498
     499        return rect;
     500      }
     501    }
     502
     503    internal Rectangle GetAutoHideWindowBounds(Rectangle rectAutoHideWindow) {
     504      if (DocumentStyle == DocumentStyle.SystemMdi ||
     505          DocumentStyle == DocumentStyle.DockingMdi)
     506        return (Parent == null) ? Rectangle.Empty : Parent.RectangleToClient(RectangleToScreen(rectAutoHideWindow));
     507      else
     508        return rectAutoHideWindow;
     509    }
     510
     511    internal void RefreshAutoHideStrip() {
     512      AutoHideStripControl.RefreshChanges();
     513    }
     514
     515  }
    612516}
Note: See TracChangeset for help on using the changeset viewer.