private void OnAutoHiddenShowingStateChanged(AutoHiddenShowingStateEventArgs e)
 {
     if (AutoHiddenShowingStateChanged != null)
     {
         AutoHiddenShowingStateChanged(this, e);
     }
 }
        private void OnSlidePanelAutoHiddenShowingStateChanged(object sender, AutoHiddenShowingStateEventArgs e)
        {
            // Generate event so that the appropriate context menu options are preseted and actioned
            KryptonDockingManager dockingManager = DockingManager;

            if (dockingManager != null)
            {
                dockingManager.RaiseAutoHiddenShowingStateChanged(e);
            }
        }
        private void MakeSlideIn()
        {
            // Check to see if we allowed to perform operations
            if (!Disposing && !IsDisposed)
            {
                // Switch to sliding inwards by changing state and starting slide timer
                _state = DockingAutoHiddenShowState.SlidingIn;
                AutoHiddenShowingStateEventArgs args = new AutoHiddenShowingStateEventArgs(_page, _state);
                _slideTimer.Start();

                // If the dockspace has the focus we need to push focus elsewhere
                if (DockspaceControl.ContainsFocus)
                {
                    DockspaceControl.CellLosesFocus -= new EventHandler <WorkspaceCellEventArgs>(OnDockspaceCellLosesFocus);
                    _dummyTarget.Select();
                }

                // Raises event to indicate change in auto hidden showing state
                OnAutoHiddenShowingStateChanged(args);
            }
        }
        private void MakeHidden()
        {
            // Check to see if we allowed to perform operations
            if (!Disposing && !IsDisposed)
            {
                if (_state != DockingAutoHiddenShowState.Hidden)
                {
                    // Set state so timer processing does not perform any slide action
                    _state = DockingAutoHiddenShowState.Hidden;
                    AutoHiddenShowingStateEventArgs args = new AutoHiddenShowingStateEventArgs(_page, _state);

                    // Remove cached references
                    _page  = null;
                    _group = null;

                    // No need for timers to be running or for our display
                    _slideTimer.Stop();
                    _dismissTimer.Stop();
                    _dismissRunning = false;
                    Visible         = false;

                    // Move to correct z-order position
                    ResetChildIndex();

                    // If the dockspace has the focus we need to push focus elsewhere
                    if (DockspaceControl.ContainsFocus)
                    {
                        DockspaceControl.CellLosesFocus -= new EventHandler <WorkspaceCellEventArgs>(OnDockspaceCellLosesFocus);
                        _dummyTarget.Select();
                    }

                    // Remove all the pages so that the pages have palette redirection reset
                    DockspaceControl.ClearAllPages();

                    // Raises event to indicate change in auto hidden showing state
                    OnAutoHiddenShowingStateChanged(args);
                }
            }
        }
        private void OnSlideTimerTick(object sender, EventArgs e)
        {
            // Check to see if we allowed to perform operations
            if (Disposing || IsDisposed)
            {
                // Make sure the timer is disposed of correctly
                if (_slideTimer != null)
                {
                    _slideTimer.Stop();
                    _slideTimer.Dispose();
                    _slideTimer = null;
                }

                return;
            }

            // Action to take depends on current state
            switch (_state)
            {
            case DockingAutoHiddenShowState.Hidden:
            case DockingAutoHiddenShowState.Showing:
                // No need for timer as sliding has finished
                _slideTimer.Stop();
                break;

            case DockingAutoHiddenShowState.SlidingOut:
            {
                bool  finished         = true;
                Size  newSlideSize     = Size;
                Point newSlideLocation = Location;
                Point newInnerLocation = _inner.Location;

                // Find the new size and location when sliding out from the edge
                switch (_edge)
                {
                case DockingEdge.Left:
                    newSlideSize.Width = Math.Min(newSlideSize.Width + SLIDE_DISTANCE, _endRect.Width);
                    newInnerLocation.X = newSlideSize.Width - _inner.Width;
                    finished           = (newSlideSize.Width == _endRect.Width);
                    break;

                case DockingEdge.Right:
                    newSlideSize.Width = Math.Min(newSlideSize.Width + SLIDE_DISTANCE, _endRect.Width);
                    newSlideLocation.X = Math.Max(newSlideLocation.X - SLIDE_DISTANCE, _endRect.X);
                    finished           = (newSlideSize.Width == _endRect.Width);
                    break;

                case DockingEdge.Top:
                    newSlideSize.Height = Math.Min(newSlideSize.Height + SLIDE_DISTANCE, _endRect.Height);
                    newInnerLocation.Y  = newSlideSize.Height - _inner.Height;
                    finished            = (newSlideSize.Height == _endRect.Height);
                    break;

                case DockingEdge.Bottom:
                    newSlideSize.Height = Math.Min(newSlideSize.Height + SLIDE_DISTANCE, _endRect.Height);
                    newSlideLocation.Y  = Math.Max(newSlideLocation.Y - SLIDE_DISTANCE, _endRect.Y);
                    finished            = (newSlideSize.Height == _endRect.Height);
                    break;
                }

                // Update position to reflect the change
                _inner.SetBounds(newInnerLocation.X, newInnerLocation.Y, _endRect.Width, _endRect.Height);
                SetBounds(newSlideLocation.X, newSlideLocation.Y, newSlideSize.Width, newSlideSize.Height);

                if (finished)
                {
                    // When finished we no longer need the timer and enter the showing state
                    _state = DockingAutoHiddenShowState.Showing;
                    AutoHiddenShowingStateEventArgs args = new AutoHiddenShowingStateEventArgs(_page, _state);
                    OnAutoHiddenShowingStateChanged(args);
                    _slideTimer.Stop();
                }
            }
            break;

            case DockingAutoHiddenShowState.SlidingIn:
            {
                bool  finished         = true;
                Size  newSlideSize     = Size;
                Point newSlideLocation = Location;
                Point newInnerLocation = _inner.Location;

                // Find the new size and location when sliding inwards to the edge
                switch (_edge)
                {
                case DockingEdge.Left:
                    newSlideSize.Width = Math.Max(newSlideSize.Width - SLIDE_DISTANCE, 0);
                    newInnerLocation.X = newSlideSize.Width - _inner.Width;
                    finished           = (newSlideSize.Width == _startRect.Width);
                    break;

                case DockingEdge.Right:
                    newSlideSize.Width = Math.Max(newSlideSize.Width - SLIDE_DISTANCE, 0);
                    newSlideLocation.X = Math.Min(newSlideLocation.X + SLIDE_DISTANCE, _startRect.X);
                    finished           = (newSlideSize.Width == _startRect.Width);
                    break;

                case DockingEdge.Top:
                    newSlideSize.Height = Math.Max(newSlideSize.Height - SLIDE_DISTANCE, 0);
                    newInnerLocation.Y  = newSlideSize.Height - _inner.Height;
                    finished            = (newSlideSize.Height == _startRect.Height);
                    break;

                case DockingEdge.Bottom:
                    newSlideSize.Height = Math.Max(newSlideSize.Height - SLIDE_DISTANCE, 0);
                    newSlideLocation.Y  = Math.Min(newSlideLocation.Y + SLIDE_DISTANCE, _startRect.Y);
                    finished            = (newSlideSize.Height == _startRect.Height);
                    break;
                }

                // Update position to reflect the change
                _inner.SetBounds(newInnerLocation.X, newInnerLocation.Y, _endRect.Width, _endRect.Height);
                SetBounds(newSlideLocation.X, newSlideLocation.Y, newSlideSize.Width, newSlideSize.Height);

                if (finished)
                {
                    MakeHidden();
                }
            }
            break;
            }
        }
        /// <summary>
        /// Requests the panel slide into view and display the provided page.
        /// </summary>
        /// <param name="page">Reference to page for display.</param>
        /// <param name="group">Reference to auto hidden group that displays the page.</param>
        /// <param name="select">Should the sliding out page become selected.</param>
        public void SlideOut(KryptonPage page, KryptonAutoHiddenGroup group, bool select)
        {
            // Check to see if we allowed to perform operations
            if (Disposing || IsDisposed)
            {
                return;
            }

            // Move to the hidden state
            switch (_state)
            {
            case DockingAutoHiddenShowState.Hidden:
                // Nothing to do, already in state we require
                break;

            case DockingAutoHiddenShowState.SlidingIn:
                // If already showing indicated page (although currently sliding inwards)
                if (page == _page)
                {
                    // Switch to sliding out again
                    _state = DockingAutoHiddenShowState.SlidingOut;

                    // Are we requested to set focus to the sliding in dockspace?
                    if (select)
                    {
                        DockspaceControl.Select();
                        DockspaceControl.CellLosesFocus += new EventHandler <WorkspaceCellEventArgs>(OnDockspaceCellLosesFocus);
                    }
                    return;
                }
                else
                {
                    // Different page, so move straight to hidden state
                    MakeHidden();
                }
                break;

            case DockingAutoHiddenShowState.SlidingOut:
            case DockingAutoHiddenShowState.Showing:
                // If already showing indicated page (or in the process of showing) then do nothing
                if (page == _page)
                {
                    // Are we requested to set focus to the sliding in dockspace?
                    if (select)
                    {
                        DockspaceControl.Select();
                        DockspaceControl.CellLosesFocus += new EventHandler <WorkspaceCellEventArgs>(OnDockspaceCellLosesFocus);
                    }
                    return;
                }
                else
                {
                    // Different page, so move straight to hidden state
                    MakeHidden();
                }
                break;
            }

            // Cache information about the page being displayed
            _page  = page;
            _group = group;

            // Make sure we have a visible cell to update
            KryptonWorkspaceCell cell = DockspaceControl.FirstVisibleCell();

            if (cell == null)
            {
                cell = new KryptonWorkspaceCell();
                DockspaceControl.Root.Children.Add(cell);
            }

            // Replace any existing page with the new one
            DockspaceControl.ClearAllPages();
            cell.Pages.Add(page);
            DockspaceControl.PerformLayout();

            // Find the starting and ending rectangles for the slide operation
            CalculateStartAndEnd();

            // Set initial positions of ourself and the contained inner panel
            _inner.SetBounds(0, 0, _endRect.Width, _endRect.Height);
            SetBounds(_startRect.X, _startRect.Y, _startRect.Width, _startRect.Height);

            // Make sure we are at the top of the z-order and visible
            _control.Controls.SetChildIndex(this, 0);
            Visible = true;

            // Switch to new state and start animation timer
            _state = DockingAutoHiddenShowState.SlidingOut;
            AutoHiddenShowingStateEventArgs args = new AutoHiddenShowingStateEventArgs(_page, _state);

            _slideTimer.Start();

            // Are we requested to set focus to the sliding in dockspace?
            if (select)
            {
                DockspaceControl.Select();
                DockspaceControl.CellLosesFocus += new EventHandler <WorkspaceCellEventArgs>(OnDockspaceCellLosesFocus);
            }

            // Raises event to indicate change in auto hidden showing state
            OnAutoHiddenShowingStateChanged(args);
        }