private void ItemDragDelta(object sender, DragablzDragDeltaEventArgs eventArgs) { var bounds = new Size(ItemsPresenterWidth, ItemsPresenterHeight); var desiredLocation = new Point( eventArgs.DragablzItem.X + eventArgs.DragDeltaEventArgs.HorizontalChange, eventArgs.DragablzItem.Y += eventArgs.DragDeltaEventArgs.VerticalChange ); if (ItemsOrganiser != null) { desiredLocation = ItemsOrganiser.ConstrainLocation(bounds, desiredLocation, eventArgs.DragablzItem.DesiredSize); } eventArgs.DragablzItem.X = desiredLocation.X; eventArgs.DragablzItem.Y = desiredLocation.Y; if (ItemsOrganiser != null) { ItemsOrganiser.OrganiseOnDrag( bounds, DragablzItems().Except(new[] { eventArgs.DragablzItem }), eventArgs.DragablzItem); } eventArgs.DragablzItem.BringIntoView(); eventArgs.Handled = true; }
private void PreviewItemDragDelta(object sender, DragablzDragDeltaEventArgs e) { if (_dragablzItemsControl == null) { return; } var sourceOfDragItemsControl = ItemsControlFromItemContainer(e.DragablzItem) as DragablzItemsControl; if (sourceOfDragItemsControl == null || !Equals(sourceOfDragItemsControl, _dragablzItemsControl)) { return; } if (Items.Count != 1 || (InterTabController != null && !InterTabController.MoveWindowWithSolitaryTabs) || Layout.IsContainedWithinBranch(sourceOfDragItemsControl)) { return; } if (MonitorReentry(e)) { return; } var myWindow = Window.GetWindow(this); if (myWindow == null) { return; } if (_interTabTransfer != null) { var cursorPos = Native.GetCursorPos(); if (_interTabTransfer.BreachOrientation == Orientation.Vertical) { var vector = cursorPos - _interTabTransfer.DragStartWindowOffset; myWindow.Left = vector.X; myWindow.Top = vector.Y; } else { var offset = e.DragablzItem.TranslatePoint(_interTabTransfer.OriginatorContainer.MouseAtDragStart, myWindow); var borderVector = myWindow.PointToScreen(new Point()) - new Point(myWindow.Left, myWindow.Top); offset.Offset(borderVector.X, borderVector.Y); myWindow.Left = cursorPos.X - offset.X; myWindow.Top = cursorPos.Y - offset.Y; } } else { myWindow.Left += e.DragDeltaEventArgs.HorizontalChange; myWindow.Top += e.DragDeltaEventArgs.VerticalChange; } e.Handled = true; }
private bool MonitorReentry(DragablzDragDeltaEventArgs e) { var screenMousePosition = _dragablzItemsControl.PointToScreen(Mouse.GetPosition(_dragablzItemsControl)); var otherTabablzControls = LoadedInstances .Where( tc => tc != this && tc.InterTabController != null && Equals(tc.InterTabController.Partition, InterTabController.Partition)) .Select(tc => { var topLeft = tc._dragablzItemsControl.PointToScreen(new Point()); var bottomRight = tc._dragablzItemsControl.PointToScreen(new Point(tc._dragablzItemsControl.ActualWidth, tc._dragablzItemsControl.ActualHeight)); return(new { tc, topLeft, bottomRight }); }); var target = Native.SortWindowsTopToBottom(Application.Current.Windows.OfType <Window>()) .Join(otherTabablzControls, w => w, a => Window.GetWindow(a.tc), (w, a) => a) .FirstOrDefault(a => new Rect(a.topLeft, a.bottomRight).Contains(screenMousePosition)); if (target != null) { var mousePositionOnItem = Mouse.GetPosition(e.DragablzItem); var floatingItemSnapShots = this.VisualTreeDepthFirstTraversal() .OfType <Layout>() .SelectMany(l => l.FloatingDragablzItems().Select(FloatingItemSnapShot.Take)) .ToList(); e.DragablzItem.IsDropTargetFound = true; var item = RemoveItem(e.DragablzItem); var interTabTransfer = new InterTabTransfer(item, e.DragablzItem, mousePositionOnItem, floatingItemSnapShots); e.DragablzItem.IsDragging = false; target.tc.ReceiveDrag(interTabTransfer); e.Cancel = true; return(true); } return(false); }
private void ItemDragDelta(object sender, DragablzDragDeltaEventArgs eventArgs) { var bounds = new Size(ItemsPresenterWidth, ItemsPresenterHeight); var desiredLocation = new Point( eventArgs.DragablzItem.X + eventArgs.DragDeltaEventArgs.HorizontalChange, eventArgs.DragablzItem.Y + eventArgs.DragDeltaEventArgs.VerticalChange ); if (ItemsOrganiser != null) { if (FixedItemCount > 0 && ItemsOrganiser.Sort(DragablzItems()).Take(FixedItemCount).Contains(eventArgs.DragablzItem)) { eventArgs.Handled = true; return; } desiredLocation = ItemsOrganiser.ConstrainLocation(this, bounds, new Point(eventArgs.DragablzItem.X, eventArgs.DragablzItem.Y), new Size(eventArgs.DragablzItem.ActualWidth, eventArgs.DragablzItem.ActualHeight), desiredLocation, eventArgs.DragablzItem.DesiredSize); } foreach (var dragableItem in DragablzItems() .Except(new[] { eventArgs.DragablzItem })) // how about Linq.Where() ? { dragableItem.IsSiblingDragging = true; } eventArgs.DragablzItem.IsDragging = true; eventArgs.DragablzItem.X = desiredLocation.X; eventArgs.DragablzItem.Y = desiredLocation.Y; if (ItemsOrganiser != null) { ItemsOrganiser.OrganiseOnDrag( this, bounds, DragablzItems().Except(new[] { eventArgs.DragablzItem }), eventArgs.DragablzItem); } eventArgs.DragablzItem.BringIntoView(); eventArgs.Handled = true; }
private void ItemDragDelta(object sender, DragablzDragDeltaEventArgs e) { if (!IsMyItem(e.DragablzItem)) { return; } if (_tabHeaderDragStartInformation != null && Equals(_tabHeaderDragStartInformation.DragItem, e.DragablzItem) && InterTabController != null) { if (InterTabController.InterTabClient == null) { throw new InvalidOperationException("An InterTabClient must be provided on an InterTabController."); } MonitorBreach(e); } }
private void ThumbOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs) { var thumb = (Thumb)sender; var previewEventArgs = new DragablzDragDeltaEventArgs(PreviewDragDelta, this, dragDeltaEventArgs); OnPreviewDragDelta(previewEventArgs); if (previewEventArgs.Cancel) { thumb.CancelDrag(); } if (!previewEventArgs.Handled) { var eventArgs = new DragablzDragDeltaEventArgs(DragDelta, this, dragDeltaEventArgs); OnDragDelta(eventArgs); if (eventArgs.Cancel) { thumb.CancelDrag(); } } }
private void ThumbOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs) { var thumb = (Thumb)sender; var previewEventArgs = new DragablzDragDeltaEventArgs(PreviewDragDelta, this, dragDeltaEventArgs); OnPreviewDragDelta(previewEventArgs); if (!_onTheMove) { var delta = MouseAtDragStart - Mouse.GetPosition(this); if ( (Math.Abs(delta.X) < SystemParameters.MinimumHorizontalDragDistance) && (Math.Abs(delta.Y) < SystemParameters.MinimumVerticalDragDistance)) { previewEventArgs.Handled = true; return; } else { _onTheMove = true; } } if (previewEventArgs.Cancel) { thumb.CancelDrag(); } if (!previewEventArgs.Handled) { var eventArgs = new DragablzDragDeltaEventArgs(DragDelta, this, dragDeltaEventArgs); OnDragDelta(eventArgs); if (eventArgs.Cancel) { thumb.CancelDrag(); } } }
private void MonitorBreach(DragablzDragDeltaEventArgs e) { var mousePositionOnHeaderItemsControl = Mouse.GetPosition(_dragablzItemsControl); Orientation? breachOrientation = null; if (mousePositionOnHeaderItemsControl.X < -InterTabController.HorizontalPopoutGrace || (mousePositionOnHeaderItemsControl.X - _dragablzItemsControl.ActualWidth) > InterTabController.HorizontalPopoutGrace) breachOrientation = Orientation.Horizontal; else if (mousePositionOnHeaderItemsControl.Y < -InterTabController.VerticalPopoutGrace || (mousePositionOnHeaderItemsControl.Y - _dragablzItemsControl.ActualHeight) > InterTabController.VerticalPopoutGrace) breachOrientation = Orientation.Vertical; if (!breachOrientation.HasValue) return; var newTabHost = InterTabController.InterTabClient.GetNewHost(InterTabController.InterTabClient, InterTabController.Partition, this); if (newTabHost == null || newTabHost.TabablzControl == null || newTabHost.Container == null) throw new ApplicationException("New tab host was not correctly provided"); var item = _dragablzItemsControl.ItemContainerGenerator.ItemFromContainer(e.DragablzItem); var myWindow = Window.GetWindow(this); if (myWindow == null) throw new ApplicationException("Unable to find owning window."); var dragStartWindowOffset = ConfigureNewHostSizeAndGetDragStartWindowOffset(myWindow, newTabHost, e.DragablzItem); var dragableItemHeaderPoint = e.DragablzItem.TranslatePoint(new Point(), _dragablzItemsControl); var dragableItemSize = new Size(e.DragablzItem.ActualWidth, e.DragablzItem.ActualHeight); var floatingItemSnapShots = this.VisualTreeDepthFirstTraversal() .OfType<Layout>() .SelectMany(l => l.FloatingDragablzItems().Select(FloatingItemSnapShot.Take)) .ToList(); var interTabTransfer = new InterTabTransfer(item, e.DragablzItem, breachOrientation.Value, dragStartWindowOffset, e.DragablzItem.MouseAtDragStart, dragableItemHeaderPoint, dragableItemSize, floatingItemSnapShots); if (myWindow.WindowState == WindowState.Maximized) { var desktopMousePosition = Native.GetCursorPos().ToWpf(); newTabHost.Container.Left = desktopMousePosition.X - dragStartWindowOffset.X; newTabHost.Container.Top = desktopMousePosition.Y - dragStartWindowOffset.Y; } else { newTabHost.Container.Left = myWindow.Left; newTabHost.Container.Top = myWindow.Top; } newTabHost.Container.Show(); var contentPresenter = FindChildContentPresenter(item); RemoveFromSource(item); _itemsHolder.Children.Remove(contentPresenter); if (Items.Count == 0) Layout.ConsolidateBranch(this); RestorePreviousSelection(); foreach (var dragablzItem in _dragablzItemsControl.DragablzItems()) { dragablzItem.IsDragging = false; dragablzItem.IsSiblingDragging = false; } newTabHost.TabablzControl.ReceiveDrag(interTabTransfer); interTabTransfer.OriginatorContainer.IsDropTargetFound = true; e.Cancel = true; }
private void ItemDragDelta(object sender, DragablzDragDeltaEventArgs e) { if (!IsMyItem(e.DragablzItem)) return; if (FixedHeaderCount > 0 && _dragablzItemsControl.ItemsOrganiser.Sort(_dragablzItemsControl.DragablzItems()) .Take(FixedHeaderCount) .Contains(e.DragablzItem)) return; if (_tabHeaderDragStartInformation != null && Equals(_tabHeaderDragStartInformation.DragItem, e.DragablzItem) && InterTabController != null) { if (InterTabController.InterTabClient == null) throw new InvalidOperationException("An InterTabClient must be provided on an InterTabController."); MonitorBreach(e); } }
private void PreviewItemDragDelta(object sender, DragablzDragDeltaEventArgs e) { if (_dragablzItemsControl == null) return; var sourceOfDragItemsControl = ItemsControlFromItemContainer(e.DragablzItem) as DragablzItemsControl; if (sourceOfDragItemsControl == null || !Equals(sourceOfDragItemsControl, _dragablzItemsControl)) return; if (!ShouldDragWindow(sourceOfDragItemsControl)) return; if (MonitorReentry(e)) return; var myWindow = Window.GetWindow(this); if (myWindow == null) return; if (_interTabTransfer != null) { var cursorPos = Native.GetCursorPos().ToWpf(); if (_interTabTransfer.BreachOrientation == Orientation.Vertical) { var vector = cursorPos - _interTabTransfer.DragStartWindowOffset; myWindow.Left = vector.X; myWindow.Top = vector.Y; } else { var offset = e.DragablzItem.TranslatePoint(_interTabTransfer.OriginatorContainer.MouseAtDragStart, myWindow); var borderVector = myWindow.PointToScreen(new Point()).ToWpf() - new Point(myWindow.Left, myWindow.Top); offset.Offset(borderVector.X, borderVector.Y); myWindow.Left = cursorPos.X - offset.X; myWindow.Top = cursorPos.Y - offset.Y; } } else { myWindow.Left += e.DragDeltaEventArgs.HorizontalChange; myWindow.Top += e.DragDeltaEventArgs.VerticalChange; } e.Handled = true; }
private bool MonitorReentry(DragablzDragDeltaEventArgs e) { var screenMousePosition = _dragablzItemsControl.PointToScreen(Mouse.GetPosition(_dragablzItemsControl)); var sourceTabablzControl = (TabablzControl) e.Source; if (sourceTabablzControl.Items.Count > 1 && e.DragablzItem.LogicalIndex < sourceTabablzControl.FixedHeaderCount) { return false; } var otherTabablzControls = LoadedInstances .Where( tc => tc != this && tc.InterTabController != null && InterTabController != null && Equals(tc.InterTabController.Partition, InterTabController.Partition)) .Select(tc => { var topLeft = tc._dragablzItemsControl.PointToScreen(new Point()); var lastFixedItem = tc._dragablzItemsControl.DragablzItems() .OrderBy(di=> di.LogicalIndex) .Take(tc._dragablzItemsControl.FixedItemCount) .LastOrDefault(); //TODO work this for vert tabs if (lastFixedItem != null) topLeft.Offset(lastFixedItem.X + lastFixedItem.ActualWidth, 0); var bottomRight = tc._dragablzItemsControl.PointToScreen(new Point(tc._dragablzItemsControl.ActualWidth, tc._dragablzItemsControl.ActualHeight)); return new {tc, topLeft, bottomRight}; }); var target = Native.SortWindowsTopToBottom(Application.Current.Windows.OfType<Window>()) .Join(otherTabablzControls, w => w, a => Window.GetWindow(a.tc), (w, a) => a) .FirstOrDefault(a => new Rect(a.topLeft, a.bottomRight).Contains(screenMousePosition)); if (target != null) { var mousePositionOnItem = Mouse.GetPosition(e.DragablzItem); var floatingItemSnapShots = this.VisualTreeDepthFirstTraversal() .OfType<Layout>() .SelectMany(l => l.FloatingDragablzItems().Select(FloatingItemSnapShot.Take)) .ToList(); e.DragablzItem.IsDropTargetFound = true; var item = RemoveItem(e.DragablzItem); var interTabTransfer = new InterTabTransfer(item, e.DragablzItem, mousePositionOnItem, floatingItemSnapShots); e.DragablzItem.IsDragging = false; target.tc.ReceiveDrag(interTabTransfer); e.Cancel = true; return true; } return false; }
private void ItemDragDelta(object sender, DragablzDragDeltaEventArgs eventArgs) { var bounds = new Size(ItemsPresenterWidth, ItemsPresenterHeight); var desiredLocation = new Point( eventArgs.DragablzItem.X + eventArgs.DragDeltaEventArgs.HorizontalChange, eventArgs.DragablzItem.Y + eventArgs.DragDeltaEventArgs.VerticalChange ); if (ItemsOrganiser != null) { if (FixedItemCount > 0 && ItemsOrganiser.Sort(DragablzItems()).Take(FixedItemCount).Contains(eventArgs.DragablzItem)) { eventArgs.Handled = true; return; } desiredLocation = ItemsOrganiser.ConstrainLocation(this, bounds, new Point(eventArgs.DragablzItem.X, eventArgs.DragablzItem.Y), new Size(eventArgs.DragablzItem.ActualWidth, eventArgs.DragablzItem.ActualHeight), desiredLocation, eventArgs.DragablzItem.DesiredSize); } eventArgs.DragablzItem.X = desiredLocation.X; eventArgs.DragablzItem.Y = desiredLocation.Y; if (ItemsOrganiser != null) ItemsOrganiser.OrganiseOnDrag( this, bounds, DragablzItems().Except(new[] {eventArgs.DragablzItem}), eventArgs.DragablzItem); eventArgs.DragablzItem.BringIntoView(); eventArgs.Handled = true; }
protected void OnPreviewDragDelta(DragablzDragDeltaEventArgs e) { RaiseEvent(e); }
private void ThumbOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs) { var thumb = (Thumb) sender; var previewEventArgs = new DragablzDragDeltaEventArgs(PreviewDragDelta, this, dragDeltaEventArgs); OnPreviewDragDelta(previewEventArgs); if (previewEventArgs.Cancel) thumb.CancelDrag(); if (!previewEventArgs.Handled) { var eventArgs = new DragablzDragDeltaEventArgs(DragDelta, this, dragDeltaEventArgs); OnDragDelta(eventArgs); if (eventArgs.Cancel) thumb.CancelDrag(); } }
protected void OnPreviewDragDelta(DragablzDragDeltaEventArgs e) { RaiseEvent(e); }
private void MonitorBreach(DragablzDragDeltaEventArgs e) { var mousePosition = Mouse.GetPosition(_dragablzItemsControl); Orientation?breachOrientation = null; if (mousePosition.X < -InterTabController.HorizontalPopoutGrace || (mousePosition.X - _dragablzItemsControl.ActualWidth) > InterTabController.HorizontalPopoutGrace) { breachOrientation = Orientation.Horizontal; } else if (mousePosition.Y < -InterTabController.VerticalPopoutGrace || (mousePosition.Y - _dragablzItemsControl.ActualHeight) > InterTabController.VerticalPopoutGrace) { breachOrientation = Orientation.Vertical; } if (breachOrientation.HasValue) { var newTabHost = InterTabController.InterTabClient.GetNewHost(InterTabController.InterTabClient, InterTabController.Partition, this); if (newTabHost == null || newTabHost.TabablzControl == null || newTabHost.Container == null) { throw new ApplicationException("New tab host was not correctly provided"); } var item = _dragablzItemsControl.ItemContainerGenerator.ItemFromContainer(e.DragablzItem); var myWindow = Window.GetWindow(this); if (myWindow == null) { throw new ApplicationException("Unable to find owning window."); } newTabHost.Container.Width = myWindow.RestoreBounds.Width; newTabHost.Container.Height = myWindow.RestoreBounds.Height; var dragStartWindowOffset = e.DragablzItem.TranslatePoint(new Point(), myWindow); dragStartWindowOffset.Offset(e.DragablzItem.MouseAtDragStart.X, e.DragablzItem.MouseAtDragStart.Y); var borderVector = myWindow.PointToScreen(new Point()) - new Point(myWindow.Left, myWindow.Top); dragStartWindowOffset.Offset(borderVector.X, borderVector.Y); var dragableItemHeaderPoint = e.DragablzItem.TranslatePoint(new Point(), _dragablzItemsControl); var dragableItemSize = new Size(e.DragablzItem.ActualWidth, e.DragablzItem.ActualHeight); var interTabTransfer = new InterTabTransfer(item, e.DragablzItem, breachOrientation.Value, dragStartWindowOffset, e.DragablzItem.MouseAtDragStart, dragableItemHeaderPoint, dragableItemSize); newTabHost.Container.Left = myWindow.Left; newTabHost.Container.Top = myWindow.Top; newTabHost.Container.Show(); var contentPresenter = FindChildContentPresenter(item); RemoveFromSource(item); _itemsHolder.Children.Remove(contentPresenter); if (Items.Count == 0) { Layout.ConsolidateBranch(this); } if (_previousSelection != null && Items.Contains(_previousSelection)) { SelectedItem = _previousSelection; } else { SelectedItem = Items.OfType <object>().FirstOrDefault(); } foreach (var dragablzItem in _dragablzItemsControl.DragablzItems()) { dragablzItem.IsDragging = false; dragablzItem.IsSiblingDragging = false; } newTabHost.TabablzControl.ReceiveDrag(interTabTransfer); interTabTransfer.OriginatorContainer.IsDropTargetFound = true; e.Cancel = true; } }