From: Robert Roebling Date: Wed, 29 Nov 2006 21:10:21 +0000 (+0000) Subject: Simpler version of [ 1604590 ] wxListCtrl::FindItem & wxString X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2373946593915777d45172bfbfebc50501f3e3c3 Simpler version of [ 1604590 ] wxListCtrl::FindItem & wxString git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43719 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/listctrl.tex b/docs/latex/wx/listctrl.tex index 05aa3c6578..538cc1942a 100644 --- a/docs/latex/wx/listctrl.tex +++ b/docs/latex/wx/listctrl.tex @@ -253,7 +253,9 @@ Ensures this item is visible. \func{long}{FindItem}{\param{long }{start}, \param{const wxString\& }{str}, \param{const bool }{partial = false}} Find an item whose label matches this string, starting from {\it start} or -the beginning if {\it start} is -1. +the beginning if {\it start} is -1. The string comparison is case +insensitive. If {\it partial} is true then this method will look for +items which begin with {\it str}. \func{long}{FindItem}{\param{long }{start}, \param{long }{data}} diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 40a79102d5..152e440036 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -4501,10 +4501,13 @@ void wxListMainWindow::EnsureVisible( long index ) MoveToItem((size_t)index); } -long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) +long wxListMainWindow::FindItem(long start, const wxString& str, bool partial ) { + if (str.empty()) + return wxNOT_FOUND; + long pos = start; - wxString tmp = str; + wxString str_upper = str.Upper(); if (pos < 0) pos = 0; @@ -4512,8 +4515,17 @@ long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(p for ( size_t i = (size_t)pos; i < count; i++ ) { wxListLineData *line = GetLine(i); - if ( line->GetText(0) == tmp ) - return i; + wxString line_upper = line->GetText(0).Upper(); + if (!partial) + { + if (line_upper == str_upper ) + return i; + } + else + { + if (line_upper.find(str_upper) == 0) + return i; + } } return wxNOT_FOUND;