示例#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);
        }
示例#2
0
        /// <summary>
        /// Updates the
        /// </summary>
        private void UpdateDaysAndWeeks()
        {
            TimeSpan span    = (new DateTime(ViewEnd.Year, ViewEnd.Month, ViewEnd.Day, 23, 59, 59)).Subtract(ViewStart.Date);
            int      preDays = 0;

            span = span.Add(new TimeSpan(0, 0, 0, 1, 0));

            if (span.Days < 1 || span.Days > MaximumViewDays)
            {
                throw new Exception("Days between ViewStart and ViewEnd should be between 1 and MaximumViewDays");
            }

            if (span.Days > MaximumFullDays)
            {
                SetDaysMode(CalendarDaysMode.Short);
                preDays = (new int[] { 0, 1, 2, 3, 4, 5, 6 })[(int)ViewStart.DayOfWeek] - (int)FirstDayOfWeek;
                span    = span.Add(new TimeSpan(preDays, 0, 0, 0));

                while (span.Days % 7 != 0)
                {
                    span = span.Add(new TimeSpan(1, 0, 0, 0));
                }
            }
            else
            {
                SetDaysMode(CalendarDaysMode.Expanded);
            }

            _days = new CalendarDay[span.Days];

            for (int i = 0; i < Days.Length; i++)
            {
                Days[i] = new CalendarDay(this, ViewStart.AddDays(-preDays + i), i);
            }


            //Weeks
            if (DaysMode == CalendarDaysMode.Short)
            {
                List <CalendarWeek> weeks = new List <CalendarWeek>();

                for (int i = 0; i < Days.Length; i++)
                {
                    if (Days[i].Date.DayOfWeek == FirstDayOfWeek)
                    {
                        weeks.Add(new CalendarWeek(this, Days[i].Date));
                    }
                }

                _weeks = weeks.ToArray();
            }
            else
            {
                _weeks = new CalendarWeek[] { };
            }

            UpdateHighlights();
        }
        /// <summary>
        /// Creates a new <see cref="CalendarTimeScaleUnit"/>
        /// </summary>
        /// <param name="day"><see cref="CalendarDay"/> this unit belongs to</param>
        /// <param name="index">Index of the unit relative to the container day</param>
        /// <param name="hours">Hour of the unit</param>
        /// <param name="minutes">Minutes of the unit</param>
        internal CalendarTimeScaleUnit(CalendarDay day, int index, int hours, int minutes)
            : base(day.Calendar)
        {
            _day     = day;
            _index   = index;
            _hours   = hours;
            _minutes = minutes;

            _passingItems = new List <CalendarItem>();
        }
示例#4
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);
                }
            }
        }
示例#5
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);
        }
示例#6
0
 /// <summary>
 /// Invalidates the bounds of the specified day
 /// </summary>
 /// <param name="day"></param>
 public void Invalidate(CalendarDay day)
 {
     InvalidateVisual(); // Invalidate(day.Bounds);
 }
 /// <summary>
 /// Creates a new <see cref="CalendarRendererDayEventArgs"/> object
 /// </summary>
 /// <param name="original">Orignal object to copy basic paramters</param>
 /// <param name="day">Day to render</param>
 public CalendarRendererDayEventArgs(CalendarRendererEventArgs original, CalendarDay day)
     : base(original)
 {
     _day = day;
 }
示例#8
0
 /// <summary>
 /// Creates a new DayTop for the specified day
 /// </summary>
 /// <param name="day"></param>
 public CalendarDayTop(CalendarDay day)
     : base(day.Calendar)
 {
     _day          = day;
     _passingItems = new List <CalendarItem>();
 }
 /// <summary>
 /// Creates a new event with the specified day
 /// </summary>
 /// <param name="day">Day of the event</param>
 public CalendarDayEventArgs(CalendarDay day)
 {
     _calendarDay = day;
 }