private List <CalendarDateRange> GetActualRangeForSingleSelection(CalendarDateRange range, int rangeStartIndex) { List <CalendarDateRange> rangesToSelect = new List <CalendarDateRange>(); // NOTE: Ignore time part for calendar calculations. if (range.StartDate.Date == range.EndDate.Date && (this.Count == 0 || this.dateRangesList[0] != range)) { CalendarCellModel firstVisibleCell = this.Owner.Model.CalendarCells[0]; CalendarCellModel lastVisibleCell = this.Owner.Model.CalendarCells[this.Owner.Model.CalendarCells.Count - 1]; CalendarCellModel cellToSelect = null; if (firstVisibleCell.Date <= range.StartDate.Date && range.StartDate.Date <= lastVisibleCell.Date) { cellToSelect = this.Owner.Model.CalendarCells[rangeStartIndex]; } if (cellToSelect == null || !cellToSelect.IsBlackout) { this.Clear(false); rangesToSelect.Add(range); } } return(rangesToSelect); }
internal void OnContentPanelTapped(TappedRoutedEventArgs e) { if (this.displayModeCache != CalendarDisplayMode.MultiDayView) { CalendarCellModel cellModel = HitTestService.GetCellFromPoint(e.GetPosition(this.contentLayer.VisualElement), this.Model.CalendarCells); if (cellModel == null) { return; } this.RaiseCellTapCommand(cellModel); } else { Point hitPoint = e.GetPosition(this.timeRulerLayer.contentPanel); CalendarMultiDayViewModel multiDayViewModel = this.model.multiDayViewModel; hitPoint.X += multiDayViewModel.timeRulerWidth; var slotContext = this.hitTestService.GetSlotContextFromPoint(hitPoint); if (slotContext != null) { this.commandService.ExecuteCommand(CommandId.TimeSlotTap, slotContext); } } }
internal CalendarCellModel GetCellModelByPoint(Point lastPointPosition) { var hitTestPoint = TruncateToBounds(this.contentLayer.VisualElement as FrameworkElement, lastPointPosition); CalendarCellModel cellModel = HitTestService.GetCellFromPoint(hitTestPoint, this.Model.CalendarCells); return(cellModel); }
internal void SplitRangeByDate(CalendarCellModel blackoutCell) { if (this.dateRangesList.Count == 0) { return; } int index = this.dateRangesList.BinarySearch(new CalendarDateRange(blackoutCell.Date, blackoutCell.Date)); if (index >= 0) { var rangeToResize = this.dateRangesList[index]; rangeToResize.StartDate = blackoutCell.Date.AddDays(1); } else { int currentIndex = ~index; if (currentIndex == 0) { return; } if (CalendarDateRangeCollection.DateIsInRange(blackoutCell.Date, this.dateRangesList[currentIndex - 1])) { this.SplitRanges(currentIndex - 1, blackoutCell.Date); } } }
internal CalendarCellModel GetCellModelByPosition(PointerRoutedEventArgs e) { Point currentPoint = e.GetCurrentPoint(this.contentLayer.VisualElement).Position; var hitTestPoint = TruncateToBounds(this.contentLayer.VisualElement as FrameworkElement, currentPoint); CalendarCellModel cellModel = HitTestService.GetCellFromPoint(hitTestPoint, this.Model.CalendarCells); return(cellModel); }
/// <summary> /// Performs the core action given the provided parameter. /// </summary> public override void Execute(object parameter) { base.Execute(parameter); CalendarCellTapContext context = parameter as CalendarCellTapContext; CalendarCellModel cellModel = context.CellModel; if (!cellModel.IsBlackout) { var calendar = this.Owner; if (calendar.DisplayMode == CalendarDisplayMode.MonthView) { bool appendToSelection = false; if (this.Owner.SelectionMode == CalendarSelectionMode.Multiple) { appendToSelection = KeyboardHelper.IsModifierKeyDown(VirtualKey.Control); } // If there is only one cell selected ,check if tap is on the same cell (prevent SelectionChanged for the same single cell). if (!appendToSelection && !calendar.SelectionService.ShouldDeselectCell(cellModel)) { calendar.SelectionService.ClearSelection(false); } // If cell is selected do not trigger selection again (only Clear and Navigation) if (!cellModel.IsSelected) { // SelectedDateRanges should not be cleared if Control key is down. if (appendToSelection) { calendar.SelectionService.Select(new CalendarDateRange(cellModel.Date, cellModel.Date)); } else { calendar.SelectionService.SelectCell(cellModel); } } calendar.RaiseMoveToDateCommand(cellModel.Date); } else { calendar.RaiseMoveToLowerCommand(cellModel.Date); } } if (this.Owner.CurrentDate != cellModel.Date) { this.Owner.CurrencyService.CurrentDate = cellModel.Date; this.Owner.FireAutomationFocusEvent(); } else { // CurrentDate is not changed but we need to update the visuals on view change. this.Owner.CurrencyService.AsyncUpdateCurrencyPresenters(this.Owner.CurrentDate, this.Owner.CurrentDate); } }
private List <CalendarDateRange> GetActualRangesForMultipleSelection(CalendarDateRange range, int rangeStartIndex, int rangeEndIndex) { List <CalendarDateRange> rangesToSelect = new List <CalendarDateRange>(); 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) { rangesToSelect.Add(range); } else { bool rangeInitialized = false; CalendarDateRange newRange = CalendarDateRange.Empty; if (range.StartDate.Date < firstVisibleCell.Date) { newRange.StartDate = range.StartDate; rangeInitialized = true; } for (int index = rangeStartIndex; index <= rangeEndIndex; index++) { if (!rangeInitialized && !this.Owner.Model.CalendarCells[index].IsBlackout) { newRange.StartDate = this.Owner.Model.CalendarCells[index].Date; rangeInitialized = true; continue; } if (this.Owner.Model.CalendarCells[index].IsBlackout && rangeInitialized) { newRange.EndDate = this.Owner.Model.CalendarCells[index - 1].Date; rangesToSelect.Add(newRange); rangeInitialized = false; } } if (rangeInitialized) { newRange.EndDate = this.Owner.Model.CalendarCells[rangeEndIndex].Date; if (range.EndDate.Date > lastVisibleCell.Date) { newRange.EndDate = range.EndDate; } rangesToSelect.Add(newRange); } } return(rangesToSelect); }
private CalendarCellInfoBaseAutomationPeer GetPeerByCurrentView(CalendarCellModel cellModel) { if (this.CalendarOwner.DisplayMode == CalendarDisplayMode.MonthView) { return(new CalendarSelectableCellnfoAutomationPeer(this, cellModel)); } else { return(new CalendarInvokableCellInfoAutomationPeer(this, cellModel)); } }
internal void OnContentPanelTapped(TappedRoutedEventArgs e) { CalendarCellModel cellModel = HitTestService.GetCellFromPoint(e.GetPosition(this.contentLayer.VisualElement), this.Model.CalendarCells); if (cellModel == null) { return; } this.RaiseCellTapCommand(cellModel); }
internal bool CanStartDrag(Point point) { CalendarCellModel cell = this.GetCellModelByPoint(point); if ((cell != null && !cell.IsBlackout) && this.SelectionMode == CalendarSelectionMode.Multiple && this.DisplayMode == CalendarDisplayMode.MonthView) { return(true); } return(false); }
internal void OnContentPanelPointerMoved(PointerRoutedEventArgs e, bool isDragging) { if (!isDragging) { this.OnContentPanelPointerOver(e); } else if (this.SelectionMode == CalendarSelectionMode.Multiple) { CalendarCellModel cellModel = this.GetCellModelByPosition(e); if (cellModel != null) { this.SelectionService.ModifySelection(cellModel); } } }
private CalendarSelectableCellnfoAutomationPeer GetOrCreatePeerFromDateTime(DateTime date) { CalendarSelectableCellnfoAutomationPeer peer = this.childrenCache.OfType <CalendarSelectableCellnfoAutomationPeer>().Where(x => x.CellModel.Date == date).FirstOrDefault(); if (peer == null && this.CalendarOwner.Model.CalendarCells != null) { CalendarCellModel model = this.CalendarOwner.Model.CalendarCells.Where(cell => cell.Date == date).FirstOrDefault(); if (model != null) { CalendarViewHostAutomationPeer hostPeer = (CalendarViewHostAutomationPeer)FrameworkElementAutomationPeer.FromElement(this.CalendarOwner.calendarViewHost); peer = new CalendarSelectableCellnfoAutomationPeer(hostPeer, model); this.childrenCache.Add(peer); } } return(peer); }
internal void RaiseCellTapCommand(CalendarCellModel cellModel) { this.CommandService.ExecuteCommand(CommandId.CellTap, new CalendarCellTapContext(cellModel)); }
/// <summary> /// Initializes a new instance of the <see cref="CalendarInvokableCellInfoAutomationPeer"/> class. /// </summary> /// <param name="parent">Parent CalendarViewHostAutomationPeer.</param> /// <param name="cellModel">The model of the calendar cell.</param> internal CalendarInvokableCellInfoAutomationPeer(CalendarViewHostAutomationPeer parent, CalendarCellModel cellModel) : base(parent, cellModel) { this.CalendarCellModel = cellModel; }
protected override DataTemplate SelectTemplateCore(CalendarAppointmentInfo context, CalendarCellModel cell) { if (string.IsNullOrEmpty(context.Subject)) { return(null); } if (context.Date.HasValue && context.Date.Value.Date == DateTime.Now.Date) { return(this.DefaultTemplate); } return(this.SpecialTemplate); }
/// <summary> /// Exposed for testing purposes. /// </summary> internal bool ProcessKeyDown(VirtualKey key) { if (!this.isCalendarViewFocused) { return(false); } bool handled = false; DateTime oldCurrentDate = this.CurrentDate; switch (key) { case VirtualKey.Left: { handled = this.CurrencyService.MoveCurrentToPrevious(KeyboardHelper.IsModifierKeyDown(VirtualKey.Control)); break; } case VirtualKey.Right: { handled = this.CurrencyService.MoveCurrentToNext(KeyboardHelper.IsModifierKeyDown(VirtualKey.Control)); break; } case VirtualKey.Up: { handled = this.CurrencyService.MoveCurrentUp(KeyboardHelper.IsModifierKeyDown(VirtualKey.Control)); break; } case VirtualKey.Down: { handled = this.CurrencyService.MoveCurrentDown(KeyboardHelper.IsModifierKeyDown(VirtualKey.Control)); break; } case VirtualKey.Home: { handled = this.CurrencyService.MoveCurrentToFirst(); break; } case VirtualKey.End: { handled = this.CurrencyService.MoveCurrentToLast(); break; } case VirtualKey.Enter: case VirtualKey.Space: { handled = this.CurrencyService.HandleCellTap(); break; } } // Shift Selection in Multiple SelectionMode. if (key != VirtualKey.Enter && key != VirtualKey.Space && KeyboardHelper.IsModifierKeyDown(VirtualKey.Shift) && !KeyboardHelper.IsModifierKeyDown(VirtualKey.Control) && oldCurrentDate != this.CurrentDate && this.SelectionMode == CalendarSelectionMode.Multiple) { CalendarCellModel oldCurrentModel = this.GetCellByDate(oldCurrentDate); CalendarCellModel newCurrentModel = this.GetCellByDate(this.CurrentDate); this.SelectionService.MakeRangeSelection(oldCurrentModel, newCurrentModel); } if (oldCurrentDate != this.CurrentDate) { this.FireAutomationFocusEvent(); } if (handled && this.FocusState != FocusState.Keyboard) { this.TryFocus(FocusState.Keyboard); } return(handled); }
private bool AreModelsEqual(CalendarNode a, CalendarCellModel b) { return(a.RowIndex == b.RowIndex && a.ColumnIndex == b.ColumnIndex && a.Label == b.Label); }
internal void RaiseCellPointerOverCommand(CalendarCellModel cellModel) { this.CommandService.ExecuteCommand(CommandId.CellPointerOver, cellModel); }