Add wxListCtrl::EnableAlternateRowColours() and SetAlternateRowColour().

Add methods to simply enable alternative row background colours in wxListCtrl.

Closes #14618.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73239 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-12-22 02:33:23 +00:00
parent 87f0b1323b
commit 0ee169da2b
13 changed files with 106 additions and 55 deletions

View File

@@ -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)
@@ -160,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
@@ -264,6 +266,7 @@ MyFrame::MyFrame(const wxChar *title)
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"));
@@ -483,6 +486,8 @@ void MyFrame::RecreateList(long flags, bool withText)
DoSize();
GetMenuBar()->Check(LIST_ROW_LINES, false);
m_logWindow->Clear();
}
@@ -836,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));
@@ -848,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"));
@@ -1328,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)

View File

@@ -37,8 +37,7 @@ public:
const wxPoint& pos,
const wxSize& size,
long style)
: wxListCtrl(parent, id, pos, size, style),
m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
: wxListCtrl(parent, id, pos, size, style)
{
m_updated = -1;
@@ -88,8 +87,6 @@ private:
virtual int OnGetItemColumnImage(long item, long column) const;
virtual wxListItemAttr *OnGetItemAttr(long item) const;
wxListItemAttr m_attr;
long m_updated;
@@ -135,6 +132,7 @@ protected:
void OnSort(wxCommandEvent& event);
void OnSetFgColour(wxCommandEvent& event);
void OnSetBgColour(wxCommandEvent& event);
void OnSetRowLines(wxCommandEvent& event);
void OnToggleMultiSel(wxCommandEvent& event);
void OnShowColInfo(wxCommandEvent& event);
void OnShowSelInfo(wxCommandEvent& event);
@@ -156,6 +154,7 @@ protected:
void OnUpdateUIEnableInReport(wxUpdateUIEvent& event);
void OnUpdateToggleMultiSel(wxUpdateUIEvent& event);
void OnUpdateToggleHeader(wxUpdateUIEvent& event);
void OnUpdateRowLines(wxUpdateUIEvent& event);
wxImageList *m_imageListNormal;
wxImageList *m_imageListSmall;
@@ -218,6 +217,7 @@ enum
LIST_FIND,
LIST_SET_FG_COL,
LIST_SET_BG_COL,
LIST_ROW_LINES,
LIST_TOGGLE_MULTI_SEL,
LIST_TOGGLE_HEADER,
LIST_TOGGLE_BELL,