X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ea4780630b335a1b8b2d3a94c0b82e46f4c56f6..fe8aa971c4c66cc68ba6b64c61fae8149477bb5f:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 8e6f0efad2..f8a8a18f3a 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -60,6 +60,7 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) 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_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -146,7 +147,7 @@ bool MyApp::OnInit(void) // Make a panel with a message frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL, wxPoint(0, 0), wxSize(400, 200), - wxLC_LIST|wxSUNKEN_BORDER); + wxLC_LIST|wxSUNKEN_BORDER|wxLC_EDIT_LABELS ); // wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE|wxSUNKEN_BORDER); @@ -353,7 +354,7 @@ void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event)) // MyListCtrl -void MyListCtrl::OnBeginDrag(wxListEvent& WXUNUSED(event)) +void MyListCtrl::OnColClick(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -362,10 +363,12 @@ void MyListCtrl::OnBeginDrag(wxListEvent& WXUNUSED(event)) if ( !text ) return; - text->WriteText("OnBeginDrag\n"); + wxString msg; + msg.Printf( "OnColumnClick at %d.\n", event.GetColumn() ); + text->WriteText(msg); } -void MyListCtrl::OnBeginRDrag(wxListEvent& WXUNUSED(event)) +void MyListCtrl::OnBeginDrag(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -373,10 +376,13 @@ void MyListCtrl::OnBeginRDrag(wxListEvent& WXUNUSED(event)) wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; if ( !text ) return; - text->WriteText("OnBeginRDrag\n"); + + wxString msg; + msg.Printf( "OnBeginDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y ); + text->WriteText(msg); } -void MyListCtrl::OnBeginLabelEdit(wxListEvent& WXUNUSED(event)) +void MyListCtrl::OnBeginRDrag(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -385,10 +391,12 @@ void MyListCtrl::OnBeginLabelEdit(wxListEvent& WXUNUSED(event)) if ( !text ) return; - text->WriteText("OnBeginLabelEdit\n"); + wxString msg; + msg.Printf( "OnBeginRDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y ); + text->WriteText(msg); } -void MyListCtrl::OnEndLabelEdit(wxListEvent& WXUNUSED(event)) +void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -397,7 +405,23 @@ void MyListCtrl::OnEndLabelEdit(wxListEvent& WXUNUSED(event)) if ( !text ) return; - text->WriteText("OnEndLabelEdit\n"); + text->WriteText("OnBeginLabelEdit: "); + text->WriteText(event.m_item.m_text); + text->WriteText("\n"); +} + +void MyListCtrl::OnEndLabelEdit(wxListEvent& event) +{ + if ( !wxGetApp().GetTopWindow() ) + return; + + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; + + text->WriteText("OnEndLabelEdit: "); + text->WriteText(event.m_item.m_text); + text->WriteText("\n"); } void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event)) @@ -412,7 +436,7 @@ void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event)) text->WriteText("OnDeleteItem\n"); } -void MyListCtrl::OnGetInfo(wxListEvent& /*event*/) +void MyListCtrl::OnGetInfo(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -421,34 +445,29 @@ void MyListCtrl::OnGetInfo(wxListEvent& /*event*/) if ( !text ) return; - text->WriteText("OnGetInfo\n"); + text->WriteText("OnGetInfo\n"); -/* - ostream str(text); - - str << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")"; + (*text) << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")"; if ( event.m_item.m_mask & wxLIST_MASK_STATE ) - str << " wxLIST_MASK_STATE"; + (*text) << " wxLIST_MASK_STATE"; if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) - str << " wxLIST_MASK_TEXT"; + (*text) << " wxLIST_MASK_TEXT"; if ( event.m_item.m_mask & wxLIST_MASK_IMAGE ) - str << " wxLIST_MASK_IMAGE"; + (*text) << " wxLIST_MASK_IMAGE"; if ( event.m_item.m_mask & wxLIST_MASK_DATA ) - str << " wxLIST_MASK_DATA"; + (*text) << " wxLIST_MASK_DATA"; if ( event.m_item.m_mask & wxLIST_SET_ITEM ) - str << " wxLIST_SET_ITEM"; + (*text) << " wxLIST_SET_ITEM"; if ( event.m_item.m_mask & wxLIST_MASK_WIDTH ) - str << " wxLIST_MASK_WIDTH"; + (*text) << " wxLIST_MASK_WIDTH"; if ( event.m_item.m_mask & wxLIST_MASK_FORMAT ) - str << " wxLIST_MASK_WIDTH"; + (*text) << " wxLIST_MASK_WIDTH"; if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) { event.m_item.m_text = "My callback text"; } - str << "\n"; - str.flush(); -*/ + (*text) << "\n"; } void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event)) @@ -463,7 +482,7 @@ void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event)) text->WriteText("OnSetInfo\n"); } -void MyListCtrl::OnSelected(wxListEvent& WXUNUSED(event)) +void MyListCtrl::OnSelected(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -472,6 +491,20 @@ void MyListCtrl::OnSelected(wxListEvent& WXUNUSED(event)) if ( !text ) return; + wxListItem info; + info.m_itemId = event.m_itemIndex; + info.m_col = 1; + info.m_mask = wxLIST_MASK_TEXT; + if ( GetItem(info) ) + { + *text << "Value of the 2nd field of the selected item: " + << info.m_text << '\n'; + } + else + { + wxFAIL_MSG("wxListCtrl::GetItem() failed"); + } + text->WriteText("OnSelected\n"); }