X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d3ca8487512246d26cb9cae4976457d12b059171..45416752623a6ac0df3a8f5f55c1933ff52e1dbb:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index b9539d55b0..eaeb8a9bd7 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -20,11 +20,11 @@ #include "wx/wx.h" #endif -#if !defined(__WXMSW__) && !defined(__WXPM__) +#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" @@ -74,9 +74,9 @@ 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; } @@ -137,6 +137,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_SORT, MyFrame::OnSort) EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour) EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour) + EVT_MENU(LIST_ROW_LINES, MyFrame::OnSetRowLines) EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo) EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo) @@ -149,6 +150,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_THAW, MyFrame::OnThaw) EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines) EVT_MENU(LIST_TOGGLE_HEADER, MyFrame::OnToggleHeader) + EVT_MENU(LIST_TOGGLE_BELL, MyFrame::OnToggleBell) #ifdef __WXOSX__ EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric) #endif // __WXOSX__ @@ -159,6 +161,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateToggleHeader) + EVT_UPDATE_UI(LIST_ROW_LINES, MyFrame::OnUpdateRowLines) END_EVENT_TABLE() // My frame constructor @@ -177,7 +180,7 @@ MyFrame::MyFrame(const wxChar *title) 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) ); @@ -258,10 +261,12 @@ MyFrame::MyFrame(const wxChar *title) menuList->Check(LIST_TOGGLE_MULTI_SEL, true); menuList->AppendCheckItem(LIST_TOGGLE_HEADER, "Toggle &header\tCtrl-H"); menuList->Check(LIST_TOGGLE_HEADER, true); + menuList->AppendCheckItem(LIST_TOGGLE_BELL, "Toggle &bell on no match"); wxMenu *menuCol = new wxMenu; menuCol->Append(LIST_SET_FG_COL, wxT("&Foreground colour...")); menuCol->Append(LIST_SET_BG_COL, wxT("&Background colour...")); + menuCol->AppendCheckItem(LIST_ROW_LINES, wxT("Alternating colours")); wxMenuBar *menubar = new wxMenuBar; menubar->Append(menuFile, wxT("&File")); @@ -335,7 +340,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageDialog dialog(this, wxT("List test sample\nJulian Smart (c) 1997"), - wxT("About list test"), wxOK|wxCANCEL); + wxT("About list test")); dialog.ShowModal(); } @@ -366,6 +371,11 @@ void MyFrame::OnToggleHeader(wxCommandEvent& event) m_listCtrl->ToggleWindowStyle(wxLC_NO_HEADER); } +void MyFrame::OnToggleBell(wxCommandEvent& event) +{ + m_listCtrl->EnableBellOnNoMatch(event.IsChecked()); +} + #ifdef __WXOSX__ void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) @@ -468,10 +478,16 @@ void MyFrame::RecreateList(long flags, bool withText) default: wxFAIL_MSG( wxT("unknown listctrl mode") ); } + + wxMenuBar* const mb = GetMenuBar(); + if ( mb ) + m_listCtrl->EnableBellOnNoMatch(mb->IsChecked(LIST_TOGGLE_BELL)); } DoSize(); + GetMenuBar()->Check(LIST_ROW_LINES, false); + m_logWindow->Clear(); } @@ -571,8 +587,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 { @@ -819,6 +841,11 @@ void MyFrame::OnUpdateToggleHeader(wxUpdateUIEvent& event) event.Check(!m_listCtrl->HasFlag(wxLC_NO_HEADER)); } +void MyFrame::OnUpdateRowLines(wxUpdateUIEvent& event) +{ + event.Enable(m_listCtrl->HasFlag(wxLC_VIRTUAL)); +} + void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) { m_listCtrl->SetForegroundColour(wxGetColourFromUser(this)); @@ -831,6 +858,12 @@ void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event)) m_listCtrl->Refresh(); } +void MyFrame::OnSetRowLines(wxCommandEvent& event) +{ + m_listCtrl->EnableAlternateRowColours(event.IsChecked()); + m_listCtrl->Refresh(); +} + void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event)) { m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), wxT("Appended item")); @@ -839,7 +872,7 @@ void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event)) { // demonstrate cancelling editing: this currently is wxMSW-only -#ifdef __WXMSW__ +#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) if ( m_listCtrl->GetEditControl() ) { m_listCtrl->EndEditLabel(true); @@ -1090,6 +1123,13 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) { long item; + if ( !wxGetKeyState(WXK_SHIFT) ) + { + LogEvent(event, wxT("OnListKeyDown")); + event.Skip(); + return; + } + switch ( event.GetKeyCode() ) { case 'C': // colorize @@ -1231,26 +1271,7 @@ void MyListCtrl::OnChar(wxKeyEvent& event) { wxLogMessage(wxT("Got char event.")); - switch ( event.GetKeyCode() ) - { - case 'n': - case 'N': - case 'c': - case 'C': - case 'r': - case 'R': - case 'u': - case 'U': - case 'd': - case 'D': - case 'i': - case 'I': - // these are the keys we process ourselves - break; - - default: - event.Skip(); - } + event.Skip(); } void MyListCtrl::OnRightClick(wxMouseEvent& event) @@ -1323,7 +1344,7 @@ wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const return &s_attrHighlight; } - return item % 2 ? NULL : (wxListItemAttr *)&m_attr; + return wxListCtrl::OnGetItemAttr(item); } void MyListCtrl::InsertItemInReportView(int i)