+ 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);
+}
+
+void MyListCtrl::OnColClick(wxListEvent& event)
+{
+ int col = event.GetColumn();
+
+ // set or unset image
+ static bool x = false;
+ x = !x;
+ SetColumnImage(col, x ? 0 : -1);
+
+ wxLogMessage( wxT("OnColumnClick at %d."), col );
+}
+
+void MyListCtrl::OnColRightClick(wxListEvent& event)
+{
+ int col = event.GetColumn();
+ if ( col != -1 )
+ {
+ SetColumnImage(col, -1);
+ }
+
+ // Show popupmenu at position
+ wxMenu menu(wxT("Test"));
+ menu.Append(LIST_ABOUT, wxT("&About"));
+ PopupMenu(&menu, event.GetPoint());
+
+ wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
+}
+
+void MyListCtrl::LogColEvent(const wxListEvent& event, const wxChar *name)
+{
+ const int col = event.GetColumn();
+
+ wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
+ name,
+ col,
+ event.GetItem().GetWidth(),
+ GetColumnWidth(col));
+}
+
+void MyListCtrl::OnColBeginDrag(wxListEvent& event)
+{
+ LogColEvent( event, wxT("OnColBeginDrag") );
+
+ if ( event.GetColumn() == 0 )
+ {
+ wxLogMessage(wxT("Resizing this column shouldn't work."));
+
+ event.Veto();
+ }
+}
+
+void MyListCtrl::OnColDragging(wxListEvent& event)
+{
+ LogColEvent( event, wxT("OnColDragging") );
+}
+
+void MyListCtrl::OnColEndDrag(wxListEvent& event)
+{
+ LogColEvent( event, wxT("OnColEndDrag") );
+}
+
+void MyListCtrl::OnBeginDrag(wxListEvent& event)
+{
+ const wxPoint& pt = event.m_pointDrag;
+
+ int flags;
+ wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
+ pt.x, pt.y, HitTest(pt, flags) );
+}
+
+void MyListCtrl::OnBeginRDrag(wxListEvent& event)
+{
+ wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
+ event.m_pointDrag.x, event.m_pointDrag.y );
+}
+
+void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
+{
+ wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
+
+ wxTextCtrl * const text = GetEditControl();
+ if ( !text )
+ {
+ wxLogMessage("BUG: started to edit but no edit control");
+ }
+ else
+ {
+ wxLogMessage("Edit control value: \"%s\"", text->GetValue());
+ }
+}
+
+void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
+{
+ wxLogMessage( wxT("OnEndLabelEdit: %s"),
+ (
+ event.IsEditCancelled() ?
+ wxString("[cancelled]") :
+ event.m_item.m_text
+ ).c_str()
+ );
+}
+
+void MyListCtrl::OnDeleteItem(wxListEvent& event)
+{
+ LogEvent(event, wxT("OnDeleteItem"));
+ wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
+}
+
+void MyListCtrl::OnDeleteAllItems(wxListEvent& event)
+{
+ LogEvent(event, wxT("OnDeleteAllItems"));
+}
+
+void MyListCtrl::OnSelected(wxListEvent& event)
+{
+ LogEvent(event, wxT("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"));
+ }
+ }