X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2049ba38adafa0ec146880de29f26e32dd69a125..6b3eb77aece0708b6c9dd0c58bd2b4408e4fac9d:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index d51ecae827..4d1ffa42c8 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -25,6 +25,10 @@ #include "wx/wx.h" #endif +#ifndef __WXMSW__ +#include "mondrian.xpm" +#endif + #include "wx/listctrl.h" #include "listtest.h" @@ -37,6 +41,8 @@ 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_DESELECT_ALL, MyFrame::OnDeselectAll) + EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) @@ -49,7 +55,8 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo) EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) - EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnKeyDown) + EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) + EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -58,56 +65,58 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit(void) { // Create the main frame window - MyFrame *frame = new MyFrame(NULL, "wxListCtrl Test", 50, 50, 450, 340); + MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "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 // frame is sent a background erase event. - frame->SetBackgroundColour(wxColour(255, 255, 255)); + frame->SetBackgroundColour( *wxWHITE ); // Give it an icon -#ifdef __WXMSW__ - frame->SetIcon(wxIcon("mondrian")); -#endif -#ifdef __X__ - frame->SetIcon(wxIcon("aiai.xbm")); -#endif + frame->SetIcon( wxICON(mondrian) ); // Make an image list containing large icons m_imageListNormal = new wxImageList(32, 32, TRUE); m_imageListSmall = new wxImageList(16, 16, TRUE); - wxIcon *icon = new wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - icon = new wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListNormal->Add(*icon); - delete icon; - - icon = new wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE); - m_imageListSmall->Add(*icon); - delete icon; +#ifdef __WXMSW__ + m_imageListNormal->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE) ); + m_imageListNormal->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE) ); + + m_imageListSmall->Add( wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE) ); + +#else + + #include "bitmaps/toolbrai.xpm" + m_imageListNormal->Add( wxIcon( toolbrai_xpm ) ); + #include "bitmaps/toolchar.xpm" + m_imageListNormal->Add( wxIcon( toolchar_xpm ) ); + #include "bitmaps/tooldata.xpm" + m_imageListNormal->Add( wxIcon( tooldata_xpm ) ); + #include "bitmaps/toolnote.xpm" + m_imageListNormal->Add( wxIcon( toolnote_xpm ) ); + #include "bitmaps/tooltodo.xpm" + m_imageListNormal->Add( wxIcon( tooltodo_xpm ) ); + #include "bitmaps/toolchec.xpm" + m_imageListNormal->Add( wxIcon( toolchec_xpm ) ); + #include "bitmaps/toolgame.xpm" + m_imageListNormal->Add( wxIcon( toolgame_xpm ) ); + #include "bitmaps/tooltime.xpm" + m_imageListNormal->Add( wxIcon( tooltime_xpm ) ); + #include "bitmaps/toolword.xpm" + m_imageListNormal->Add( wxIcon( toolword_xpm ) ); + + #include "bitmaps/small1.xpm" + m_imageListSmall->Add( wxIcon( small1_xpm) ); + +#endif // Make a menubar wxMenu *file_menu = new wxMenu; @@ -118,6 +127,8 @@ bool MyApp::OnInit(void) file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text"); file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view"); file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text"); + file_menu->Append(LIST_DESELECT_ALL, "&Deselect All"); + file_menu->Append(LIST_SELECT_ALL, "S&elect All"); file_menu->AppendSeparator(); file_menu->Append(LIST_ABOUT, "&About"); file_menu->Append(LIST_QUIT, "E&xit"); @@ -150,7 +161,7 @@ bool MyApp::OnInit(void) { char buf[20]; sprintf(buf, "Item %d", i); - long tmp = frame->m_listCtrl->InsertItem(i, buf); + frame->m_listCtrl->InsertItem(i, buf); } frame->CreateStatusBar(3); @@ -168,8 +179,8 @@ bool MyApp::OnInit(void) MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) { - m_listCtrl = NULL; - m_logWindow = NULL; + m_listCtrl = (MyListCtrl *) NULL; + m_logWindow = (wxTextCtrl *) NULL; } MyFrame::~MyFrame(void) @@ -178,12 +189,12 @@ MyFrame::~MyFrame(void) delete wxGetApp().m_imageListSmall; } -void MyFrame::OnQuit(wxCommandEvent& event) +void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); } -void MyFrame::OnAbout(wxCommandEvent& event) +void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997", "About list test", wxOK|wxCANCEL); @@ -191,28 +202,44 @@ void MyFrame::OnAbout(wxCommandEvent& event) dialog.ShowModal(); } -void MyFrame::OnListView(wxCommandEvent& event) +void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) +{ + int n = m_listCtrl->GetItemCount(); + int i; + for(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++) + m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); +} + +void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); m_listCtrl->SetSingleStyle(wxLC_LIST); - m_listCtrl->SetImageList(NULL, wxIMAGE_LIST_NORMAL); - m_listCtrl->SetImageList(NULL, wxIMAGE_LIST_SMALL); + 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); - long tmp = m_listCtrl->InsertItem(i, buf); + m_listCtrl->InsertItem(i, buf); } } -void MyFrame::OnReportView(wxCommandEvent& event) +void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) { - m_logWindow->Clear(); m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); m_listCtrl->SetSingleStyle(wxLC_REPORT); - m_listCtrl->SetImageList(NULL, wxIMAGE_LIST_NORMAL); + 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); @@ -229,24 +256,24 @@ void MyFrame::OnReportView(wxCommandEvent& event) } } -void MyFrame::OnIconView(wxCommandEvent& event) +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); for ( int i=0; i < 9; i++) { - long tmp = m_listCtrl->InsertItem(i, i); + m_listCtrl->InsertItem(i, i); } } -void MyFrame::OnIconTextView(wxCommandEvent& 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); @@ -255,41 +282,41 @@ void MyFrame::OnIconTextView(wxCommandEvent& event) { char buf[20]; sprintf(buf, "Label %d", i); - long tmp = m_listCtrl->InsertItem(i, buf, i); + m_listCtrl->InsertItem(i, buf, i); } } -void MyFrame::OnSmallIconView(wxCommandEvent& event) +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); for ( int i=0; i < 9; i++) { - long tmp = m_listCtrl->InsertItem(i, 0); + m_listCtrl->InsertItem(i, 0); } } -void MyFrame::OnSmallIconTextView(wxCommandEvent& 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); for ( int i=0; i < 9; i++) { - long tmp = m_listCtrl->InsertItem(i, "Label", 0); + m_listCtrl->InsertItem(i, "Label", 0); } } // MyListCtrl -void MyListCtrl::OnBeginDrag(wxListEvent& event) +void MyListCtrl::OnBeginDrag(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -298,15 +325,10 @@ void MyListCtrl::OnBeginDrag(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnBeginDrag\n"; - str.flush(); -#endif + text->WriteText("OnBeginDrag\n"); } -void MyListCtrl::OnBeginRDrag(wxListEvent& event) +void MyListCtrl::OnBeginRDrag(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -314,15 +336,10 @@ void MyListCtrl::OnBeginRDrag(wxListEvent& event) wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnBeginRDrag\n"; - str.flush(); -#endif + text->WriteText("OnBeginRDrag\n"); } -void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) +void MyListCtrl::OnBeginLabelEdit(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -331,15 +348,10 @@ void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnBeginLabelEdit\n"; - str.flush(); -#endif + text->WriteText("OnBeginLabelEdit\n"); } -void MyListCtrl::OnEndLabelEdit(wxListEvent& event) +void MyListCtrl::OnEndLabelEdit(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -348,15 +360,10 @@ void MyListCtrl::OnEndLabelEdit(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnEndLabelEdit\n"; - str.flush(); -#endif + text->WriteText("OnEndLabelEdit\n"); } -void MyListCtrl::OnDeleteItem(wxListEvent& event) +void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -365,15 +372,10 @@ void MyListCtrl::OnDeleteItem(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnDeleteItem\n"; - str.flush(); -#endif + text->WriteText("OnDeleteItem\n"); } -void MyListCtrl::OnGetInfo(wxListEvent& event) +void MyListCtrl::OnGetInfo(wxListEvent& /*event*/) { if ( !wxGetApp().GetTopWindow() ) return; @@ -382,7 +384,9 @@ void MyListCtrl::OnGetInfo(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ + text->WriteText("OnGetInfo\n"); + +/* ostream str(text); str << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")"; @@ -407,10 +411,10 @@ void MyListCtrl::OnGetInfo(wxListEvent& event) } str << "\n"; str.flush(); -#endif +*/ } -void MyListCtrl::OnSetInfo(wxListEvent& event) +void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -419,15 +423,10 @@ void MyListCtrl::OnSetInfo(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnSetInfo\n"; - str.flush(); -#endif + text->WriteText("OnSetInfo\n"); } -void MyListCtrl::OnSelected(wxListEvent& event) +void MyListCtrl::OnSelected(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -436,15 +435,10 @@ void MyListCtrl::OnSelected(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnSelected\n"; - str.flush(); -#endif + text->WriteText("OnSelected\n"); } -void MyListCtrl::OnDeselected(wxListEvent& event) +void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -453,15 +447,10 @@ void MyListCtrl::OnDeselected(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); - - str << "OnDeselected\n"; - str.flush(); -#endif + text->WriteText("OnDeselected\n"); } -void MyListCtrl::OnKeyDown(wxListEvent& event) +void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event)) { if ( !wxGetApp().GetTopWindow() ) return; @@ -470,11 +459,19 @@ void MyListCtrl::OnKeyDown(wxListEvent& event) if ( !text ) return; -#ifndef __GNUWIN32__ - ostream str(text); + text->WriteText("OnActivated\n"); +} - str << "OnKeyDown\n"; - str.flush(); -#endif +void MyListCtrl::OnListKeyDown(wxListEvent& event) +{ + if ( !wxGetApp().GetTopWindow() ) + return; + + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; + + text->WriteText("OnListKeyDown\n"); } +