Event arguments for events that need to provide a unique name but can be cancelled.
Inheritance: UniqueNameEventArgs
Example #1
0
        private void OnDockableNavigatorPageDrop(object sender, PageDropEventArgs e)
        {
            // Use event to indicate the page is moving to a navigator and allow it to be cancelled
            KryptonDockingManager dockingManager = DockingManager;

            if (dockingManager != null)
            {
                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(e.Page.UniqueName, false);
                dockingManager.RaisePageNavigatorRequest(args);

                // Pass back the result of the event
                e.Cancel = args.Cancel;
            }
        }
        /// <summary>
        /// Occurs when a page is dropped on the control.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A PageDropEventArgs containing the event data.</param>
        protected override void RaiseSpacePageDrop(object sender, PageDropEventArgs e)
        {
            // Use event to indicate the page is moving to a workspace and allow it to be cancelled
            KryptonDockingManager dockingManager = DockingManager;

            if (dockingManager != null)
            {
                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(e.Page.UniqueName, false);
                dockingManager.RaisePageWorkspaceRequest(args);

                // Pass back the result of the event
                e.Cancel = args.Cancel;
            }
        }
Example #3
0
        /// <summary>
        /// Generate an implementation of the IDragPageNotify class that will be used to handle the drag/drop operation.
        /// </summary>
        /// <param name="screenPoint">Screen point of the mouse for the drag operation.</param>
        /// <param name="elementOffset">Offset from top left of element causing the drag.</param>
        /// <param name="c">Control that started the drag operation.</param>
        /// <param name="pages">Set of pages requested to be dragged.</param>
        public virtual void DoDragDrop(Point screenPoint, Point elementOffset, Control c, KryptonPageCollection pages)
        {
            // Cannot drag a null reference
            if (pages == null)
                throw new ArgumentNullException("pages");

            // Cannot drag an empty collection
            if (pages.Count == 0)
                throw new ArgumentOutOfRangeException("pages", "collection cannot be empry");

            // Create docking specific drag manager for moving the pages around
            DockingDragManager dragManager = new DockingDragManager(this, c);
            dragManager.FloatingWindowOffset = elementOffset;

            bool atLeastOneFloating = false;
            KryptonPage firstFloatingPage = null;
            foreach (KryptonPage page in pages)
            {
                // You cannot drag a store page
                if (!(page is KryptonStorePage))
                {
                    // Cannot drag a null page reference
                    if (page == null)
                        throw new ArgumentNullException("pages collection contains a null page reference");

                    // Remember the first page that is allowed to be made floating
                    if (!atLeastOneFloating && page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating))
                    {
                        // Use event to indicate the page is becoming floating and allow it to be cancelled
                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, false);
                        OnPageFloatingRequest(args);

                        if (!args.Cancel)
                        {
                            firstFloatingPage = page;
                            atLeastOneFloating = true;
                        }
                    }
                }
            }

            // If we have at least one page that is allowed to be floating
            if (atLeastOneFloating)
            {
                // Can we find an existing floating store page...
                KryptonDockingFloatspace floatspace = FindStorePageElement(DockingLocation.Floating, firstFloatingPage) as KryptonDockingFloatspace;
                if (floatspace != null)
                {
                    KryptonDockingFloatingWindow floatingWindow = floatspace.GetParentType(typeof(KryptonDockingFloatingWindow)) as KryptonDockingFloatingWindow;
                    if (floatingWindow != null)
                    {
                        // If the floating window is not currently visible...
                        if (!floatingWindow.FloatingWindow.Visible)
                        {
                            using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                            {
                                //...then we can use it for dragging. We want the floating window to become visible and show just the set of pages
                                // that are allowed to be floating from the set of pages passed into this function. As the window is not currently
                                // visible it means all the contained pages are hidden and so we can make only the pages we are interested in visible
                                // and it will have the appearance we need.
                                dragManager.FloatingWindow = floatingWindow.FloatingWindow;

                                // Convert the existing page loaction, if any, to store and restore it in this floating window
                                KryptonPage[] firstFloatingPages = new KryptonPage[] { firstFloatingPage };
                                PropogateAction(DockingPropogateAction.StorePages, firstFloatingPages);
                                floatingWindow.PropogateAction(DockingPropogateAction.RestorePages, firstFloatingPages);

                                // Make a list of all pages that should be appended to the floating window
                                List<string> appendUniqueNames = new List<string>();
                                List<KryptonPage> appendPages = new List<KryptonPage>();
                                foreach (KryptonPage page in pages)
                                    if (!(page is KryptonStorePage) && (page != firstFloatingPage) && page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating))
                                    {
                                        appendUniqueNames.Add(page.UniqueName);
                                        appendPages.Add(page);
                                    }

                                // Set the window location before it is shown otherwise we see a brief flash as it appears at the
                                // existing location and then it moves to the correct location based on the screen mouse position
                                dragManager.FloatingWindow.Location = new Point(screenPoint.X - elementOffset.X, screenPoint.Y - elementOffset.Y);

                                // Convert the append pages to store pages and then append to the same cell as the just restore page above
                                PropogateAction(DockingPropogateAction.StorePages, appendUniqueNames.ToArray());
                                KryptonWorkspaceCell cell = floatingWindow.CellForPage(firstFloatingPage.UniqueName);
                                cell.Pages.AddRange(appendPages.ToArray());
                            }
                        }
                    }
                }

                // Do we need to create a new floating window?
                if (dragManager.FloatingWindow == null)
                {
                    // Get access to a floating element that allows a new floating window to be created
                    KryptonDockingFloating floating = FindDockingFloating(firstFloatingPage.UniqueName);
                    if (floating != null)
                    {
                        KryptonDockingFloatingWindow floatingWindow = floating.AddFloatingWindow();
                        if (floatingWindow != null)
                        {
                            using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                            {
                                // This is the window that will be moved during the drag operation
                                dragManager.FloatingWindow = floatingWindow.FloatingWindow;

                                // Make a list of all pages that should be appended to the floating window
                                List<string> appendUniqueNames = new List<string>();
                                List<KryptonPage> appendPages = new List<KryptonPage>();
                                foreach (KryptonPage page in pages)
                                    if (!(page is KryptonStorePage) && page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating))
                                    {
                                        appendUniqueNames.Add(page.UniqueName);
                                        appendPages.Add(page);
                                    }

                                // Set the window location before it is shown otherwise we see a brief flash as it appears at the
                                // existing location and then it moves to the correct location based on the screen mouse position
                                dragManager.FloatingWindow.Location = new Point(screenPoint.X - elementOffset.X, screenPoint.Y - elementOffset.Y);

                                // Append the pages inside the new window, storing the current locations for later use
                                PropogateAction(DockingPropogateAction.StorePages, appendUniqueNames.ToArray());
                                floatingWindow.FloatspaceElement.Append(appendPages.ToArray());
                                floatingWindow.FloatingWindow.Show();
                            }
                        }
                    }
                }
            }

            // Alow workspace controls to compact and update based on changes from above
            Application.DoEvents();

            // Add ourself as a source of drag targets and then begin the dragging process
            dragManager.DragTargetProviders.Add(new DockingDragTargetProvider(this, dragManager.FloatingWindow, pages));
            dragManager.DragStart(screenPoint, new PageDragEndData(this, pages));
        }
Example #4
0
        /// <summary>
        /// Occurs when a page is dropped on the control.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A PageDropEventArgs containing the event data.</param>
        protected override void RaiseSpacePageDrop(object sender, PageDropEventArgs e)
        {
            // Use event to indicate the page is moving to a workspace and allow it to be cancelled
            KryptonDockingManager dockingManager = DockingManager;
            if (dockingManager != null)
            {
                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(e.Page.UniqueName, false);
                dockingManager.RaisePageDockedRequest(args);

                // Pass back the result of the event
                e.Cancel = args.Cancel;
            }
        }
Example #5
0
 /// <summary>
 /// Raises the PageNavigatorRequest event.
 /// </summary>
 /// <param name="e">An CancelUniqueNameEventArgs containing the event args.</param>
 protected virtual void OnPageNavigatorRequest(CancelUniqueNameEventArgs e)
 {
     if (PageNavigatorRequest != null)
         PageNavigatorRequest(this, e);
 }
Example #6
0
 /// <summary>
 /// Raises the PageWorkspaceRequest event.
 /// </summary>
 /// <param name="e">An CancelUniqueNameEventArgs containing the event args.</param>
 protected virtual void OnPageWorkspaceRequest(CancelUniqueNameEventArgs e)
 {
     if (PageWorkspaceRequest != null)
         PageWorkspaceRequest(this, e);
 }
Example #7
0
 internal void RaisePageWorkspaceRequest(CancelUniqueNameEventArgs e)
 {
     OnPageWorkspaceRequest(e);
 }
Example #8
0
 /// <summary>
 /// Raises the PageAutoHiddenRequest event.
 /// </summary>
 /// <param name="e">An CancelUniqueNameEventArgs containing the event args.</param>
 protected virtual void OnPageAutoHiddenRequest(CancelUniqueNameEventArgs e)
 {
     if (PageAutoHiddenRequest != null)
         PageAutoHiddenRequest(this, e);
 }
Example #9
0
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Find our docking edge
            KryptonDockingEdge dockingEdge = null;

            switch (Edge)
            {
            case VisualOrientation.Left:
                dockingEdge = ControlElement["Left"] as KryptonDockingEdge;
                break;

            case VisualOrientation.Right:
                dockingEdge = ControlElement["Right"] as KryptonDockingEdge;
                break;

            case VisualOrientation.Top:
                dockingEdge = ControlElement["Top"] as KryptonDockingEdge;
                break;

            case VisualOrientation.Bottom:
                dockingEdge = ControlElement["Bottom"] as KryptonDockingEdge;
                break;
            }

            if (dockingEdge != null)
            {
                // Find the docked edge
                KryptonDockingEdgeDocked dockedEdge = dockingEdge["Docked"] as KryptonDockingEdgeDocked;
                if (dockingEdge != null)
                {
                    KryptonDockingManager manager = dockedEdge.DockingManager;
                    if (manager != null)
                    {
                        // Create a list of pages that are allowed to be transferred into the dockspace
                        List <KryptonPage> transferPages       = new List <KryptonPage>();
                        List <string>      transferUniqueNames = new List <string>();
                        foreach (KryptonPage page in data.Pages)
                        {
                            if (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))
                            {
                                // Use event to indicate the page is becoming docked and allow it to be cancelled
                                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, false);
                                manager.RaisePageDockedRequest(args);

                                if (!args.Cancel)
                                {
                                    transferPages.Add(page);
                                    transferUniqueNames.Add(page.UniqueName);
                                }
                            }
                        }

                        // Transfer valid pages into the new dockspace
                        if (transferPages.Count > 0)
                        {
                            // Convert the incoming pages into store pages for restoring later
                            manager.PropogateAction(DockingPropogateAction.StorePages, transferUniqueNames.ToArray());

                            // Create a new dockspace at the start of the list so it is closest to the control edge
                            KryptonDockingDockspace dockspace = (_outsideEdge ? dockedEdge.InsertDockspace(0) : dockedEdge.AppendDockspace());

                            // Add pages into the target
                            dockspace.Append(transferPages.ToArray());

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #10
0
        /// <summary>
        /// Make the named page workspace tabbed.
        /// </summary>
        /// <param name="uniqueName">Unique name of page to become workspace tabbed.</param>
        public virtual void MakeWorkspaceRequest(string uniqueName)
        {
            // Cannot process a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // If the named page exists and is not already workspace tabbed
            if (ContainsPage(uniqueName) && (FindPageLocation(uniqueName) != DockingLocation.Workspace))
            {
                // If we can find a workspace element appropriate for the named page
                KryptonDockingWorkspace workspaceElement = FindDockingWorkspace(uniqueName);
                if (workspaceElement != null)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        // Ensure all docking controls have been layed out before the change is processed
                        Application.DoEvents();

                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(uniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowWorkspace));
                        OnPageWorkspaceRequest(args);

                        if (args.Cancel)
                            return;

                        using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                        {
                            // Convert the page to a placeholder so it can be returned to the same location
                            PropogateAction(DockingPropogateAction.StorePages, new string[] { uniqueName });

                            // Find the target cell, if there is one, that contains a store page
                            KryptonWorkspaceCell cell = workspaceElement.CellForPage(uniqueName);

                            if (cell != null)
                            {
                                // Insert the page at the same index as the restore page
                                int pageIndex = cell.Pages.IndexOf(cell.Pages[uniqueName]);
                                workspaceElement.CellInsert(cell, pageIndex, new KryptonPage[] { page });
                                workspaceElement.SelectPage(uniqueName);
                                workspaceElement.DockableWorkspaceControl.Select();
                            }
                            else
                            {
                                // No existing store page so just append to the worksapce
                                workspaceElement.Append(new KryptonPage[] { page });
                                workspaceElement.SelectPage(uniqueName);
                                workspaceElement.DockableWorkspaceControl.Select();
                            }
                        }
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// Perform a switch from floating to docked for the named pages.
        /// </summary>
        /// <param name="uniqueNames">Unique name of floating pages that need switching.</param>
        /// <returns>KryptonDockingDockspace reference if a new dockspace needed to be created; otherwise false.</returns>
        public virtual KryptonDockingDockspace SwitchFloatingToDockedRequest(string[] uniqueNames)
        {
            // Cannot action a null reference
            if (uniqueNames == null)
                throw new ArgumentNullException("uniqueNames");

            // Cannot action an empty array
            if (uniqueNames.Length == 0)
                throw new ArgumentOutOfRangeException("uniqueNames", "array cannot be empry");

            // Cannot action a null or zero length unique name
            foreach (string uniqueName in uniqueNames)
            {
                if (uniqueName == null)
                    throw new ArgumentNullException("uniqueNames array contains a null string reference");

                if (uniqueName.Length == 0)
                    throw new ArgumentException("uniqueNames array contains a zero length string");
            }

            // Use events to determine which pages should be switched
            List<string> switchUniqueNames = new List<string>();
            List<KryptonPage> switchPages = new List<KryptonPage>();
            string selectedPage = null;
            foreach (string uniqueName in uniqueNames)
            {
                // Does the provided unique name exist and is in the required 'floating' state
                if (FindPageLocation(uniqueName) == DockingLocation.Floating)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked));
                        OnPageDockedRequest(args);

                        if (!args.Cancel)
                        {
                            switchUniqueNames.Add(page.UniqueName);
                            switchPages.Add(page);

                            // Navigate to the cell that holds the page
                            KryptonDockingFloatspace floatspace = FindPageElement(page) as KryptonDockingFloatspace;
                            if (floatspace != null)
                            {
                                KryptonWorkspaceCell cell = floatspace.CellForPage(uniqueName);
                                if (cell != null)
                                {
                                    // Remember the page that is active
                                    if (cell.SelectedPage == page)
                                        selectedPage = page.UniqueName;
                                }
                            }
                        }
                    }
                }
            }

            // Still any pages to be switched?
            if (switchUniqueNames.Count > 0)
            {
                using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                {
                    // Convert the pages to placeholders so they can be returned to the same location
                    PropogateAction(DockingPropogateAction.StorePages, switchUniqueNames.ToArray());

                    // Try and restore each page, but make a note of thos that failed to be restore
                    List<string> defaultUniqueNames = new List<string>();
                    List<KryptonPage> defaultPages = new List<KryptonPage>();
                    KryptonPage defaultSelectedPage = null;
                    for(int i=0; i<switchUniqueNames.Count; i++)
                    {
                        // Find any dockspace that contains a restore page for this named page
                        string switchUniqueName = switchUniqueNames[i];
                        KryptonDockingDockspace restoreElement = DockingManager.FindStorePageElement(DockingLocation.Docked, switchUniqueName) as KryptonDockingDockspace;
                        if (restoreElement != null)
                        {
                            // Find the target cell and the index of the restore page
                            KryptonWorkspaceCell cell = restoreElement.CellForPage(switchUniqueName);
                            int pageIndex = cell.Pages.IndexOf(cell.Pages[switchUniqueName]);

                            // Insert the set of pages at the same index as the restore page
                            restoreElement.CellInsert(cell, pageIndex, switchPages[i]);

                            // Make sure the same page is selected as was selected in the floating source
                            if (switchUniqueName == selectedPage)
                            {
                                restoreElement.SelectPage(selectedPage);
                                restoreElement.DockspaceControl.UpdateVisible(true);
                            }
                        }
                        else
                        {
                            defaultUniqueNames.Add(switchUniqueName);
                            defaultPages.Add(switchPages[i]);

                            // Note the default page that should become selected
                            if (switchUniqueName == selectedPage)
                                defaultSelectedPage = switchPages[i];
                        }
                    }

                    // Any pages that need default positioning because they could not be restored?
                    if (defaultPages.Count > 0)
                    {
                        // Cannot switch to docked unless we can find a docked element as the target
                        KryptonDockingEdgeDocked edgeDocked = FindDockingEdgeDocked(defaultSelectedPage != null ? defaultSelectedPage.UniqueName : defaultPages[0].UniqueName);
                        if (edgeDocked != null)
                        {
                            KryptonDockingDockspace dockspace = edgeDocked.AppendDockspace();
                            dockspace.Append(defaultPages.ToArray());

                            // Make sure the same page is selected as was selected in the floating source
                            if (defaultSelectedPage != null)
                            {
                                dockspace.SelectPage(defaultSelectedPage.UniqueName);
                                dockspace.DockspaceControl.UpdateVisible(true);
                            }
                        }
                    }
                }
            }

            return null;
        }
Example #12
0
 internal void RaisePageDockedRequest(CancelUniqueNameEventArgs e)
 {
     OnPageDockedRequest(e);
 }
Example #13
0
        /// <summary>
        /// Perform a switch from docked pages to floating window for the named pages.
        /// </summary>
        /// <param name="uniqueNames">Unique name of pages inside a docked cell that needs switching.</param>
        /// <returns>KryptonDockingFloatingWindow reference on success; otherwise null.</returns>
        public virtual KryptonDockingFloatingWindow SwitchDockedToFloatingWindowRequest(string[] uniqueNames)
        {
            // Cannot action a null reference
            if (uniqueNames == null)
                throw new ArgumentNullException("uniqueNames");

            // Cannot action an empty array
            if (uniqueNames.Length == 0)
                throw new ArgumentOutOfRangeException("uniqueNames", "array cannot be empry");

            // Cannot action a null or zero length unique name
            foreach (string uniqueName in uniqueNames)
            {
                if (uniqueName == null)
                    throw new ArgumentNullException("uniqueNames array contains a null string reference");

                if (uniqueName.Length == 0)
                    throw new ArgumentException("uniqueNames array contains a zero length string");
            }

            // Use events to determine which pages should be switched
            List<string> switchUniqueNames = new List<string>();
            List<KryptonPage> switchPages = new List<KryptonPage>();
            string selectedPage = null;
            foreach (string uniqueName in uniqueNames)
            {
                // Does the provided unique name exist and is in the required 'docked' state
                if (FindPageLocation(uniqueName) == DockingLocation.Docked)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating));
                        OnPageFloatingRequest(args);

                        if (!args.Cancel)
                        {
                            switchUniqueNames.Add(page.UniqueName);
                            switchPages.Add(page);

                            // Navigate to the cell that holds the page
                            KryptonDockingDockspace dockspace = FindPageElement(page) as KryptonDockingDockspace;
                            if (dockspace != null)
                            {
                                KryptonWorkspaceCell cell = dockspace.CellForPage(uniqueName);
                                if (cell != null)
                                {
                                    // Remember the page that is active
                                    if (cell.SelectedPage == page)
                                        selectedPage = page.UniqueName;
                                }
                            }
                        }
                    }
                }
            }

            // Still any pages to be switched?
            if (switchUniqueNames.Count > 0)
            {
                // Find a floating element that is the target for the switching
                KryptonDockingFloating floating = FindDockingFloating(selectedPage != null ? selectedPage : switchUniqueNames[0]);
                if (floating != null)
                {
                    using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                    {
                        // Convert the pages to placeholders so they can be returned to the same location
                        PropogateAction(DockingPropogateAction.StorePages, switchUniqueNames.ToArray());

                        KryptonWorkspaceCell cell = null;
                        foreach (string switchUniqueName in switchUniqueNames)
                        {
                            // Is there a floating window with a restore page for this unique name?
                            KryptonDockingFloatingWindow restoreElement = floating.FloatingWindowForStorePage(switchUniqueName);
                            if (restoreElement != null)
                            {
                                // Find the target cell and the index of the restore page
                                cell = restoreElement.CellForPage(switchUniqueName);
                                int pageIndex = cell.Pages.IndexOf(cell.Pages[switchUniqueName]);

                                // Insert the set of pages at the same index as the restore page
                                restoreElement.FloatspaceElement.CellInsert(cell, pageIndex, switchPages.ToArray());

                                // Make sure the same page is selected as was selected in the docked source
                                if (selectedPage != null)
                                    restoreElement.SelectPage(selectedPage);

                                return restoreElement;
                            }
                        }

                        // No floating window found to restore into, so create a new window
                        KryptonDockingFloatingWindow floatingElement = floating.AddFloatingWindow();
                        floatingElement.FloatspaceElement.Append(switchPages.ToArray());

                        // Make sure the same page is selected as was selected in the docked source
                        if (selectedPage != null)
                            floatingElement.SelectPage(selectedPage);

                        floatingElement.FloatingWindow.Show();
                        return floatingElement;
                    }
                }
            }

            return null;
        }
Example #14
0
        /// <summary>
        /// Perform a switch from docked cell to auto hidden group for the visible pages inside the cell.
        /// </summary>
        /// <param name="uniqueName">Unique name of page inside docked cell that needs switching.</param>
        /// <returns>KryptonDockingAutoHiddenGroup reference on success; otherwise null.</returns>
        public virtual KryptonDockingAutoHiddenGroup SwitchDockedCellToAutoHiddenGroupRequest(string uniqueName)
        {
            // Cannot switch a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // Does the provided unique name exist and is in the required 'docked' state
            if (FindPageLocation(uniqueName) == DockingLocation.Docked)
            {
                // Grab the dockspace element that we expect to contain the target unique name
                KryptonDockingDockspace dockspace = (KryptonDockingDockspace)ExpectPageElement(uniqueName, typeof(KryptonDockingDockspace));
                if (dockspace != null)
                {
                    // Does the dockspace currently have the focus?
                    bool hadFocus = dockspace.DockspaceControl.ContainsFocus;

                    // Find the sibling auto hidden edge so we can add a new auto hidden group to it later on
                    KryptonDockingEdgeAutoHidden edgeAutoHidden = dockspace.EdgeAutoHiddenElement;
                    if (edgeAutoHidden != null)
                    {
                        // Grab the set of visible pages in the same cell as the target unique name
                        KryptonPage[] visiblePages = dockspace.CellVisiblePages(uniqueName);
                        if (visiblePages.Length > 0)
                        {
                            // Use events to determine which pages in the cell should be switched
                            List<string> switchUniqueNames = new List<string>();
                            List<KryptonPage> switchPages = new List<KryptonPage>();
                            foreach (KryptonPage page in visiblePages)
                            {
                                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowAutoHidden));
                                OnPageAutoHiddenRequest(args);

                                if (!args.Cancel)
                                {
                                    switchUniqueNames.Add(page.UniqueName);
                                    switchPages.Add(page);
                                }
                            }

                            // Any pages that actually need to be switched?
                            if (switchPages.Count > 0)
                            {
                                using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                                {
                                    // Convert the pages to placeholders so they can be returned to the same location
                                    string[] uniqueNames = switchUniqueNames.ToArray();
                                    dockspace.PropogateAction(DockingPropogateAction.StorePages, uniqueNames);

                                    // Create a new auto hidden group and add the switch pages into it
                                    KryptonDockingAutoHiddenGroup group = edgeAutoHidden.AppendAutoHiddenGroup();
                                    group.Append(switchPages.ToArray());

                                    // If we had the focus at the start of the process and the dockspace no longer has it...
                                    if (hadFocus && !dockspace.DockspaceControl.ContainsFocus)
                                    {
                                        // ...and focus has not moved to another part of the form...
                                        Form topForm = dockspace.DockspaceControl.FindForm();
                                        if ((topForm != null) && !topForm.ContainsFocus)
                                        {
                                            // ...then shift focus to the auto hidden group placeholder, to ensure the form still has the
                                            // focus and so hovering the mouse over the auto hidden tabs will correctly get them to slide out
                                            KryptonDockingEdgeAutoHidden edge = group.GetParentType(typeof(KryptonDockingEdgeAutoHidden)) as KryptonDockingEdgeAutoHidden;
                                            if (edge != null)
                                                topForm.Focus();
                                        }
                                    }

                                    return group;
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
Example #15
0
        /// <summary>
        /// Perform a switch from auto hidden group to docked cell for the visible pages inside the group.
        /// </summary>
        /// <param name="uniqueName">Unique name of page inside auto hidden group that needs switching.</param>
        /// <returns>KryptonDockingDockspace reference if a new dockspace needed to be created; otherwise false.</returns>
        public virtual KryptonDockingDockspace SwitchAutoHiddenGroupToDockedCellRequest(string uniqueName)
        {
            // Cannot switch a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // Does the provided unique name exist and is in the required 'autohidden' state
            if (FindPageLocation(uniqueName) == DockingLocation.AutoHidden)
            {
                // Grab the auto hidden group docking element that we expect to contain the target unique name
                KryptonDockingAutoHiddenGroup autoHiddenGroup = (KryptonDockingAutoHiddenGroup)ExpectPageElement(uniqueName, typeof(KryptonDockingAutoHiddenGroup));
                if (autoHiddenGroup != null)
                {
                    // Find the sibling docked edge so we can add/restore pages
                    KryptonDockingEdgeDocked edgeDocked = autoHiddenGroup.EdgeDockedElement;
                    if (edgeDocked != null)
                    {
                        // Grab the set of visible pages in the auto hidden group
                        KryptonPage[] visiblePages = autoHiddenGroup.VisiblePages();
                        if (visiblePages.Length > 0)
                        {
                            // Use events to determine which pages in the cell should be switched
                            List<string> switchUniqueNames = new List<string>();
                            List<KryptonPage> switchPages = new List<KryptonPage>();
                            foreach (KryptonPage page in visiblePages)
                            {
                                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked));
                                OnPageDockedRequest(args);

                                if (!args.Cancel)
                                {
                                    switchUniqueNames.Add(page.UniqueName);
                                    switchPages.Add(page);
                                }
                            }

                            // Any pages that actually need to be switched?
                            if (switchPages.Count > 0)
                            {
                                using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                                {
                                    // Remove the pages from the auto hidden group
                                    string[] uniqueNames = switchUniqueNames.ToArray();
                                    PropogateAction(DockingPropogateAction.RemovePages, uniqueNames);

                                    // Attempt to restore each page back to original location on the same edge
                                    List<KryptonPage> defaultPages = new List<KryptonPage>();
                                    KryptonPage defaultSelectedPage = null;
                                    for(int i=0; i<switchPages.Count; i++)
                                    {
                                        // If we find a store page then we can simply restore straight back to that position
                                        bool? canRestore = edgeDocked.PropogateBoolState(DockingPropogateBoolState.ContainsStorePage, uniqueNames[i]);
                                        if (canRestore.HasValue && canRestore.Value)
                                        {
                                            // Restore page back into a dockspace
                                            edgeDocked.PropogateAction(DockingPropogateAction.RestorePages, new KryptonPage[] { switchPages[i] });

                                            // Should this page become the selected and focused page?
                                            if (uniqueName == uniqueNames[i])
                                            {
                                                // If this restored page was the selected page in the auto hidden group, make it selected in the dockspace
                                                KryptonDockingDockspace restoreElement = edgeDocked.FindPageElement(uniqueNames[i]) as KryptonDockingDockspace;
                                                if (restoreElement != null)
                                                {
                                                    restoreElement.SelectPage(uniqueNames[i]);
                                                    restoreElement.DockspaceControl.UpdateVisible(true);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            defaultPages.Add(switchPages[i]);

                                            // Note the default page that should become selected
                                            if (uniqueName == uniqueNames[i])
                                                defaultSelectedPage = switchPages[i];
                                        }
                                    }

                                    // Remove any existing placeholders in all the docked edges
                                    RemoveControlStorePages(edgeDocked, uniqueNames, false, true);

                                    // Do we have some pages that still need adding?
                                    if (defaultPages.Count > 0)
                                    {
                                        // Place them all inside a new dockspace
                                        KryptonDockingDockspace newDockspace = edgeDocked.AppendDockspace();
                                        newDockspace.Append(defaultPages.ToArray());

                                        // Make sure the same page is selected as was selected in the auto hidden group
                                        if (defaultSelectedPage != null)
                                        {
                                            newDockspace.SelectPage(defaultSelectedPage.UniqueName);
                                            newDockspace.DockspaceControl.UpdateVisible(true);
                                        }

                                        return newDockspace;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Find our docking edge
            KryptonDockingEdge dockingEdge = null;
            switch (Edge)
            {
                case VisualOrientation.Left:
                    dockingEdge = ControlElement["Left"] as KryptonDockingEdge;
                    break;
                case VisualOrientation.Right:
                    dockingEdge = ControlElement["Right"] as KryptonDockingEdge;
                    break;
                case VisualOrientation.Top:
                    dockingEdge = ControlElement["Top"] as KryptonDockingEdge;
                    break;
                case VisualOrientation.Bottom:
                    dockingEdge = ControlElement["Bottom"] as KryptonDockingEdge;
                    break;
            }

            if (dockingEdge != null)
            {
                // Find the docked edge
                KryptonDockingEdgeDocked dockedEdge = dockingEdge["Docked"] as KryptonDockingEdgeDocked;
                if (dockingEdge != null)
                {
                    KryptonDockingManager manager = dockedEdge.DockingManager;
                    if (manager != null)
                    {
                        // Create a list of pages that are allowed to be transferred into the dockspace
                        List<KryptonPage> transferPages = new List<KryptonPage>();
                        List<string> transferUniqueNames = new List<string>();
                        foreach (KryptonPage page in data.Pages)
                            if (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))
                            {
                                // Use event to indicate the page is becoming docked and allow it to be cancelled
                                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, false);
                                manager.RaisePageDockedRequest(args);

                                if (!args.Cancel)
                                {
                                    transferPages.Add(page);
                                    transferUniqueNames.Add(page.UniqueName);
                                }
                            }

                        // Transfer valid pages into the new dockspace
                        if (transferPages.Count > 0)
                        {
                            // Convert the incoming pages into store pages for restoring later
                            manager.PropogateAction(DockingPropogateAction.StorePages, transferUniqueNames.ToArray());

                            // Create a new dockspace at the start of the list so it is closest to the control edge
                            KryptonDockingDockspace dockspace = (_outsideEdge ? dockedEdge.InsertDockspace(0) : dockedEdge.AppendDockspace());

                            // Add pages into the target
                            dockspace.Append(transferPages.ToArray());

                            return true;
                        }
                    }
                }
            }

            return false;
        }
Example #17
0
        /// <summary>
        /// Make the named page floating.
        /// </summary>
        /// <param name="uniqueName">Unique name of page to become floating.</param>
        public virtual void MakeFloatingRequest(string uniqueName)
        {
            // Cannot process a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // If the named page exists and is not already floating
            if (ContainsPage(uniqueName) && (FindPageLocation(uniqueName) != DockingLocation.Floating))
            {
                // If we can find a floating element appropriate for the named page
                KryptonDockingFloating floating = FindDockingFloating(uniqueName);
                if (floating != null)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        // Ensure all docking controls have been layed out before the change is processed
                        Application.DoEvents();

                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(uniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating));
                        OnPageFloatingRequest(args);

                        if (args.Cancel)
                            return;

                        using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                        {
                            // Convert the page to a placeholder so it can be returned to the same location
                            PropogateAction(DockingPropogateAction.StorePages, new string[] { uniqueName });

                            // Is there a floating window with a restore page for the named page?
                            KryptonDockingFloatingWindow restoreElement = floating.FloatingWindowForStorePage(uniqueName);
                            if (restoreElement != null)
                            {
                                // Find the target cell and the index of the restore page
                                KryptonWorkspaceCell cell = restoreElement.CellForPage(uniqueName);
                                int pageIndex = cell.Pages.IndexOf(cell.Pages[uniqueName]);

                                // Insert the page at the same index as the restore page
                                restoreElement.FloatspaceElement.CellInsert(cell, pageIndex, new KryptonPage[] { page });
                                restoreElement.SelectPage(uniqueName);
                                restoreElement.FloatingWindow.Select();
                            }
                            else
                            {
                                // No floating window found to restore into, so create a new window
                                KryptonDockingFloatingWindow floatingElement = floating.AddFloatingWindow();
                                floatingElement.FloatspaceElement.Append(new KryptonPage[] { page });
                                floatingElement.SelectPage(uniqueName);
                                floatingElement.FloatingWindow.Show();
                            }
                        }
                    }
                }
            }
        }
Example #18
0
 internal void RaisePageFloatingRequest(CancelUniqueNameEventArgs e)
 {
     OnPageFloatingRequest(e);
 }
Example #19
0
        /// <summary>
        /// Make the named page navigator tabbed.
        /// </summary>
        /// <param name="uniqueName">Unique name of page to become navigator tabbed.</param>
        public virtual void MakeNavigatorRequest(string uniqueName)
        {
            // Cannot process a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // If the named page exists and is not already navigator tabbed
            if (ContainsPage(uniqueName) && (FindPageLocation(uniqueName) != DockingLocation.Navigator))
            {
                // If we can find a navigator element appropriate for the named page
                KryptonDockingNavigator navigatorElement = FindDockingNavigator(uniqueName);
                if (navigatorElement != null)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        // Ensure all docking controls have been layed out before the change is processed
                        Application.DoEvents();

                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(uniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowNavigator));
                        OnPageNavigatorRequest(args);

                        if (args.Cancel)
                            return;

                        using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                        {
                            // Convert the page to a placeholder so it can be returned to the same location
                            PropogateAction(DockingPropogateAction.StorePages, new string[] { uniqueName });

                            // If we can find an existing page in the target navigator with the name we are inserting
                            KryptonDockableNavigator navigatorControl = navigatorElement.DockableNavigatorControl;
                            KryptonPage insertPage = navigatorControl.Pages[uniqueName];
                            if (insertPage != null)
                            {
                                int pageIndex = navigatorControl.Pages.IndexOf(insertPage);

                                if (pageIndex >= 0)
                                {
                                    // Insert the page at the same index as the restore page
                                    navigatorControl.Pages.Insert(pageIndex, page);
                                    navigatorElement.SelectPage(uniqueName);
                                    navigatorControl.Select();
                                }
                                else
                                {
                                    // Append at end of current page collection
                                    navigatorControl.Pages.Add(page);
                                    navigatorElement.SelectPage(uniqueName);
                                    navigatorControl.Select();
                                }
                            }
                        }
                    }
                }
            }
        }
Example #20
0
 internal void RaisePageNavigatorRequest(CancelUniqueNameEventArgs e)
 {
     OnPageNavigatorRequest(e);
 }
Example #21
0
        /// <summary>
        /// Make the named page auto hidden.
        /// </summary>
        /// <param name="uniqueName">Unique name of page to become auto hidden.</param>
        public virtual void MakeAutoHiddenRequest(string uniqueName)
        {
            // Cannot process a null reference
            if (uniqueName == null)
                throw new ArgumentNullException("uniqueName");

            // Unique names cannot be zero length
            if (uniqueName.Length == 0)
                throw new ArgumentException("uniqueName cannot be zero length");

            // If the named page exists and is not already auto hidden
            if (ContainsPage(uniqueName) && (FindPageLocation(uniqueName) != DockingLocation.AutoHidden))
            {
                // If we can find an auto hidden edge element appropriate for the named page
                KryptonDockingEdgeAutoHidden autoHidden = FindDockingEdgeAutoHidden(uniqueName);
                if (autoHidden != null)
                {
                    KryptonPage page = PageForUniqueName(uniqueName);
                    if (page != null)
                    {
                        // Ensure all docking controls have been layed out before the change is processed
                        Application.DoEvents();

                        CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(uniqueName, !page.AreFlagsSet(KryptonPageFlags.DockingAllowAutoHidden));
                        OnPageAutoHiddenRequest(args);

                        if (args.Cancel)
                            return;

                        using (DockingMultiUpdate update = new DockingMultiUpdate(this))
                        {
                            // Convert the page to a placeholder so it can be returned to the same location
                            PropogateAction(DockingPropogateAction.StorePages, new string[] { uniqueName });

                            // Is there a auto hidden group with a restore page for the named page?
                            KryptonDockingAutoHiddenGroup restoreElement = autoHidden.FindStorePageElement(DockingLocation.AutoHidden, uniqueName) as KryptonDockingAutoHiddenGroup;
                            if (restoreElement != null)
                            {
                                // Find the target index of the restore page
                                KryptonAutoHiddenGroup control = restoreElement.AutoHiddenGroupControl;
                                int pageIndex = control.Pages.IndexOf(control.Pages[uniqueName]);

                                // Insert the page at the same index as the restore page
                                control.Pages.Insert(pageIndex, new KryptonAutoHiddenProxyPage(page));
                            }
                            else
                            {
                                // No existing store page so add as a new group
                                restoreElement = autoHidden.AppendAutoHiddenGroup();
                                restoreElement.Append(new KryptonPage[] { page });
                            }
                        }
                    }
                }
            }
        }