From 1bab36277c418507195638ace24ea9cedc78391c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 6 Mar 2010 00:31:00 +0000 Subject: [PATCH] Fix toggling the header in the generic wxListCtrl. We need to update the lfags first before deciding whether we should create or destroy the header. Also add a test for toggling the header to the listctrl sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63637 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/listctrl/listtest.cpp | 29 ++++++++++++++++++++++++----- samples/listctrl/listtest.h | 5 ++++- src/generic/listctrl.cpp | 6 ++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index ba3e871b45..bf2ef2c376 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -150,13 +150,17 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze) EVT_MENU(LIST_THAW, MyFrame::OnThaw) EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines) + EVT_MENU(LIST_TOGGLE_HEADER, MyFrame::OnToggleHeader) #ifdef __WXOSX__ EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric) #endif // __WXOSX__ EVT_MENU(LIST_FIND, MyFrame::OnFind) - EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo) + EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateUIEnableInReport) + EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateUIEnableInReport) + EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) + EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateToggleHeader) END_EVENT_TABLE() // My frame constructor @@ -251,8 +255,11 @@ MyFrame::MyFrame(const wxChar *title) menuList->Append(LIST_THAW, wxT("Tha&w\tCtrl-W")); menuList->AppendSeparator(); menuList->AppendCheckItem(LIST_TOGGLE_LINES, wxT("Toggle &lines\tCtrl-I")); - menuList->Append(LIST_TOGGLE_MULTI_SEL, wxT("&Multiple selection\tCtrl-M"), - wxT("Toggle multiple selection"), true); + menuList->AppendCheckItem(LIST_TOGGLE_MULTI_SEL, + wxT("&Multiple selection\tCtrl-M")); + menuList->Check(LIST_TOGGLE_MULTI_SEL, true); + menuList->AppendCheckItem(LIST_TOGGLE_HEADER, "Toggle &header\tCtrl-H"); + menuList->Check(LIST_TOGGLE_HEADER, true); wxMenu *menuCol = new wxMenu; menuCol->Append(LIST_SET_FG_COL, wxT("&Foreground colour...")); @@ -354,6 +361,13 @@ void MyFrame::OnToggleLines(wxCommandEvent& event) m_listCtrl->SetSingleStyle(wxLC_HRULES | wxLC_VRULES, event.IsChecked()); } +void MyFrame::OnToggleHeader(wxCommandEvent& event) +{ + wxLogMessage("%s the header", event.IsChecked() ? "Showing" : "Hiding"); + + m_listCtrl->ToggleWindowStyle(wxLC_NO_HEADER); +} + #ifdef __WXOSX__ void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) @@ -778,7 +792,7 @@ void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event)) } } -void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent& event) +void MyFrame::OnUpdateUIEnableInReport(wxUpdateUIEvent& event) { event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 ); } @@ -799,7 +813,12 @@ void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event) { - event.Check((m_listCtrl->GetWindowStyleFlag() & wxLC_SINGLE_SEL) == 0); + event.Check(!m_listCtrl->HasFlag(wxLC_SINGLE_SEL)); +} + +void MyFrame::OnUpdateToggleHeader(wxUpdateUIEvent& event) +{ + event.Check(!m_listCtrl->HasFlag(wxLC_NO_HEADER)); } void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index f99982d698..5b8d2f3a8d 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -146,13 +146,15 @@ protected: void OnFreeze(wxCommandEvent& event); void OnThaw(wxCommandEvent& event); void OnToggleLines(wxCommandEvent& event); + void OnToggleHeader(wxCommandEvent& event); #ifdef __WXOSX__ void OnToggleMacUseGeneric(wxCommandEvent& event); #endif // __WXOSX__ void OnFind(wxCommandEvent& event); - void OnUpdateShowColInfo(wxUpdateUIEvent& event); + void OnUpdateUIEnableInReport(wxUpdateUIEvent& event); void OnUpdateToggleMultiSel(wxUpdateUIEvent& event); + void OnUpdateToggleHeader(wxUpdateUIEvent& event); wxImageList *m_imageListNormal; wxImageList *m_imageListSmall; @@ -216,6 +218,7 @@ enum LIST_SET_FG_COL, LIST_SET_BG_COL, LIST_TOGGLE_MULTI_SEL, + LIST_TOGGLE_HEADER, LIST_TOGGLE_FIRST, LIST_SHOW_COL_INFO, LIST_SHOW_SEL_INFO, diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 4cd96c9e6a..951768cae0 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -4446,6 +4446,10 @@ void wxGenericListCtrl::SetSingleStyle( long style, bool add ) void wxGenericListCtrl::SetWindowStyleFlag( long flag ) { + // update the window style first so that the header is created or destroyed + // corresponding to the new style + wxWindow::SetWindowStyleFlag( flag ); + if (m_mainWin) { // m_mainWin->DeleteEverything(); wxMSW doesn't do that @@ -4454,8 +4458,6 @@ void wxGenericListCtrl::SetWindowStyleFlag( long flag ) GetSizer()->Layout(); } - - wxWindow::SetWindowStyleFlag( flag ); } bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const -- 2.47.2