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
This commit is contained in:
Vadim Zeitlin 2010-03-06 00:31:00 +00:00
parent 98e956503d
commit 1bab36277c
3 changed files with 32 additions and 8 deletions

View File

@ -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))

View File

@ -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,

View File

@ -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