X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e487524e492809638b7e335937c41fd432458a54..e57e26dd03d65ccb816d34b5254398b448e74018:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index d745798ddf..acdf26adfd 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -56,6 +56,7 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) 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) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -64,7 +65,7 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit(void) { // Create the main frame window - MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxListCtrl Test", 50, 50, 450, 340); + MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxListCtrl Test", 50, 50, 450, 340); // This reduces flicker effects - even better would be to define OnEraseBackground // to do nothing. When the list control's scrollbars are show or hidden, the @@ -158,8 +159,8 @@ bool MyApp::OnInit(void) for ( int i=0; i < 30; i++) { - char buf[20]; - sprintf(buf, "Item %d", i); + wxChar buf[20]; + wxSprintf(buf, _T("Item %d"), i); frame->m_listCtrl->InsertItem(i, buf); } @@ -204,61 +205,68 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) { int n = m_listCtrl->GetItemCount(); - int i; - for(i = 0; i < n; i++) + for (int i = 0; i < n; i++) m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED); } void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) { int n = m_listCtrl->GetItemCount(); - int i; - for(i = 0; i < n; i++) + for (int i = 0; i < n; i++) m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); - m_listCtrl->DeleteAllItems(); - m_listCtrl->SetSingleStyle(wxLC_LIST); + m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); + m_listCtrl->SetSingleStyle(wxLC_LIST); m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL); - for ( int i=0; i < 30; i++) - { - char buf[20]; - sprintf(buf, "Item %d", i); - m_listCtrl->InsertItem(i, buf); - } + for ( int i=0; i < 30; i++) + { + wxChar buf[20]; + wxSprintf(buf, _T("Item %d"), i); + m_listCtrl->InsertItem(i, buf); + } } void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); - m_listCtrl->DeleteAllItems(); - m_listCtrl->SetSingleStyle(wxLC_REPORT); + m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); + + m_listCtrl->SetSingleStyle(wxLC_REPORT); m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); - m_listCtrl->InsertColumn(0, "Column 1", wxLIST_FORMAT_LEFT, 140); - m_listCtrl->InsertColumn(1, "Column 2", wxLIST_FORMAT_LEFT, 140); - - for ( int i=0; i < 30; i++) - { - char buf[20]; - sprintf(buf, "Item %d, col 1", i); - long tmp = m_listCtrl->InsertItem(i, buf, 0); - - sprintf(buf, "Item %d, col 2", i); - tmp = m_listCtrl->SetItem(i, 1, buf); - } + m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140); + m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140); + m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140); + + for ( int i=0; i < 30; i++) + { + wxChar buf[50]; + wxSprintf(buf, _T("This is item %d"), i); + long tmp = m_listCtrl->InsertItem(i, buf, 0); + + wxSprintf(buf, _T("Col 1, item %d"), i); + tmp = m_listCtrl->SetItem(i, 1, buf); + + wxSprintf(buf, _T("Item %d in column 2"), i); + tmp = m_listCtrl->SetItem(i, 2, buf); + } + + m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); + m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); + m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); } void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); m_listCtrl->SetSingleStyle(wxLC_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); @@ -271,24 +279,24 @@ void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); m_listCtrl->SetSingleStyle(wxLC_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); for ( int i=0; i < 9; i++) { - char buf[20]; - sprintf(buf, "Label %d", i); + wxChar buf[20]; + wxSprintf(buf, _T("Label %d"), i); m_listCtrl->InsertItem(i, buf, i); } } void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); @@ -301,8 +309,8 @@ void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); @@ -449,7 +457,19 @@ void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event)) text->WriteText("OnDeselected\n"); } -void MyListCtrl::OnListKeyDown(wxListEvent& WXUNUSED(event)) +void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event)) +{ + if ( !wxGetApp().GetTopWindow() ) + return; + + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; + + text->WriteText("OnActivated\n"); +} + +void MyListCtrl::OnListKeyDown(wxListEvent& event) { if ( !wxGetApp().GetTopWindow() ) return; @@ -461,3 +481,4 @@ void MyListCtrl::OnListKeyDown(wxListEvent& WXUNUSED(event)) text->WriteText("OnListKeyDown\n"); } +