protected virtual void OnDragServiceDragOver(object sender, RadDragOverEventArgs e) { if (e.HitTarget is DraggableLayoutControlItem) { e.CanDrop = true; LayoutControlContainerElement ancestor = ((DraggableLayoutControlItem)e.HitTarget).AssociatedItem.FindAncestor <LayoutControlContainerElement>(); LayoutControlDropTargetInfo dropTargetNode = ancestor.LayoutTree.GetDropTargetNode(e.HitTarget as DraggableLayoutControlItem, this.layoutControl.PointToClient(Control.MousePosition), this.GetDragContext(e.DragInstance)); dropTargetNode?.TargetBounds.Offset(ancestor.ControlBoundingRectangle.Location); this.layoutControl.DragOverlay.SetPreviewRectangle(dropTargetNode != null ? dropTargetNode.TargetBounds : Rectangle.Empty); } else if (e.HitTarget is DraggableLayoutControlOverlayElement) { DraggableLayoutControlOverlayElement hitTarget = e.HitTarget as DraggableLayoutControlOverlayElement; if (hitTarget.Parent is RootRadElement && hitTarget.Items.Count == 0) { e.CanDrop = true; this.layoutControl.DragOverlay.SetPreviewRectangle(new Rectangle(Point.Empty, this.layoutControl.Size)); } else { e.CanDrop = false; } } else { e.CanDrop = false; this.layoutControl.DragOverlay.SetPreviewRectangle(Rectangle.Empty); } }
protected virtual void UpdateDragHintLocation(Point mousePosition) { if (!this.CanCommit) { this.overlay.SetPreviewRectangle(Rectangle.Empty); } else { DraggableLayoutControlItem dropTarget = this.DropTarget as DraggableLayoutControlItem; if (dropTarget != null) { LayoutControlContainerElement ancestor = dropTarget.AssociatedItem.FindAncestor <LayoutControlContainerElement>(); Point client = this.overlay.PointToClient(mousePosition); LayoutControlDropTargetInfo dropTargetNode = ancestor.LayoutTree.GetDropTargetNode(dropTarget, client, this.draggedItem.AssociatedItem.GetType()); if (dropTargetNode != null) { this.ValidCursor = (Cursor)null; dropTargetNode.TargetBounds.Offset(ancestor.ControlBoundingRectangle.Location); this.overlay.SetPreviewRectangle(dropTargetNode.TargetBounds); return; } } else if ((this.DropTarget is BaseListViewElement || this.DropTarget is BaseListViewVisualItem) && this.CanDropOnListView(this.DropTarget as RadElement)) { this.overlay.SetPreviewRectangle(Rectangle.Empty); this.ValidCursor = this.deleteCursor; return; } this.ValidCursor = (Cursor)null; this.overlay.SetPreviewRectangle(Rectangle.Empty); } }
public Rectangle GetDropHintPreviewRectangle( DraggableLayoutControlItem item, Point controlPoint, System.Type dragContext) { LayoutControlDropTargetInfo dropTargetNode = this.LayoutTree.GetDropTargetNode(item, controlPoint, dragContext); dropTargetNode?.TargetBounds.Offset(this.ControlBoundingRectangle.Location); if (dropTargetNode == null) { return(Rectangle.Empty); } return(dropTargetNode.TargetBounds); }
internal void HandleDrop( DraggableLayoutControlItem dropTargetElement, LayoutControlItemBase draggedElement, Point mousePosition) { Point mousePosition1 = mousePosition; mousePosition.Offset(-this.owner.ControlBoundingRectangle.X, -this.owner.ControlBoundingRectangle.Y); if (draggedElement is DraggableLayoutControlItem) { draggedElement = ((DraggableLayoutControlItem)draggedElement).AssociatedItem; } LayoutTreeNode draggedNode = this.FindNodeByItem(draggedElement); if (draggedNode != null) { if (!this.RemoveNode(draggedNode, false)) { return; } } else { draggedNode = new LayoutTreeNode(); draggedNode.Item = draggedElement; } LayoutControlDropTargetInfo dropTargetNode = this.GetDropTargetNode(dropTargetElement, mousePosition1, draggedElement.GetType()); if (dropTargetNode.TargetNode == null) { return; } LayoutTreeNode targetNode = dropTargetNode.TargetNode; LayoutControlDropPosition targetPosition = dropTargetNode.TargetPosition; RectangleF targetBounds = (RectangleF)dropTargetNode.TargetBounds; ILayoutControlItemsHost controlItemsHost = dropTargetElement.AssociatedItem.GetParentItemsContainer(); if (targetPosition == LayoutControlDropPosition.Center) { LayoutControlGroupItem associatedItem1 = dropTargetElement.AssociatedItem as LayoutControlGroupItem; LayoutControlTabbedGroup associatedItem2 = dropTargetElement.AssociatedItem as LayoutControlTabbedGroup; if (associatedItem1 != null) { controlItemsHost = (ILayoutControlItemsHost)associatedItem1.ContainerElement; } if (associatedItem2 != null) { controlItemsHost = (ILayoutControlItemsHost)null; } } ILayoutControlItemsHost parentItemsContainer = draggedElement.GetParentItemsContainer(); if (controlItemsHost != parentItemsContainer) { parentItemsContainer?.Items.Remove((RadItem)draggedElement); controlItemsHost?.Items.Add((RadItem)draggedElement); } if (dropTargetElement.AssociatedItem is LayoutControlGroupItem && targetPosition == LayoutControlDropPosition.Center) { (dropTargetElement.AssociatedItem as LayoutControlGroupItem).ContainerElement.RebuildLayoutTree(); } else { if (dropTargetElement.AssociatedItem is LayoutControlTabbedGroup && targetPosition == LayoutControlDropPosition.Center) { LayoutControlTabbedGroup associatedItem = (LayoutControlTabbedGroup)dropTargetElement.AssociatedItem; LayoutControlGroupItem controlGroupItem = draggedElement as LayoutControlGroupItem; if (controlGroupItem != null) { if (dropTargetNode.TargetTabIndex >= 0 && dropTargetNode.TargetTabIndex <= associatedItem.ItemGroups.Count) { associatedItem.ItemGroups.Insert(dropTargetNode.TargetTabIndex, (RadItem)controlGroupItem); return; } associatedItem.ItemGroups.Add((RadItem)controlGroupItem); return; } } LayoutTreeNode node = new LayoutTreeNode(); node.Item = targetNode.Item; node.Parent = targetNode; node.Left = targetNode.Left; node.Right = targetNode.Right; node.OriginalBounds = targetNode.OriginalBounds; node.Bounds = targetNode.Bounds; node.SplitType = targetNode.SplitType; node.SplitPosition = targetNode.SplitPosition; node.OriginalSplitPosition = targetNode.OriginalSplitPosition; node.MinSize = targetNode.MinSize; node.MaxSize = targetNode.MaxSize; if (targetNode.Left != null) { targetNode.Left.Parent = node; } if (targetNode.Right != null) { targetNode.Right.Parent = node; } draggedNode.Parent = targetNode; draggedNode.Bounds = targetBounds; targetNode.Item = (LayoutControlItemBase)null; targetNode.SplitType = targetPosition == LayoutControlDropPosition.Top || targetPosition == LayoutControlDropPosition.Bottom ? Orientation.Vertical : Orientation.Horizontal; targetNode.Left = targetPosition == LayoutControlDropPosition.Left || targetPosition == LayoutControlDropPosition.Top ? draggedNode : node; targetNode.Right = targetPosition == LayoutControlDropPosition.Left || targetPosition == LayoutControlDropPosition.Top ? node : draggedNode; switch (targetPosition) { case LayoutControlDropPosition.Left: this.ChangeBounds(new RectangleF(targetNode.Bounds.X + targetBounds.Width, targetNode.Bounds.Y, targetNode.Bounds.Width - targetBounds.Width, targetNode.Bounds.Height), node); break; case LayoutControlDropPosition.Right: this.ChangeBounds(new RectangleF(targetNode.Bounds.X, targetNode.Bounds.Y, targetNode.Bounds.Width - targetBounds.Width, targetNode.Bounds.Height), node); break; case LayoutControlDropPosition.Top: this.ChangeBounds(new RectangleF(targetNode.Bounds.X, targetNode.Bounds.Y + targetBounds.Height, targetNode.Bounds.Width, targetNode.Bounds.Height - targetBounds.Height), node); break; case LayoutControlDropPosition.Bottom: this.ChangeBounds(new RectangleF(targetNode.Bounds.X, targetNode.Bounds.Y, targetNode.Bounds.Width, targetNode.Bounds.Height - targetBounds.Height), node); break; } targetNode.SplitPosition = targetNode.OriginalSplitPosition = targetNode.SplitType == Orientation.Vertical ? targetNode.Right.Bounds.Top : targetNode.Right.Bounds.Left; targetNode.OriginalBounds = targetNode.Bounds; this.ChangeBounds(this.root.Bounds); this.UpdateItemsBounds(); this.owner.PerformControlLayout(); if (this.owner.ElementTree == null || this.owner.ElementTree.Control == null) { return; } (this.owner.ElementTree.Control as RadLayoutControl)?.OnHandleDropCompleted((object)this); } }
public LayoutControlDropTargetInfo GetDropTargetNode( DraggableLayoutControlItem dropTargetElement, Point mousePosition, System.Type dragContext) { LayoutControlContainerElement ancestor = dropTargetElement.AssociatedItem.FindAncestor <LayoutControlContainerElement>(); mousePosition.Offset(-ancestor.ControlBoundingRectangle.X, -ancestor.ControlBoundingRectangle.Y); LayoutControlDropTargetInfo controlDropTargetInfo = new LayoutControlDropTargetInfo(); Rectangle bounds = dropTargetElement.Bounds; Point point = new Point(mousePosition.X - bounds.X, mousePosition.Y - bounds.Y); LayoutTreeNode nodeByItem = this.FindNodeByItem(dropTargetElement.AssociatedItem); if (dropTargetElement.AssociatedItem is LayoutControlGroupItem && ((LayoutControlGroupItem)dropTargetElement.AssociatedItem).Items.Count == 0) { LayoutControlGroupItem associatedItem = dropTargetElement.AssociatedItem as LayoutControlGroupItem; Point location = new Point(dropTargetElement.ControlBoundingRectangle.X - this.owner.ControlBoundingRectangle.X, dropTargetElement.ControlBoundingRectangle.Y - this.owner.ControlBoundingRectangle.Y); location.Offset(associatedItem.ContainerElement.BoundingRectangle.Location); controlDropTargetInfo.TargetBounds = new Rectangle(location, associatedItem.ContainerElement.BoundingRectangle.Size); controlDropTargetInfo.TargetNode = nodeByItem; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Center; return(controlDropTargetInfo); } if (dropTargetElement.AssociatedItem is LayoutControlTabbedGroup) { LayoutControlTabbedGroup associatedItem = dropTargetElement.AssociatedItem as LayoutControlTabbedGroup; if ((object)dragContext != null && typeof(LayoutControlGroupItem).IsAssignableFrom(dragContext) && ((double)point.Y / (double)bounds.Height >= 0.333333343267441 && (double)point.Y / (double)bounds.Height <= 0.666666686534882 && ((double)point.X / (double)bounds.Width > 0.25 && (double)point.X / (double)bounds.Width < 0.75) && associatedItem.ItemGroups.Count == 0 || associatedItem.TabStrip.ItemContainer.BoundingRectangle.Contains(point))) { Point location = new Point((int)nodeByItem.Bounds.Location.X, (int)nodeByItem.Bounds.Location.Y); location.Offset(associatedItem.TabStrip.ContentArea.BoundingRectangle.Location); controlDropTargetInfo.TargetTabIndex = associatedItem.GetTargetDropIndex(point); controlDropTargetInfo.TargetBounds = controlDropTargetInfo.TargetTabIndex >= 0 ? associatedItem.GetTargetBounds(controlDropTargetInfo.TargetTabIndex) : new Rectangle(location, associatedItem.TabStrip.ContentArea.BoundingRectangle.Size); controlDropTargetInfo.TargetNode = nodeByItem; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Center; return(controlDropTargetInfo); } } if ((double)point.Y / (double)bounds.Height <= 0.16666667163372) { float num = Math.Min(0.99f, (float)point.Y / ((float)bounds.Height / 6f)); List <LayoutTreeNode> groupsWithSameEdge = this.GetParentGroupsWithSameEdge(nodeByItem, bounds.Top, RadDirection.Up); if (groupsWithSameEdge.Count == 0) { return((LayoutControlDropTargetInfo)null); } int index = Math.Min(groupsWithSameEdge.Count - 1, (int)((double)groupsWithSameEdge.Count * (double)num)); LayoutTreeNode layoutTreeNode = groupsWithSameEdge[index]; controlDropTargetInfo.TargetBounds = new Rectangle((int)layoutTreeNode.Bounds.X, (int)layoutTreeNode.Bounds.Y, (int)layoutTreeNode.Bounds.Width, 26); controlDropTargetInfo.TargetNode = layoutTreeNode; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Top; } else if ((double)point.Y / (double)bounds.Height > 0.16666667163372 && (double)point.Y / (double)bounds.Height < 0.333333343267441) { controlDropTargetInfo.TargetBounds = new Rectangle(bounds.Location, new Size(bounds.Width, bounds.Height / 2)); controlDropTargetInfo.TargetNode = nodeByItem; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Top; } else if ((double)point.Y / (double)bounds.Height > 0.666666686534882 && (double)point.Y / (double)bounds.Height < 0.833333313465118) { controlDropTargetInfo.TargetBounds = new Rectangle(new Point(bounds.X, bounds.Y + bounds.Height / 2), new Size(bounds.Width, bounds.Height / 2)); controlDropTargetInfo.TargetNode = nodeByItem; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Bottom; } else if ((double)point.Y / (double)bounds.Height >= 0.833333313465118) { float num = Math.Min(0.99f, (float)(bounds.Height - point.Y) / ((float)bounds.Height / 6f)); List <LayoutTreeNode> groupsWithSameEdge = this.GetParentGroupsWithSameEdge(nodeByItem, bounds.Bottom, RadDirection.Down); if (groupsWithSameEdge.Count == 0) { return((LayoutControlDropTargetInfo)null); } int index = Math.Min(groupsWithSameEdge.Count - 1, (int)((double)groupsWithSameEdge.Count * (double)num)); LayoutTreeNode layoutTreeNode = groupsWithSameEdge[index]; controlDropTargetInfo.TargetBounds = new Rectangle((int)layoutTreeNode.Bounds.X, (int)layoutTreeNode.Bounds.Bottom - 26, (int)layoutTreeNode.Bounds.Width, 26); controlDropTargetInfo.TargetNode = layoutTreeNode; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Bottom; } else if ((double)point.Y / (double)bounds.Height >= 0.333333343267441 && (double)point.Y / (double)bounds.Height <= 0.666666686534882) { if ((double)point.X / (double)bounds.Width <= 0.25) { float num = Math.Min(0.99f, (float)point.X / ((float)bounds.Width / 4f)); List <LayoutTreeNode> groupsWithSameEdge = this.GetParentGroupsWithSameEdge(nodeByItem, bounds.Left, RadDirection.Left); if (groupsWithSameEdge.Count == 0) { return((LayoutControlDropTargetInfo)null); } int index = Math.Min(groupsWithSameEdge.Count - 1, (int)((double)groupsWithSameEdge.Count * (double)num)); LayoutTreeNode layoutTreeNode = groupsWithSameEdge[index]; controlDropTargetInfo.TargetBounds = new Rectangle((int)layoutTreeNode.Bounds.X, (int)layoutTreeNode.Bounds.Y, 86, (int)layoutTreeNode.Bounds.Height); controlDropTargetInfo.TargetNode = layoutTreeNode; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Left; } else if ((double)point.X / (double)bounds.Width > 0.25 && (double)point.X / (double)bounds.Width <= 0.5) { controlDropTargetInfo.TargetBounds = new Rectangle(bounds.Location, new Size(bounds.Width / 2, bounds.Height)); controlDropTargetInfo.TargetNode = nodeByItem; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Left; } else if ((double)point.X / (double)bounds.Width > 0.5 && (double)point.X / (double)bounds.Width < 0.75) { controlDropTargetInfo.TargetBounds = new Rectangle(new Point(bounds.X + bounds.Width / 2, bounds.Y), new Size(bounds.Width / 2, bounds.Height)); controlDropTargetInfo.TargetNode = nodeByItem; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Right; } else if ((double)point.X / (double)bounds.Width >= 0.75) { float num = Math.Min(0.99f, (float)(bounds.Width - point.X) / ((float)bounds.Width / 4f)); List <LayoutTreeNode> groupsWithSameEdge = this.GetParentGroupsWithSameEdge(nodeByItem, bounds.Right, RadDirection.Right); if (groupsWithSameEdge.Count == 0) { return((LayoutControlDropTargetInfo)null); } int index = Math.Min(groupsWithSameEdge.Count - 1, (int)((double)groupsWithSameEdge.Count * (double)num)); LayoutTreeNode layoutTreeNode = groupsWithSameEdge[index]; controlDropTargetInfo.TargetBounds = new Rectangle((int)layoutTreeNode.Bounds.Right - 86, (int)layoutTreeNode.Bounds.Y, 86, (int)layoutTreeNode.Bounds.Height); controlDropTargetInfo.TargetNode = layoutTreeNode; controlDropTargetInfo.TargetPosition = LayoutControlDropPosition.Right; } } return(controlDropTargetInfo); }