+void MyListCtrl::OnGetInfo(wxListEvent& event)
+{
+ wxString msg;
+
+ msg << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
+ if ( event.m_item.m_mask & wxLIST_MASK_STATE )
+ msg << " wxLIST_MASK_STATE";
+ if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
+ msg << " wxLIST_MASK_TEXT";
+ if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
+ msg << " wxLIST_MASK_IMAGE";
+ if ( event.m_item.m_mask & wxLIST_MASK_DATA )
+ msg << " wxLIST_MASK_DATA";
+ if ( event.m_item.m_mask & wxLIST_SET_ITEM )
+ msg << " wxLIST_SET_ITEM";
+ if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
+ msg << " wxLIST_MASK_WIDTH";
+ if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
+ msg << " wxLIST_MASK_WIDTH";
+
+ if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
+ {
+ event.m_item.m_text = "My callback text";
+ }
+
+ wxLogMessage(msg);
+}
+
+void MyListCtrl::OnSetInfo(wxListEvent& event)
+{
+ LogEvent(event, _T("OnSetInfo"));
+}
+
+void MyListCtrl::OnSelected(wxListEvent& event)
+{
+ LogEvent(event, _T("OnSelected"));
+
+ if ( GetWindowStyle() & wxLC_REPORT )
+ {
+ wxListItem info;
+ info.m_itemId = event.m_itemIndex;
+ info.m_col = 1;
+ info.m_mask = wxLIST_MASK_TEXT;
+ if ( GetItem(info) )
+ {
+ wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"),
+ info.m_text.c_str());
+ }
+ else
+ {
+ wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
+ }
+ }
+}
+
+void MyListCtrl::OnDeselected(wxListEvent& event)
+{
+ LogEvent(event, _T("OnDeselected"));
+}
+
+void MyListCtrl::OnActivated(wxListEvent& event)
+{
+ LogEvent(event, _T("OnActivated"));
+}
+
+void MyListCtrl::OnListKeyDown(wxListEvent& event)
+{
+ switch ( event.GetCode() )
+ {
+ case 'c':
+ {
+ wxListItem info;
+ info.m_itemId = event.GetIndex();
+ GetItem(info);
+
+ wxListItemAttr *attr = info.GetAttributes();
+ if ( !attr || !attr->HasTextColour() )
+ {
+ info.SetTextColour(*wxCYAN);
+
+ SetItem(info);
+ }
+ }
+ break;
+
+ case WXK_DELETE:
+ {
+ long item = GetNextItem(-1,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ while ( item != -1 )
+ {
+ DeleteItem(item);
+
+ wxLogMessage(_T("Item %ld deleted"), item);
+
+ // -1 because the indices were shifted by DeleteItem()
+ item = GetNextItem(item - 1,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ }
+ }
+ break;
+
+ case WXK_INSERT:
+ if ( GetWindowStyle() & wxLC_REPORT )
+ {
+ if ( GetWindowStyle() & wxLC_VIRTUAL )
+ {
+ SetItemCount(GetItemCount() + 1);
+ }
+ else // !virtual
+ {
+ InsertItemInReportView(event.GetIndex());
+ }
+ }
+ //else: fall through
+
+ default:
+ LogEvent(event, _T("OnListKeyDown"));
+
+ event.Skip();
+ }
+}
+
+void MyListCtrl::OnChar(wxKeyEvent& event)
+{
+ wxLogMessage(_T("Got char event."));
+
+ event.Skip();
+}
+
+void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName)
+{
+ wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
+ event.GetIndex(), eventName,
+ event.GetText().c_str(), event.GetData());
+}
+
+wxString MyListCtrl::OnGetItemText(long item, long column) const
+{
+ return wxString::Format(_T("Column %ld of item %ld"), column, item);
+}
+
+int MyListCtrl::OnGetItemImage(long item) const
+{
+ return 0;
+}
+
+wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const
+{
+ return item % 2 ? NULL : (wxListItemAttr *)&m_attr;