コード例 #1
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)
        {
            // Transfer the dragged pages into our navigator instance
            KryptonPage page = ProcessDragEndData(_navigator, data);

            // Make the last page transfer the newly selected page of the navigator
            if (page != null)
            {
                // If the navigator is allowed to have a selected page then select it
                if (_navigator.AllowTabSelect)
                {
                    _navigator.SelectedPage = page;
                }

                // Need to layout so the new cell has been added as a child control and
                // therefore can receive the focus we want to give it immediately afterwards
                _navigator.PerformLayout();

                if (!_navigator.IsDisposed)
                {
                    // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                    // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                    // change activation is causing the source workspace control to dispose to earlier.
                    Application.DoEvents();
                    _navigator.Select();
                }
            }

            return(true);
        }
        /// <summary>
        /// Is this target a match for the provided screen position.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if a match; otherwise false.</returns>
        public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
        {
            // First time around...
            if (_notDraggedPagesFromCell == -1)
            {
                // Search for any pages that are not from this cell
                _notDraggedPagesFromCell = 0;
                foreach (KryptonPage page in dragEndData.Pages)
                {
                    if (!_cell.Pages.Contains(page))
                    {
                        _notDraggedPagesFromCell = 1;
                        break;
                    }
                }
            }

            // If 1 or more pages are not from this cell then allow transfer into the target
            if (_notDraggedPagesFromCell > 0)
            {
                return(base.IsMatch(screenPt, dragEndData));
            }
            else
            {
                return(false);
            }
        }
        /// <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)
        {
            // Transfer the dragged pages into the existing cell
            KryptonPage page = ProcessDragEndData(Workspace, _cell, data);

            // Make the last page transfer the newly selected page of the cell
            if (page != null)
            {
                // Does the cell allow the selection of tabs?
                if (_cell.AllowTabSelect)
                {
                    _cell.SelectedPage = page;
                }

                if (!_cell.IsDisposed)
                {
                    // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                    // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                    // change activation is causing the source workspace control to dispose to earlier.
                    Application.DoEvents();
                    _cell.Select();
                }
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Process the drag pages in the context of a target navigator.
        /// </summary>
        /// <param name="workspace">Target workspace instance.</param>
        /// <param name="target">Target workspace cell instance.</param>
        /// <param name="data">Dragged page data.</param>
        /// <returns>Last page to be transferred.</returns>
        protected KryptonPage ProcessDragEndData(KryptonWorkspace workspace,
                                                 KryptonWorkspaceCell target,
                                                 PageDragEndData data)
        {
            KryptonPage ret = null;

            // Add each source page to the target
            foreach (KryptonPage page in data.Pages)
            {
                // Only add the page if one of the allow flags is set
                if ((page.Flags & (int)AllowFlags) != 0)
                {
                    // Use event to allow decision on if the page should be dropped
                    // (or even swap the page for a different page to be dropped)
                    PageDropEventArgs e = new PageDropEventArgs(page);
                    workspace.OnPageDrop(e);

                    if (!e.Cancel && (e.Page != null))
                    {
                        target.Pages.Add(e.Page);
                        ret = e.Page;
                    }
                }
            }

            return(ret);
        }
コード例 #5
0
ファイル: PageDragTreeView.cs プロジェクト: zqh2945/Krypton
            /// <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>True if the drop was performed and the source can remove any pages.</returns>
            public override bool PerformDrop(Point screenPt, PageDragEndData data)
            {
                // Create a node for each page
                foreach (KryptonPage page in data.Pages)
                {
                    // Create node and populate with page details
                    TreeNode node = new TreeNode();
                    node.Text               = page.Text;
                    node.ImageIndex         = int.Parse((string)page.Tag);
                    node.SelectedImageIndex = node.ImageIndex;
                    node.Tag = page.Tag;

                    // Add to end of root nodes
                    _treeView.Nodes.Add(node);
                }

                // Take focus and select the last node added
                if (_treeView.Nodes.Count > 0)
                {
                    _treeView.SelectedNode = _treeView.Nodes[_treeView.Nodes.Count - 1];
                    _treeView.Select();
                }

                return(true);
            }
コード例 #6
0
        /// <summary>
        /// Propagates a request for drag targets down the hierarchy of docking elements.
        /// </summary>
        /// <param name="floatingWindow">Reference to window being dragged.</param>
        /// <param name="dragData">Set of pages being dragged.</param>
        /// <param name="targets">Collection of drag targets.</param>
        public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                                  PageDragEndData dragData,
                                                  DragTargetList targets)
        {
            // Create list of the pages that are allowed to be dropped into this navigator
            KryptonPageCollection pages = new();

            foreach (KryptonPage page in dragData.Pages.Where(static page => page.AreFlagsSet(KryptonPageFlags.DockingAllowNavigator)))
コード例 #7
0
        /// <summary>
        /// Generate a list of drag targets that are relevant to the provided end data.
        /// </summary>
        /// <param name="dragEndData">Pages data being dragged.</param>
        /// <returns>List of drag targets.</returns>
        public DragTargetList GenerateDragTargets(PageDragEndData dragEndData)
        {
            DragTargetList targets = new DragTargetList();

            // Generate target for the entire navigator client area
            targets.Add(new DragTargetTreeViewTransfer(RectangleToScreen(ClientRectangle), this));

            return(targets);
        }
コード例 #8
0
        /// <summary>
        /// Add a list of drag targets from the provided interface.
        /// </summary>
        /// <param name="provider">Interface reference.</param>
        /// <param name="dragEndData">Pages data being dragged.</param>
        public void AddRange(IDragTargetProvider provider, PageDragEndData dragEndData)
        {
            DragTargetList targets = provider?.GenerateDragTargets(dragEndData);

            if ((targets != null) && (targets.Count > 0))
            {
                AddRange(targets);
            }
        }
コード例 #9
0
 /// <summary>
 /// Propogates a request for drag targets down the hierarchy of docking elements.
 /// </summary>
 /// <param name="floatingWindow">Reference to window being dragged.</param>
 /// <param name="dragData">Set of pages being dragged.</param>
 /// <param name="targets">Collection of drag targets.</param>
 public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                           PageDragEndData dragData,
                                           DragTargetList targets)
 {
     // Can only generate targets for a floating window that is actually visible and not the one being dragged
     if (FloatingWindow.Visible && (floatingWindow != FloatingWindow))
     {
         base.PropogateDragTargets(floatingWindow, dragData, targets);
     }
 }
コード例 #10
0
        /// <summary>
        /// Occurs when dragging starts.
        /// </summary>
        /// <param name="screenPt">Mouse screen point at start of drag.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if dragging waas started; otherwise false.</returns>
        public override bool DragStart(Point screenPt, PageDragEndData dragEndData)
        {
            if (FloatingWindow != null)
            {
                FloatingWindow.Capture = true;
            }

            AddFilter();
            return(base.DragStart(screenPt, dragEndData));
        }
コード例 #11
0
ファイル: DockingElement.cs プロジェクト: dbremner/Krypton
 /// <summary>
 /// Propogates a request for drag targets down the hierarchy of docking elements.
 /// </summary>
 /// <param name="floatingWindow">Reference to window being dragged.</param>
 /// <param name="dragData">Set of pages being dragged.</param>
 /// <param name="targets">Collection of drag targets.</param>
 public virtual void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                          PageDragEndData dragData,
                                          DragTargetList targets)
 {
     // Propogate the request to all child elements
     foreach (IDockingElement child in this)
     {
         child.PropogateDragTargets(floatingWindow, dragData, targets);
     }
 }
コード例 #12
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
 {
     // Cannot drag back to ourself
     if ((dragEndData.Source != null) &&
         (dragEndData.Source is PageDragTreeView) &&
         (dragEndData.Source == _treeView))
     {
         return(false);
     }
     else
     {
         return(base.IsMatch(screenPt, dragEndData));
     }
 }
コード例 #13
0
        /// <summary>
        /// Find the target the first matches the provided screen point.
        /// </summary>
        /// <param name="screenPt">Point in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>First target that matches; otherwise null.</returns>
        protected virtual DragTarget FindTarget(Point screenPt, PageDragEndData dragEndData)
        {
            // Ask each target in turn if they are a match for the given screen point
            foreach (DragTarget target in DragTargets)
            {
                if (target.IsMatch(screenPt, dragEndData))
                {
                    return(target);
                }
            }

            // Nothing matches
            return(null);
        }
コード例 #14
0
        /// <summary>
        /// Generate a list of drag targets that are relevant to the provided end data.
        /// </summary>
        /// <param name="dragEndData">Pages data being dragged.</param>
        /// <returns>List of drag targets.</returns>
        public DragTargetList GenerateDragTargets(PageDragEndData dragEndData)
        {
            DragTargetList targets = new DragTargetList();

            // Generate the set of targets from the element hierarchy
            _manager.PropogateDragTargets(_floatingWindow, dragEndData, targets);

            // Must have at least one target
            if (targets.Count == 0)
            {
                targets.Add(new DragTargetNull());
            }

            return(targets);
        }
コード例 #15
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public virtual void Start(IPaletteDragDrop paletteDragDrop,
                                  IRenderer renderer,
                                  PageDragEndData pageDragEndData,
                                  DragTargetList dragTargets)
        {
            Debug.Assert(paletteDragDrop != null);
            Debug.Assert(renderer != null);
            Debug.Assert(pageDragEndData != null);
            Debug.Assert(dragTargets != null);

            PaletteDragDrop = paletteDragDrop;
            Renderer        = renderer;
            PageDragEndData = pageDragEndData;
            DragTargets     = dragTargets;
        }
コード例 #16
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public override void Start(IPaletteDragDrop paletteDragDrop,
                                   IRenderer renderer,
                                   PageDragEndData pageDragEndData,
                                   DragTargetList dragTargets)
        {
            base.Start(paletteDragDrop, renderer, pageDragEndData, dragTargets);

            if (_solid == null)
            {
                // Create and show a window without it taking focus
                _solid = new DropSolidWindow(PaletteDragDrop, Renderer);
                _solid.SetBounds(0, 0, 1, 1, BoundsSpecified.All);
                _solid.ShowWithoutActivate();
                _solid.Refresh();
            }
        }
コード例 #17
0
        /// <summary>
        /// Is this target a match for the provided screen position.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if a match; otherwise false.</returns>
        public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
        {
            // First time around...
            if (_visibleNotDraggedPages == -1)
            {
                // If pages are being dragged from this cell
                if (dragEndData.Navigator == Cell)
                {
                    // Create list of all the visible pages in the cell
                    KryptonPageCollection visiblePages = new KryptonPageCollection();
                    foreach (KryptonPage page in Cell.Pages)
                    {
                        if (page.LastVisibleSet)
                        {
                            visiblePages.Add(page);
                        }
                    }

                    // Remove all those that are being dragged
                    foreach (KryptonPage page in dragEndData.Pages)
                    {
                        visiblePages.Remove(page);
                    }

                    // Cache number of visible pages in target that are not part of the dragging set
                    _visibleNotDraggedPages = visiblePages.Count;
                }
                else
                {
                    // Pages not coming from this cell so we always allow the cell edge targets
                    _visibleNotDraggedPages = int.MaxValue;
                }
            }

            // If the drop leaves at least 1 page in the navigator then allow drag to edge
            if (_visibleNotDraggedPages >= 1)
            {
                return(base.IsMatch(screenPt, dragEndData));
            }
            else
            {
                return(false);
            }
        }
コード例 #18
0
        /// <summary>
        /// Is this target a match for the provided screen position.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if a match; otherwise false.</returns>
        public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
        {
            // First time around...
            if (_notDraggedPagesFromNavigator == -1)
            {
                // Search for any pages that are not from this navigator
                _notDraggedPagesFromNavigator = 0;
                foreach (KryptonPage page in dragEndData.Pages)
                {
                    if (!_navigator.Pages.Contains(page))
                    {
                        _notDraggedPagesFromNavigator = 1;
                        break;
                    }
                }
            }

            // If 1 or more pages are not from this navigator then allow transfer into the target
            return(_notDraggedPagesFromNavigator > 0 && base.IsMatch(screenPt, dragEndData));
        }
        /// <summary>
        /// Propagates a request for drag targets down the hierarchy of docking elements.
        /// </summary>
        /// <param name="floatingWindow">Reference to window being dragged.</param>
        /// <param name="dragData">Set of pages being dragged.</param>
        /// <param name="targets">Collection of drag targets.</param>
        public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                                  PageDragEndData dragData,
                                                  DragTargetList targets)
        {
            // Create list of the pages that are allowed to be dropped into this workspace
            KryptonPageCollection pages = new KryptonPageCollection();

            foreach (KryptonPage page in dragData.Pages)
            {
                if (page.AreFlagsSet(KryptonPageFlags.DockingAllowWorkspace))
                {
                    pages.Add(page);
                }
            }

            // Do we have any pages left for dragging?
            if (pages.Count > 0)
            {
                DragTargetList workspaceTargets = DockableWorkspaceControl.GenerateDragTargets(new PageDragEndData(this, pages), KryptonPageFlags.DockingAllowWorkspace);
                targets.AddRange(workspaceTargets.ToArray());
            }
        }
コード例 #20
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
 {
     return(true);
 }
コード例 #21
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public virtual bool IsMatch(Point screenPt, PageDragEndData dragEndData) =>
 // Default to matching if the mouse is inside the targets hot area
 HotRect.Contains(screenPt);
コード例 #22
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;
            }

            // Find the docked edge
            KryptonDockingEdgeDocked dockedEdge = dockingEdge?["Docked"] as KryptonDockingEdgeDocked;
            KryptonDockingManager    manager    = dockedEdge?.DockingManager;

            if (manager != null)
            {
                // Create a list of pages that are allowed to be transferred into the dockspace
                var transferPages       = new List <KryptonPage>();
                var 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(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);
        }
コード例 #23
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public override bool IsMatch(Point screenPt, PageDragEndData dragEndData) => true;
コード例 #24
0
 /// <summary>
 /// Perform the drop action associated with the target.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
 public abstract bool PerformDrop(Point screenPt, PageDragEndData dragEndData);
コード例 #25
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) => true;
コード例 #26
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)
        {
            // We need a parent sequence in order to perform drop
            if (Cell.WorkspaceParent is KryptonWorkspaceSequence parent)
            {
                // Transfer the dragged pages into a new cell
                KryptonWorkspaceCell cell = new KryptonWorkspaceCell();
                KryptonPage          page = ProcessDragEndData(Workspace, cell, data);

                // If no pages are transferred then we do nothing and no longer need cell instance
                if (page == null)
                {
                    cell.Dispose();
                }
                else
                {
                    // If the parent sequence is not the same direction as that needed for the drop then...
                    bool dropHorizontal = (Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Right);
                    if ((dropHorizontal && (parent.Orientation == Orientation.Vertical)) ||
                        (!dropHorizontal && (parent.Orientation == Orientation.Horizontal)))
                    {
                        // Find opposite direction to the parent sequence
                        Orientation sequenceOrientation = parent.Orientation == Orientation.Horizontal
                            ? Orientation.Vertical
                            : Orientation.Horizontal;

                        // Create a new sequence and transfer the target cell into it
                        KryptonWorkspaceSequence sequence = new KryptonWorkspaceSequence(sequenceOrientation);
                        int index = parent.Children.IndexOf(Cell);
                        parent.Children.RemoveAt(index);
                        sequence.Children.Add(Cell);

                        // Put the sequence into the place where the target cell used to be
                        parent.Children.Insert(index, sequence);

                        // Add new cell to the start or the end of the new sequence?
                        if ((Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Top))
                        {
                            sequence.Children.Insert(0, cell);
                        }
                        else
                        {
                            sequence.Children.Add(cell);
                        }
                    }
                    else
                    {
                        // Find position of the target cell
                        int index = parent.Children.IndexOf(Cell);

                        // Add new cell before or after the target cell?
                        if ((Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Top))
                        {
                            parent.Children.Insert(index, cell);
                        }
                        else
                        {
                            parent.Children.Insert(index + 1, cell);
                        }
                    }

                    // Make the last page transferred the newly selected page of the cell
                    if (page != null)
                    {
                        // Does the cell allow the selection of tabs?
                        if (cell.AllowTabSelect)
                        {
                            cell.SelectedPage = page;
                        }

                        // Need to layout so the new cell has been added as a child control and
                        // therefore can receive the focus we want to give it immediately afterwards
                        Workspace.PerformLayout();

                        if (!cell.IsDisposed)
                        {
                            // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                            // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                            // change activation is causing the source workspace control to dispose to earlier.
                            Application.DoEvents();
                            cell.Select();
                        }
                    }
                }
            }

            return(true);
        }
コード例 #27
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)
        {
            // Transfer the dragged pages into a new cell
            KryptonWorkspaceCell cell = new KryptonWorkspaceCell();
            KryptonPage          page = ProcessDragEndData(Workspace, cell, data);

            // If no pages are transferred then we do nothing and no longer need cell instance
            if (page == null)
            {
                cell.Dispose();
            }
            else
            {
                // If the root is not the same direction as that needed for the drop then...
                bool dropHorizontal = (Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Right);
                if ((dropHorizontal && (Workspace.Root.Orientation == Orientation.Vertical)) ||
                    (!dropHorizontal && (Workspace.Root.Orientation == Orientation.Horizontal)))
                {
                    // Create a new sequence and place all existing root items into it
                    KryptonWorkspaceSequence sequence = new KryptonWorkspaceSequence(Workspace.Root.Orientation);
                    for (int i = Workspace.Root.Children.Count - 1; i >= 0; i--)
                    {
                        Component child = Workspace.Root.Children[i];
                        Workspace.Root.Children.RemoveAt(i);
                        sequence.Children.Insert(0, child);
                    }

                    // Put the new sequence in the root so all items are now grouped together
                    Workspace.Root.Children.Add(sequence);

                    // Switch the direction of the root
                    Workspace.Root.Orientation = Workspace.Root.Orientation == Orientation.Horizontal
                        ? Orientation.Vertical
                        : Orientation.Horizontal;
                }

                // Add to the start or the end of the root sequence?
                if ((Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Top))
                {
                    Workspace.Root.Children.Insert(0, cell);
                }
                else
                {
                    Workspace.Root.Children.Add(cell);
                }

                // Make the last page transfer the newly selected page of the cell
                // Does the cell allow the selection of tabs?
                if (cell.AllowTabSelect)
                {
                    cell.SelectedPage = page;
                }

                // Need to layout so the new cell has been added as a child control and
                // therefore can receive the focus we want to give it immediately afterwards
                Workspace.PerformLayout();

                if (!cell.IsDisposed)
                {
                    // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                    // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                    // change activation is causing the source workspace control to dispose to earlier.
                    Application.DoEvents();
                    cell.Select();
                }
            }

            return(true);
        }
コード例 #28
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)
 {
     return(true);
 }
コード例 #29
0
        /// <summary>
        /// Propogates a request for drag targets down the hierarchy of docking elements.
        /// </summary>
        /// <param name="floatingWindow">Reference to window being dragged.</param>
        /// <param name="dragData">Set of pages being dragged.</param>
        /// <param name="targets">Collection of drag targets.</param>
        public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                                  PageDragEndData dragData,
                                                  DragTargetList targets)
        {
            // Create a list of pages that are allowed to be transferred into a dockspace
            List <KryptonPage> transferPages = new List <KryptonPage>();

            foreach (KryptonPage page in dragData.Pages)
            {
                if (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))
                {
                    transferPages.Add(page);
                }
            }

            // Only generate targets if we have some valid pages to transfer
            if (transferPages.Count > 0)
            {
                // Generate targets for the four control edges
                Rectangle   screenRect = Control.RectangleToScreen(Control.ClientRectangle);
                Rectangle[] rectsDraw  = SubdivideRectangle(screenRect, 3, int.MaxValue);
                Rectangle[] rectsHot   = SubdivideRectangle(screenRect, 10, 20);

                // Must insert at start of target list as they are higher priority than cell targets
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[0], rectsDraw[0], DragTargetHint.EdgeLeft | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[1], rectsDraw[1], DragTargetHint.EdgeRight | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[2], rectsDraw[2], DragTargetHint.EdgeTop | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[3], rectsDraw[3], DragTargetHint.EdgeBottom | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));

                // If we have no designated inner element when we have to decide if we can place edge drag drop targets based on the
                // available space at the center of the control after taking into account any edge docked controls already in place.
                if (_innerElement == null)
                {
                    // Find the inner rectangle after taking docked controls into account
                    Size tl = Size.Empty;
                    Size br = Control.ClientSize;
                    foreach (Control c in Control.Controls)
                    {
                        if (c.Visible)
                        {
                            switch (c.Dock)
                            {
                            case DockStyle.Left:
                                tl.Width = Math.Max(tl.Width, c.Right);
                                break;

                            case DockStyle.Right:
                                br.Width = Math.Min(br.Width, c.Left);
                                break;

                            case DockStyle.Top:
                                tl.Height = Math.Max(tl.Height, c.Bottom);
                                break;

                            case DockStyle.Bottom:
                                br.Height = Math.Min(br.Height, c.Top);
                                break;
                            }
                        }
                    }

                    // If there is inner space available
                    Rectangle innerRect = new Rectangle(tl.Width, tl.Height, br.Width - tl.Width, br.Height - tl.Height);
                    if ((innerRect.Width > 0) && (innerRect.Height > 0))
                    {
                        Rectangle   innerScreenRect = Control.RectangleToScreen(innerRect);
                        Rectangle[] innerRectsDraw  = SubdivideRectangle(innerScreenRect, 3, int.MaxValue);
                        Rectangle[] innerRectsHot   = SubdivideRectangle(innerScreenRect, 10, 20);
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[0], innerRectsDraw[0], DragTargetHint.EdgeLeft, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[1], innerRectsDraw[1], DragTargetHint.EdgeRight, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[2], innerRectsDraw[2], DragTargetHint.EdgeTop, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[3], innerRectsDraw[3], DragTargetHint.EdgeBottom, this, KryptonPageFlags.DockingAllowDocked, false));
                    }
                }
                else if (_innerElement is KryptonDockingNavigator)
                {
                    KryptonDockingNavigator dockingNavigator = (KryptonDockingNavigator)_innerElement;

                    // If there is inner space available
                    Rectangle innerScreenRect = dockingNavigator.DockableNavigatorControl.RectangleToScreen(dockingNavigator.DockableNavigatorControl.ClientRectangle);
                    if ((innerScreenRect.Width > 0) && (innerScreenRect.Height > 0))
                    {
                        Rectangle[] innerRectsDraw = SubdivideRectangle(innerScreenRect, 3, int.MaxValue);
                        Rectangle[] innerRectsHot  = SubdivideRectangle(innerScreenRect, 10, 20);
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[0], innerRectsDraw[0], DragTargetHint.EdgeLeft, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[1], innerRectsDraw[1], DragTargetHint.EdgeRight, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[2], innerRectsDraw[2], DragTargetHint.EdgeTop, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[3], innerRectsDraw[3], DragTargetHint.EdgeBottom, this, KryptonPageFlags.DockingAllowDocked, false));
                    }
                }

                // Let base class generate targets for contained elements
                base.PropogateDragTargets(floatingWindow, dragData, targets);
            }
        }