Example #1
0
        public void TestSearchForVirtualItemEventArgs()
        {
            SearchDirectionHint sdh = SearchDirectionHint.Right;
            bool   includesubitems  = true;
            int    index            = 84;
            bool   isprefix         = true;
            bool   istext           = false;
            int    start            = 34;
            Point  startpoint       = new Point(64, 35);
            string text             = "HiThere!";

            SearchForVirtualItemEventArgs e = new SearchForVirtualItemEventArgs(istext, isprefix, includesubitems, text, startpoint, sdh, start);

            Assert.AreEqual(sdh, e.Direction, "A1");
            Assert.AreEqual(includesubitems, e.IncludeSubItemsInSearch, "A2");
            Assert.AreEqual(-1, e.Index, "A3");
            Assert.AreEqual(isprefix, e.IsPrefixSearch, "A4");
            Assert.AreEqual(istext, e.IsTextSearch, "A5");
            Assert.AreEqual(start, e.StartIndex, "A6");
            Assert.AreEqual(startpoint, e.StartingPoint, "A7");
            Assert.AreEqual(text, e.Text, "A8");

            e.Index = index;
            Assert.AreEqual(index, e.Index, "A9");
        }
        // This performs item sleection by keys
        private void SelectNextItem(SearchDirectionHint dir)
        {
            ListViewItem lvi;
            Point        spos;

            // Not when selecting is prevented
            if (preventselection)
            {
                return;
            }

            // Nothing selected?
            if (list.SelectedItems.Count == 0)
            {
                // Select first
                SelectFirstItem();
            }
            else
            {
                // Get selected item
                lvi = list.SelectedItems[0];
                Rectangle lvirect = list.GetItemRect(lvi.Index, ItemBoundsPortion.Entire);
                spos = new Point(lvirect.Location.X + lvirect.Width / 2, lvirect.Y + lvirect.Height / 2);

                // Try finding 5 times in the given direction
                for (int i = 0; i < 5; i++)
                {
                    // Move point in given direction
                    switch (dir)
                    {
                    case SearchDirectionHint.Left: spos.X -= list.TileSize.Width / 2; break;

                    case SearchDirectionHint.Right: spos.X += list.TileSize.Width / 2; break;

                    case SearchDirectionHint.Up: spos.Y -= list.TileSize.Height / 2; break;

                    case SearchDirectionHint.Down: spos.Y += list.TileSize.Height / 2; break;
                    }

                    // Test position
                    lvi = list.GetItemAt(spos.X, spos.Y);
                    if (lvi != null)
                    {
                        // Select item
                        list.SelectedItems.Clear();
                        lvi.Selected = true;
                        break;
                    }
                }

                // Make selection visible
                if (list.SelectedItems.Count > 0)
                {
                    list.SelectedItems[0].EnsureVisible();
                }
            }

            UpdateTextureSizeLabel();
        }
 /// <include file='doc\SearchForVirtualItemEventArgs.uex' path='docs/doc[@for="SearchForVirtualItemEventArgs.SearchForVirtualItemEventArgs"]/*' />
 public SearchForVirtualItemEventArgs(bool isTextSearch, bool isPrefixSearch, bool includeSubItemsInSearch, string text, Point startingPoint, SearchDirectionHint direction, int startIndex) {
     this.isTextSearch = isTextSearch;
     this.isPrefixSearch = isPrefixSearch;
     this.includeSubItemsInSearch = includeSubItemsInSearch;
     this.text = text;
     this.startingPoint = startingPoint;
     this.direction = direction;
     this.startIndex = startIndex;
 }
 public SearchForVirtualItemEventArgs(bool isTextSearch, bool isPrefixSearch, bool includeSubItemsInSearch, string text, Point startingPoint, SearchDirectionHint direction, int startIndex)
 {
     IsTextSearch            = isTextSearch;
     IsPrefixSearch          = isPrefixSearch;
     IncludeSubItemsInSearch = includeSubItemsInSearch;
     Text          = text;
     StartingPoint = startingPoint;
     Direction     = direction;
     StartIndex    = startIndex;
 }
		public SearchForVirtualItemEventArgs (bool isTextSearch, bool isPrefixSearch,
			bool includeSubItemsInSearch, string text, Point startingPoint, 
			SearchDirectionHint direction, int startIndex) : base ()
		{
			this.is_text_search = isTextSearch;
			this.is_prefix_search = isPrefixSearch;
			this.include_sub_items_in_search = includeSubItemsInSearch;
			this.text = text;
			this.starting_point = startingPoint;
			this.direction = direction;
			this.start_index = startIndex;
			this.index = -1;
		}
Example #6
0
 public SearchForVirtualItemEventArgs(bool isTextSearch, bool isPrefixSearch,
                                      bool includeSubItemsInSearch, string text, Point startingPoint,
                                      SearchDirectionHint direction, int startIndex) : base()
 {
     this.is_text_search              = isTextSearch;
     this.is_prefix_search            = isPrefixSearch;
     this.include_sub_items_in_search = includeSubItemsInSearch;
     this.text           = text;
     this.starting_point = startingPoint;
     this.direction      = direction;
     this.start_index    = startIndex;
     this.index          = -1;
 }
Example #7
0
 public ListViewItem FindNearestItem(SearchDirectionHint searchDirection, int x, int y)
 {
     throw null;
 }
	public ListViewItem FindNearestItem(SearchDirectionHint searchDirection) {}
Example #9
0
		public ListViewItem FindNearestItem (SearchDirectionHint dir, Point point)
		{
			if (dir < SearchDirectionHint.Left || dir > SearchDirectionHint.Down)
				throw new ArgumentOutOfRangeException ("searchDirection");

			if (view != View.LargeIcon && view != View.SmallIcon)
				throw new InvalidOperationException ();

			if (virtual_mode) {
				SearchForVirtualItemEventArgs args = new SearchForVirtualItemEventArgs (false,
						false, false, String.Empty, point, 
						dir, 0);

				OnSearchForVirtualItem (args);
				int idx = args.Index;
				if (idx >= 0 && idx < virtual_list_size)
					return items [idx];

				return null;
			}

			ListViewItem item = null;
			int min_dist = Int32.MaxValue;

			//
			// It looks like .Net does a previous adjustment
			//
			switch (dir) {
				case SearchDirectionHint.Up:
					point.Y -= item_size.Height;
					break;
				case SearchDirectionHint.Down:
					point.Y += item_size.Height;
					break;
				case SearchDirectionHint.Left:
					point.X -= item_size.Width;
					break;
				case SearchDirectionHint.Right:
					point.X += item_size.Width;
					break;
			}

			for (int i = 0; i < items.Count; i++) {
				Point item_loc = GetItemLocation (i);

				if (dir == SearchDirectionHint.Up) {
					if (point.Y < item_loc.Y)
						continue;
				} else if (dir == SearchDirectionHint.Down) {
					if (point.Y > item_loc.Y)
						continue;
				} else if (dir == SearchDirectionHint.Left) {
					if (point.X < item_loc.X)
						continue;
				} else if (dir == SearchDirectionHint.Right) {
					if (point.X > item_loc.X)
						continue;
				}

				int x_dist = point.X - item_loc.X;
				int y_dist = point.Y - item_loc.Y;

				int dist = x_dist * x_dist  + y_dist * y_dist;
				if (dist < min_dist) {
					item = items [i];
					min_dist = dist;
				}
			}

			return item;
		}
Example #10
0
 ///<summary>
 ///Finds the next item from the given x- and y-coordinates, searching in the specified direction. 
 ///</summary>
 ///
 ///<returns>
 ///The <see cref="T:System.Windows.Forms.ListViewItem"></see> that is closest to the given coordinates, searching in the specified direction.
 ///</returns>
 ///
 ///<param name="y">The y-coordinate for the point at which to begin searching.</param>
 ///<param name="searchDirection">One of the <see cref="T:System.Windows.Forms.SearchDirectionHint"></see> values.</param>
 ///<param name="x">The x-coordinate for the point at which to begin searching.</param>
 ///<exception cref="T:System.InvalidOperationException"><see cref="P:System.Windows.Forms.ListView.View"></see> is set to a value other than <see cref="F:System.Windows.Forms.View.SmallIcon"></see> or <see cref="F:System.Windows.Forms.View.LargeIcon"></see>. </exception>
 public ListViewItem FindNearestItem(SearchDirectionHint searchDirection, int x, int y)
 {
     return shortcutList.FindNearestItem(searchDirection, x, y);
 }
 public ListViewItem FindNearestItem(SearchDirectionHint dir, System.Drawing.Point point)
 {
 }
Example #12
0
		public ListViewItem FindNearestItem (SearchDirectionHint searchDirection)
		{
			if (owner == null)
				return null;

			Point loc = owner.GetItemLocation (display_index);
			return owner.FindNearestItem (searchDirection, loc);
		}
 ///<summary>
 ///Finds the next item from the given x- and y-coordinates, searching in the specified direction.
 ///</summary>
 ///
 ///<returns>
 ///The <see cref="T:System.Windows.Forms.ListViewItem"></see> that is closest to the given coordinates, searching in the specified direction.
 ///</returns>
 ///
 ///<param name="y">The y-coordinate for the point at which to begin searching.</param>
 ///<param name="searchDirection">One of the <see cref="T:System.Windows.Forms.SearchDirectionHint"></see> values.</param>
 ///<param name="x">The x-coordinate for the point at which to begin searching.</param>
 ///<exception cref="T:System.InvalidOperationException"><see cref="P:System.Windows.Forms.ListView.View"></see> is set to a value other than <see cref="F:System.Windows.Forms.View.SmallIcon"></see> or <see cref="F:System.Windows.Forms.View.LargeIcon"></see>. </exception>
 public ListViewItem FindNearestItem(SearchDirectionHint searchDirection, int x, int y)
 {
     return(shortcutList.FindNearestItem(searchDirection, x, y));
 }
 ///<summary>
 ///Finds the next item from the given point, searching in the specified direction
 ///</summary>
 ///
 ///<returns>
 ///The <see cref="T:System.Windows.Forms.ListViewItem"></see> that is closest to the given point, searching in the specified direction.
 ///</returns>
 ///
 ///<param name="dir">One of the <see cref="T:System.Windows.Forms.SearchDirectionHint"></see> values.</param>
 ///<param name="point">The point at which to begin searching.</param>
 ///<exception cref="T:System.InvalidOperationException"><see cref="P:System.Windows.Forms.ListView.View"></see> is set to a value other than <see cref="F:System.Windows.Forms.View.SmallIcon"></see> or <see cref="F:System.Windows.Forms.View.LargeIcon"></see>. </exception>
 public ListViewItem FindNearestItem(SearchDirectionHint dir, Point point)
 {
     return(shortcutList.FindNearestItem(dir, point));
 }
        public ListViewItem FindNearestItem(SearchDirectionHint searchDirection)
        {
            Rectangle bounds = this.Bounds;
            switch (searchDirection)
            {
                case SearchDirectionHint.Left:
                    return this.ListView.FindNearestItem(searchDirection, bounds.Left, bounds.Top);

                case SearchDirectionHint.Up:
                    return this.ListView.FindNearestItem(searchDirection, bounds.Left, bounds.Top);

                case SearchDirectionHint.Right:
                    return this.ListView.FindNearestItem(searchDirection, bounds.Right, bounds.Top);

                case SearchDirectionHint.Down:
                    return this.ListView.FindNearestItem(searchDirection, bounds.Left, bounds.Bottom);
            }
            return null;
        }
Example #16
0
        // This performs item sleection by keys
        private void SelectNextItem(SearchDirectionHint dir)
        {
            // Not when selecting is prevented
            if (preventselection)
            {
                return;
            }

            // Nothing selected?
            if (list.SelectedItems.Count == 0)
            {
                // Select first
                SelectFirstItem();
            }
            else
            {
                //mxd
                int           index       = list.SelectedItems[0].Index;
                int           targetindex = -1;
                ListViewGroup startgroup  = list.SelectedItems[0].Group;
                Rectangle     startrect   = list.SelectedItems[0].GetBounds(ItemBoundsPortion.Entire);

                switch (dir)
                {
                // Check previous items untill groups match...
                case SearchDirectionHint.Left:
                    if (list.SelectedIndices[0] > 0)
                    {
                        while (--index > -1)
                        {
                            if (list.Items[index].Group == startgroup)
                            {
                                targetindex = index;
                                break;
                            }
                        }
                    }
                    break;

                // Same thing, other direction...
                case SearchDirectionHint.Right:
                    if (list.SelectedIndices[0] < list.Items.Count - 1)
                    {
                        while (++index < list.Items.Count)
                        {
                            if (list.Items[index].Group == startgroup)
                            {
                                targetindex = index;
                                break;
                            }
                        }
                    }
                    break;

                // Check previous items untill X coordinate match and Y coordinate is less than the start ones...
                case SearchDirectionHint.Up:
                    while (--index > -1)
                    {
                        ListViewItem item = list.Items[index];
                        if (item != null && item.Group == startgroup)
                        {
                            Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);
                            if (rect.X == startrect.X && rect.Y < startrect.Y)
                            {
                                targetindex = index;
                                break;
                            }
                        }
                    }
                    break;

                // Same thing, other direction...
                case SearchDirectionHint.Down:
                    if (list.SelectedIndices[0] < list.Items.Count - 1)
                    {
                        while (++index < list.Items.Count)
                        {
                            ListViewItem item = list.Items[index];
                            if (item != null && item.Group == startgroup)
                            {
                                Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);
                                if (rect.X == startrect.X && rect.Y > startrect.Y)
                                {
                                    targetindex = index;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }

                //mxd. Use the old method for Up/Down keys, becaue it can jump between Groups...
                if (targetindex == -1 && (dir == SearchDirectionHint.Up || dir == SearchDirectionHint.Down))
                {
                    Point spos = new Point(startrect.Location.X + startrect.Width / 2, startrect.Y + startrect.Height / 2);

                    // Try finding 5 times in the given direction
                    for (int i = 0; i < 5; i++)
                    {
                        // Move point in given direction
                        switch (dir)
                        {
                        case SearchDirectionHint.Up: spos.Y -= list.TileSize.Height / 2; break;

                        case SearchDirectionHint.Down: spos.Y += list.TileSize.Height / 2; break;
                        }

                        // Test position
                        ListViewItem lvi = list.GetItemAt(spos.X, spos.Y);
                        if (lvi != null)
                        {
                            targetindex = lvi.Index;
                            break;
                        }
                    }
                }

                //mxd. Found something?..
                if (targetindex != -1)
                {
                    // Select item
                    list.SelectedItems.Clear();
                    list.Items[targetindex].Selected = true;
                    list.SelectedItems[0].EnsureVisible();
                }
            }
        }
 // Constructors
 public SearchForVirtualItemEventArgs(bool isTextSearch, bool isPrefixSearch, bool includeSubItemsInSearch, string text, System.Drawing.Point startingPoint, SearchDirectionHint direction, int startIndex)
 {
 }
        public void Ctor_Bool_Bool_Bool_String_Point_SearchDirectionHint_Int(bool isTextSearch, bool isPrefixSearch, bool includeSubItemsInSearch, string text, Point startingPoint, SearchDirectionHint direction, int startIndex)
        {
            var e = new SearchForVirtualItemEventArgs(isTextSearch, isPrefixSearch, includeSubItemsInSearch, text, startingPoint, direction, startIndex);

            Assert.Equal(isTextSearch, e.IsTextSearch);
            Assert.Equal(isPrefixSearch, e.IsPrefixSearch);
            Assert.Equal(includeSubItemsInSearch, e.IncludeSubItemsInSearch);
            Assert.Equal(text, e.Text);
            Assert.Equal(startingPoint, e.StartingPoint);
            Assert.Equal(direction, e.Direction);
            Assert.Equal(startIndex, e.StartIndex);
            Assert.Equal(-1, e.Index);
        }
        public void SelectNextItem(SearchDirectionHint dir)
        {
            if (!allowselection)
            {
                return;
            }

            if (selection.Count == 0)
            {
                if (items.Count > 0)
                {
                    SetSelectedItem(items[0]);
                }
                return;
            }

            int       targetindex = items.IndexOf(selection[0]);
            Rectangle rect = rectangles[targetindex];
            int       index, newindex, tx, cx, cy;

            switch (dir)
            {
            case SearchDirectionHint.Right:
                // Just select the next item
                if (targetindex < items.Count - 1)
                {
                    SetSelectedItem(items[targetindex + 1]);
                }
                break;

            case SearchDirectionHint.Left:
                // Just select the previous item
                if (targetindex > 0)
                {
                    SetSelectedItem(items[targetindex - 1]);
                }
                break;

            case SearchDirectionHint.Up:
                // Skip current row...
                index = targetindex - 1;
                if (index < 0)
                {
                    break;
                }
                while (index > 0)
                {
                    if (rectangles[index].Y != rect.Y)
                    {
                        break;
                    }
                    index--;
                }

                // Check upper row for best match
                tx       = rect.X + rect.Width / 2;
                cx       = int.MaxValue;
                cy       = rectangles[index].Y;
                newindex = int.MaxValue;

                while (index >= 0 && rectangles[index].Y == cy)
                {
                    int ccx = Math.Abs(rectangles[index].X + rectangles[index].Width / 2 - tx);
                    if (ccx < cx)
                    {
                        cx       = ccx;
                        newindex = index;
                    }
                    index--;
                }

                // Select item
                if (newindex != int.MaxValue)
                {
                    SetSelectedItem(items[newindex]);
                }
                break;

            case SearchDirectionHint.Down:
                // Skip current row...
                index = targetindex + 1;
                if (index > rectangles.Count - 1)
                {
                    break;
                }
                while (index < rectangles.Count - 1)
                {
                    if (rectangles[index].Y != rect.Y)
                    {
                        break;
                    }
                    index++;
                }

                // Check upper row for best match
                tx       = rect.X + rect.Width / 2;
                cx       = int.MaxValue;
                cy       = rectangles[index].Y;
                newindex = int.MaxValue;

                while (index < rectangles.Count && rectangles[index].Y == cy)
                {
                    int ccx = Math.Abs(rectangles[index].X + rectangles[index].Width / 2 - tx);
                    if (ccx < cx)
                    {
                        cx       = ccx;
                        newindex = index;
                    }
                    index++;
                }

                // Select item
                if (newindex != int.MaxValue)
                {
                    SetSelectedItem(items[newindex]);
                }
                break;
            }
        }
Example #20
0
        /// <include file='doc\ListView.uex' path='docs/doc[@for="ListView.FindNearestItem2"]/*' />
        /// <devdoc>
        /// </devdoc>
        public ListViewItem FindNearestItem(SearchDirectionHint searchDirection, int x, int y)
        {
            if (this.View != View.SmallIcon && this.View != View.LargeIcon) {
                throw new InvalidOperationException(SR.GetString(SR.ListViewFindNearestItemWorksOnlyInIconView));
            }

            if ( searchDirection < SearchDirectionHint.Left || searchDirection > SearchDirectionHint.Down) {
                throw new ArgumentOutOfRangeException("searchDirection", SR.GetString(SR.InvalidArgument, "searchDirection", (searchDirection).ToString()));
            }

            // the win32 ListView::FindNearestItem does some pretty weird things to determine the nearest item.
            // simply passing the (x,y) coordinates will cause problems when we call FindNearestItem for a point inside an item.
            // so we have to do some special processing when (x,y) falls inside an item;
            // take a look at VSWHIDBEY bug 178646 and the attached ListView_IFindNearestItem.c file for a complete story.
            ListViewItem lvi = this.GetItemAt(x,y);

            if (lvi != null) {
                Rectangle itemBounds = lvi.Bounds;
                // LVM_FINDITEM is a nightmare
                // LVM_FINDITEM will use the top left corner of icon rectangle to determine the closest item
                // What happens if there is no icon for this item? then the top left corner of the icon rectangle falls INSIDE the item label (???)
                //

                Rectangle iconBounds = this.GetItemRect(lvi.Index, ItemBoundsPortion.Icon);

                switch (searchDirection) {
                    case SearchDirectionHint.Up:
                        y = Math.Max(itemBounds.Top, iconBounds.Top) - 1;
                        break;
                    case SearchDirectionHint.Down:
                        y = Math.Max(itemBounds.Top, iconBounds.Top) + 1;
                        break;
                    case SearchDirectionHint.Left:
                        x = Math.Max(itemBounds.Left, iconBounds.Left) - 1;
                        break;
                    case SearchDirectionHint.Right:
                        x = Math.Max(itemBounds.Left, iconBounds.Left) + 1;
                        break;
                    default:
                        Debug.Assert(false, "these are all the search directions");
                        break;
                 }
            }

            return FindItem(false, String.Empty, false, new Point(x, y), searchDirection, -1, false);
        }
Example #21
0
 public ListViewItem FindNearestItem(SearchDirectionHint searchDirection)
 {
 }
Example #22
0
 ///<summary>
 ///Finds the next item from the given point, searching in the specified direction
 ///</summary>
 ///
 ///<returns>
 ///The <see cref="T:System.Windows.Forms.ListViewItem"></see> that is closest to the given point, searching in the specified direction.
 ///</returns>
 ///
 ///<param name="dir">One of the <see cref="T:System.Windows.Forms.SearchDirectionHint"></see> values.</param>
 ///<param name="point">The point at which to begin searching.</param>
 ///<exception cref="T:System.InvalidOperationException"><see cref="P:System.Windows.Forms.ListView.View"></see> is set to a value other than <see cref="F:System.Windows.Forms.View.SmallIcon"></see> or <see cref="F:System.Windows.Forms.View.LargeIcon"></see>. </exception>
 public ListViewItem FindNearestItem(SearchDirectionHint dir, Point point)
 {
     return shortcutList.FindNearestItem(dir, point);
 }
Example #23
0
 /// <include file='doc\ListView.uex' path='docs/doc[@for="ListView.FindNearestItem"]/*' />
 /// <devdoc>
 /// </devdoc>
 public ListViewItem FindNearestItem(SearchDirectionHint dir, Point point) {
     return FindNearestItem(dir, point.X, point.Y);
 }
Example #24
0
 public SearchForVirtualItemEventArgs(bool isTextSearch, bool isPrefixSearch, bool includeSubItemsInSearch, string text, Point startingPoint, SearchDirectionHint direction, int startIndex)
 {
     throw null;
 }
Example #25
0
        private ListViewItem FindItem(bool isTextSearch, string text, bool isPrefixSearch, Point pt, SearchDirectionHint dir, int startIndex, bool includeSubItemsInSearch) {
            if (this.Items.Count == 0) {
                return null;
            }

            if (!IsHandleCreated)
                CreateHandle();
            if (VirtualMode) {
                SearchForVirtualItemEventArgs sviEvent = new SearchForVirtualItemEventArgs(isTextSearch, isPrefixSearch, includeSubItemsInSearch, text, pt, dir, startIndex);

                OnSearchForVirtualItem(sviEvent);
                // NOTE: this will cause a RetrieveVirtualItem event w/o a corresponding cache hint event.
                if (sviEvent.Index != -1) {
                    return this.Items[sviEvent.Index];
                } else {
                    return null;
                }
            } else {
                NativeMethods.LVFINDINFO lvFindInfo = new NativeMethods.LVFINDINFO();
                if (isTextSearch) {
                    lvFindInfo.flags = NativeMethods.LVFI_STRING;
                    lvFindInfo.flags |= (isPrefixSearch ? NativeMethods.LVFI_PARTIAL : 0);
                    lvFindInfo.psz = text;
                } else {
                    lvFindInfo.flags = NativeMethods.LVFI_NEARESTXY;
                    lvFindInfo.ptX = pt.X;
                    lvFindInfo.ptY = pt.Y;
                    // we can do this because SearchDirectionHint is set to the VK_*
                    lvFindInfo.vkDirection = (int)dir;
                }
                lvFindInfo.lParam = IntPtr.Zero;
                int index = (int)UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle),
                                                                 NativeMethods.LVM_FINDITEM,
                                                                 startIndex-1,                      // decrement startIndex so that the search is 0-based
                                                                 ref lvFindInfo);
                if (index >= 0) {
                    return Items[index];
                } else if (isTextSearch && includeSubItemsInSearch) {
                    // win32 listView control can't search inside sub items
                    for (int i = startIndex; i < this.Items.Count; i ++) {
                        ListViewItem lvi = this.Items[i];
                        for (int j = 0; j < lvi.SubItems.Count; j ++) {
                            ListViewItem.ListViewSubItem lvsi = lvi.SubItems[j];
                            // the win32 list view search for items w/ text is case insensitive
                            // do the same for sub items
                            // because we are comparing user defined strings we have to do the slower String search
                            // ie, use String.Compare(string, string, case sensitive, CultureInfo)
                            // instead of new Whidbey String.Equals overload
                            // String.Equals(string, string, StringComparison.OrdinalIgnoreCase
                            if (String.Equals(text,lvsi.Text, StringComparison.OrdinalIgnoreCase)) {
                                return lvi;
                            } else if (isPrefixSearch && CultureInfo.CurrentCulture.CompareInfo.IsPrefix(lvsi.Text, text, CompareOptions.IgnoreCase)) {
                                return lvi;
                            }
                        }
                    }
                    return null;
                } else {
                    return null;
                }
            }
        }
	public ListViewItem FindNearestItem(SearchDirectionHint dir, System.Drawing.Point point) {}
Example #27
0
		public ListViewItem FindNearestItem (SearchDirectionHint searchDirection, int x, int y)
		{
			return FindNearestItem (searchDirection, new Point (x, y));
		}
        public ListViewItem FindNearestItem(SearchDirectionHint searchDirection, int x, int y)
        {
            if ((this.View != System.Windows.Forms.View.SmallIcon) && (this.View != System.Windows.Forms.View.LargeIcon))
            {
                throw new InvalidOperationException(System.Windows.Forms.SR.GetString("ListViewFindNearestItemWorksOnlyInIconView"));
            }
            if ((searchDirection < SearchDirectionHint.Left) || (searchDirection > SearchDirectionHint.Down))
            {
                throw new ArgumentOutOfRangeException("searchDirection", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "searchDirection", searchDirection.ToString() }));
            }
            ListViewItem itemAt = this.GetItemAt(x, y);
            if (itemAt != null)
            {
                Rectangle bounds = itemAt.Bounds;
                Rectangle itemRect = this.GetItemRect(itemAt.Index, ItemBoundsPortion.Icon);
                switch (searchDirection)
                {
                    case SearchDirectionHint.Left:
                        x = Math.Max(bounds.Left, itemRect.Left) - 1;
                        break;

                    case SearchDirectionHint.Up:
                        y = Math.Max(bounds.Top, itemRect.Top) - 1;
                        break;

                    case SearchDirectionHint.Right:
                        x = Math.Max(bounds.Left, itemRect.Left) + 1;
                        break;

                    case SearchDirectionHint.Down:
                        y = Math.Max(bounds.Top, itemRect.Top) + 1;
                        break;
                }
            }
            return this.FindItem(false, string.Empty, false, new Point(x, y), searchDirection, -1, false);
        }
 private ListViewItem FindItem(bool isTextSearch, string text, bool isPrefixSearch, Point pt, SearchDirectionHint dir, int startIndex, bool includeSubItemsInSearch)
 {
     if (this.Items.Count != 0)
     {
         if (!base.IsHandleCreated)
         {
             this.CreateHandle();
         }
         if (this.VirtualMode)
         {
             SearchForVirtualItemEventArgs e = new SearchForVirtualItemEventArgs(isTextSearch, isPrefixSearch, includeSubItemsInSearch, text, pt, dir, startIndex);
             this.OnSearchForVirtualItem(e);
             if (e.Index != -1)
             {
                 return this.Items[e.Index];
             }
             return null;
         }
         System.Windows.Forms.NativeMethods.LVFINDINFO lParam = new System.Windows.Forms.NativeMethods.LVFINDINFO();
         if (isTextSearch)
         {
             lParam.flags = 2;
             lParam.flags |= isPrefixSearch ? 8 : 0;
             lParam.psz = text;
         }
         else
         {
             lParam.flags = 0x40;
             lParam.ptX = pt.X;
             lParam.ptY = pt.Y;
             lParam.vkDirection = (int) dir;
         }
         lParam.lParam = IntPtr.Zero;
         int num = (int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), System.Windows.Forms.NativeMethods.LVM_FINDITEM, startIndex - 1, ref lParam);
         if (num >= 0)
         {
             return this.Items[num];
         }
         if (isTextSearch && includeSubItemsInSearch)
         {
             for (int i = startIndex; i < this.Items.Count; i++)
             {
                 ListViewItem item = this.Items[i];
                 for (int j = 0; j < item.SubItems.Count; j++)
                 {
                     ListViewItem.ListViewSubItem item2 = item.SubItems[j];
                     if (string.Equals(text, item2.Text, StringComparison.OrdinalIgnoreCase))
                     {
                         return item;
                     }
                     if (isPrefixSearch && CultureInfo.CurrentCulture.CompareInfo.IsPrefix(item2.Text, text, CompareOptions.IgnoreCase))
                     {
                         return item;
                     }
                 }
             }
         }
     }
     return null;
 }
        /// <include file='doc\ListViewItem.uex' path='docs/doc[@for="ListViewItem.FindNearestItem"]/*' />
        public ListViewItem FindNearestItem(SearchDirectionHint searchDirection) {
            Rectangle r = this.Bounds;

            switch (searchDirection) {
                case SearchDirectionHint.Up: 
                    return this.ListView.FindNearestItem(searchDirection, r.Left, r.Top);
                case SearchDirectionHint.Down:
                    return this.ListView.FindNearestItem(searchDirection, r.Left, r.Bottom);
                case SearchDirectionHint.Left:
                    return this.ListView.FindNearestItem(searchDirection, r.Left, r.Top);
                case SearchDirectionHint.Right:
                    return this.ListView.FindNearestItem(searchDirection, r.Right, r.Top);
                default :
                    Debug.Fail("we handled all the 4 directions");
                    return null;
            }
        }
Example #31
0
        /// <summary>
        /// Find the first row after the given start in which the text value in the
        /// comparison column begins with the given text. The comparison column is column 0,
        /// unless IsSearchOnSortColumn is true, in which case the current sort column is used.
        /// </summary>
        /// <param name="text">The text to be prefix matched</param>
        /// <param name="start">The index of the first row to consider</param>
        /// <param name="direction">Which direction should be searched?</param>
        /// <returns>The index of the first row that matched, or -1</returns>
        /// <remarks>The text comparison is a case-insensitive, prefix match. The search will
        /// search the every row until a match is found, wrapping at the end if needed.</remarks>
        public virtual int FindMatchingRow(string text, int start, SearchDirectionHint direction)
        {
            // We also can't do anything if we don't have data
            int rowCount = this.GetItemCount();
            if (rowCount == 0)
                return -1;

            // Which column are we going to use for our comparing?
            OLVColumn column = this.GetColumn(0);
            if (this.IsSearchOnSortColumn && this.View == View.Details && this.LastSortColumn != null)
                column = this.LastSortColumn;

            // Do two searches if necessary to find a match. The second search is the wrap-around part of searching
            int i;
            if (direction == SearchDirectionHint.Down) {
                i = this.FindMatchInRange(text, start, rowCount - 1, column);
                if (i == -1 && start > 0)
                    i = this.FindMatchInRange(text, 0, start - 1, column);
            } else {
                i = this.FindMatchInRange(text, start, 0, column);
                if (i == -1 && start != rowCount)
                    i = this.FindMatchInRange(text, rowCount - 1, start + 1, column);
            }

            return i;
        }
Example #32
0
 public ListViewItem FindNearestItem(SearchDirectionHint dir, Point point)
 {
     throw null;
 }