private DateTime?GetNextSelectedDate(DateTimeAutomationPeer currentDatePeer, bool isSelected) { DateTime startDate = (currentDatePeer != null) ? currentDatePeer.Date : OwningCalendar.DisplayDate; if (isSelected) { // If SelectedDates is empty or startDate is beyond last SelectedDate if (!OwningCalendar.SelectedDates.MaximumDate.HasValue || OwningCalendar.SelectedDates.MaximumDate <= startDate) { return(null); } // startDate is before first SelectedDate if (OwningCalendar.SelectedDates.MinimumDate.HasValue && startDate < OwningCalendar.SelectedDates.MinimumDate) { return(OwningCalendar.SelectedDates.MinimumDate); } } while (true) { startDate = startDate.AddDays(1); if (OwningCalendar.SelectedDates.Contains(startDate) == isSelected) { break; } } return(startDate); }
// Token: 0x0600252B RID: 9515 RVA: 0x000B3338 File Offset: 0x000B1538 protected override void SetFocusCore() { System.Windows.Controls.Calendar owningCalendar = this.OwningCalendar; if (owningCalendar.Focusable) { if (!owningCalendar.Focus()) { DateTime date; if (owningCalendar.SelectedDate != null && DateTimeHelper.CompareYearMonth(owningCalendar.SelectedDate.Value, owningCalendar.DisplayDateInternal) == 0) { date = owningCalendar.SelectedDate.Value; } else { date = owningCalendar.DisplayDate; } DateTimeAutomationPeer orCreateDateTimeAutomationPeer = this.GetOrCreateDateTimeAutomationPeer(date, owningCalendar.DisplayMode, false); FrameworkElement owningButton = orCreateDateTimeAutomationPeer.OwningButton; if (owningButton == null || !owningButton.IsKeyboardFocused) { throw new InvalidOperationException(SR.Get("SetFocusFailed")); } } return; } throw new InvalidOperationException(SR.Get("SetFocusFailed")); }
private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, CalendarMode buttonMode, bool addParentInfo) { DateTimeCalendarModePair dateTimeCalendarModePair = new DateTimeCalendarModePair(date, buttonMode); DateTimeAutomationPeer dateTimeAutomationPeer = null; this.DateTimePeers.TryGetValue(dateTimeCalendarModePair, out dateTimeAutomationPeer); if (dateTimeAutomationPeer == null) { dateTimeAutomationPeer = this.GetPeerFromWeakRefStorage(dateTimeCalendarModePair); if (dateTimeAutomationPeer != null && !addParentInfo) { dateTimeAutomationPeer.AncestorsInvalid = false; dateTimeAutomationPeer.ChildrenValid = false; } } if (dateTimeAutomationPeer == null) { dateTimeAutomationPeer = new DateTimeAutomationPeer(date, this.OwningCalendar, buttonMode); if (addParentInfo && dateTimeAutomationPeer != null) { dateTimeAutomationPeer.TrySetParentInfo(this); } } AutomationPeer wrapperPeer = dateTimeAutomationPeer.WrapperPeer; if (wrapperPeer != null) { wrapperPeer.EventsSource = dateTimeAutomationPeer; } return(dateTimeAutomationPeer); }
// Provides Peer if exist in Weak Reference Storage private DateTimeAutomationPeer GetPeerFromWeakRefStorage(DateTimeCalendarModePair dateTimeCalendarModePairKey) { DateTimeAutomationPeer returnPeer = null; WeakReference weakRefEP = null; WeakRefElementProxyStorage.TryGetValue(dateTimeCalendarModePairKey, out weakRefEP); if (weakRefEP != null) { ElementProxy provider = weakRefEP.Target as ElementProxy; if (provider != null) { returnPeer = PeerFromProvider(provider as IRawElementProviderSimple) as DateTimeAutomationPeer; if (returnPeer == null) { WeakRefElementProxyStorage.Remove(dateTimeCalendarModePairKey); } } else { WeakRefElementProxyStorage.Remove(dateTimeCalendarModePairKey); } } return(returnPeer); }
protected override void SetFocusCore() { System.Windows.Controls.Calendar owner = OwningCalendar; if (owner.Focusable) { if (!owner.Focus()) { DateTime focusedDate; // Focus should have moved to either SelectedDate or DisplayDate if (owner.SelectedDate.HasValue && DateTimeHelper.CompareYearMonth(owner.SelectedDate.Value, owner.DisplayDateInternal) == 0) { focusedDate = owner.SelectedDate.Value; } else { focusedDate = owner.DisplayDate; } DateTimeAutomationPeer focusedItem = GetOrCreateDateTimeAutomationPeer(focusedDate, owner.DisplayMode, /*addParentInfo*/ false); FrameworkElement focusedButton = focusedItem.OwningButton; if (focusedButton == null || !focusedButton.IsKeyboardFocused) { throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } } } else { throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } }
// Called by DateTimeAutomationPeer internal void AddProxyToWeakRefStorage(WeakReference wr, DateTimeAutomationPeer dateTimePeer) { DateTimeCalendarModePair key = new DateTimeCalendarModePair(dateTimePeer.Date, dateTimePeer.ButtonMode); if (GetPeerFromWeakRefStorage(key) == null) { WeakRefElementProxyStorage.Add(key, wr); } }
/// <summary>Retrieves an element by the specified property value.</summary> /// <param name="startAfterProvider">The item in the container after which to begin the search.</param> /// <param name="propertyId">The property that contains the value to retrieve.</param> /// <param name="value">The value to retrieve.</param> /// <returns>The first item that matches the search criterion; otherwise, <see langword="null" /> if no items match.</returns> // Token: 0x0600253B RID: 9531 RVA: 0x000B38D4 File Offset: 0x000B1AD4 IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfterProvider, int propertyId, object value) { DateTimeAutomationPeer dateTimeAutomationPeer = null; if (startAfterProvider != null) { dateTimeAutomationPeer = (base.PeerFromProvider(startAfterProvider) as DateTimeAutomationPeer); if (dateTimeAutomationPeer == null) { throw new InvalidOperationException(SR.Get("InavalidStartItem")); } } DateTime? dateTime = null; CalendarMode calendarMode; if (propertyId == SelectionItemPatternIdentifiers.IsSelectedProperty.Id) { calendarMode = CalendarMode.Month; dateTime = this.GetNextSelectedDate(dateTimeAutomationPeer, (bool)value); } else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) { DateTimeFormatInfo currentDateFormat = DateTimeHelper.GetCurrentDateFormat(); DateTime value2; if (DateTime.TryParse(value as string, currentDateFormat, DateTimeStyles.None, out value2)) { dateTime = new DateTime?(value2); } if (dateTime == null || (dateTimeAutomationPeer != null && dateTime <= dateTimeAutomationPeer.Date)) { throw new InvalidOperationException(SR.Get("CalendarNamePropertyValueNotValid")); } calendarMode = ((dateTimeAutomationPeer != null) ? dateTimeAutomationPeer.ButtonMode : this.OwningCalendar.DisplayMode); } else { if (propertyId != 0 && propertyId != AutomationElementIdentifiers.ControlTypeProperty.Id) { throw new ArgumentException(SR.Get("PropertyNotSupported")); } if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id && (int)value != ControlType.Button.Id) { return(null); } calendarMode = ((dateTimeAutomationPeer != null) ? dateTimeAutomationPeer.ButtonMode : this.OwningCalendar.DisplayMode); dateTime = this.GetNextDate(dateTimeAutomationPeer, calendarMode); } if (dateTime != null) { AutomationPeer orCreateDateTimeAutomationPeer = this.GetOrCreateDateTimeAutomationPeer(dateTime.Value, calendarMode); if (orCreateDateTimeAutomationPeer != null) { return(base.ProviderFromPeer(orCreateDateTimeAutomationPeer)); } } return(null); }
// Token: 0x06002529 RID: 9513 RVA: 0x000B319C File Offset: 0x000B139C protected override List <AutomationPeer> GetChildrenCore() { if (this.OwningCalendar.MonthControl == null) { return(null); } List <AutomationPeer> list = new List <AutomationPeer>(); Dictionary <DateTimeCalendarModePair, DateTimeAutomationPeer> dictionary = new Dictionary <DateTimeCalendarModePair, DateTimeAutomationPeer>(); AutomationPeer automationPeer = UIElementAutomationPeer.CreatePeerForElement(this.OwningCalendar.MonthControl.PreviousButton); if (automationPeer != null) { list.Add(automationPeer); } automationPeer = UIElementAutomationPeer.CreatePeerForElement(this.OwningCalendar.MonthControl.HeaderButton); if (automationPeer != null) { list.Add(automationPeer); } automationPeer = UIElementAutomationPeer.CreatePeerForElement(this.OwningCalendar.MonthControl.NextButton); if (automationPeer != null) { list.Add(automationPeer); } foreach (object obj in this.OwningGrid.Children) { UIElement uielement = (UIElement)obj; int num = (int)uielement.GetValue(Grid.RowProperty); if (this.OwningCalendar.DisplayMode == CalendarMode.Month && num == 0) { AutomationPeer automationPeer2 = UIElementAutomationPeer.CreatePeerForElement(uielement); if (automationPeer2 != null) { list.Add(automationPeer2); } } else { Button button = uielement as Button; if (button != null && button.DataContext is DateTime) { DateTime date = (DateTime)button.DataContext; DateTimeAutomationPeer orCreateDateTimeAutomationPeer = this.GetOrCreateDateTimeAutomationPeer(date, this.OwningCalendar.DisplayMode, false); list.Add(orCreateDateTimeAutomationPeer); DateTimeCalendarModePair key = new DateTimeCalendarModePair(date, this.OwningCalendar.DisplayMode); dictionary.Add(key, orCreateDateTimeAutomationPeer); } } } this.DateTimePeers = dictionary; return(list); }
// Token: 0x0600253C RID: 9532 RVA: 0x000B3A48 File Offset: 0x000B1C48 private DateTime?GetNextDate(DateTimeAutomationPeer currentDatePeer, CalendarMode currentMode) { DateTime?result = null; DateTime dateTime = (currentDatePeer != null) ? currentDatePeer.Date : this.OwningCalendar.DisplayDate; if (currentMode == CalendarMode.Month) { result = new DateTime?(dateTime.AddDays(1.0)); } else if (currentMode == CalendarMode.Year) { result = new DateTime?(dateTime.AddMonths(1)); } else if (currentMode == CalendarMode.Decade) { result = new DateTime?(dateTime.AddYears(1)); } return(result); }
private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, CalendarMode buttonMode, bool addParentInfo) { // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client DateTimeCalendarModePair key = new DateTimeCalendarModePair(date, buttonMode); DateTimeAutomationPeer peer = null; DateTimePeers.TryGetValue(key, out peer); if (peer == null) { peer = GetPeerFromWeakRefStorage(key); if (peer != null && !addParentInfo) { // As cached peer is getting used it must be invalidated. addParentInfo check ensures that call is coming from GetChildrenCore peer.AncestorsInvalid = false; peer.ChildrenValid = false; } } if (peer == null) { peer = new DateTimeAutomationPeer(date, OwningCalendar, buttonMode); // Sets hwnd and parent info if (addParentInfo) { if (peer != null) { peer.TrySetParentInfo(this); } } } // Set EventsSource if visual exists AutomationPeer wrapperPeer = peer.WrapperPeer; if (wrapperPeer != null) { wrapperPeer.EventsSource = peer; } return(peer); }
// Token: 0x0600253D RID: 9533 RVA: 0x000B3ABC File Offset: 0x000B1CBC private DateTime?GetNextSelectedDate(DateTimeAutomationPeer currentDatePeer, bool isSelected) { DateTime dateTime = (currentDatePeer != null) ? currentDatePeer.Date : this.OwningCalendar.DisplayDate; if (isSelected) { if (this.OwningCalendar.SelectedDates.MaximumDate == null || this.OwningCalendar.SelectedDates.MaximumDate <= dateTime) { return(null); } if (this.OwningCalendar.SelectedDates.MinimumDate != null && dateTime < this.OwningCalendar.SelectedDates.MinimumDate) { return(this.OwningCalendar.SelectedDates.MinimumDate); } } do { dateTime = dateTime.AddDays(1.0); }while (this.OwningCalendar.SelectedDates.Contains(dateTime) != isSelected); return(new DateTime?(dateTime)); }
private DateTime?GetNextDate(DateTimeAutomationPeer currentDatePeer, CalendarMode currentMode) { DateTime?nextDate = null; DateTime startDate = (currentDatePeer != null) ? currentDatePeer.Date : OwningCalendar.DisplayDate; if (currentMode == CalendarMode.Month) { nextDate = startDate.AddDays(1); } else if (currentMode == CalendarMode.Year) { nextDate = startDate.AddMonths(1); } else if (currentMode == CalendarMode.Decade) { nextDate = startDate.AddYears(1); } return(nextDate); }
internal void RaiseSelectionEvents(SelectionChangedEventArgs e) { int numSelected = OwningCalendar.SelectedDates.Count; int numAdded = e.AddedItems.Count; if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && numSelected == 1 && numAdded == 1) { DateTimeAutomationPeer peer = GetOrCreateDateTimeAutomationPeer((DateTime)e.AddedItems[0], CalendarMode.Month); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } else { if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)) { foreach (DateTime date in e.AddedItems) { DateTimeAutomationPeer peer = GetOrCreateDateTimeAutomationPeer(date, CalendarMode.Month); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } } } if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { foreach (DateTime date in e.RemovedItems) { DateTimeAutomationPeer peer = GetOrCreateDateTimeAutomationPeer(date, CalendarMode.Month); if (peer != null) { peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } }
// Token: 0x06002530 RID: 9520 RVA: 0x000B3504 File Offset: 0x000B1704 internal void RaiseSelectionEvents(SelectionChangedEventArgs e) { int count = this.OwningCalendar.SelectedDates.Count; int count2 = e.AddedItems.Count; if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && count == 1 && count2 == 1) { DateTimeAutomationPeer orCreateDateTimeAutomationPeer = this.GetOrCreateDateTimeAutomationPeer((DateTime)e.AddedItems[0], CalendarMode.Month); if (orCreateDateTimeAutomationPeer != null) { orCreateDateTimeAutomationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected); } } else if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)) { foreach (object obj in e.AddedItems) { DateTime date = (DateTime)obj; DateTimeAutomationPeer orCreateDateTimeAutomationPeer2 = this.GetOrCreateDateTimeAutomationPeer(date, CalendarMode.Month); if (orCreateDateTimeAutomationPeer2 != null) { orCreateDateTimeAutomationPeer2.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } } if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { foreach (object obj2 in e.RemovedItems) { DateTime date2 = (DateTime)obj2; DateTimeAutomationPeer orCreateDateTimeAutomationPeer3 = this.GetOrCreateDateTimeAutomationPeer(date2, CalendarMode.Month); if (orCreateDateTimeAutomationPeer3 != null) { orCreateDateTimeAutomationPeer3.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } }
// Token: 0x0600252E RID: 9518 RVA: 0x000B346C File Offset: 0x000B166C private DateTimeAutomationPeer GetPeerFromWeakRefStorage(DateTimeCalendarModePair dateTimeCalendarModePairKey) { DateTimeAutomationPeer dateTimeAutomationPeer = null; WeakReference weakReference = null; this.WeakRefElementProxyStorage.TryGetValue(dateTimeCalendarModePairKey, out weakReference); if (weakReference != null) { ElementProxy elementProxy = weakReference.Target as ElementProxy; if (elementProxy != null) { dateTimeAutomationPeer = (base.PeerFromProvider(elementProxy) as DateTimeAutomationPeer); if (dateTimeAutomationPeer == null) { this.WeakRefElementProxyStorage.Remove(dateTimeCalendarModePairKey); } } else { this.WeakRefElementProxyStorage.Remove(dateTimeCalendarModePairKey); } } return(dateTimeAutomationPeer); }
IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfterProvider, int propertyId, object value) { DateTimeAutomationPeer startAfterDatePeer = null; if (startAfterProvider != null) { startAfterDatePeer = PeerFromProvider(startAfterProvider) as DateTimeAutomationPeer; // if provider is not null, peer must exist if (startAfterDatePeer == null) { throw new InvalidOperationException(SR.Get(SRID.InavalidStartItem)); } } DateTime? nextDate = null; CalendarMode currentMode = 0; if (propertyId == SelectionItemPatternIdentifiers.IsSelectedProperty.Id) { currentMode = CalendarMode.Month; nextDate = GetNextSelectedDate(startAfterDatePeer, (bool)value); } else if (propertyId == AutomationElementIdentifiers.NameProperty.Id) { // finds the button for the given DateTime DateTimeFormatInfo format = DateTimeHelper.GetCurrentDateFormat(); DateTime parsedDate; if (DateTime.TryParse((value as string), format, System.Globalization.DateTimeStyles.None, out parsedDate)) { nextDate = parsedDate; } if (!nextDate.HasValue || (startAfterDatePeer != null && nextDate <= startAfterDatePeer.Date)) { throw new InvalidOperationException(SR.Get(SRID.CalendarNamePropertyValueNotValid)); } currentMode = (startAfterDatePeer != null) ? startAfterDatePeer.ButtonMode : OwningCalendar.DisplayMode; } else if (propertyId == 0 || propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id) { // propertyId = 0 returns the button next to the startAfter or the DisplayDate if startAfter is null // All items here are buttons, so same behaviour as propertyId = 0 if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id && (int)value != ControlType.Button.Id) { return(null); } currentMode = (startAfterDatePeer != null) ? startAfterDatePeer.ButtonMode : OwningCalendar.DisplayMode; nextDate = GetNextDate(startAfterDatePeer, currentMode); } else { throw new ArgumentException(SR.Get(SRID.PropertyNotSupported)); } if (nextDate.HasValue) { AutomationPeer nextPeer = GetOrCreateDateTimeAutomationPeer(nextDate.Value, currentMode); if (nextPeer != null) { return(ProviderFromPeer(nextPeer)); } } return(null); }
// Called by DateTimeAutomationPeer internal void AddProxyToWeakRefStorage(WeakReference wr, DateTimeAutomationPeer dateTimePeer) { DateTimeCalendarModePair key = new DateTimeCalendarModePair(dateTimePeer.Date, dateTimePeer.ButtonMode); if (GetPeerFromWeakRefStorage(key) == null) WeakRefElementProxyStorage.Add(key, wr); }
private DateTimeAutomationPeer GetOrCreateDateTimeAutomationPeer(DateTime date, CalendarMode buttonMode, bool addParentInfo) { // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client DateTimeCalendarModePair key = new DateTimeCalendarModePair(date, buttonMode); DateTimeAutomationPeer peer = null; DateTimePeers.TryGetValue(key, out peer); if (peer == null) { peer = GetPeerFromWeakRefStorage(key); if (peer != null && !addParentInfo) { // As cached peer is getting used it must be invalidated. addParentInfo check ensures that call is coming from GetChildrenCore peer.AncestorsInvalid = false; peer.ChildrenValid = false; } } if( peer == null ) { peer = new DateTimeAutomationPeer(date, OwningCalendar, buttonMode); // Sets hwnd and parent info if (addParentInfo) { if(peer != null) peer.TrySetParentInfo(this); } } // Set EventsSource if visual exists AutomationPeer wrapperPeer = peer.WrapperPeer; if (wrapperPeer != null) { wrapperPeer.EventsSource = peer; } return peer; }
private DateTime? GetNextDate(DateTimeAutomationPeer currentDatePeer, CalendarMode currentMode) { DateTime? nextDate = null; DateTime startDate = (currentDatePeer != null) ? currentDatePeer.Date : OwningCalendar.DisplayDate; if (currentMode == CalendarMode.Month) nextDate = startDate.AddDays(1); else if (currentMode == CalendarMode.Year) nextDate = startDate.AddMonths(1); else if (currentMode == CalendarMode.Decade) nextDate = startDate.AddYears(1); return nextDate; }
private DateTime? GetNextSelectedDate(DateTimeAutomationPeer currentDatePeer, bool isSelected) { DateTime startDate = (currentDatePeer != null) ? currentDatePeer.Date : OwningCalendar.DisplayDate; if (isSelected) { // If SelectedDates is empty or startDate is beyond last SelectedDate if (!OwningCalendar.SelectedDates.MaximumDate.HasValue || OwningCalendar.SelectedDates.MaximumDate <= startDate) { return null; } // startDate is before first SelectedDate if (OwningCalendar.SelectedDates.MinimumDate.HasValue && startDate < OwningCalendar.SelectedDates.MinimumDate) { return OwningCalendar.SelectedDates.MinimumDate; } } while (true) { startDate = startDate.AddDays(1); if (OwningCalendar.SelectedDates.Contains(startDate) == isSelected) { break; } } return startDate; }