// Token: 0x060057EE RID: 22510 RVA: 0x00185A70 File Offset: 0x00183C70
        internal static TextSearch EnsureInstance(ItemsControl itemsControl)
        {
            TextSearch textSearch = (TextSearch)itemsControl.GetValue(TextSearch.TextSearchInstanceProperty);

            if (textSearch == null)
            {
                textSearch = new TextSearch(itemsControl);
                itemsControl.SetValue(TextSearch.TextSearchInstancePropertyKey, textSearch);
            }
            return(textSearch);
        }
예제 #2
0
        /// <summary>
        ///     Get the instance of TextSearch attached to the given ItemsControl or make one and attach it if it's not.
        /// </summary>
        /// <param name="itemsControl"></param>
        /// <returns></returns>
        internal static TextSearch EnsureInstance(ItemsControl itemsControl)
        {
            TextSearch instance = (TextSearch)itemsControl.GetValue(TextSearchInstanceProperty);

            if (instance == null)
            {
                instance = new TextSearch(itemsControl);
                itemsControl.SetValue(TextSearchInstancePropertyKey, instance);
            }

            return(instance);
        }
예제 #3
0
        /// <summary> 
        ///     Get the instance of TextSearch attached to the given ItemsControl or make one and attach it if it's not.
        /// </summary> 
        /// <param name="itemsControl"></param> 
        /// <returns></returns>
        internal static TextSearch EnsureInstance(ItemsControl itemsControl) 
        {
            TextSearch instance = (TextSearch)itemsControl.GetValue(TextSearchInstanceProperty);

            if (instance == null) 
            {
                instance = new TextSearch(itemsControl); 
                itemsControl.SetValue(TextSearchInstancePropertyKey, instance); 
            }
 
            return instance;
        }
        // Token: 0x060057FD RID: 22525 RVA: 0x00186038 File Offset: 0x00184238
        internal static string GetPrimaryTextFromItem(ItemsControl itemsControl, object item)
        {
            if (item == null)
            {
                return(string.Empty);
            }
            BindingExpression bindingExpression = TextSearch.CreateBindingExpression(itemsControl, item, TextSearch.GetPrimaryTextPath(itemsControl));

            TextSearch.TextValueBindingExpression.SetValue(itemsControl, bindingExpression);
            string primaryText = TextSearch.GetPrimaryText(item, bindingExpression, itemsControl);

            TextSearch.TextValueBindingExpression.ClearValue(itemsControl);
            return(primaryText);
        }
        // Token: 0x060057FB RID: 22523 RVA: 0x00185FB0 File Offset: 0x001841B0
        private static string GetPrimaryText(object item, BindingExpression primaryTextBinding, DependencyObject primaryTextBindingHome)
        {
            DependencyObject dependencyObject = item as DependencyObject;

            if (dependencyObject != null)
            {
                string text = (string)dependencyObject.GetValue(TextSearch.TextProperty);
                if (!string.IsNullOrEmpty(text))
                {
                    return(text);
                }
            }
            if (primaryTextBinding != null && primaryTextBindingHome != null)
            {
                primaryTextBinding.Activate(item);
                object value = primaryTextBinding.Value;
                return(TextSearch.ConvertToPlainText(value));
            }
            return(TextSearch.ConvertToPlainText(item));
        }
        // Token: 0x060057F3 RID: 22515 RVA: 0x00185B20 File Offset: 0x00183D20
        internal bool DoSearch(string nextChar)
        {
            bool           lookForFallbackMatchToo = false;
            int            num   = 0;
            ItemCollection items = this._attachedTo.Items;

            if (this.IsActive)
            {
                num = this.MatchedItemIndex;
            }
            if (this._charsEntered.Count > 0 && string.Compare(this._charsEntered[this._charsEntered.Count - 1], nextChar, true, TextSearch.GetCulture(this._attachedTo)) == 0)
            {
                lookForFallbackMatchToo = true;
            }
            string primaryTextPath = TextSearch.GetPrimaryTextPath(this._attachedTo);
            bool   flag            = false;
            int    num2            = TextSearch.FindMatchingPrefix(this._attachedTo, primaryTextPath, this.Prefix, nextChar, num, lookForFallbackMatchToo, ref flag);

            if (num2 != -1)
            {
                if (!this.IsActive || num2 != num)
                {
                    object item = items[num2];
                    this._attachedTo.NavigateToItem(item, num2, new ItemsControl.ItemNavigateArgs(Keyboard.PrimaryDevice, ModifierKeys.None));
                    this.MatchedItemIndex = num2;
                }
                if (flag)
                {
                    this.AddCharToPrefix(nextChar);
                }
                if (!this.IsActive)
                {
                    this.IsActive = true;
                }
            }
            if (this.IsActive)
            {
                this.ResetTimeout();
            }
            return(num2 != -1);
        }
        // Token: 0x060057F7 RID: 22519 RVA: 0x00185E84 File Offset: 0x00184084
        internal static MatchedTextInfo FindMatchingPrefix(ItemsControl itemsControl, string prefix)
        {
            bool            flag = false;
            int             num  = TextSearch.FindMatchingPrefix(itemsControl, TextSearch.GetPrimaryTextPath(itemsControl), prefix, string.Empty, 0, false, ref flag);
            MatchedTextInfo result;

            if (num >= 0)
            {
                CultureInfo culture = TextSearch.GetCulture(itemsControl);
                bool        isTextSearchCaseSensitive = itemsControl.IsTextSearchCaseSensitive;
                string      primaryTextFromItem       = TextSearch.GetPrimaryTextFromItem(itemsControl, itemsControl.Items[num]);
                int         matchedPrefixLength;
                int         textExcludingPrefixLength;
                TextSearch.GetMatchingPrefixAndRemainingTextLength(primaryTextFromItem, prefix, culture, !isTextSearchCaseSensitive, out matchedPrefixLength, out textExcludingPrefixLength);
                result = new MatchedTextInfo(num, primaryTextFromItem, matchedPrefixLength, textExcludingPrefixLength);
            }
            else
            {
                result = MatchedTextInfo.NoMatch;
            }
            return(result);
        }
예제 #8
0
        /// <summary>
        ///     This is the method that responds to the KeyDown event.
        /// </summary>
        /// <param name="e">Event Arguments</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool handled = true;
            Key  key     = e.Key;

            switch (key)
            {
            case Key.Divide:
            case Key.Oem2:
                // Ctrl-Fowardslash = Select All
                if (((Keyboard.Modifiers & ModifierKeys.Control) == (ModifierKeys.Control)) && (SelectionMode == SelectionMode.Extended))
                {
                    SelectAll();
                }
                else
                {
                    handled = false;
                }

                break;

            case Key.Oem5:
                // Ctrl-Backslash = Select the item with focus.
                if (((Keyboard.Modifiers & ModifierKeys.Control) == (ModifierKeys.Control)) && (SelectionMode == SelectionMode.Extended))
                {
                    ListBoxItem focusedItemUI = (FocusedInfo != null) ? FocusedInfo.Container as ListBoxItem : null;
                    if (focusedItemUI != null)
                    {
                        MakeSingleSelection(focusedItemUI);
                    }
                }
                else
                {
                    handled = false;
                }

                break;

            case Key.Up:
            case Key.Left:
            case Key.Down:
            case Key.Right:
            {
                KeyboardNavigation.ShowFocusVisual();

                // Depend on logical orientation we decide to move focus or just scroll
                // shouldScroll also detects if we can scroll more in this direction
                bool shouldScroll = ScrollHost != null;
                if (shouldScroll)
                {
                    shouldScroll =
                        ((key == Key.Down && IsLogicalHorizontal && DoubleUtil.GreaterThan(ScrollHost.ScrollableHeight, ScrollHost.VerticalOffset))) ||
                        ((key == Key.Up && IsLogicalHorizontal && DoubleUtil.GreaterThan(ScrollHost.VerticalOffset, 0d))) ||
                        ((key == Key.Right && IsLogicalVertical && DoubleUtil.GreaterThan(ScrollHost.ScrollableWidth, ScrollHost.HorizontalOffset))) ||
                        ((key == Key.Left && IsLogicalVertical && DoubleUtil.GreaterThan(ScrollHost.HorizontalOffset, 0d)));
                }

                if (shouldScroll)
                {
                    ScrollHost.ScrollInDirection(e);
                }
                else
                {
                    if ((ItemsHost != null && ItemsHost.IsKeyboardFocusWithin) || IsKeyboardFocused)
                    {
                        if (!NavigateByLine(KeyboardNavigation.KeyToTraversalDirection(key),
                                            new ItemNavigateArgs(e.Device, Keyboard.Modifiers)))
                        {
                            handled = false;
                        }
                    }
                    else
                    {
                        handled = false;
                    }
                }
            }
            break;

            case Key.Home:
                NavigateToStart(new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            case Key.End:
                NavigateToEnd(new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            case Key.Space:
            case Key.Enter:
            {
                if (e.Key == Key.Enter && (bool)GetValue(KeyboardNavigation.AcceptsReturnProperty) == false)
                {
                    handled = false;
                    break;
                }

                // If the event came from a ListBoxItem that's a child of ours, then look at it.
                ListBoxItem source = e.OriginalSource as ListBoxItem;

                // If ALT is down & Ctrl is up, then we shouldn't handle this. (system menu)
                if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Alt)) == ModifierKeys.Alt)
                {
                    handled = false;
                    break;
                }

                // If the user hits just "space" while text searching, do not handle the event
                // Note: Space cannot be the first character in a string sent to ITS.
                if (IsTextSearchEnabled && Keyboard.Modifiers == ModifierKeys.None)
                {
                    TextSearch instance = TextSearch.EnsureInstance(this);
                    // If TextSearch enabled and Prefix is not empty
                    // then let this SPACE go so ITS can process it.
                    if (instance != null && (instance.GetCurrentPrefix() != String.Empty))
                    {
                        handled = false;
                        break;
                    }
                }

                if (source != null && ItemsControlFromItemContainer(source) == this)
                {
                    switch (SelectionMode)
                    {
                    case SelectionMode.Single:
                        if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                        {
                            MakeToggleSelection(source);
                        }
                        else
                        {
                            MakeSingleSelection(source);
                        }

                        break;

                    case SelectionMode.Multiple:
                        MakeToggleSelection(source);
                        break;

                    case SelectionMode.Extended:
                        if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Control)
                        {
                            // Only CONTROL
                            MakeToggleSelection(source);
                        }
                        else if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Shift)
                        {
                            // Only SHIFT
                            MakeAnchorSelection(source, true /* clearCurrent */);
                        }
                        else if ((Keyboard.Modifiers & ModifierKeys.Shift) == 0)
                        {
                            MakeSingleSelection(source);
                        }
                        else
                        {
                            handled = false;
                        }

                        break;
                    }
                }
                else
                {
                    handled = false;
                }
            }
            break;

            case Key.PageUp:
                NavigateByPage(FocusNavigationDirection.Up, new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            case Key.PageDown:
                NavigateByPage(FocusNavigationDirection.Down, new ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                break;

            default:
                handled = false;
                break;
            }
            if (handled)
            {
                e.Handled = true;
            }
            else
            {
                base.OnKeyDown(e);
            }
        }
 // Token: 0x06005802 RID: 22530 RVA: 0x00186161 File Offset: 0x00184361
 private static TextSearch GetInstance(DependencyObject d)
 {
     return(TextSearch.EnsureInstance(d as ItemsControl));
 }
        // Token: 0x060057F6 RID: 22518 RVA: 0x00185D48 File Offset: 0x00183F48
        private static int FindMatchingPrefix(ItemsControl itemsControl, string primaryTextPath, string prefix, string newChar, int startItemIndex, bool lookForFallbackMatchToo, ref bool wasNewCharUsed)
        {
            ItemCollection items = itemsControl.Items;
            int            num   = -1;
            int            num2  = -1;
            int            count = items.Count;

            if (count == 0)
            {
                return(-1);
            }
            string value = prefix + newChar;

            if (string.IsNullOrEmpty(value))
            {
                return(-1);
            }
            BindingExpression bindingExpression = null;
            object            item = itemsControl.Items[0];

            if (SystemXmlHelper.IsXmlNode(item) || !string.IsNullOrEmpty(primaryTextPath))
            {
                bindingExpression = TextSearch.CreateBindingExpression(itemsControl, item, primaryTextPath);
                TextSearch.TextValueBindingExpression.SetValue(itemsControl, bindingExpression);
            }
            bool flag = true;

            wasNewCharUsed = false;
            CultureInfo culture = TextSearch.GetCulture(itemsControl);
            int         i       = startItemIndex;

            while (i < count)
            {
                object obj = items[i];
                if (obj != null)
                {
                    string primaryText = TextSearch.GetPrimaryText(obj, bindingExpression, itemsControl);
                    bool   isTextSearchCaseSensitive = itemsControl.IsTextSearchCaseSensitive;
                    if (primaryText != null && primaryText.StartsWith(value, !isTextSearchCaseSensitive, culture))
                    {
                        wasNewCharUsed = true;
                        num            = i;
                        break;
                    }
                    if (lookForFallbackMatchToo)
                    {
                        if (!flag && prefix != string.Empty)
                        {
                            if (primaryText != null && num2 == -1 && primaryText.StartsWith(prefix, !isTextSearchCaseSensitive, culture))
                            {
                                num2 = i;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
                i++;
                if (i >= count)
                {
                    i = 0;
                }
                if (i == startItemIndex)
                {
                    break;
                }
            }
            if (bindingExpression != null)
            {
                TextSearch.TextValueBindingExpression.ClearValue(itemsControl);
            }
            if (num == -1 && num2 != -1)
            {
                num = num2;
            }
            return(num);
        }
예제 #11
0
        /// <summary>Responds to the <see cref="E:System.Windows.UIElement.KeyDown" /> event. </summary>
        /// <param name="e">Provides data for <see cref="T:System.Windows.Input.KeyEventArgs" />.</param>
        // Token: 0x06005131 RID: 20785 RVA: 0x0016C2F0 File Offset: 0x0016A4F0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool flag = true;
            Key  key  = e.Key;

            if (key <= Key.Down)
            {
                if (key != Key.Return)
                {
                    switch (key)
                    {
                    case Key.Space:
                        break;

                    case Key.Prior:
                        base.NavigateByPage(FocusNavigationDirection.Up, new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                        goto IL_379;

                    case Key.Next:
                        base.NavigateByPage(FocusNavigationDirection.Down, new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                        goto IL_379;

                    case Key.End:
                        base.NavigateToEnd(new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                        goto IL_379;

                    case Key.Home:
                        base.NavigateToStart(new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers));
                        goto IL_379;

                    case Key.Left:
                    case Key.Up:
                    case Key.Right:
                    case Key.Down:
                    {
                        KeyboardNavigation.ShowFocusVisual();
                        bool flag2 = base.ScrollHost != null;
                        if (flag2)
                        {
                            flag2 = ((key == Key.Down && base.IsLogicalHorizontal && DoubleUtil.GreaterThan(base.ScrollHost.ScrollableHeight, base.ScrollHost.VerticalOffset)) || (key == Key.Up && base.IsLogicalHorizontal && DoubleUtil.GreaterThan(base.ScrollHost.VerticalOffset, 0.0)) || (key == Key.Right && base.IsLogicalVertical && DoubleUtil.GreaterThan(base.ScrollHost.ScrollableWidth, base.ScrollHost.HorizontalOffset)) || (key == Key.Left && base.IsLogicalVertical && DoubleUtil.GreaterThan(base.ScrollHost.HorizontalOffset, 0.0)));
                        }
                        if (flag2)
                        {
                            base.ScrollHost.ScrollInDirection(e);
                            goto IL_379;
                        }
                        if ((base.ItemsHost == null || !base.ItemsHost.IsKeyboardFocusWithin) && !base.IsKeyboardFocused)
                        {
                            flag = false;
                            goto IL_379;
                        }
                        if (!base.NavigateByLine(KeyboardNavigation.KeyToTraversalDirection(key), new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers)))
                        {
                            flag = false;
                            goto IL_379;
                        }
                        goto IL_379;
                    }

                    default:
                        goto IL_377;
                    }
                }
                if (e.Key == Key.Return && !(bool)base.GetValue(KeyboardNavigation.AcceptsReturnProperty))
                {
                    flag = false;
                    goto IL_379;
                }
                ListBoxItem listBoxItem = e.OriginalSource as ListBoxItem;
                if ((Keyboard.Modifiers & (ModifierKeys.Alt | ModifierKeys.Control)) == ModifierKeys.Alt)
                {
                    flag = false;
                    goto IL_379;
                }
                if (base.IsTextSearchEnabled && Keyboard.Modifiers == ModifierKeys.None)
                {
                    TextSearch textSearch = TextSearch.EnsureInstance(this);
                    if (textSearch != null && textSearch.GetCurrentPrefix() != string.Empty)
                    {
                        flag = false;
                        goto IL_379;
                    }
                }
                if (listBoxItem == null || ItemsControl.ItemsControlFromItemContainer(listBoxItem) != this)
                {
                    flag = false;
                    goto IL_379;
                }
                switch (this.SelectionMode)
                {
                case SelectionMode.Single:
                    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        this.MakeToggleSelection(listBoxItem);
                        goto IL_379;
                    }
                    this.MakeSingleSelection(listBoxItem);
                    goto IL_379;

                case SelectionMode.Multiple:
                    this.MakeToggleSelection(listBoxItem);
                    goto IL_379;

                case SelectionMode.Extended:
                    if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Control)
                    {
                        this.MakeToggleSelection(listBoxItem);
                        goto IL_379;
                    }
                    if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Shift)
                    {
                        this.MakeAnchorSelection(listBoxItem, true);
                        goto IL_379;
                    }
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.None)
                    {
                        this.MakeSingleSelection(listBoxItem);
                        goto IL_379;
                    }
                    flag = false;
                    goto IL_379;

                default:
                    goto IL_379;
                }
            }
            else if (key != Key.Divide && key != Key.Oem2)
            {
                if (key == Key.Oem5)
                {
                    if ((Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control || this.SelectionMode != SelectionMode.Extended)
                    {
                        flag = false;
                        goto IL_379;
                    }
                    ListBoxItem listBoxItem2 = (base.FocusedInfo != null) ? (base.FocusedInfo.Container as ListBoxItem) : null;
                    if (listBoxItem2 != null)
                    {
                        this.MakeSingleSelection(listBoxItem2);
                        goto IL_379;
                    }
                    goto IL_379;
                }
            }
            else
            {
                if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && this.SelectionMode == SelectionMode.Extended)
                {
                    this.SelectAll();
                    goto IL_379;
                }
                flag = false;
                goto IL_379;
            }
IL_377:
            flag = false;
IL_379:
            if (flag)
            {
                e.Handled = true;
                return;
            }
            base.OnKeyDown(e);
        }