Exemplo n.º 1
0
        /// <summary>
        /// Exposed for testing purposes.
        /// </summary>
        internal void UpdateHoverDecoration(CalendarCellModel hoveredCellModel)
        {
            if (hoveredCellModel != null && hoveredCellModel == this.lastHoveredCell)
            {
                return;
            }

            this.cellsToUpdate.Clear();

            if (this.lastHoveredCell != null)
            {
                this.lastHoveredCell.IsPointerOver = false;
                this.cellsToUpdate.Add(this.lastHoveredCell);
            }

            this.lastHoveredCell = hoveredCellModel;

            if (hoveredCellModel != null)
            {
                hoveredCellModel.IsPointerOver = true;
                this.cellsToUpdate.Add(hoveredCellModel);
            }

            if (this.cellsToUpdate.Count > 0)
            {
                this.Owner.UpdatePresenters(this.cellsToUpdate);
            }
        }
        private void EnsureTodaySlot()
        {
            MultiDayViewSettings settings = this.Calendar.multiDayViewSettings;
            DateTime             today    = DateTime.Now.Date;

            if (this.todaySlot == null)
            {
                this.todaySlot       = new Slot();
                this.todaySlot.Start = today.AddTicks(settings.DayStartTime.Ticks);
                this.todaySlot.End   = today.AddTicks(settings.DayEndTime.Ticks);
            }

            double   startY  = this.DateToVerticalPosition(today, this.todaySlot.Start);
            DateTime endDate = this.todaySlot.End.TimeOfDay > settings.DayEndTime
                ? endDate = this.todaySlot.End.Add(TimeSpan.FromTicks(settings.DayEndTime.Ticks - this.todaySlot.End.TimeOfDay.Ticks))
                : endDate = this.todaySlot.End;

            double            endY      = this.DateToVerticalPosition(today, endDate);
            CalendarCellModel todayCell = this.CalendarCells.FirstOrDefault(a => a.Date == today);

            if (todayCell != null && startY < endY)
            {
                RadRect layoutSlot = new RadRect(todayCell.layoutSlot.X - this.timeRulerWidth, startY, todayCell.layoutSlot.Width, endY - startY);
                this.todaySlot.layoutSlot = layoutSlot;
            }
            else if (todayCell == null)
            {
                this.todaySlot.layoutSlot = RadRect.Empty;
            }
        }
        internal void InitSelection(CalendarCellModel cellModel)
        {
            this.selectOperation = new SelectOperation(cellModel);
            this.UpdateCellsIsSelectedFlags(this.selectOperation.CurrentSelectedRange, true);

            this.RefreshModifiedCells();
        }
Exemplo n.º 4
0
        private void EnsureCalendarCells()
        {
            if (this.calendarCells == null)
            {
                this.calendarCells = new ElementCollection <CalendarCellModel>(this);

                int itemCount = this.RowCount * this.ColumnCount;
                for (int cellIndex = 0; cellIndex < itemCount; cellIndex++)
                {
                    CalendarCellModel cell = new CalendarCellModel();

                    this.calendarCells.Add(cell);
                }
            }
            else
            {
                foreach (CalendarCellModel cell in this.calendarCells)
                {
                    cell.ClearValue(CalendarCellModel.IsBlackoutPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsHighlightedPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsSelectedPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsFromAnotherViewPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsCurrentPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsPointerOverPropertyKey);
                }
            }
        }
Exemplo n.º 5
0
        internal static Slot GetSlotFromPoint(Point hitPoint, ElementCollection <CalendarTimeRulerItem> calendarTimeRulerItems, ElementCollection <CalendarCellModel> calendarCells, int visibleDays)
        {
            Slot slot = new Slot();

            foreach (CalendarTimeRulerItem item in calendarTimeRulerItems)
            {
                if (item.layoutSlot.Y <= hitPoint.Y && item.layoutSlot.Y + item.layoutSlot.Height >= hitPoint.Y)
                {
                    int cellsCount = calendarCells.Count;
                    for (int i = 0; i < cellsCount; i++)
                    {
                        CalendarCellModel cell = calendarCells[i];
                        if (cell.layoutSlot.X <= hitPoint.X && cell.layoutSlot.X + cell.layoutSlot.Width >= hitPoint.X &&
                            i + visibleDays < cellsCount)
                        {
                            DateTime date      = cell.Date.AddDays(visibleDays);
                            TimeSpan startTime = item.StartTime;
                            slot.Start = new DateTime(date.Year, date.Month, date.Day, startTime.Hours, startTime.Minutes, startTime.Seconds);

                            TimeSpan endTime = item.EndTime;
                            slot.End = new DateTime(date.Year, date.Month, date.Day, endTime.Hours, endTime.Minutes, endTime.Seconds);
                        }
                    }
                }
            }

            return(slot);
        }
Exemplo n.º 6
0
        internal override void PrepareCalendarCell(CalendarCellModel cell, DateTime date)
        {
            cell.Date  = date;
            cell.Label = string.Format(this.Calendar.Culture, this.Calendar.MonthViewCellFormat, date);

            cell.IsFromAnotherView = date.Month != this.Calendar.DisplayDate.Month;
        }
Exemplo n.º 7
0
        internal override void PrepareCalendarCell(CalendarCellModel cell, DateTime date)
        {
            cell.Date  = date;
            cell.Label = string.Format(this.Calendar.Culture, this.Calendar.CenturyViewCellFormat, date, date.AddYears(9));

            //// NOTE: With default (5x2) layout there are no cells from another view - consider adding this logic if option to change the layout is added.
        }
Exemplo n.º 8
0
        private void EnsureCalendarCells()
        {
            if (this.calendarCells == null || this.calendarCells.Count == 0)
            {
                if (this.calendarCells == null)
                {
                    this.calendarCells = new ElementCollection <CalendarCellModel>(this);
                }

                // New way of indexing cell models to support the ITableProvider and IGridProvider automation providers.
                for (int i = 0; i < this.RowCount; i++)
                {
                    for (int j = 0; j < this.ColumnCount + (this.BufferItemsCount * 2); j++)
                    {
                        CalendarCellModel cell = new CalendarCellModel(i, j);

                        this.calendarCells.Add(cell);
                    }
                }
            }
            else
            {
                foreach (CalendarCellModel cell in this.calendarCells)
                {
                    cell.ClearValue(CalendarCellModel.IsBlackoutPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsHighlightedPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsSelectedPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsFromAnotherViewPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsCurrentPropertyKey);
                    cell.ClearValue(CalendarCellModel.IsPointerOverPropertyKey);
                }
            }
        }
Exemplo n.º 9
0
        internal bool HandleCellTap()
        {
            bool handled = false;

            if (this.CurrentDate != DateTime.MinValue)
            {
                if (this.Owner.DisplayMode != CalendarDisplayMode.MonthView)
                {
                    this.Owner.RaiseMoveToLowerCommand(this.CurrentDate);

                    // CurrentDate is not changed but we need to update the visuals on view change.
                    this.AsyncUpdateCurrencyPresenters(this.CurrentDate, this.CurrentDate);
                }
                else
                {
                    // We are certain that for month view there is indeed calendar cell that represents the date in CurrentDate property.
                    CalendarCellModel currentCell = this.Owner.GetCellByDate(this.CurrentDate);
                    if (currentCell != null)
                    {
                        this.Owner.RaiseCellTapCommand(currentCell);
                    }
                }

                handled = true;
            }

            return(handled);
        }
Exemplo n.º 10
0
 internal void ClearHoverState()
 {
     if (this.lastHoveredCell != null)
     {
         this.lastHoveredCell.IsPointerOver = false;
         this.lastHoveredCell = null;
     }
 }
Exemplo n.º 11
0
        internal void SelectCell(CalendarCellModel currentModelSelected)
        {
            this.lastPivotIndex = currentModelSelected.CollectionIndex;

            this.UpdateCellsToRefresh(this.CurrentSelectedRange, this.lastPivotIndex);

            this.UpdateCurrentRange(this.lastPivotIndex);
        }
Exemplo n.º 12
0
        public SelectOperation(CalendarCellModel startCell)
        {
            this.firstCellIndex = startCell.CollectionIndex;
            this.lastPivotIndex = startCell.CollectionIndex;

            this.CellRangeToRefresh   = new Tuple <int, int>(this.firstCellIndex, this.firstCellIndex);
            this.CurrentSelectedRange = new Tuple <int, int>(this.firstCellIndex, this.firstCellIndex);
        }
Exemplo n.º 13
0
        private FrameworkElement GetCalendarCellVisual(CalendarCellModel cell)
        {
            if (ShouldRenderDefaultVisual(cell))
            {
                return(this.GetDefaultVisual(cell));
            }

            return(this.GetTemplatedVisual(cell));
        }
        /// <summary>
        /// Evaluates the appearance settings to be applied on the respective calendar appointment control.
        /// </summary>
        /// <param name="context">The CalendarAppointmentInfo context.</param>
        /// <param name="cell">The CalendarCellModel cell.</param>
        public DataTemplate SelectTemplate(CalendarAppointmentInfo context, CalendarCellModel cell)
        {
            if (cell == null)
            {
                return(null);
            }

            return(this.SelectTemplateCore(context, cell));
        }
Exemplo n.º 15
0
        internal bool ShouldDeselectCell(CalendarCellModel cell)
        {
            // NOTE: Ignore time part for calendar calculations.
            if (this.selectedDateRanges.Count == 1 && this.selectedDateRanges[0].StartDate.Date == this.selectedDateRanges[0].EndDate.Date)
            {
                return(this.Owner.GetCellByDate(this.selectedDateRanges[0].StartDate) == cell);
            }

            return(false);
        }
Exemplo n.º 16
0
        internal void ArrangeCalendarContent(RadRect rect)
        {
            this.EnsureCalendarCells();

            double cellWidth = rect.Width / (this.ColumnCount + (this.BufferItemsCount * 2));

            if (this.SpecificColumnCount == 0)
            {
                this.SpecificColumnCount = this.RowCount;
            }

            double cellHeight = rect.Height / this.SpecificColumnCount;

            DateTime dateToRender = this.GetFirstDateToRender(this.Calendar.DisplayDate);

            int bufferItemsCount = this.BufferItemsCount;

            if (bufferItemsCount > 0)
            {
                dateToRender = dateToRender.AddDays(-bufferItemsCount);
            }

            int    itemIndex      = 0;
            double previousRight  = rect.X;
            double previousBottom = rect.Y;

            for (int rowIndex = 0; rowIndex < this.RowCount; rowIndex++)
            {
                previousRight = rect.X;

                for (int columnIndex = 0; columnIndex < this.ColumnCount + (bufferItemsCount * 2); columnIndex++)
                {
                    CalendarCellModel calendarCell = this.CalendarCells[itemIndex];

                    this.PrepareCalendarCell(calendarCell, dateToRender);

                    double horizontalDifference = columnIndex * cellWidth - previousRight + rect.X;
                    double verticalDifference   = rowIndex * cellHeight - previousBottom + rect.Y;

                    calendarCell.Arrange(new RadRect(previousRight, previousBottom, cellWidth + horizontalDifference, cellHeight + verticalDifference));

                    previousRight = calendarCell.layoutSlot.Right;
                    if (columnIndex == (this.ColumnCount + (bufferItemsCount * 2)) - 1)
                    {
                        previousBottom = calendarCell.layoutSlot.Bottom;
                    }

                    this.SnapToGridLines(calendarCell, rowIndex, columnIndex);

                    dateToRender = this.GetNextDateToRender(dateToRender);
                    itemIndex++;
                }
            }
        }
Exemplo n.º 17
0
        private static void ApplyStyleToDefaultVisual(TextBlock visual, CalendarCellModel cell)
        {
            Style cellStyle = cell.Context.GetEffectiveCellContentStyle();

            if (cellStyle == null)
            {
                return;
            }

            visual.Style = cellStyle;
        }
Exemplo n.º 18
0
        private FrameworkElement GetTemplatedVisual(CalendarCellModel cell)
        {
            DataTemplate     cellTemplate    = cell.Context.CellTemplate;
            FrameworkElement templatedVisual = cellTemplate.LoadContent() as FrameworkElement;

            if (templatedVisual == null)
            {
                return(null);
            }

            templatedVisual.DataContext = cell;

            this.AddVisualChild(templatedVisual);
            this.realizedCalendarCellTemplatedPresenters.Add(cell, templatedVisual);

            return(templatedVisual);
        }
Exemplo n.º 19
0
        private void ArrangeCalendarColumnHeaders(RadRect viewRect, ref int itemIndex)
        {
            CalendarModel model = this.Calendar;

            if (!model.AreDayNamesVisible)
            {
                return;
            }

            double previousRight  = viewRect.X;
            double cellWidth      = viewRect.Width / (this.ColumnCount + (this.BufferItemsCount * 2));
            double cellHeight     = viewRect.Y;
            int    firstDayOfWeek = (int)model.Culture.DateTimeFormat.FirstDayOfWeek;

            for (int columnIndex = 0; columnIndex < this.ColumnCount + (this.BufferItemsCount * 2); columnIndex++)
            {
                CalendarHeaderCellModel calendarCell = this.calendarHeaderCells[itemIndex];
                calendarCell.Type = CalendarHeaderCellType.DayName;

                string label = string.Empty;
                if (model.DisplayMode != CalendarDisplayMode.MultiDayView)
                {
                    int dayNameIndex = (firstDayOfWeek + columnIndex) % this.ColumnCount;
                    label = this.GetFormattedDayName(dayNameIndex);
                }
                else
                {
                    CalendarCellModel cellOfHeader = this.CalendarCells.FirstOrDefault(a => a.ColumnIndex == columnIndex);
                    if (cellOfHeader != null)
                    {
                        label = this.GetFormattedDayName((int)cellOfHeader.Date.DayOfWeek);
                    }
                }

                calendarCell.Label = label;

                double horizontalDifference = columnIndex * cellWidth - previousRight + viewRect.X;
                calendarCell.Arrange(new RadRect(previousRight, 0d, cellWidth + horizontalDifference, cellHeight));

                this.SnapToGridLines(calendarCell, -1, columnIndex);

                itemIndex++;
                previousRight = calendarCell.layoutSlot.Right;
            }
        }
Exemplo n.º 20
0
        private void UpdatePointerOverCellDecoration(CalendarCellModel cell)
        {
            if (!cell.IsPointerOver || this.Owner.PointerOverCellStyle == null || this.Owner.PointerOverCellStyle.DecorationStyle == null)
            {
                return;
            }

            if (this.pointerOverCellDecorationVisual == null)
            {
                this.pointerOverCellDecorationVisual = this.CreateDecorationVisual();
            }

            this.pointerOverCellDecorationVisual.Tag = cell;
            this.pointerOverCellDecorationVisual.ClearValue(Border.VisibilityProperty);

            this.ApplyStyleToCellDecorationVisual(this.pointerOverCellDecorationVisual, this.Owner.PointerOverCellStyle.DecorationStyle);

            this.ArrangeCellDecoration(this.pointerOverCellDecorationVisual, cell.layoutSlot, cell.PointerOverDecorationZIndex);
        }
Exemplo n.º 21
0
        private void UpdateCurrentCellDecoration(CalendarCellModel cell)
        {
            if (!cell.IsCurrent || !this.Owner.ShouldRenderCurrentVisuals || this.Owner.CurrentCellStyle == null || this.Owner.CurrentCellStyle.DecorationStyle == null)
            {
                return;
            }

            if (this.currentCellDecorationVisual == null)
            {
                this.currentCellDecorationVisual = this.CreateDecorationVisual();
            }

            this.currentCellDecorationVisual.Tag = cell;
            this.currentCellDecorationVisual.ClearValue(Border.VisibilityProperty);

            this.ApplyStyleToCellDecorationVisual(this.currentCellDecorationVisual, this.Owner.CurrentCellStyle.DecorationStyle);

            this.ArrangeCellDecoration(this.currentCellDecorationVisual, cell.layoutSlot, cell.CurrentDecorationZIndex);
        }
Exemplo n.º 22
0
        private FrameworkElement GetDefaultVisual(CalendarCellModel cell)
        {
            TextBlock visual;

            if (this.recycledContainers.Count > 0)
            {
                visual = this.recycledContainers.Dequeue();
                visual.ClearValue(TextBlock.VisibilityProperty);
                this.realizedCalendarCellDefaultPresenters.Add(cell, visual);
            }
            else
            {
                visual = this.CreateDefaultVisual();
                this.realizedCalendarCellDefaultPresenters.Add(cell, visual);
            }

            XamlContentLayerHelper.PrepareDefaultVisual(visual, cell);

            return(visual);
        }
Exemplo n.º 23
0
        private void UpdatePresenters(DateTime oldCurrentDate, DateTime newCurrentDate)
        {
            if (this.currentCellsToUpdate == null)
            {
                this.currentCellsToUpdate = new List <CalendarCellModel>();
            }
            else
            {
                this.currentCellsToUpdate.Clear();
            }

            if (oldCurrentDate != DateTime.MinValue && oldCurrentDate != newCurrentDate)
            {
                oldCurrentDate = CalendarMathHelper.GetCellDateForViewLevel(oldCurrentDate, this.Owner.DisplayMode);
                CalendarCellModel previousCell = this.Owner.GetCellByDate(oldCurrentDate);
                if (previousCell != null)
                {
                    previousCell.IsCurrent = false;
                    this.currentCellsToUpdate.Add(previousCell);
                }
            }

            if (newCurrentDate != DateTime.MinValue)
            {
                newCurrentDate = CalendarMathHelper.GetCellDateForViewLevel(newCurrentDate, this.Owner.DisplayMode);
                if (newCurrentDate == oldCurrentDate && this.currentCellsToUpdate.Count > 0)
                {
                    return;
                }

                CalendarCellModel currentCell = this.Owner.GetCellByDate(newCurrentDate);
                if (currentCell != null)
                {
                    currentCell.IsCurrent = true;
                    this.currentCellsToUpdate.Add(currentCell);
                }
            }

            this.Owner.UpdatePresenters(this.currentCellsToUpdate);
        }
Exemplo n.º 24
0
        internal void ModifySelection(CalendarCellModel currentModelSelected)
        {
            if (this.selectOperation == null || !this.selectOperation.ShouldModifySelection(currentModelSelected))
            {
                return;
            }

            if (this.selectOperation.ShouldModifySelection(currentModelSelected))
            {
                this.Owner.VisualStateService.UpdateHoldDecoration(null);
            }

            this.selectOperation.SelectCell(currentModelSelected);

            this.UpdateCellsIsSelectedFlags(this.selectOperation.CellRangeToRefresh, false);
            this.UpdateCellsIsSelectedFlags(this.selectOperation.CurrentSelectedRange, true);

            this.UpdateSelectedCells();

            var cellsToUpdate = this.GetCellModelsByRange(this.selectOperation.CellRangeToRefresh);

            this.Owner.UpdatePresenters(cellsToUpdate);
        }
Exemplo n.º 25
0
        internal Tuple <int, int> GetVisibleSelectedIndicesFromRange(CalendarDateRange range)
        {
            CalendarCellModel firstVisibleCell = this.Owner.Model.CalendarCells[0];
            CalendarCellModel lastVisibleCell  = this.Owner.Model.CalendarCells[this.Owner.Model.CalendarCells.Count - 1];

            // NOTE: Ignore time part for calendar calculations.
            if (range.EndDate.Date < firstVisibleCell.Date || range.StartDate.Date > lastVisibleCell.Date)
            {
                return(null);
            }

            int firstCellIndex, lastCellIndex;

            if (range.StartDate.Date < firstVisibleCell.Date && range.EndDate.Date > lastVisibleCell.Date)
            {
                firstCellIndex = firstVisibleCell.CollectionIndex;
                lastCellIndex  = lastVisibleCell.CollectionIndex;
            }
            else if (range.StartDate.Date < firstVisibleCell.Date)
            {
                firstCellIndex = firstVisibleCell.CollectionIndex;
                lastCellIndex  = this.Owner.GetCellByDate(range.EndDate).CollectionIndex;
            }
            else if (range.EndDate.Date > lastVisibleCell.Date)
            {
                firstCellIndex = this.Owner.GetCellByDate(range.StartDate).CollectionIndex;
                lastCellIndex  = lastVisibleCell.CollectionIndex;
            }
            else
            {
                firstCellIndex = this.Owner.GetCellByDate(range.StartDate).CollectionIndex;
                lastCellIndex  = this.Owner.GetCellByDate(range.EndDate).CollectionIndex;
            }

            return(new Tuple <int, int>(firstCellIndex, lastCellIndex));
        }
Exemplo n.º 26
0
 internal abstract void PrepareCalendarCell(CalendarCellModel cell, DateTime date);
Exemplo n.º 27
0
 internal bool ShouldModifySelection(CalendarCellModel currentModelSelected)
 {
     return(this.lastPivotIndex != currentModelSelected.CollectionIndex);
 }
Exemplo n.º 28
0
 internal override void PrepareCalendarCell(CalendarCellModel cell, DateTime date)
 {
     cell.Date  = date;
     cell.Label = string.Format(this.Calendar.Culture, this.Calendar.YearViewCellFormat, date);
 }
Exemplo n.º 29
0
 private static bool ShouldRenderDefaultVisual(CalendarCellModel cell)
 {
     return(cell.Context.CellTemplate == null);
 }
Exemplo n.º 30
0
 internal void UpdateHoldDecoration(CalendarCellModel hoveredCellModel)
 {
     this.Owner.visualStateLayer.UpdateHoldDecoration(hoveredCellModel);
 }