Example #1
0
        private void GanttRow_MouseMove(object sender, MouseEventArgs e)
        {
            _sameSizeCnt = 1;

            if (_ProcessingMove || IsReadOnly)
            {
                return;
            }
            else
            {
                _ProcessingMove = true;
            }

            Point cursorPosition = e.GetPosition(this.RootUI());

            List <GanttItem> items = ItemsPresenter.Children.OfType <GanttItem>().ToList();

            for (int i = 0; i < items.Count; i++)
            {
                GanttItem item = items[i];

                GeneralTransform gt           = item.TransformToVisual(this.RootUI());
                Point            itemPosition = gt.Transform(new Point(0, 0));

                double distance = 0d;
                distance = cursorPosition.X - _DragStart.X;

                if (item.DragState == DragState.ResizeLeft)
                {
                    Cursor = Cursors.SizeWE;
                }
                else if (item.DragState == DragState.ResizeRight)
                {
                    Cursor = Cursors.SizeWE;
                }
                else if (item.DragState == DragState.Whole)
                {
                    Cursor = Cursors.Hand;
                }
                else
                {
                    _ProcessingMove = false;
                    continue;
                }

                TimeSpan ts = GetTimeSpanFromDistance(distance);

#if DEBUG
                ParentPanel.Content = item.Name;
                ParentPanel.Content = distance.ToString() + "   " + ts.ToString() + " " + item.DragState.ToString();
#endif

                if (Math.Abs(ts.TotalDays) >= 1)
                {
                    if (item.DragState == DragState.ResizeLeft)
                    {
                        ParentPanel.RaiseItemChanging(new GanttItemEventArgs(item));
                        DateTime newDate = item.Section.StartDate.Add(ts);

                        if (newDate < item.Section.EndDate)
                        {
                            item.Section.StartDate = newDate;
                            item.InvalidateMeasure();

                            if (RowIndex > 0)
                            {
                                (ParentPanel.RowPresenter.Children[RowIndex - 1] as GanttRow).Invalidate();
                            }
                        }
                        ParentPanel.RaiseItemChanged(new GanttItemEventArgs(item));
                    }
                    else if (item.DragState == DragState.ResizeRight)
                    {
                        ParentPanel.RaiseItemChanging(new GanttItemEventArgs(item));
                        DateTime newDate = item.Section.EndDate.Add(ts);

                        if (newDate > item.Section.StartDate)
                        {
                            item.Section.EndDate = newDate;
                            item.InvalidateMeasure();

                            if (RowIndex > 0)
                            {
                                (ParentPanel.RowPresenter.Children[RowIndex - 1] as GanttRow).Invalidate();
                            }
                        }

                        ParentPanel.RaiseItemChanged(new GanttItemEventArgs(item));
                    }
                    else if (item.DragState == DragState.Whole)
                    {
                        ParentPanel.RaiseItemChanging(new GanttItemEventArgs(item));

                        DateTime newStart = item.Section.StartDate.Add(ts);
                        DateTime newEnd   = item.Section.EndDate.Add(ts);

                        if (distance > 0)
                        {
                            item.Section.EndDate   = newEnd;
                            item.Section.StartDate = newStart;
                        }
                        else
                        {
                            item.Section.StartDate = newStart;
                            item.Section.EndDate   = newEnd;
                        }
                        Invalidate();

                        // item.InvalidateArrange();
                        if (RowIndex > 0)
                        {
                            (ParentPanel.RowPresenter.Children[RowIndex - 1] as GanttRow).Invalidate();
                        }

                        ParentPanel.RaiseItemChanged(new GanttItemEventArgs(item));
                    }

                    _DragStart = e.GetPosition(this.RootUI());
                }
            }

            _ProcessingMove = false;
        }