+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 );
+}
+
+void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event))
+{
+ long flags = m_listCtrl->GetWindowStyleFlag();
+ if ( flags & wxLC_SINGLE_SEL )
+ flags &= ~wxLC_SINGLE_SEL;
+ else
+ flags |= wxLC_SINGLE_SEL;
+
+ m_logWindow->WriteText(wxString::Format(wxT("Current selection mode: %sle\n"),
+ (flags & wxLC_SINGLE_SEL) ? wxT("sing") : wxT("multip")));
+
+ RecreateList(flags);
+}
+
+void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event)
+{
+ event.Check(!m_listCtrl->HasFlag(wxLC_SINGLE_SEL));
+}
+
+void MyFrame::OnUpdateToggleHeader(wxUpdateUIEvent& event)
+{
+ event.Check(!m_listCtrl->HasFlag(wxLC_NO_HEADER));
+}
+
+void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
+ m_listCtrl->Refresh();
+}
+
+void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this));
+ m_listCtrl->Refresh();
+}
+
+void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), wxT("Appended item"));
+}
+
+void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event))
+{
+ // demonstrate cancelling editing: this currently is wxMSW-only
+#ifdef __WXMSW__
+ if ( m_listCtrl->GetEditControl() )
+ {
+ m_listCtrl->EndEditLabel(true);
+ }
+ else // start editing
+#endif // __WXMSW__
+ {
+ long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
+ wxLIST_STATE_FOCUSED);
+
+ if ( itemCur != -1 )
+ {
+ m_listCtrl->EditLabel(itemCur);
+ }
+ else
+ {
+ m_logWindow->WriteText(wxT("No item to edit"));
+ }
+ }
+}
+
+void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
+{
+ if ( m_listCtrl->GetItemCount() )
+ {
+ m_listCtrl->DeleteItem(0);
+ }
+ else
+ {
+ m_logWindow->WriteText(wxT("Nothing to delete"));
+ }
+}
+
+void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
+{
+ wxStopWatch sw;
+
+ int itemCount = m_listCtrl->GetItemCount();
+
+ m_listCtrl->DeleteAllItems();
+
+ m_logWindow->WriteText(wxString::Format(wxT("Deleting %d items took %ld ms\n"),
+ itemCount,
+ sw.Time()));
+}
+
+
+// ----------------------------------------------------------------------------
+// MyListCtrl
+// ----------------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
+ EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
+ EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
+ EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)
+ EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit)
+ EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
+ EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
+ EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected)
+ EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
+ EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
+ EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
+ EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
+
+ EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
+ EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
+ EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
+ EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
+ EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
+
+ EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
+
+#if USE_CONTEXT_MENU
+ EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
+#endif
+ EVT_CHAR(MyListCtrl::OnChar)
+
+ EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
+END_EVENT_TABLE()
+
+void MyListCtrl::OnCacheHint(wxListEvent& event)
+{
+ wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
+ event.GetCacheFrom(), event.GetCacheTo() );
+}
+
+void MyListCtrl::SetColumnImage(int col, int image)
+{
+ wxListItem item;
+ item.SetMask(wxLIST_MASK_IMAGE);
+ item.SetImage(image);
+ SetColumn(col, item);