Esempio n. 1
0
        internal void ReceiveDrag(InterTabTransfer interTabTransfer)
        {
            var myWindow = Window.GetWindow(this);

            if (myWindow == null)
            {
                throw new ApplicationException("Unable to find owning window.");
            }
            myWindow.Activate();

            _interTabTransfer = interTabTransfer;

            if (Items.Count == 0)
            {
                _dragablzItemsControl.LockedMeasure = new Size(
                    interTabTransfer.ItemPositionWithinHeader.X + interTabTransfer.ItemSize.Width,
                    interTabTransfer.ItemPositionWithinHeader.Y + interTabTransfer.ItemSize.Height);
            }

            AddToSource(interTabTransfer.Item);
            SelectedItem = interTabTransfer.Item;

            Dispatcher.BeginInvoke(new Action(() => Layout.RestoreFloatingItemSnapShots(this, interTabTransfer.FloatingItemSnapShots)), DispatcherPriority.Loaded);

            _dragablzItemsControl.InstigateDrag(interTabTransfer.Item, newContainer =>
            {
                newContainer.PartitionAtDragStart = interTabTransfer.OriginatorContainer.PartitionAtDragStart;
                newContainer.IsDropTargetFound    = true;

                if (interTabTransfer.TransferReason == InterTabTransferReason.Breach)
                {
                    if (interTabTransfer.BreachOrientation == Orientation.Horizontal)
                    {
                        newContainer.Y = interTabTransfer.OriginatorContainer.Y;
                    }
                    else
                    {
                        newContainer.X = interTabTransfer.OriginatorContainer.X;
                    }
                }
                else
                {
                    var mouseXOnItemsControl = Native.GetCursorPos().X - _dragablzItemsControl.PointToScreen(new Point()).X;
                    newContainer.X           = mouseXOnItemsControl - interTabTransfer.DragStartItemOffset.X;
                    newContainer.Y           = 0;
                }
                newContainer.MouseAtDragStart = interTabTransfer.DragStartItemOffset;
            });
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
0
        private bool MonitorReentry(DockDragDeltaEventArgs e)
        {
            var screenMousePosition = MouseDevice.Instance.Position;

            var sourceDockControl = (DockControl)e.Source;

            if (((IList)sourceDockControl.Items).Count > 1 && e.DockItem.LogicalIndex < sourceDockControl.FixedHeaderCount)
            {
                return(false);
            }

            var otherDockControls = LoadedInstances
                                    .Where(
                dc =>
                dc != this && dc.InterTabController != null && InterTabController != null &&
                Equals(dc.InterTabController.Partition, InterTabController.Partition))
                                    .Select(dc =>
            {
                var topLeft       = dc._dockItemsControl.PointToScreen(new Point());
                var lastFixedItem = dc._dockItemsControl.DockItems()
                                    .OrderBy(di => di.LogicalIndex)
                                    .Take(dc._dockItemsControl.FixedItemCount)
                                    .LastOrDefault();

                if (lastFixedItem != null)
                {
                    topLeft.WithX(lastFixedItem.X + lastFixedItem.Width);
                }

                var bottomRight = dc.PointToScreen(new Point(dc._dockItemsControl.Width,
                                                             dc._dockItemsControl.Height));

                return(new { dc, topLeft, bottomRight });
            });

            // Perspex does not yet support iterating windows on top of this,
            // Perspex does not allow access to Application from the current library setup.
            Window target = null;

            // force fail for now
            if (target == null)
            {
                return(false);
            }

            var mousePositionOnItem = screenMousePosition * e.DockItem.TransformToVisual(e.DockItem);

            var floatingItemSnapShots = e.DockItem.GetVisualChildren().OfType <Layout>()
                                        .SelectMany(l => l.FloatingDockItems().Select(FloatingItemSnapShot.Take))
                                        .ToList();

            e.DockItem.IsDropTargetFound = true;
            var item = RemoveItem(e.DockItem);

            var interTabTransfer = new InterTabTransfer(item, e.DockItem, mousePositionOnItem.Value, floatingItemSnapShots);

            e.DockItem.IsDragging = false;

            //target.tc.RecieveDrag(interTabTransfer);
            e.Cancel = true;

            return(true);
        }