Page 1 of 1

Filtered wxListBox Problem with WxWidgets-3.1.1

Posted: Thu May 17, 2018 3:26 am
by ggbutcher
For completeness, I searched first, only found this thread:
viewtopic.php?f=1&t=19997&hilit=filtered+wxListBox

I subclassed wxListBox to do just this, filter the list based on a string, list pares down to just those entries that contain the string. It behaves fine in wxWidgets-3.1.0, but the listbox just stops working (no scroll, no select, no filter) when a space character is encountered in the filter string with wxWidgets-3.1.1. I reviewed the commits between the two versions, can't find anything pertinent. Here's the code:

Code: Select all

class myListCtrl: public wxListCtrl
{
	public:
		//Constructs the list control, populated with the items passed in the listitems wxArrayString:
		myListCtrl(wxWindow *parent, wxWindowID id, wxString listname, wxArrayString listitems, const wxPoint &pos=wxDefaultPositi
			wxListCtrl(parent, id, pos, size, wxLC_REPORT | wxLC_NO_HEADER | wxLC_HRULES, wxDefaultValidator, listname)
		{
			//SetDoubleBuffered(true);
			name = listname;
			width = size.x;
			wxListItem col0;
			col0.SetId(0);
			col0.SetText(name );
			col0.SetWidth(width);
			InsertColumn(0, col0);

			itemlist = listitems;

			for (int i=0; i<itemlist.GetCount(); i++) {
				wxListItem item;
				item.SetId(i);
				item.SetText( itemlist[i] );
				InsertItem( item );
			}

			filter = "";
			selected = "";

			Bind(wxEVT_LIST_ITEM_SELECTED, &myListCtrl::Selected, this);
		}

		//Filters the list to include only entries that contain the specified string:
		void setFilter(wxString f)
		{
			filter = f;
			DeleteAllItems();

			for (int i=0; i<itemlist.GetCount(); i++) {
				if (itemlist[i].Find(filter) != wxNOT_FOUND) {
					wxListItem item;
					item.SetId(j);
					item.SetText( itemlist[i] );
					InsertItem( item );
					j++;
					filteredlist.Add(itemlist[i]);
				}
			}
			Refresh();
		}

		//Captures the entry selected, at selection:
		void Selected(wxListEvent& event)
		{
			selected = event.GetText();
			event.Skip();
		}

		//Returns the selected entry, as populated by the wxListEvent method:
		wxString GetSelected()
		{
			return selected;
		}

	private:
		int width;
		wxArrayString itemlist;
		wxString filter, selected, name;
};
Insights would be much appreciated!

Re: Filtered wxListBox Problem with WxWidgets-3.1.1

Posted: Thu May 17, 2018 8:43 am
by doublemax
It behaves fine in wxWidgets-3.1.0, but the listbox just stops working (no scroll, no select, no filter) when a space character is encountered in the filter string with wxWidgets-3.1.1
I assume that you mean that the list is always empty after filtering? That would mean that wxString::Find is buggy, which i find very unlikely.

Can you try to narrow it down a bit more and check where exactly the problem occurs?

Edit: Just tested this in 3.1.1, works fine. Either the problem lies somewhere else or i misunderstood what the problem is.

Re: Filtered wxListBox Problem with WxWidgets-3.1.1

Posted: Thu May 17, 2018 4:06 pm
by ONEEYEMAN
Hi,
Can you do the git bisection to find the breaking commit?

More info here.

Git is great for that.

Thank you.

Re: Filtered wxListBox Problem with WxWidgets-3.1.1

Posted: Fri May 18, 2018 12:05 am
by ggbutcher
Well, came back home from work with the intent to duplicate the problem, and now I can't. I thought it'd be Win32 specific, but that seems to be working now, both wxWidgets-3.1.0 and 3.1.1.

Thanks for investigating, and enjoy the sub-class...!