public void MouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            Appointment selection = m_dayView.SelectedAppointment;

            UpdateCursor(e, selection);

            if ((selection == null) || selection.Locked || (m_mode == Mode.None))
            {
                return;
            }

            Rectangle viewrect = m_dayView.GetTrueRectangle();
            Rectangle fdrect   = m_dayView.GetFullDayApptsRectangle();

            if ((e.Button == System.Windows.Forms.MouseButtons.Left) &&
                (viewrect.Contains(e.Location) || fdrect.Contains(e.Location)))
            {
                // Get time at mouse position
                bool longAppt        = IsResizingLongAppt();
                bool ptInLongAptRect = fdrect.Contains(e.Location);

                DateTime dateAtCursor = m_dayView.GetDateTimeAt(e.X, e.Y, longAppt);

                switch (m_mode)
                {
                case Mode.Move:
                    if (!selection.IsLongAppt() && !ptInLongAptRect)
                    {
                        if (m_length == TimeSpan.Zero)
                        {
                            m_startDate = selection.StartDate;
                            m_length    = selection.Length;
                        }
                        else
                        {
                            DateTime startDate = dateAtCursor.Add(m_delta);
                            DateTime endDate   = startDate.Add(m_length);

                            if (startDate.Date < dateAtCursor.Date)
                            {
                                // User has dragged off the top
                                startDate = dateAtCursor.Date;
                                endDate   = startDate.Add(m_length);
                            }
                            else if (endDate > dateAtCursor.Date.AddDays(1))
                            {
                                // User has dragged off the bottom
                                startDate = endDate.Date.Subtract(m_length);
                                endDate   = (startDate + m_length);
                            }

                            // Handle horizontal drag
                            DateTime date     = m_dayView.GetDateAt(e.X, false);
                            DateTime datePrev = m_dayView.GetDateAt(m_lastMouseMove.X, false);

                            if (date != datePrev)
                            {
                                startDate = date.Date.Add(startDate.TimeOfDay);
                                endDate   = startDate.Add(m_length);
                            }

                            // Check for a change
                            if (startDate != selection.StartDate)
                            {
                                selection.StartDate = startDate;
                                selection.EndDate   = endDate;

                                m_dayView.Invalidate();
                                m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                            }
                        }
                    }
                    else if (selection.IsLongAppt() && ptInLongAptRect)
                    {
                        dateAtCursor = dateAtCursor.Add(m_delta);

                        int      hoursDiff = dateAtCursor.Subtract(selection.StartDate).Hours;
                        TimeSpan apptLen   = selection.Length;

                        if (hoursDiff != 0)
                        {
                            System.DateTime newStart = selection.StartDate.AddHours(hoursDiff);

                            if (newStart != selection.StartDate)
                            {
                                selection.StartDate = newStart;
                                selection.EndDate   = (newStart + apptLen);

                                m_dayView.Invalidate();
                                m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                            }
                        }
                    }
                    break;

                case Mode.ResizeBottom:
                    if (!ptInLongAptRect)
                    {
                        // Note: the current algorithm tends to 'floor' the time
                        // which makes selecting all the way to midnight tricky.
                        // We solve it by adding half the slot height to the
                        // mouse position
                        dateAtCursor = m_dayView.GetDateTimeAt(e.X, e.Y + m_dayView.SlotHeight, longAppt);

                        if (dateAtCursor == dateAtCursor.Date)
                        {
                            dateAtCursor = dateAtCursor.AddDays(1).AddSeconds(-1);
                        }

                        if (dateAtCursor > selection.StartDate)
                        {
                            if (SameDay(selection.EndDate, dateAtCursor))
                            {
                                selection.EndDate = dateAtCursor;

                                m_dayView.Invalidate();
                                m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                            }
                        }
                    }
                    break;

                case Mode.ResizeTop:
                    if (!ptInLongAptRect && (dateAtCursor < selection.EndDate))
                    {
                        if (selection.StartDate.Day == dateAtCursor.Day)
                        {
                            selection.StartDate = dateAtCursor;
                            m_dayView.Invalidate();
                            m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                        }
                    }
                    break;

                case Mode.ResizeLeft:
                    if (ptInLongAptRect && (dateAtCursor.Date < selection.EndDate.AddHours(-1)))
                    {
                        selection.StartDate = dateAtCursor;

                        m_dayView.Invalidate();
                        m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                    }
                    break;

                case Mode.ResizeRight:
                    if (ptInLongAptRect && (dateAtCursor >= selection.StartDate.AddHours(1)))
                    {
                        selection.EndDate = dateAtCursor;

                        m_dayView.Invalidate();
                        m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                    }
                    break;
                }

                m_lastMouseMove = e.Location;
            }
        }
Esempio n. 2
0
        public void MouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            Appointment selection = dayView.SelectedAppointment;
            Rectangle   viewrect  = dayView.GetTrueRectangle();
            Rectangle   fdrect    = dayView.GetFullDayApptsRectangle();

            if (viewrect.Contains(e.Location) || fdrect.Contains(e.Location))
            {
                if ((selection != null) && (!selection.Locked))
                {
                    switch (e.Button)
                    {
                    case System.Windows.Forms.MouseButtons.Left:

                        // Get time at mouse position
                        DateTime m_Date = dayView.GetTimeAt(e.X, e.Y);

                        switch (mode)
                        {
                        case Mode.Move:

                            // This works for regular (i.e. non full-day or multi-day appointments)

                            if (!selection.AllDayEvent && viewrect.Contains(e.Location))
                            {
                                // add delta value
                                m_Date = m_Date.Add(delta);

                                if (length == TimeSpan.Zero)
                                {
                                    startDate = selection.StartDate;
                                    length    = selection.EndDate - startDate;
                                }
                                else
                                {
                                    DateTime m_EndDate = m_Date.Add(length);

                                    if (m_EndDate.Day == m_Date.Day)
                                    {
                                        selection.StartDate = m_Date;
                                        selection.EndDate   = m_EndDate;
                                        dayView.Invalidate();
                                        dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                    }
                                }
                            }
                            else
                            {
                                if (fdrect.Contains(e.Location))
                                {
                                    m_Date = m_Date.Add(delta);

                                    int m_DateDiff = m_Date.Subtract(selection.StartDate).Days;

                                    if (m_DateDiff != 0)
                                    {
                                        if (selection.StartDate.AddDays(m_DateDiff) > dayView.StartDate)
                                        {
                                            selection.StartDate = selection.StartDate.AddDays(m_DateDiff);
                                            selection.EndDate   = selection.EndDate.AddDays(m_DateDiff);
                                            dayView.Invalidate();
                                            dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                        }
                                    }
                                }
                            }

                            break;

                        case Mode.ResizeBottom:

                            if (m_Date > selection.StartDate)
                            {
                                if (selection.EndDate.Day == m_Date.Day)
                                {
                                    selection.EndDate = m_Date;
                                    dayView.Invalidate();
                                    dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                }
                            }

                            break;

                        case Mode.ResizeTop:

                            if (m_Date < selection.EndDate)
                            {
                                if (selection.StartDate.Day == m_Date.Day)
                                {
                                    selection.StartDate = m_Date;
                                    dayView.Invalidate();
                                    dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                }
                            }
                            break;

                        case Mode.ResizeLeft:
                            if (m_Date.Date < selection.EndDate.Date)
                            {
                                selection.StartDate = m_Date.Date;
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }
                            break;

                        case Mode.ResizeRight:
                            if (m_Date.Date >= selection.StartDate.Date)
                            {
                                selection.EndDate = m_Date.Date.AddDays(1);
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }
                            break;
                        }

                        break;

                    default:

                        Mode tmpNode = GetMode(e);

                        switch (tmpNode)
                        {
                        case Mode.Move:
                            dayView.Cursor = System.Windows.Forms.Cursors.Default;
                            break;

                        case Mode.ResizeBottom:
                        case Mode.ResizeTop:
                            if (!selection.AllDayEvent)
                            {
                                dayView.Cursor = System.Windows.Forms.Cursors.SizeNS;
                            }
                            break;

                        case Mode.ResizeLeft:         // changed by Gimlei
                        case Mode.ResizeRight:
                            if (selection.AllDayEvent)
                            {
                                DayView.Cursor = System.Windows.Forms.Cursors.SizeWE;
                            }
                            break;
                        }

                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        virtual protected bool MoveAppointment(System.Windows.Forms.MouseEventArgs e)
        {
            Debug.Assert(CanModifyAppointment(e, true));

            if (m_mode != Mode.Move)
            {
                return(false);
            }

            Rectangle shortApptsRect = m_dayView.GetTrueRectangle();
            Rectangle longApptsRect  = m_dayView.GetFullDayApptsRectangle();

            if (!shortApptsRect.Contains(e.Location) && !longApptsRect.Contains(e.Location))
            {
                return(false);
            }

            Appointment selection = m_dayView.SelectedAppointment;

            bool longAppt          = IsEditingLongAppt;
            bool ptInLongApptsRect = longApptsRect.Contains(e.Location);

            bool shortAppt          = !longAppt;
            bool ptInShortApptsRect = !ptInLongApptsRect;

            // Get date/time at mouse position
            DateTime dateAtCursor = m_dayView.GetDateTimeAt(e.X, e.Y, longAppt);

            if (shortAppt && ptInShortApptsRect)
            {
                if (m_length == TimeSpan.Zero)
                {
                    m_startDate = selection.StartDate;
                    m_length    = selection.Length;
                }
                else
                {
                    DateTime startDate = dateAtCursor.Add(m_delta);
                    DateTime endDate   = startDate.Add(m_length);

                    if (startDate.Date < dateAtCursor.Date)
                    {
                        // User has dragged off the top
                        startDate = dateAtCursor.Date;
                        endDate   = startDate.Add(m_length);
                    }
                    else if (endDate > dateAtCursor.Date.AddDays(1))
                    {
                        // User has dragged off the bottom
                        startDate = endDate.Date.Subtract(m_length);
                        endDate   = (startDate + m_length);
                    }

                    // Handle horizontal drag
                    DateTime date     = m_dayView.GetDateAt(e.X, false);
                    DateTime datePrev = m_dayView.GetDateAt(m_lastMouseMove.X, false);

                    if (date != datePrev)
                    {
                        startDate = date.Date.Add(startDate.TimeOfDay);
                        endDate   = startDate.Add(m_length);
                    }

                    // Check for a change
                    if (startDate != selection.StartDate)
                    {
                        selection.StartDate = startDate;
                        selection.EndDate   = endDate;

                        return(true);
                    }
                }
            }
            else if (longAppt && ptInLongApptsRect)
            {
                dateAtCursor = dateAtCursor.Add(m_delta);

                int      hoursDiff = dateAtCursor.Subtract(selection.StartDate).Hours;
                TimeSpan apptLen   = selection.Length;

                if (hoursDiff != 0)
                {
                    System.DateTime newStart = selection.StartDate.AddHours(hoursDiff);

                    if (newStart != selection.StartDate)
                    {
                        selection.StartDate = newStart;
                        selection.EndDate   = (newStart + apptLen);

                        return(true);
                    }
                }
            }

            // all else
            return(false);
        }