Esempio n. 1
0
 /// <summary>
 /// Adds the specified unit as a passing unit
 /// </summary>
 /// <param name="calendarTimeScaleUnit"></param>
 internal void AddUnitPassing(CalendarTimeScaleUnit calendarTimeScaleUnit)
 {
     if (!UnitsPassing.Contains(calendarTimeScaleUnit))
     {
         UnitsPassing.Add(calendarTimeScaleUnit);
     }
 }
Esempio n. 2
0
        public override void OnDrawTimeScale(CalendarRendererEventArgs e)
        {
            int margin  = 5;
            int largeX1 = TimeScaleBounds.Left + margin;
            int largeX2 = TimeScaleBounds.Right - margin;
            int shortX1 = TimeScaleBounds.Left + TimeScaleBounds.Width / 2;
            int shortX2 = largeX2;
            int top     = 0;
            Pen p       = new Pen(ColorTable.TimeScaleLine);

            for (int i = 0; i < e.Calendar.Days[0].TimeUnits.Length; i++)
            {
                CalendarTimeScaleUnit unit = e.Calendar.Days[0].TimeUnits[i];

                if (!unit.Visible)
                {
                    continue;
                }

                top = unit.Bounds.Top;

                if (unit.Minutes == 0)
                {
                    e.DrawingContext.DrawLine(p, largeX1, top, largeX2, top);
                }
                else
                {
                    e.DrawingContext.DrawLine(p, shortX1, top, shortX2, top);
                }
            }

            if (e.Calendar.DaysMode == CalendarDaysMode.Expanded &&
                e.Calendar.Days != null &&
                e.Calendar.Days.Length > 0 &&
                e.Calendar.Days[0].TimeUnits != null &&
                e.Calendar.Days[0].TimeUnits.Length > 0
                )
            {
                top = e.Calendar.Days[0].BodyBounds.Top;

                //Timescale top line is full
                e.DrawingContext.DrawLine(p, TimeScaleBounds.Left, top, TimeScaleBounds.Right, top);
            }

            p.Dispose();

            base.OnDrawTimeScale(e);
        }
Esempio n. 3
0
        /// <summary>
        /// Ensures the scrolling shows the specified time unit. It doesn't affect View date ranges.
        /// </summary>
        /// <param name="unit">Unit to ensure visibility</param>
        public void EnsureVisible(CalendarTimeScaleUnit unit)
        {
            if (Days == null || Days.Length == 0)
            {
                return;
            }

            Rect view = Days[0].BodyBounds;

            if (unit.Bounds.Bottom > view.Bottom)
            {
                TimeUnitsOffset = -Convert.ToInt32(Math.Ceiling(unit.Date.TimeOfDay.TotalMinutes / (double)TimeScale))
                                  + Renderer.GetVisibleTimeUnits();
            }
            else if (unit.Bounds.Top < view.Top)
            {
                TimeUnitsOffset = -Convert.ToInt32(Math.Ceiling(unit.Date.TimeOfDay.TotalMinutes / (double)TimeScale));
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Updates the value of <see cref="TimeUnits"/> property
        /// </summary>
        internal void UpdateUnits()
        {
            int factor = 0;

            switch (Calendar.TimeScale)
            {
            case CalendarTimeScale.SixtyMinutes:    factor = 1;     break;

            case CalendarTimeScale.ThirtyMinutes:   factor = 2;     break;

            case CalendarTimeScale.FifteenMinutes:  factor = 4;     break;

            case CalendarTimeScale.TenMinutes:      factor = 6;     break;

            case CalendarTimeScale.SixMinutes:      factor = 10;    break;

            case CalendarTimeScale.FiveMinutes:     factor = 12;    break;

            default: throw new NotImplementedException("TimeScale not supported");
            }

            _timeUnits = new CalendarTimeScaleUnit[24 * factor];

            int hourSum = 0;
            int minSum  = 0;

            for (int i = 0; i < _timeUnits.Length; i++)
            {
                _timeUnits[i] = new CalendarTimeScaleUnit(this, i, hourSum, minSum);

                minSum += 60 / factor;

                if (minSum >= 60)
                {
                    minSum = 0;
                    hourSum++;
                }
            }

            UpdateHighlights();
        }
 public CalendarRendererTimeUnitEventArgs(CalendarRendererEventArgs original, CalendarTimeScaleUnit unit)
     : base(original)
 {
     _unit = unit;
 }
Esempio n. 7
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);
        }
Esempio n. 8
0
 /// <summary>
 /// Ivalidates the bounds of the specified unit
 /// </summary>
 /// <param name="unit"></param>
 public void Invalidate(CalendarTimeScaleUnit unit)
 {
     InvalidateVisual(); //Invalidate(unit.Bounds);
 }