diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index d91afe13a6..5a95a2b626 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -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,22 @@ void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event) event.Check(!m_listCtrl->HasFlag(wxLC_SINGLE_SEL)); } +void MyFrame::OnToggleCheckboxes(wxCommandEvent& WXUNUSED(event)) +{ + m_listCtrl->EnableCheckboxes(!m_listCtrl->HasCheckboxes()); + + m_logWindow->WriteText(wxString::Format(wxT("Checkboxes: %s\n"), + m_listCtrl->HasCheckboxes() ? wxT("enabled") : wxT("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 +919,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 +988,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_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick) @@ -1118,6 +1173,20 @@ void MyListCtrl::OnFocused(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; diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index cc8e84b3b5..29024eb724 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -61,6 +61,8 @@ public: void OnListKeyDown(wxListEvent& event); void OnActivated(wxListEvent& event); void OnFocused(wxListEvent& event); + void OnChecked(wxListEvent& event); + void OnUnChecked(wxListEvent& event); void OnCacheHint(wxListEvent& event); void OnChar(wxKeyEvent& event); @@ -146,9 +148,13 @@ protected: void OnToggleMacUseGeneric(wxCommandEvent& event); #endif // __WXOSX__ void OnFind(wxCommandEvent& event); + void OnToggleItemCheckbox(wxCommandEvent& event); + void OnGetItemCheckbox(wxCommandEvent& event); + void OnToggleCheckboxes(wxCommandEvent& event); void OnUpdateUIEnableInReport(wxUpdateUIEvent& event); void OnUpdateToggleMultiSel(wxUpdateUIEvent& event); + void OnUpdateToggleCheckboxes(wxUpdateUIEvent& event); void OnUpdateToggleHeader(wxUpdateUIEvent& event); void OnUpdateRowLines(wxUpdateUIEvent& event); @@ -217,6 +223,9 @@ enum LIST_TOGGLE_MULTI_SEL, LIST_TOGGLE_HEADER, LIST_TOGGLE_BELL, + LIST_TOGGLE_CHECKBOX, + LIST_GET_CHECKBOX, + LIST_TOGGLE_CHECKBOXES, LIST_TOGGLE_FIRST, LIST_SHOW_COL_INFO, LIST_SHOW_SEL_INFO,