Пример #1
0
        public virtual int IndexOfKey(string key)
        {
            // Step 0 - Arg validation
            if ((key is null) || (key.Length == 0))
            {
                return(-1); // we dont support empty or null keys.
            }

            // step 1 - check the last cached item
            if (IsValidIndex(_lastAccessedIndex))
            {
                if (WindowsFormsUtils.SafeCompareStrings(this[_lastAccessedIndex].Name, key, /* ignoreCase = */ true))
                {
                    return(_lastAccessedIndex);
                }
            }

            // step 2 - search for the item
            for (int i = 0; i < Count; i++)
            {
                if (WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, /* ignoreCase = */ true))
                {
                    _lastAccessedIndex = i;
                    return(i);
                }
            }

            // step 3 - we didn't find it.  Invalidate the last accessed index and return -1.
            _lastAccessedIndex = -1;
            return(-1);
        }
Пример #2
0
            private ArrayList FindInternal(string key, bool searchAllSubItems, ListViewItemCollection listViewItems, ArrayList foundItems)
            {
                if ((listViewItems is null) || (foundItems is null))
                {
                    return(null);  //
                }

                for (int i = 0; i < listViewItems.Count; i++)
                {
                    if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].Name, key, /* ignoreCase = */ true))
                    {
                        foundItems.Add(listViewItems[i]);
                    }
                    else
                    {
                        if (searchAllSubItems)
                        {
                            // start from 1, as we've already compared subitems[0]
                            for (int j = 1; j < listViewItems[i].SubItems.Count; j++)
                            {
                                if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].SubItems[j].Name, key, /* ignoreCase = */ true))
                                {
                                    foundItems.Add(listViewItems[i]);
                                    break;
                                }
                            }
                        }
                    }
                }

                return(foundItems);
            }
 private static void FindInternal(string key, bool searchAllSubItems, ListViewItemCollection listViewItems, List <ListViewItem> foundItems)
 {
     for (int i = 0; i < listViewItems.Count; i++)
     {
         if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].Name, key, ignoreCase: true))
         {
             foundItems.Add(listViewItems[i]);
         }
         else
         {
             if (searchAllSubItems)
             {
                 // start from 1, as we've already compared subitems[0]
                 for (int j = 1; j < listViewItems[i].SubItems.Count; j++)
                 {
                     if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].SubItems[j].Name, key, ignoreCase: true))
                     {
                         foundItems.Add(listViewItems[i]);
                         break;
                     }
                 }
             }
         }
     }
 }
Пример #4
0
            public virtual int IndexOfKey(string key)
            {
                if (string.IsNullOrEmpty(key))
                {
                    return(-1);
                }

                if (IsValidIndex(lastAccessedIndex))
                {
                    if (WindowsFormsUtils.SafeCompareStrings(this[lastAccessedIndex].Name, key, true))
                    {
                        return(lastAccessedIndex);
                    }
                }

                for (int i = 0; i < Count; i++)
                {
                    if (!WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, true))
                    {
                        continue;
                    }

                    lastAccessedIndex = i;
                    return(i);
                }

                lastAccessedIndex = -1;
                return(-1);
            }
Пример #5
0
 private ArrayList FindInternal(string key, bool searchAllChildren, TreeNodeCollection treeNodeCollectionToLookIn, ArrayList foundTreeNodes)
 {
     if ((treeNodeCollectionToLookIn == null) || (foundTreeNodes == null))
     {
         return(null);
     }
     for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
     {
         if ((treeNodeCollectionToLookIn[i] != null) && WindowsFormsUtils.SafeCompareStrings(treeNodeCollectionToLookIn[i].Name, key, true))
         {
             foundTreeNodes.Add(treeNodeCollectionToLookIn[i]);
         }
     }
     if (searchAllChildren)
     {
         for (int j = 0; j < treeNodeCollectionToLookIn.Count; j++)
         {
             if (((treeNodeCollectionToLookIn[j] != null) && (treeNodeCollectionToLookIn[j].Nodes != null)) && (treeNodeCollectionToLookIn[j].Nodes.Count > 0))
             {
                 foundTreeNodes = this.FindInternal(key, searchAllChildren, treeNodeCollectionToLookIn[j].Nodes, foundTreeNodes);
             }
         }
     }
     return(foundTreeNodes);
 }
Пример #6
0
 private ArrayList FindInternal(string key, bool searchAllChildren, Menu.MenuItemCollection menuItemsToLookIn, ArrayList foundMenuItems)
 {
     if ((menuItemsToLookIn == null) || (foundMenuItems == null))
     {
         return(null);
     }
     for (int i = 0; i < menuItemsToLookIn.Count; i++)
     {
         if ((menuItemsToLookIn[i] != null) && WindowsFormsUtils.SafeCompareStrings(menuItemsToLookIn[i].Name, key, true))
         {
             foundMenuItems.Add(menuItemsToLookIn[i]);
         }
     }
     if (searchAllChildren)
     {
         for (int j = 0; j < menuItemsToLookIn.Count; j++)
         {
             if (((menuItemsToLookIn[j] != null) && (menuItemsToLookIn[j].MenuItems != null)) && (menuItemsToLookIn[j].MenuItems.Count > 0))
             {
                 foundMenuItems = this.FindInternal(key, searchAllChildren, menuItemsToLookIn[j].MenuItems, foundMenuItems);
             }
         }
     }
     return(foundMenuItems);
 }
Пример #7
0
            /// <devdoc> ApplySettings - applies settings from the stub into a full-fledged
            ///          TableLayoutSettings.
            ///
            ///          NOTE: this is a one-time only operation - there is data loss to the stub
            ///          as a result of calling this function. we hand as much over to the other guy
            ///          so we dont have to reallocate anything
            /// </devdoc>
            internal void ApplySettings(TableLayoutSettings settings)
            {
                //
                // apply row,column,rowspan,colspan
                //
                TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(settings.Owner);
                Control appliedControl = containerInfo.Container as Control;

                if (appliedControl != null && controlsInfo != null)
                {
                    // we store the control names, look up the controls
                    // in the appliedControl's control collection and apply the row,column settings.
                    foreach (object controlName in controlsInfo.Keys)
                    {
                        ControlInformation controlInfo = controlsInfo[controlName];

                        // Look for the control in our table, we have to go through
                        // PropertyDescriptor rather than just going using appliedControl.Controls[controlName]
                        // because the Name property is shadowed at design time
                        foreach (Control tableControl in appliedControl.Controls)
                        {
                            if (tableControl != null)
                            {
                                string             name = null;
                                PropertyDescriptor prop = TypeDescriptor.GetProperties(tableControl)["Name"];
                                if (prop != null && prop.PropertyType == typeof(string))
                                {
                                    name = prop.GetValue(tableControl) as string;
                                }
                                else
                                {
                                    Debug.Fail("Name property missing on control");
                                }
                                if (WindowsFormsUtils.SafeCompareStrings(name, controlName as string, /* ignoreCase = */ false))
                                {
                                    settings.SetRow(tableControl, controlInfo.Row);
                                    settings.SetColumn(tableControl, controlInfo.Column);
                                    settings.SetRowSpan(tableControl, controlInfo.RowSpan);
                                    settings.SetColumnSpan(tableControl, controlInfo.ColumnSpan);
                                    break;
                                }
                            }
                        }
                    }
                }

                //
                // assign over the row and column styles
                //
                containerInfo.RowStyles    = rowStyles;
                containerInfo.ColumnStyles = columnStyles;

                // since we've given over the styles to the other guy, null out.
                columnStyles = null;
                rowStyles    = null;

                // set a flag for assertion detection.
                isValid = false;
            }
Пример #8
0
        /// <devdoc>
        ///     <para>Searches for Items by their Name property, builds up an array list
        ///           of all the items that match.
        ///     </para>
        /// </devdoc>
        /// <internalonly/>
        private ArrayList FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, ArrayList foundItems)
        {
            if ((itemsToLookIn == null) || (foundItems == null))
            {
                return(null);  //
            }

            try
            {
                for (int i = 0; i < itemsToLookIn.Count; i++)
                {
                    if (itemsToLookIn[i] == null)
                    {
                        continue;
                    }

                    if (WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, /* ignoreCase = */ true))
                    {
                        foundItems.Add(itemsToLookIn[i]);
                    }
                }


                // Optional recurive search for controls in child collections.

                if (searchAllChildren)
                {
                    for (int j = 0; j < itemsToLookIn.Count; j++)
                    {
                        ToolStripDropDownItem item = itemsToLookIn[j] as ToolStripDropDownItem;
                        if (item == null)
                        {
                            continue;
                        }
                        if (item.HasDropDownItems)
                        {
                            // if it has a valid child collecion, append those results to our collection
                            foundItems = FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Make sure we deal with non-critical failures gracefully.
                if (ClientUtils.IsCriticalException(e))
                {
                    throw;
                }
            }

            return(foundItems);
        }
Пример #9
0
            /// <summary>
            ///  Searches for Controls by their Name property, builds up an array list
            ///  of all the controls that match.
            /// </summary>
            private ArrayList FindInternal(string key, bool searchAllChildren, ControlCollection controlsToLookIn, ArrayList foundControls)
            {
                if ((controlsToLookIn == null) || (foundControls == null))
                {
                    return(null);
                }

                try
                {
                    // Perform breadth first search - as it's likely people will want controls belonging
                    // to the same parent close to each other.
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] == null)
                        {
                            continue;
                        }

                        if (WindowsFormsUtils.SafeCompareStrings(controlsToLookIn[i].Name, key, /* ignoreCase = */ true))
                        {
                            foundControls.Add(controlsToLookIn[i]);
                        }
                    }

                    // Optional recurive search for controls in child collections.

                    if (searchAllChildren)
                    {
                        for (int i = 0; i < controlsToLookIn.Count; i++)
                        {
                            if (controlsToLookIn[i] == null)
                            {
                                continue;
                            }
                            if ((controlsToLookIn[i].Controls != null) && controlsToLookIn[i].Controls.Count > 0)
                            {
                                // if it has a valid child collecion, append those results to our collection
                                foundControls = FindInternal(key, searchAllChildren, controlsToLookIn[i].Controls, foundControls);
                            }
                        }
                    }
                }
                catch (Exception e) when(!ClientUtils.IsSecurityOrCriticalException(e))
                {
                }
                return(foundControls);
            }
        public virtual int IndexOfKey(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(-1);
            }

            for (int i = 0; i < Count; i++)
            {
                if (WindowsFormsUtils.SafeCompareStrings(items[i].Name, key, true))
                {
                    return(i);
                }
            }

            return(-1);
        }
        private static ArrayList FindInternal(string key, bool searchAllChildren, TreeNodeCollection collection, ArrayList nodes)
        {
            if (collection == null || nodes == null)
            {
                return(null);
            }

            var collectionCount = collection.Count;

            for (int i = 0; i < collectionCount; i++)
            {
                var node = collection[i];
                if (node == null)
                {
                    continue;
                }

                if (WindowsFormsUtils.SafeCompareStrings(node.Name, key, true))
                {
                    nodes.Add(node);
                }
            }

            if (searchAllChildren)
            {
                for (int i = 0; i < collectionCount; i++)
                {
                    var node = collection[i];
                    if (node == null)
                    {
                        continue;
                    }

                    var nodeNodes = node.Nodes;
                    if (nodeNodes != null && nodeNodes.Count > 0)
                    {
                        nodes = FindInternal(key, true, nodeNodes, nodes);
                    }
                }
            }
            return(nodes);
        }
Пример #12
0
        private ArrayList FindInternal(string key, bool searchAllChildren, TreeNodeCollection treeNodeCollectionToLookIn, ArrayList foundTreeNodes)
        {
            if ((treeNodeCollectionToLookIn == null) || (foundTreeNodes == null))
            {
                return(null);
            }

            // Perform breadth first search - as it's likely people will want tree nodes belonging
            // to the same parent close to each other.

            for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
            {
                if (treeNodeCollectionToLookIn[i] == null)
                {
                    continue;
                }

                if (WindowsFormsUtils.SafeCompareStrings(treeNodeCollectionToLookIn[i].Name, key, /* ignoreCase = */ true))
                {
                    foundTreeNodes.Add(treeNodeCollectionToLookIn[i]);
                }
            }

            // Optional recurive search for controls in child collections.

            if (searchAllChildren)
            {
                for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
                {
                    if (treeNodeCollectionToLookIn[i] == null)
                    {
                        continue;
                    }
                    if ((treeNodeCollectionToLookIn[i].Nodes != null) && treeNodeCollectionToLookIn[i].Nodes.Count > 0)
                    {
                        // if it has a valid child collecion, append those results to our collection
                        foundTreeNodes = FindInternal(key, searchAllChildren, treeNodeCollectionToLookIn[i].Nodes, foundTreeNodes);
                    }
                }
            }
            return(foundTreeNodes);
        }
 public int IndexOfKey(string key)
 {
     if ((key != null) && (key.Length != 0))
     {
         if ((this.IsValidIndex(this.lastAccessedIndex) && (this.imageInfoCollection[this.lastAccessedIndex] != null)) && WindowsFormsUtils.SafeCompareStrings(((ImageInfo)this.imageInfoCollection[this.lastAccessedIndex]).Name, key, true))
         {
             return(this.lastAccessedIndex);
         }
         for (int i = 0; i < this.Count; i++)
         {
             if ((this.imageInfoCollection[i] != null) && WindowsFormsUtils.SafeCompareStrings(((ImageInfo)this.imageInfoCollection[i]).Name, key, true))
             {
                 this.lastAccessedIndex = i;
                 return(i);
             }
         }
         this.lastAccessedIndex = -1;
     }
     return(-1);
 }
Пример #14
0
 public virtual int IndexOfKey(string key)
 {
     if (!string.IsNullOrEmpty(key))
     {
         if (this.IsValidIndex(this.lastAccessedIndex) && WindowsFormsUtils.SafeCompareStrings(this[this.lastAccessedIndex].Name, key, true))
         {
             return(this.lastAccessedIndex);
         }
         for (int i = 0; i < this.Count; i++)
         {
             if (WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, true))
             {
                 this.lastAccessedIndex = i;
                 return(i);
             }
         }
         this.lastAccessedIndex = -1;
     }
     return(-1);
 }
            private void FindInternal(string key, bool searchAllChildren, ControlCollection controlsToLookIn, List <Control> foundControls)
            {
                try
                {
                    // Perform breadth first search - as it's likely people will want controls belonging
                    // to the same parent close to each other.
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] is null)
                        {
                            continue;
                        }

                        if (WindowsFormsUtils.SafeCompareStrings(controlsToLookIn[i].Name, key, ignoreCase: true))
                        {
                            foundControls.Add(controlsToLookIn[i]);
                        }
                    }

                    // Optional recursive search for controls in child collections.
                    if (searchAllChildren)
                    {
                        for (int i = 0; i < controlsToLookIn.Count; i++)
                        {
                            if (controlsToLookIn[i] is null)
                            {
                                continue;
                            }

                            if (controlsToLookIn[i].Controls.Count > 0)
                            {
                                // If it has a valid child collection, append those results to our collection.
                                FindInternal(key, true, controlsToLookIn[i].Controls, foundControls);
                            }
                        }
                    }
                }
                catch (Exception e) when(!ClientUtils.IsCriticalException(e))
                {
                }
            }
Пример #16
0
        private void FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, List <ToolStripItem> foundItems)
        {
            try
            {
                for (int i = 0; i < itemsToLookIn.Count; i++)
                {
                    if (itemsToLookIn[i] is null)
                    {
                        continue;
                    }

                    if (WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, ignoreCase: true))
                    {
                        foundItems.Add(itemsToLookIn[i]);
                    }
                }

                // Optional recursive search for controls in child collections.
                if (searchAllChildren)
                {
                    for (int j = 0; j < itemsToLookIn.Count; j++)
                    {
                        if (itemsToLookIn[j] is not ToolStripDropDownItem item)
                        {
                            continue;
                        }

                        if (item.HasDropDownItems)
                        {
                            // If it has a valid child collection, append those results to our collection.
                            FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
                        }
                    }
                }
            }
            catch (Exception e) when(!ClientUtils.IsCriticalException(e))
            {
            }
        }
Пример #17
0
            internal void ApplySettings(TableLayoutSettings settings)
            {
                TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(settings.Owner);
                Control container = containerInfo.Container as Control;

                if ((container != null) && (this.controlsInfo != null))
                {
                    foreach (object obj2 in this.controlsInfo.Keys)
                    {
                        TableLayoutSettings.ControlInformation information = this.controlsInfo[obj2];
                        foreach (Control control2 in container.Controls)
                        {
                            if (control2 != null)
                            {
                                string             str        = null;
                                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(control2)["Name"];
                                if ((descriptor != null) && (descriptor.PropertyType == typeof(string)))
                                {
                                    str = descriptor.GetValue(control2) as string;
                                }
                                if (WindowsFormsUtils.SafeCompareStrings(str, obj2 as string, false))
                                {
                                    settings.SetRow(control2, information.Row);
                                    settings.SetColumn(control2, information.Column);
                                    settings.SetRowSpan(control2, information.RowSpan);
                                    settings.SetColumnSpan(control2, information.ColumnSpan);
                                    break;
                                }
                            }
                        }
                    }
                }
                containerInfo.RowStyles    = this.rowStyles;
                containerInfo.ColumnStyles = this.columnStyles;
                this.columnStyles          = null;
                this.rowStyles             = null;
                this.isValid = false;
            }
 private ArrayList FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, ArrayList foundItems)
 {
     if ((itemsToLookIn == null) || (foundItems == null))
     {
         return(null);
     }
     try
     {
         for (int i = 0; i < itemsToLookIn.Count; i++)
         {
             if ((itemsToLookIn[i] != null) && WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, true))
             {
                 foundItems.Add(itemsToLookIn[i]);
             }
         }
         if (!searchAllChildren)
         {
             return(foundItems);
         }
         for (int j = 0; j < itemsToLookIn.Count; j++)
         {
             ToolStripDropDownItem item = itemsToLookIn[j] as ToolStripDropDownItem;
             if ((item != null) && item.HasDropDownItems)
             {
                 foundItems = this.FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
             }
         }
     }
     catch (Exception exception)
     {
         if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
         {
             throw;
         }
     }
     return(foundItems);
 }
            public virtual int IndexOfKey(string key)
            {
                if (owner.VirtualMode)
                {
                    throw new InvalidOperationException(SR.ListViewCantAccessSelectedItemsCollectionWhenInVirtualMode);
                }

                // Step 0 - Arg validation
                if (string.IsNullOrEmpty(key))
                {
                    return(-1); // we dont support empty or null keys.
                }

                // step 1 - check the last cached item
                if (IsValidIndex(lastAccessedIndex))
                {
                    if (WindowsFormsUtils.SafeCompareStrings(this[lastAccessedIndex].Name, key, /* ignoreCase = */ true))
                    {
                        return(lastAccessedIndex);
                    }
                }

                // step 2 - search for the item
                for (int i = 0; i < Count; i++)
                {
                    if (WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, /* ignoreCase = */ true))
                    {
                        lastAccessedIndex = i;
                        return(i);
                    }
                }

                // step 3 - we didn't find it.  Invalidate the last accessed index and return -1.
                lastAccessedIndex = -1;
                return(-1);
            }