X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1bab36277c418507195638ace24ea9cedc78391c..e0dec8753abaf97e006ea1185bfb6775b28df0a8:/samples/listctrl/listtest.cpp?ds=sidebyside diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index bf2ef2c376..c7fbde5c45 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". @@ -20,11 +20,11 @@ #include "wx/wx.h" #endif -#if !defined(__WXMSW__) && !defined(__WXPM__) - #include "mondrian.xpm" +#ifndef wxHAS_IMAGES_IN_RESOURCES + #include "../sample.xpm" #endif -#ifndef __WXMSW__ +#ifndef wxHAS_IMAGES_IN_RESOURCES #include "bitmaps/toolbrai.xpm" #include "bitmaps/toolchar.xpm" #include "bitmaps/tooldata.xpm" @@ -70,13 +70,13 @@ const wxChar *SMALL_VIRTUAL_VIEW_ITEMS[][2] = static const int NUM_ICONS = 9; int wxCALLBACK -MyCompareFunction(long item1, long item2, wxIntPtr WXUNUSED(sortData)) +MyCompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr WXUNUSED(sortData)) { // inverse the order if (item1 < item2) - return -1; - if (item1 > item2) return 1; + if (item1 > item2) + return -1; return 0; } @@ -100,8 +100,6 @@ bool MyApp::OnInit() // Show the frame frame->Show(true); - SetTopWindow(frame); - return true; } @@ -173,13 +171,13 @@ MyFrame::MyFrame(const wxChar *title) m_numListItems = 10; // Give it an icon - SetIcon( wxICON(mondrian) ); + SetIcon(wxICON(sample)); // Make an image list containing large icons m_imageListNormal = new wxImageList(32, 32, true); m_imageListSmall = new wxImageList(16, 16, true); -#ifdef __WXMSW__ +#ifdef wxHAS_IMAGES_IN_RESOURCES m_imageListNormal->Add( wxIcon(wxT("icon1"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(wxT("icon2"), wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon(wxT("icon3"), wxBITMAP_TYPE_ICO_RESOURCE) ); @@ -283,7 +281,7 @@ MyFrame::MyFrame(const wxChar *title) #ifdef __WXMSW__ // this is useful to know specially when debugging :) - wxLogMessage("Your version of comctl32.dll is: %d", + wxLogMessage("Your version of comctl32.dll is: %d", wxApp::GetComCtl32Version()); #endif @@ -573,8 +571,14 @@ void MyFrame::InitWithIconItems(bool withText, bool sameIcon) if ( withText ) { - m_listCtrl->InsertItem(i, wxString::Format(wxT("Label %d"), i), - image); + // Make labels of different widths to test the layout. + wxString label; + if ( !(i % 5) ) + label.Printf("Longer label %d", i); + else + label.Printf("Label %d", i); + + m_listCtrl->InsertItem(i, label, image); } else { @@ -840,16 +844,26 @@ void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event)) { - long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, - wxLIST_STATE_FOCUSED); - - if ( itemCur != -1 ) + // demonstrate cancelling editing: this currently is wxMSW-only +#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) + if ( m_listCtrl->GetEditControl() ) { - m_listCtrl->EditLabel(itemCur); + m_listCtrl->EndEditLabel(true); } - else + else // start editing +#endif // __WXMSW__ { - m_logWindow->WriteText(wxT("No item to edit")); + long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, + wxLIST_STATE_FOCUSED); + + if ( itemCur != -1 ) + { + m_listCtrl->EditLabel(itemCur); + } + else + { + m_logWindow->WriteText(wxT("No item to edit")); + } } }