Add wxListCtrl::SetHeaderAttr()

This method can be used to change the list view header appearance.

Add the method declaration, documentation, show it in the sample and implement
it for wxMSW (only, for now).
This commit is contained in:
Vadim Zeitlin
2016-04-17 17:43:09 +02:00
parent dfb993274c
commit 5388c7a72e
7 changed files with 154 additions and 0 deletions

View File

@@ -137,6 +137,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
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_CUSTOM_HEADER_ATTR, MyFrame::OnCustomHeaderAttr)
EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
@@ -160,6 +161,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateUIEnableInReport)
EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateUIEnableInReport)
EVT_UPDATE_UI(LIST_CUSTOM_HEADER_ATTR, MyFrame::OnUpdateUIEnableInReport)
EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
EVT_UPDATE_UI(LIST_TOGGLE_CHECKBOXES, MyFrame::OnUpdateToggleCheckboxes)
@@ -276,6 +278,7 @@ MyFrame::MyFrame(const wxChar *title)
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"));
menuCol->AppendCheckItem(LIST_CUSTOM_HEADER_ATTR, "&Custom header attributes");
wxMenuBar *menubar = new wxMenuBar;
menubar->Append(menuFile, wxT("&File"));
@@ -894,6 +897,20 @@ void MyFrame::OnSetRowLines(wxCommandEvent& event)
m_listCtrl->Refresh();
}
void MyFrame::OnCustomHeaderAttr(wxCommandEvent& event)
{
wxItemAttr attr;
if ( event.IsChecked() )
{
attr.SetTextColour(*wxBLUE);
attr.SetFont(wxFontInfo(24).Italic());
}
//else: leave it as default to disable custom header attributes
if ( !m_listCtrl->SetHeaderAttr(attr) )
wxLogMessage("Sorry, header attributes not supported on this platform");
}
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
{
m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), wxT("Appended item"));