/// <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); }
/// <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 KryptonWorkspaceSequence parent = Cell.WorkspaceParent as KryptonWorkspaceSequence; if (parent != null) { // 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; if (parent.Orientation == Orientation.Horizontal) { sequenceOrientation = Orientation.Vertical; } else { sequenceOrientation = 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 transfered 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); }
/// <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 if (Workspace.Root.Orientation == Orientation.Horizontal) { Workspace.Root.Orientation = Orientation.Vertical; } else { Workspace.Root.Orientation = 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 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); }