X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c41ea66a5de1e88529e0ce2e629f5757b219b97d..790ba06b28f232abc42c4ed784df4b86bfbfe5e6:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index c90a74ae76..5ebd4f6568 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -40,6 +40,7 @@ #include "bitmaps/small1.xpm" #endif +#include "wx/imaglist.h" #include "wx/listctrl.h" #include "wx/timer.h" // for wxStopWatch #include "wx/colordlg.h" // for wxGetColourFromUser @@ -57,6 +58,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView) EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView) EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView) + EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel) EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll) @@ -64,6 +66,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour) EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour) EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) + EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo) + EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo) END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) @@ -80,6 +84,8 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) + + EVT_CHAR(MyListCtrl::OnChar) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -165,8 +171,10 @@ MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text\tF6"); wxMenu *menuList = new wxMenu; + menuList->Append(LIST_TOGGLE_FIRST, "&Toggle first item\tCtrl-T"); menuList->Append(LIST_DESELECT_ALL, "&Deselect All\tCtrl-D"); menuList->Append(LIST_SELECT_ALL, "S&elect All\tCtrl-A"); + menuList->Append(LIST_SHOW_COL_INFO, "Show &column info\tCtrl-C"); menuList->AppendSeparator(); menuList->Append(LIST_SORT, "&Sort\tCtrl-S"); menuList->AppendSeparator(); @@ -258,6 +266,11 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) dialog.ShowModal(); } +void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event)) +{ + m_listCtrl->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); +} + void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) { int n = m_listCtrl->GetItemCount(); @@ -308,7 +321,7 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) wxStopWatch sw; wxString buf; - static const int NUM_ITEMS = 3000; + static const int NUM_ITEMS = 30;//00; for ( int i = 0; i < NUM_ITEMS; i++ ) { buf.Printf(_T("This is item %d"), i); @@ -422,6 +435,22 @@ void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) sw.Time())); } +void MyFrame::OnShowColInfo(wxCommandEvent& event) +{ + int count = m_listCtrl->GetColumnCount(); + wxLogMessage("%d columns:", count); + for ( int c = 0; c < count; c++ ) + { + wxLogMessage("\tcolumn %d has width %d", c, + m_listCtrl->GetColumnWidth(c)); + } +} + +void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent& event) +{ + event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 ); +} + void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event)) { m_logWindow->WriteText("Current selection mode: "); @@ -571,11 +600,21 @@ void MyListCtrl::OnActivated(wxListEvent& event) void MyListCtrl::OnListKeyDown(wxListEvent& event) { 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 data = %ld)"), - event.GetIndex(), eventName, event.GetData()); + wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"), + event.GetIndex(), eventName, + event.GetText().c_str(), event.GetData()); }