From bc9406afe65785f92c9e6c7c3d0ebf6f7f595286 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 6 Apr 2003 14:20:49 +0000 Subject: [PATCH] Fx for sending event from wxCheckListBox::Check(). Backported from head. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20009 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/checklst.tex | 3 ++- src/msw/checklst.cpp | 24 ++++++++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9f779ab04d..9d95368367 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -202,6 +202,7 @@ wxMSW: - no longer take ampersand into account in wxStaticText::GetBestSize - set orientation for scrollbar events - fix for explicit keyword detection (VC++) +- fix for sending event from wxCheckListBox::Check() wxMotif: diff --git a/docs/latex/wx/checklst.tex b/docs/latex/wx/checklst.tex index cf9dba3c67..a66f7c944d 100644 --- a/docs/latex/wx/checklst.tex +++ b/docs/latex/wx/checklst.tex @@ -89,7 +89,8 @@ Destructor, destroying the list box. \func{void}{Check}{\param{int }{item}, \param{bool}{ check = TRUE}} -Checks the given item. +Checks the given item. Note that calling this method doesn't result in +wxEVT\_COMMAND\_CHECKLISTBOX\_TOGGLE being emitted. \wxheading{Parameters} diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index 1b95e98a2a..ae9d13cd19 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -81,11 +81,14 @@ public: // drawing functions virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat); - // simple accessors + // simple accessors and operations bool IsChecked() const { return m_bChecked; } + void Check(bool bCheck); void Toggle() { Check(!IsChecked()); } + void SendEvent(); + private: bool m_bChecked; wxCheckListBox *m_pParent; @@ -220,7 +223,7 @@ void wxCheckListBoxItem::Check(bool check) { m_bChecked = check; - // index may be chanegd because new items were added/deleted + // index may be changed because new items were added/deleted if ( m_pParent->GetItemIndex(this) != (int)m_nIndex ) { // update it @@ -253,7 +256,11 @@ void wxCheckListBoxItem::Check(bool check) #endif // Win32/16 InvalidateRect(hwndListbox, &rcUpdate, FALSE); +} +// send an "item checked" event +void wxCheckListBoxItem::SendEvent() +{ wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId()); event.SetInt(m_nIndex); event.SetEventObject(m_pParent); @@ -300,6 +307,8 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, } +// misc overloaded methods +// ----------------------- void wxCheckListBox::Delete(int N) { @@ -446,6 +455,10 @@ void wxCheckListBox::OnKeyDown(wxKeyEvent& event) default: wxFAIL_MSG( _T("what should this key do?") ); } + + // we should send an event as this has been done by the user and + // not by the program + item->SendEvent(); } } else // nothing to do @@ -460,8 +473,11 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event) if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) { int nItem = HitTest(event.GetX(), event.GetY()); - if ( nItem != wxNOT_FOUND ) - GetItem(nItem)->Toggle(); + if ( nItem != wxNOT_FOUND ) { + wxCheckListBoxItem *item = GetItem(nItem); + item->Toggle(); + item->SendEvent(); + } //else: it's not an error, just click outside of client zone } else {