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
This commit is contained in:
Julian Smart
2003-04-06 14:20:49 +00:00
parent 9856829d76
commit bc9406afe6
3 changed files with 23 additions and 5 deletions

View File

@@ -202,6 +202,7 @@ wxMSW:
- no longer take ampersand into account in wxStaticText::GetBestSize - no longer take ampersand into account in wxStaticText::GetBestSize
- set orientation for scrollbar events - set orientation for scrollbar events
- fix for explicit keyword detection (VC++) - fix for explicit keyword detection (VC++)
- fix for sending event from wxCheckListBox::Check()
wxMotif: wxMotif:

View File

@@ -89,7 +89,8 @@ Destructor, destroying the list box.
\func{void}{Check}{\param{int }{item}, \param{bool}{ check = TRUE}} \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} \wxheading{Parameters}

View File

@@ -81,11 +81,14 @@ public:
// drawing functions // drawing functions
virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat); virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat);
// simple accessors // simple accessors and operations
bool IsChecked() const { return m_bChecked; } bool IsChecked() const { return m_bChecked; }
void Check(bool bCheck); void Check(bool bCheck);
void Toggle() { Check(!IsChecked()); } void Toggle() { Check(!IsChecked()); }
void SendEvent();
private: private:
bool m_bChecked; bool m_bChecked;
wxCheckListBox *m_pParent; wxCheckListBox *m_pParent;
@@ -220,7 +223,7 @@ void wxCheckListBoxItem::Check(bool check)
{ {
m_bChecked = 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 ) if ( m_pParent->GetItemIndex(this) != (int)m_nIndex )
{ {
// update it // update it
@@ -253,7 +256,11 @@ void wxCheckListBoxItem::Check(bool check)
#endif // Win32/16 #endif // Win32/16
InvalidateRect(hwndListbox, &rcUpdate, FALSE); InvalidateRect(hwndListbox, &rcUpdate, FALSE);
}
// send an "item checked" event
void wxCheckListBoxItem::SendEvent()
{
wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId()); wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId());
event.SetInt(m_nIndex); event.SetInt(m_nIndex);
event.SetEventObject(m_pParent); event.SetEventObject(m_pParent);
@@ -300,6 +307,8 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
} }
// misc overloaded methods
// -----------------------
void wxCheckListBox::Delete(int N) void wxCheckListBox::Delete(int N)
{ {
@@ -446,6 +455,10 @@ void wxCheckListBox::OnKeyDown(wxKeyEvent& event)
default: default:
wxFAIL_MSG( _T("what should this key do?") ); 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 else // nothing to do
@@ -460,8 +473,11 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) { if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) {
int nItem = HitTest(event.GetX(), event.GetY()); int nItem = HitTest(event.GetX(), event.GetY());
if ( nItem != wxNOT_FOUND ) if ( nItem != wxNOT_FOUND ) {
GetItem(nItem)->Toggle(); wxCheckListBoxItem *item = GetItem(nItem);
item->Toggle();
item->SendEvent();
}
//else: it's not an error, just click outside of client zone //else: it's not an error, just click outside of client zone
} }
else { else {