Example #1
0
 /// <summary>
 /// Adds the specified <see cref="CalendarDayTop"/> as a passing one
 /// </summary>
 /// <param name="top"></param>
 internal void AddTopPassing(CalendarDayTop top)
 {
     if (!TopsPassing.Contains(top))
     {
         TopsPassing.Add(top);
     }
 }
Example #2
0
        /// <summary>
        /// Creates a new Day
        /// </summary>
        /// <param name="calendar">Calendar this day belongs to</param>
        /// <param name="date">Date of the day</param>
        /// <param name="index">Index of the day on the current calendar's view</param>
        internal CalendarDay(Calendar calendar, DateTime date, int index)
            : base(calendar)
        {
            _containedItems = new List <CalendarItem>();
            _calendar       = calendar;
            _dayTop         = new CalendarDayTop(this);
            _date           = date;
            _index          = index;

            UpdateUnits();
        }
Example #3
0
        /// <summary>
        /// Creates a new item on the current selection.
        /// If there's no selection, this will be ignored.
        /// </summary>
        /// <param name="itemText">Text of the item</param>
        /// <param name="editMode">If <c>true</c> activates the edit mode so user can edit the text of the item.</param>
        public void CreateItemOnSelection(string itemText, bool editMode)
        {
            if (SelectedElementEnd == null || SelectedElementStart == null)
            {
                return;
            }

            CalendarTimeScaleUnit unitEnd = SelectedElementEnd as CalendarTimeScaleUnit;
            CalendarDayTop        dayTop  = SelectedElementEnd as CalendarDayTop;
            CalendarDay           day     = SelectedElementEnd as CalendarDay;
            TimeSpan     duration         = unitEnd != null ? unitEnd.Duration : new TimeSpan(23, 59, 59);
            CalendarItem item             = new CalendarItem(this);

            DateTime dstart = SelectedElementStart.Date;
            DateTime dend   = SelectedElementEnd.Date;

            if (dend.CompareTo(dstart) < 0)
            {
                DateTime dtmp = dend;
                dend   = dstart;
                dstart = dtmp;
            }

            item.StartDate = dstart;
            item.EndDate   = dend.Add(duration);
            item.Text      = itemText;

            CalendarItemCancelEventArgs evtA = new CalendarItemCancelEventArgs(item);

            OnItemCreating(evtA);

            if (!evtA.Cancel)
            {
                Items.Add(item);

                if (editMode)
                {
                    _creatingItem = true;
                    ActivateEditMode(item);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Informs elements who's selected and who's not, and repaints <see cref="_selectedElementSquare"/>
        /// </summary>
        private void UpdateSelectionElements()
        {
            CalendarTimeScaleUnit unitStart = _selectedElementStart as CalendarTimeScaleUnit;
            CalendarDayTop        topStart  = _selectedElementStart as CalendarDayTop;
            CalendarDay           dayStart  = _selectedElementStart as CalendarDay;
            CalendarTimeScaleUnit unitEnd   = _selectedElementEnd as CalendarTimeScaleUnit;
            CalendarDayTop        topEnd    = _selectedElementEnd as CalendarDayTop;
            CalendarDay           dayEnd    = _selectedElementEnd as CalendarDay;

            ClearSelectedComponents();

            if (_selectedElementEnd == null || _selectedElementStart == null)
            {
                return;
            }

            if (_selectedElementEnd.CompareTo(SelectedElementStart) < 0)
            {
                //swap
                unitStart = _selectedElementEnd as CalendarTimeScaleUnit;
                topStart  = _selectedElementEnd as CalendarDayTop;
                dayStart  = _selectedElementEnd as CalendarDay;
                unitEnd   = SelectedElementStart as CalendarTimeScaleUnit;
                topEnd    = SelectedElementStart as CalendarDayTop;
                dayEnd    = _selectedElementStart as CalendarDay;
            }

            if (unitStart != null && unitEnd != null)
            {
                bool reached = false;
                for (int i = unitStart.Day.Index; !reached; i++)
                {
                    for (int j = (i == unitStart.Day.Index ? unitStart.Index : 0); i < Days.Length && j < Days[i].TimeUnits.Length; j++)
                    {
                        CalendarTimeScaleUnit unit = Days[i].TimeUnits[j];
                        unit.SetSelected(true);
                        GrowSquare(unit.Bounds);
                        _selectedElements.Add(unit);

                        if (unit.Equals(unitEnd))
                        {
                            reached = true;
                            break;
                        }
                    }
                }
            }
            else if (topStart != null && topEnd != null)
            {
                for (int i = topStart.Day.Index; i <= topEnd.Day.Index; i++)
                {
                    CalendarDayTop top = Days[i].DayTop;

                    top.SetSelected(true);
                    GrowSquare(top.Bounds);
                    _selectedElements.Add(top);
                }
            }
            else if (dayStart != null && dayEnd != null)
            {
                for (int i = dayStart.Index; i <= dayEnd.Index; i++)
                {
                    CalendarDay day = Days[i];

                    day.SetSelected(true);
                    GrowSquare(day.Bounds);
                    _selectedElements.Add(day);
                }
            }

            InvalidateVisual(); // Invalidate(_selectedElementSquare);
        }
Example #5
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;
                }
            }
        }