예제 #1
0
		private bool CheckDockLocation(MultiSplitContainer container)
		{
			var horizontal = container.Horizontal;
			var absoluteBounds = container.Parent.RectangleToScreen(container.Bounds);
			if (!absoluteBounds.Contains(Cursor.Position)) return false;

			foreach (var panel in container.Panels)
			{
				if (CheckGroupDock(panel.ControlContainer.Controls[0] as IdePanel)) return true;
			}

			var splits = new List<LayoutSplit>();
			var splitIndex = 0;
			var closestSplit = new LayoutSplit
			{
				Location = horizontal ? absoluteBounds.Left : absoluteBounds.Top,
				Index = splitIndex,
				Parent = container,
				Horizontal = horizontal
			};
			foreach (var split in container.Splits)
				splits.Add(new LayoutSplit
				{
					Location = closestSplit.Location + split,
					Index = ++splitIndex,
					Parent = container,
					Horizontal = horizontal
				});
			SuggestClosestSplit(closestSplit, splits, absoluteBounds, horizontal);
			return true;
		}
예제 #2
0
		private void SuggestClosestSplit(LayoutSplit closestSplit, List<LayoutSplit> splits, Rectangle absoluteBounds, bool horizontal)
		{
			var cursorIndex = (horizontal ? Cursor.Position.X : Cursor.Position.Y);
			var closestSplitDistance = Math.Abs(cursorIndex - closestSplit.Location);
			foreach (var split in splits)
			{
				var distance = Math.Abs(cursorIndex - split.Location);
				if (distance < closestSplitDistance)
				{
					closestSplitDistance = distance;
					closestSplit = split;
				}
			}

			Rectangle suggestion;
			if (horizontal)
			{
				var targetWidth = absoluteBounds.Width / (splits.Count + 1);
				suggestion = new Rectangle(closestSplit.Location - (targetWidth / 2), absoluteBounds.Top, targetWidth, absoluteBounds.Height);
				var oversized = suggestion.Right - absoluteBounds.Right;
				if (oversized > 0) suggestion.X -= oversized;
				oversized = absoluteBounds.Left - suggestion.Left;
				if (oversized > 0) suggestion.X += oversized;
			}
			else
			{
				var targetHeight = absoluteBounds.Height / (splits.Count + 1);
				suggestion = new Rectangle(absoluteBounds.Left, closestSplit.Location - (targetHeight / 2), absoluteBounds.Width, targetHeight);
				var oversized = suggestion.Bottom - absoluteBounds.Bottom;
				if (oversized > 0) suggestion.Y -= oversized;
				oversized = absoluteBounds.Top - suggestion.Top;
				if (oversized > 0) suggestion.Y += oversized;
			}
			if (DockSuggestion == null || suggestion != DockSuggestion.Bounds)
			{
				DockSuggestion = new DockSuggestion
				{
					Bounds = suggestion,
					LayoutSplit = closestSplit
				};
			}
		}