Merge branch listctrl-with-checkboxes

Add support for native checkboxes to wxMSW wxListCtrl.

Closes https://github.com/wxWidgets/wxWidgets/pull/153
This commit is contained in:
Vadim Zeitlin
2016-02-06 01:05:01 +01:00
8 changed files with 209 additions and 0 deletions

View File

@@ -154,11 +154,15 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric)
#endif // __WXOSX__
EVT_MENU(LIST_FIND, MyFrame::OnFind)
EVT_MENU(LIST_TOGGLE_CHECKBOX, MyFrame::OnToggleItemCheckbox)
EVT_MENU(LIST_GET_CHECKBOX, MyFrame::OnGetItemCheckbox)
EVT_MENU(LIST_TOGGLE_CHECKBOXES, MyFrame::OnToggleCheckboxes)
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_CHECKBOXES, MyFrame::OnUpdateToggleCheckboxes)
EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateToggleHeader)
EVT_UPDATE_UI(LIST_ROW_LINES, MyFrame::OnUpdateRowLines)
wxEND_EVENT_TABLE()
@@ -261,6 +265,12 @@ MyFrame::MyFrame(const wxChar *title)
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");
menuList->AppendSeparator();
menuList->AppendCheckItem(LIST_TOGGLE_CHECKBOXES,
wxT("&Enable Checkboxes"));
menuList->Check(LIST_TOGGLE_CHECKBOXES, true);
menuList->Append(LIST_TOGGLE_CHECKBOX, wxT("Toggle the item checkbox state"));
menuList->Append(LIST_GET_CHECKBOX, wxT("Get the item checkbox state"));
wxMenu *menuCol = new wxMenu;
menuCol->Append(LIST_SET_FG_COL, wxT("&Foreground colour..."));
@@ -835,6 +845,27 @@ void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event)
event.Check(!m_listCtrl->HasFlag(wxLC_SINGLE_SEL));
}
void MyFrame::OnToggleCheckboxes(wxCommandEvent& WXUNUSED(event))
{
if ( !m_listCtrl->EnableCheckboxes(!m_listCtrl->HasCheckboxes()) )
{
wxLogMessage("Failed to toggle checkboxes (not supported?)");
}
else
{
wxLogMessage("Checkboxes are now %s",
m_listCtrl->HasCheckboxes() ? "enabled" : "disabled");
}
}
void MyFrame::OnUpdateToggleCheckboxes(wxUpdateUIEvent& event)
{
bool cbEnabled = m_listCtrl->HasCheckboxes();
event.Check(cbEnabled);
GetMenuBar()->Enable(LIST_TOGGLE_CHECKBOX, cbEnabled);
GetMenuBar()->Enable(LIST_GET_CHECKBOX, cbEnabled);
}
void MyFrame::OnUpdateToggleHeader(wxUpdateUIEvent& event)
{
event.Check(!m_listCtrl->HasFlag(wxLC_NO_HEADER));
@@ -893,6 +924,33 @@ void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event))
}
}
void MyFrame::OnToggleItemCheckbox(wxCommandEvent& WXUNUSED(event))
{
long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while (item != -1)
{
bool checked = m_listCtrl->IsItemChecked(item);
m_listCtrl->CheckItem(item, !checked);
item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
}
}
void MyFrame::OnGetItemCheckbox(wxCommandEvent& WXUNUSED(event))
{
long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while (item != -1)
{
bool checked = m_listCtrl->IsItemChecked(item);
wxLogMessage(wxT("Item %ld is %s"), item, checked ? wxT("checked") : wxT("unchecked"));
item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
}
}
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
{
if ( m_listCtrl->GetItemCount() )
@@ -935,6 +993,8 @@ wxBEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
EVT_LIST_ITEM_CHECKED(LIST_CTRL, MyListCtrl::OnChecked)
EVT_LIST_ITEM_UNCHECKED(LIST_CTRL, MyListCtrl::OnUnChecked)
EVT_LIST_ITEM_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnItemRightClick)
@@ -1127,6 +1187,20 @@ void MyListCtrl::OnItemRightClick(wxListEvent& event)
event.Skip();
}
void MyListCtrl::OnChecked(wxListEvent& event)
{
LogEvent(event, wxT("OnChecked"));
event.Skip();
}
void MyListCtrl::OnUnChecked(wxListEvent& event)
{
LogEvent(event, wxT("OnUnChecked"));
event.Skip();
}
void MyListCtrl::OnListKeyDown(wxListEvent& event)
{
long item;