+void MyFrame::OnSmallVirtualView(wxCommandEvent& WXUNUSED(event))
+{
+ m_smallVirtual = true;
+ RecreateList(wxLC_REPORT | wxLC_VIRTUAL);
+}
+
+void MyFrame::OnSetItemsCount(wxCommandEvent& WXUNUSED(event))
+{
+ int numItems = wxGetNumberFromUser
+ (
+ "Enter the initial number of items for "
+ "the list and report views",
+ "Number of items:",
+ "wxWidgets wxListCtrl sample",
+ m_numListItems,
+ 0,
+ 10000,
+ this
+ );
+ if ( numItems == -1 || numItems == m_numListItems )
+ return;
+
+ m_numListItems = numItems;
+
+ if ( m_listCtrl->HasFlag(wxLC_REPORT) &&
+ !m_listCtrl->HasFlag(wxLC_VIRTUAL) )
+ RecreateList(wxLC_REPORT);
+ else if ( m_listCtrl->HasFlag(wxLC_LIST) )
+ RecreateList(wxLC_LIST);
+}
+
+void MyFrame::InitWithVirtualItems()
+{
+ m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
+
+ if ( m_smallVirtual )
+ {
+ m_listCtrl->InsertColumn(0, wxT("Animal"));
+ m_listCtrl->InsertColumn(1, wxT("Sound"));
+ m_listCtrl->SetItemCount(WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS));
+ }
+ else
+ {
+ m_listCtrl->InsertColumn(0, wxT("First Column"));
+ m_listCtrl->InsertColumn(1, wxT("Second Column"));
+ m_listCtrl->SetColumnWidth(0, 150);
+ m_listCtrl->SetColumnWidth(1, 150);
+ m_listCtrl->SetItemCount(1000000);
+ }
+}
+
+void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
+{
+ wxStopWatch sw;
+
+ m_listCtrl->SortItems(MyCompareFunction, 0);
+
+ m_logWindow->WriteText(wxString::Format(wxT("Sorting %d items took %ld ms\n"),
+ m_listCtrl->GetItemCount(),
+ sw.Time()));
+}
+
+void MyFrame::OnFind(wxCommandEvent& WXUNUSED(event))
+{
+ wxStopWatch sw;
+
+ const int itemCount = m_listCtrl->GetItemCount();
+ for ( int i = 0; i < itemCount; i++ )
+ m_listCtrl->FindItem(-1, i);
+
+ wxLogMessage("Calling Find() for all %d items took %ld ms",
+ itemCount, sw.Time());
+}
+
+void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event))
+{
+ int selCount = m_listCtrl->GetSelectedItemCount();
+ wxLogMessage(wxT("%d items selected:"), selCount);
+
+ // don't show too many items
+ size_t shownCount = 0;
+
+ long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+ while ( item != -1 )
+ {
+ wxLogMessage(wxT("\t%ld (%s)"),
+ item, m_listCtrl->GetItemText(item).c_str());
+
+ if ( ++shownCount > 10 )
+ {
+ wxLogMessage(wxT("\t... more selected items snipped..."));
+ break;
+ }
+
+ item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+ }
+}
+
+void MyFrame::OnShowViewRect(wxCommandEvent& WXUNUSED(event))
+{
+ const wxRect r = m_listCtrl->GetViewRect();
+ wxLogMessage("View rect: (%d, %d)-(%d, %d)",
+ r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+}
+
+// ----------------------------------------------------------------------------
+// column order tests
+// ----------------------------------------------------------------------------
+
+#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
+
+static wxString DumpIntArray(const wxArrayInt& a)
+{
+ wxString s("{ ");
+ const size_t count = a.size();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ if ( n )
+ s += ", ";
+ s += wxString::Format("%lu", (unsigned long)a[n]);
+ }
+
+ s += " }";
+
+ return s;
+}
+
+void MyFrame::OnSetColOrder(wxCommandEvent& WXUNUSED(event))
+{
+ wxArrayInt order(3);
+ order[0] = 2;
+ order[1] = 0;
+ order[2] = 1;
+ if ( m_listCtrl->SetColumnsOrder(order) )
+ {
+ wxLogMessage("Column order set to %s", DumpIntArray(order));
+ }
+}
+
+void MyFrame::OnGetColOrder(wxCommandEvent& WXUNUSED(event))
+{
+ // show what GetColumnsOrder() returns
+ const wxArrayInt order = m_listCtrl->GetColumnsOrder();
+ wxString msg = "Columns order: " +
+ DumpIntArray(m_listCtrl->GetColumnsOrder()) + "\n";
+
+ int n;
+ const int count = m_listCtrl->GetColumnCount();
+
+ // show the results of GetColumnOrder() for each column
+ msg += "GetColumnOrder() results:\n";
+ for ( n = 0; n < count; n++ )
+ {
+ msg += wxString::Format(" %2d -> %2d\n",
+ n, m_listCtrl->GetColumnOrder(n));
+ }
+
+ // and the results of GetColumnIndexFromOrder() too
+ msg += "GetColumnIndexFromOrder() results:\n";
+ for ( n = 0; n < count; n++ )
+ {
+ msg += wxString::Format(" %2d -> %2d\n",
+ n, m_listCtrl->GetColumnIndexFromOrder(n));
+ }
+
+ wxLogMessage("%s", msg);
+}
+
+#endif // wxHAS_LISTCTRL_COLUMN_ORDER
+
+void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event))
+{
+ int count = m_listCtrl->GetColumnCount();
+ wxLogMessage(wxT("%d columns:"), count);
+ for ( int c = 0; c < count; c++ )
+ {
+ wxLogMessage(wxT("\tcolumn %d has width %d"), c,
+ m_listCtrl->GetColumnWidth(c));
+ }
+}
+
+void MyFrame::OnUpdateUIEnableInReport(wxUpdateUIEvent& event)
+{
+ event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 );
+}