Exemplo n.º 1
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);

            ICalendarSelectableElement hitted = HitTest(e.GetPosition(this), State == CalendarState.DraggingTimeSelection);
            CalendarItem hittedItem           = hitted as CalendarItem;
            CalendarDay  hittedDay            = hitted as CalendarDay;
            bool         shiftPressed         = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

            switch (State)
            {
            case CalendarState.Idle:

                break;

            case CalendarState.DraggingTimeSelection:
                if (SelectedElementStart == null || (hitted != null && !SelectedElementEnd.Equals(hitted)))
                {
                    SelectedElementEnd = hitted;
                }
                if (hittedDay != null)
                {
                    if (hittedDay.HeaderBounds.Contains(e.GetPosition(this)))
                    {
                        OnDayHeaderClick(new CalendarDayEventArgs(hittedDay));
                    }
                }
                break;

            case CalendarState.DraggingItem:
                if (itemOnStateChanged)
                {
                    OnItemDatesChanged(new CalendarItemEventArgs(itemOnState));
                }
                break;

            case CalendarState.ResizingItem:
                if (itemOnStateChanged)
                {
                    OnItemDatesChanged(new CalendarItemEventArgs(itemOnState));
                }
                break;

            case CalendarState.EditingItemText:
                break;
            }

            if (itemOnState != null)
            {
                itemOnState.SetIsDragging(false);
                itemOnState.SetIsResizingEndDate(false);
                itemOnState.SetIsResizingStartDate(false);
                Invalidate(itemOnState);
                OnItemClick(new CalendarItemEventArgs(itemOnState));
                itemOnState = null;
            }
            SetState(CalendarState.Idle);
        }
Exemplo n.º 2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            ICalendarSelectableElement hitted = HitTest(e.GetPosition(this), State != CalendarState.Idle);
            CalendarItem   hittedItem         = hitted as CalendarItem;
            CalendarDayTop hittedTop          = hitted as CalendarDayTop;
            bool           shiftPressed       = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

            if (hitted != null)
            {
                switch (State)
                {
                case CalendarState.Idle:
                    Cursor should = Cursors.Arrow;

                    if (hittedItem != null)
                    {
                        if ((hittedItem.ResizeEndDateZone(e.GetPosition(this)) || hittedItem.ResizeStartDateZone(e.GetPosition(this))) && AllowItemResize)
                        {
                            should = hittedItem.IsOnDayTop || DaysMode == CalendarDaysMode.Short ? Cursors.SizeWE : Cursors.SizeNS;
                        }

                        OnItemMouseHover(new CalendarItemEventArgs(hittedItem));
                    }
                    if (!Cursor.Equals(should))
                    {
                        Cursor = should;
                    }
                    break;

                case CalendarState.DraggingTimeSelection:
                    if (SelectedElementStart != null && !SelectedElementEnd.Equals(hitted))
                    {
                        SelectedElementEnd = hitted;
                    }
                    break;

                case CalendarState.DraggingItem:
                    TimeSpan duration = itemOnState.Duration;
                    itemOnState.SetIsDragging(true);
                    itemOnState.StartDate = hitted.Date;
                    itemOnState.EndDate   = itemOnState.StartDate.Add(duration);
                    Renderer.PerformItemsLayout();
                    Invalidate();
                    itemOnStateChanged = true;
                    break;

                case CalendarState.ResizingItem:
                    if (itemOnState.IsResizingEndDate && hitted.Date.CompareTo(itemOnState.StartDate) >= 0)
                    {
                        itemOnState.EndDate = hitted.Date.Add(hittedTop != null || DaysMode == CalendarDaysMode.Short ? new TimeSpan(23, 59, 59) : Days[0].TimeUnits[0].Duration);
                    }
                    else if (itemOnState.IsResizingStartDate && hitted.Date.CompareTo(itemOnState.EndDate) <= 0)
                    {
                        itemOnState.StartDate = hitted.Date;
                    }
                    Renderer.PerformItemsLayout();
                    Invalidate();
                    itemOnStateChanged = true;
                    break;

                case CalendarState.EditingItemText:
                    break;
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            ICalendarSelectableElement hitted = HitTest(e.GetPosition(this));
            CalendarItem hittedItem           = hitted as CalendarItem;
            bool         shiftPressed         = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

            if (!Focused)
            {
                Focus();
            }

            switch (State)
            {
            case CalendarState.Idle:
                if (hittedItem != null)
                {
                    if (!shiftPressed)
                    {
                        ClearSelectedItems();
                    }

                    hittedItem.SetSelected(true);
                    Invalidate(hittedItem);
                    OnItemSelected(new CalendarItemEventArgs(hittedItem));

                    itemOnState        = hittedItem;
                    itemOnStateChanged = false;

                    if (AllowItemEdit)
                    {
                        if (itemOnState.ResizeStartDateZone(e.GetPosition(this)) && AllowItemResize)
                        {
                            SetState(CalendarState.ResizingItem);
                            itemOnState.SetIsResizingStartDate(true);
                        }
                        else if (itemOnState.ResizeEndDateZone(e.GetPosition(this)) && AllowItemResize)
                        {
                            SetState(CalendarState.ResizingItem);
                            itemOnState.SetIsResizingEndDate(true);
                        }
                        else
                        {
                            SetState(CalendarState.DraggingItem);
                        }
                    }

                    SetSelectionRange(null, null);
                }
                else
                {
                    ClearSelectedItems();

                    if (shiftPressed)
                    {
                        if (hitted != null && SelectedElementEnd == null && !SelectedElementEnd.Equals(hitted))
                        {
                            SelectedElementEnd = hitted;
                        }
                    }
                    else
                    {
                        if (SelectedElementStart == null || (hitted != null && !SelectedElementStart.Equals(hitted)))
                        {
                            SetSelectionRange(hitted, hitted);
                        }
                    }

                    SetState(CalendarState.DraggingTimeSelection);
                }
                break;

            case CalendarState.DraggingTimeSelection:
                break;

            case CalendarState.DraggingItem:
                break;

            case CalendarState.ResizingItem:
                break;

            case CalendarState.EditingItemText:
                break;
            }
        }