public void PerformControlLayout(bool recursive) { if (!this.IsInValidState(true) || this.Size == Size.Empty) { return; } if (this.LayoutTree.Root == null) { this.RebuildLayoutTree(false); } this.ElementTree.Control.SuspendLayout(); foreach (RadItem radItem in (RadItemCollection)this.items) { LayoutControlGroupItem controlGroupItem = radItem as LayoutControlGroupItem; LayoutControlTabbedGroup controlTabbedGroup = radItem as LayoutControlTabbedGroup; if (controlGroupItem != null && recursive) { controlGroupItem.ContainerElement.PerformControlLayout(recursive); } else if (controlTabbedGroup != null && controlTabbedGroup.SelectedLayoutContainer != null && recursive) { controlTabbedGroup.SelectedLayoutContainer.PerformControlLayout(recursive); } LayoutControlItem layoutControlItem = radItem as LayoutControlItem; if (layoutControlItem != null && layoutControlItem.AssociatedControl != null) { layoutControlItem.UpdateControlBounds(); } } this.ElementTree.Control.ResumeLayout(true); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButtons.Left) { Cursor cursorAtPoint = this.owner.GetCursorAtPoint(e.Location); LayoutControlResizingBehavior behaviorAtPoint = this.owner.GetBehaviorAtPoint(e.Location); if (cursorAtPoint != Cursors.Default) { Orientation resizeType = cursorAtPoint == Cursors.SizeNS ? Orientation.Vertical : Orientation.Horizontal; if (behaviorAtPoint.BeginResize(e.Location, resizeType)) { this.capturedBehavior = behaviorAtPoint; this.capturedBehavior.Resized += new EventHandler(this.ResizingBehavior_Resized); this.Capture = true; } this.canStartDrag = false; } else { DraggableLayoutControlItem elementAtPoint = this.ElementTree.GetElementAtPoint(e.Location) as DraggableLayoutControlItem; if (elementAtPoint == null) { return; } if (elementAtPoint.AssociatedItem is LayoutControlTabbedGroup) { LayoutControlTabbedGroup associatedItem = elementAtPoint.AssociatedItem as LayoutControlTabbedGroup; foreach (LayoutControlTabStripItem controlTabStripItem in (IEnumerable <RadPageViewItem>)associatedItem.TabStrip.Items) { if (controlTabStripItem.ControlBoundingRectangle.Contains(e.Location)) { associatedItem.TabStrip.SelectedItem = (RadPageViewItem)controlTabStripItem; this.canStartDrag = true; this.initialMousePos = e.Location; this.UpdatePreview(); return; } } } this.SelectItem(elementAtPoint, Control.ModifierKeys == Keys.Control); this.canStartDrag = true; this.initialMousePos = e.Location; } } else { if (e.Button != MouseButtons.Right || this.SelectedItems.Count > 1) { return; } this.SelectItem(this.ElementTree.GetElementAtPoint(e.Location) as DraggableLayoutControlItem, false); } }
private void InitializeChildItem(LayoutControlTabbedGroup tabbedItem) { if (tabbedItem.ItemGroups.Count == 0 || tabbedItem.SelectedGroup == null) { return; } this.childItem = new DraggableLayoutControlItem() { AssociatedItem = (LayoutControlItemBase)tabbedItem.SelectedGroup }; this.Children.Add((RadElement)this.childItem); tabbedItem.TabStrip.UpdateLayout(); Rectangle boundingRectangle = tabbedItem.TabStrip.ContentArea.BoundingRectangle; boundingRectangle.Offset(tabbedItem.TabStrip.ContentArea.Padding.Left, tabbedItem.TabStrip.ContentArea.Padding.Right); boundingRectangle.Size = new Size(boundingRectangle.Width - tabbedItem.TabStrip.ContentArea.Padding.Horizontal, boundingRectangle.Height - tabbedItem.TabStrip.ContentArea.Padding.Vertical); this.childItem.Bounds = boundingRectangle; }
public void InvalidateSnapshot() { if (this.associatedItem.AutoSize || this.associatedItem.Size != this.Size) { if (this.cachedElement != null) { this.cachedElement.Dispose(); } this.cachedElement = (Bitmap)null; } if (!this.associatedItem.AutoSize) { this.Bounds = this.associatedItem.Bounds; } if (this.groupContainer != null) { LayoutControlGroupItem associatedItem = this.AssociatedItem as LayoutControlGroupItem; if (associatedItem != null) { this.groupContainer.Bounds = associatedItem.ContainerElement.BoundingRectangle; } foreach (DraggableLayoutControlItem layoutControlItem in (RadItemCollection)this.groupContainer.Items) { layoutControlItem.InvalidateSnapshot(); } } if (this.childItem == null) { return; } LayoutControlTabbedGroup associatedItem1 = this.AssociatedItem as LayoutControlTabbedGroup; if (associatedItem1 != null) { Rectangle boundingRectangle = associatedItem1.TabStrip.ContentArea.BoundingRectangle; boundingRectangle.Offset(associatedItem1.TabStrip.ContentArea.Padding.Left, associatedItem1.TabStrip.ContentArea.Padding.Right); boundingRectangle.Size = new Size(boundingRectangle.Width - associatedItem1.TabStrip.ContentArea.Padding.Horizontal, boundingRectangle.Height - associatedItem1.TabStrip.ContentArea.Padding.Vertical); this.childItem.Bounds = boundingRectangle; } this.childItem.InvalidateSnapshot(); }
private IEnumerable <LayoutControlItemBase> FindCardViewItemsByType( System.Type itemType, RadItemCollection layoutContainerItems) { foreach (LayoutControlItemBase layoutContainerItem in layoutContainerItems) { if ((object)layoutContainerItem.GetType() == (object)itemType) { yield return(layoutContainerItem); } LayoutControlGroupItem groupItem = layoutContainerItem as LayoutControlGroupItem; LayoutControlTabbedGroup tabbedGroup = layoutContainerItem as LayoutControlTabbedGroup; if (groupItem != null) { this.FindCardViewItemsByType(itemType, groupItem.Items); } else if (tabbedGroup != null) { this.FindCardViewItemsByType(itemType, (RadItemCollection)tabbedGroup.ItemGroups); } } }
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); }