예제 #1
0
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructs a DragEventArgs instance.
        /// </summary>
        /// <param name="data">
        /// The data object used in this drag drop operation.
        /// </param>
        /// <param name="dragDropKeyStates">
        /// The current state of the mouse button and modifier keys.
        /// </param>
        /// <param name="allowedEffects">
        /// Allowed effects of a drag-and-drop operation.
        /// </param>
        /// <param name="target">
        /// The target of the event.
        /// </param>
        /// <param name="point">
        /// The current mouse position of the target.
        /// </param>
        internal DragEventArgs(IDataObject data, DragDropKeyStates dragDropKeyStates, DragDropEffects allowedEffects, DependencyObject target, Point point)
        {
            if (!DragDrop.IsValidDragDropKeyStates(dragDropKeyStates))
            {
                Debug.Assert(false, "Invalid dragDropKeyStates");
            }

            if (!DragDrop.IsValidDragDropEffects(allowedEffects))
            {
                Debug.Assert(false, "Invalid allowedEffects");
            }

            if (target == null)
            {
                Debug.Assert(false, "Invalid target");
            }

            this._data = data;
            this._dragDropKeyStates = dragDropKeyStates;
            this._allowedEffects    = allowedEffects;
            this._target            = target;
            this._dropPoint         = point;
            this._effects           = allowedEffects;
        }
        private void OnDrop(object sender, DragDrop.DragEventArgs e)
        {
#if SILVERLIGHT
            var swimlane = e.Data as SwimlaneShapeBase;
#else
            var swimlane = (e.Data as DataObject).GetData(typeof(SwimlaneShapeBase)) as SwimlaneShapeBase;
#endif
            if (swimlane != null)
            {
                var transformedPoint = this.GetTransformedPoint(e.GetPosition(this));
                var newPosition = transformedPoint.Substract(swimlane.DragStartOffset);
                var oldPosition = swimlane.Position;
                var mainParent = swimlane.ParentContainer as MainContainerShapeBase;
                if (mainParent != null)
                {
                    var command = new UndoableDelegateCommand("Remove container from main",
                        new Action<object>((o) =>
                        {
                            swimlane.Position = newPosition;
                            mainParent.Items.Remove(swimlane);
                            mainParent.UpdateChildContainers();
                        }),
                           new Action<object>((o) =>
                           {
                               swimlane.Position = oldPosition;
                               mainParent.Items.Add(swimlane);
                               mainParent.UpdateChildContainers();
                           }));

                    this.UndoRedoService.ExecuteCommand(command);
                }
                else
                {
                    var command = new UndoableDelegateCommand("Remove container from main",
                                          new Action<object>((o) =>
                                          {
                                              swimlane.Position = newPosition;
                                          }),
                                          new Action<object>((o) =>
                                          {
                                              swimlane.Position = oldPosition;
                                          }));

                    this.UndoRedoService.ExecuteCommand(command);
                }
            }
        }
 private void OnDragEnterManager(object sender, DragDrop.DragEventArgs e)
 {
     if (this.GetSwimlane(e) != null)
         base.OnDragEnter(new DragItemsEventArgs());
 }
        protected override void OnManagerDrop(object sender, DragDrop.DragEventArgs e)
        {
            SwimlaneShapeBase swimlane = this.GetSwimlane(e);
            if (swimlane != null)
            {
                VisualStateManager.GoToState(this, "DropNormal", false);
                var tmpCollapsed = this.IsCollapsed;
                if (tmpCollapsed)
                    this.IsCollapsed = false;

                if (swimlane != null)
                    this.MoveTo(swimlane, this.Items.Count);

                this.TryToSelect();

                this.IsCollapsed = tmpCollapsed;

                e.Handled = true;
            }
        }
        protected MainContainerShapeBase GetMainContainer(DragDrop.DragEventArgs e)
        {
#if SILVERLIGHT
            var mainContainer = e.Data as MainContainerShapeBase;
#else
            var mainContainer = (e.Data as DataObject).GetData(typeof(MainContainerShapeBase)) as MainContainerShapeBase;
#endif
            if (mainContainer == null)
            {
#if SILVERLIGHT
                var data = e.Data is DiagramDropInfo ? e.Data : null;
#else
                var data = (e.Data as DataObject).GetData(typeof(DiagramDropInfo));
#endif
                if (data != null)
                {
                    var dropInfo = (DiagramDropInfo)data;
                    var items = Core.SerializationService.Default.DeserializeItems(dropInfo.Info, true);
                    return items.FirstOrDefault(i => i is MainContainerShapeBase) as MainContainerShapeBase;
                }
            }

            return mainContainer;
        }
        protected SwimlaneShapeBase GetSwimlane(DragDrop.DragEventArgs e)
        {
#if SILVERLIGHT
            var swimlane = e.Data as SwimlaneShapeBase;
#else
            var swimlane = (e.Data as DataObject).GetData(typeof(SwimlaneShapeBase)) as SwimlaneShapeBase;
#endif
            if (swimlane == null)
            {
#if SILVERLIGHT
                var data = e.Data is DiagramDropInfo ? e.Data : null;
#else
                var data = (e.Data as DataObject).GetData(typeof(DiagramDropInfo));
#endif
                if (data != null)
                {
                    var dropInfo = (DiagramDropInfo)data;
                    var items = Core.SerializationService.Default.DeserializeItems(dropInfo.Info, true);
                    return items.FirstOrDefault(i => i is SwimlaneShapeBase) as SwimlaneShapeBase;
                }
            }

            return swimlane;
        }
 private void OnDragLeaveManager(object sender, DragDrop.DragEventArgs e)
 {
     if (this.GetSwimlane(e) != null)
     {
         this.swimlaneDiagram.HideDragOverVisual();
     }
     else if (this.GetMainContainer(e) == null)
     {
         base.OnDragLeave(new DragItemsEventArgs());
     }
 }
        protected override void OnManagerDrop(object sender, DragDrop.DragEventArgs e)
        {
            this.swimlaneDiagram.HideDragOverVisual();

            SwimlaneShapeBase swimlane = this.GetSwimlane(e);
            if (swimlane != null && this != swimlane)
            {
                if (this.ParentMainContainer == null) return;

                var transformedPoint = (this.Diagram as RadDiagram).GetTransformedPoint(e.GetPosition(this.Diagram as UIElement));

                this.ParentMainContainer.MoveTo(swimlane, this.ContainerPosition);

                if (swimlane.IsPointOverHeaderElement(transformedPoint))
                    swimlane.keepBackground = true;

                e.Handled = true;
            }
            else if (this.GetMainContainer(e) == null)
            {
                base.OnManagerDrop(sender, e);
            }
        }