/// <summary> /// Occurs when the component is being removed from the designer. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">A ComponentEventArgs containing event data.</param> protected override void OnComponentRemoving(object sender, ComponentEventArgs e) { // If our control is being removed if (e.Component == Navigator) { // If this workspace cell is inside a parent KryptonWorkspaceCell cell = (KryptonWorkspaceCell)Navigator; // Cell an only be inside a workspace sequence KryptonWorkspaceSequence sequence = (KryptonWorkspaceSequence)cell.WorkspaceParent; // Remove the cell from the parent sequence?.Children.Remove(cell); } base.OnComponentRemoving(sender, e); }
/// <summary> /// Converts the given value object to the specified type, using the specified context and culture information. /// </summary> /// <param name="context">An ITypeDescriptorContext that provides a format context.</param> /// <param name="culture">A CultureInfo. If a null reference (Nothing in Visual Basic) is passed, the current culture is assumed.</param> /// <param name="value">The Object to convert.</param> /// <param name="destinationType">The Type to convert the value parameter to.</param> /// <returns>An Object that represents the converted value.</returns> public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { // Can always convert to a string representation if (destinationType == typeof(string)) { KryptonWorkspaceSequence sequence = (KryptonWorkspaceSequence)value; return(sequence.ToString()); } // Let base class attempt other conversions return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Initializes the designer with the specified component. /// </summary> /// <param name="component">The IComponent to associate the designer with.</param> public override void Initialize(IComponent component) { Debug.Assert(component != null); // Validate the parameter reference if (component == null) { throw new ArgumentNullException(nameof(component)); } // Let base class do standard stuff base.Initialize(component); // Cast to correct type _sequence = (KryptonWorkspaceSequence)component; // Get access to the services _changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); // We need to know when we are being removed/changed _changeService.ComponentRemoving += OnComponentRemoving; }
/// <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); }
/// <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); }
/// <summary> /// Initialize a new instance of the KryptonWorkspaceCollection class. /// </summary> /// <param name="sequence">Reference to the owning sequence.</param> public KryptonWorkspaceCollection(KryptonWorkspaceSequence sequence) { _sequence = sequence; }