Example #1
0
        void TimeLineControl_DragOver(object sender, DragEventArgs e)
        {
            //throw new NotImplementedException();
            TimeLineItemControl d = e.Data.GetData(typeof(TimeLineItemControl)) as TimeLineItemControl;
            if (d != null)
            {
                if (Manager != null)
                {
                    if (!Manager.CanAddToTimeLine(d.DataContext as ITimeLineDataItem))
                    {
                        e.Effects = DragDropEffects.None;
                        return;
                    }
                }
                e.Effects = DragDropEffects.Move;
                //this is an internal drag or a drag from another time line control
                if (DragAdorner == null)
                {
                    _dragAdorner = new TimeLineDragAdorner(d, ItemTemplate);

                }
                DragAdorner.MousePosition = e.GetPosition(d);
                DragAdorner.InvalidateVisual();

            }
            else
            {//GongSolutions.Wpf.DragDrop

                var d2 = e.Data.GetData("GongSolutions.Wpf.DragDrop");
                if (d2 != null)
                {
                    if (Manager != null)
                    {
                        if (!Manager.CanAddToTimeLine(d2 as ITimeLineDataItem))
                        {
                            e.Effects = DragDropEffects.None;
                            return;
                        }
                    }

                    e.Effects = DragDropEffects.Move;
                    if (DragAdorner == null)
                    {
                        //we are dragging from an external source and we don't have a timeline item control of any sort
                        Children.Remove(_tmpDraggAdornerControl);
                        //in order to get an adornment layer the control has to be somewhere
                        _tmpDraggAdornerControl = new TimeLineItemControl();
                        _tmpDraggAdornerControl.UnitSize = UnitSize;
                        Children.Add(_tmpDraggAdornerControl);
                        Canvas.SetLeft(_tmpDraggAdornerControl, -1000000);
                        _tmpDraggAdornerControl.DataContext = d2;
                        _tmpDraggAdornerControl.StartTime = StartDate;
                        _tmpDraggAdornerControl.InitializeDefaultLength();
                        _tmpDraggAdornerControl.ContentTemplate = ItemTemplate;

                        _dragAdorner = new TimeLineDragAdorner(_tmpDraggAdornerControl, ItemTemplate);
                    }
                    DragAdorner.MousePosition = e.GetPosition(_tmpDraggAdornerControl);
                    DragAdorner.InvalidateVisual();
                }
            }
            DragScroll(e);
        }
Example #2
0
        void TimeLineControl_Drop(object sender, DragEventArgs e)
        {
            DragAdorner = null;

            TimeLineItemControl dropper = e.Data.GetData(typeof(TimeLineItemControl)) as TimeLineItemControl;
            ITimeLineDataItem dropData = null;
            if (dropper == null)
            {
                //dropData = e.Data.GetData(typeof(ITimeLineDataItem)) as ITimeLineDataItem;
                dropData = e.Data.GetData("GongSolutions.Wpf.DragDrop") as ITimeLineDataItem;
                if (dropData != null)
                {
                    //I haven't figured out why but
                    //sometimes when dropping from an external source
                    //the drop event hits twice.
                    //that results in ugly duplicates ending up in the timeline
                    //and it is a mess.
                    if (Items.Contains(dropData))
                        return;
                    //create a new timeline item control from this data
                    dropper = CreateTimeLineItemControl(dropData);
                    dropper.StartTime = StartDate;
                    dropper.InitializeDefaultLength();
                    Children.Remove(_tmpDraggAdornerControl);
                    _tmpDraggAdornerControl = null;

                }
            }
            var dropX = e.GetPosition(this).X;
            int newIndex = GetDroppedNewIndex(dropX);
            var curData = dropper.DataContext as ITimeLineDataItem;
            var curIndex = Items.IndexOf(curData);
            if ((curIndex == newIndex || curIndex + 1 == newIndex) && dropData == null && dropper.Parent == this)//dropdata null is to make sure we aren't failing on adding a new data item into the timeline
            //dropper.parent==this makes it so that we allow a dropper control from another timeline to be inserted in at the start.
            {
                return;//our drag did nothing meaningful so we do nothing.
            }

            if (dropper != null)
            {
                DateTime start = (DateTime)GetValue(StartDateProperty);
                if (newIndex == 0)
                {
                    if (dropData == null)
                    {
                        RemoveTimeLineItemControl(dropper);
                    }
                    if (dropper.Parent != this && dropper.Parent is TimeLineControl)
                    {
                        var tlCtrl = dropper.Parent as TimeLineControl;
                        tlCtrl.RemoveTimeLineItemControl(dropper);
                    }
                    InsertTimeLineItemControlAt(newIndex, dropper);
                    dropper.MoveToNewStartTime(start);
                    MakeRoom(newIndex, dropper.Width);

                }
                else//we are moving this after something.
                {

                    //find out if we are moving the existing one back or forward.
                    var placeAfter = GetTimeLineItemControlAt(newIndex - 1);
                    if (placeAfter != null)
                    {
                        start = placeAfter.EndTime;
                        RemoveTimeLineItemControl(dropper);
                        if (curIndex < newIndex && curIndex >= 0)//-1 is on an insert in which case we definitely don't want to take off on our new index value
                        {
                            //we are moving forward.
                            newIndex--;//when we removed our item, we shifted our insert index back 1
                        }
                        if (dropper.Parent != null && dropper.Parent != this)
                        {
                            var ptl = dropper.Parent as TimeLineControl;
                            ptl.RemoveTimeLineItemControl(dropper);
                        }

                        InsertTimeLineItemControlAt(newIndex, dropper);
                        dropper.MoveToNewStartTime(start);
                        MakeRoom(newIndex, dropper.Width);
                    }
                }
            }
            //ReDrawChildren();
            DrawBackGround();
            e.Handled = true;
        }
Example #3
0
 void TimeLineControL_DragLeave(object sender, DragEventArgs e)
 {
     DragAdorner = null;
     Children.Remove(_tmpDraggAdornerControl);
     _tmpDraggAdornerControl = null;
 }