X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f5851311d3cafff78097f8441d3dc5bf1fc1e6b0..5fab0c8d86f7bd7015db8d0ece8ce02ba1b602d8:/src/msw/checklst.cpp diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index 933537bc1b..7cfdff2a5f 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -47,6 +47,7 @@ #include "wx/renderer.h" #include "wx/msw/private.h" +#include "wx/msw/dc.h" // ---------------------------------------------------------------------------- // private functions @@ -145,7 +146,7 @@ private: wxCheckListBox *m_pParent; size_t m_nIndex; - DECLARE_NO_COPY_CLASS(wxCheckListBoxItem) + wxDECLARE_NO_COPY_CLASS(wxCheckListBoxItem); }; wxCheckListBoxItem::wxCheckListBoxItem(wxCheckListBox *pParent, size_t nIndex) @@ -174,8 +175,9 @@ bool wxCheckListBoxItem::OnDrawItem(wxDC& dc, const wxRect& rc, if ( !wxOwnerDrawn::OnDrawItem(dc, rc, act, stat) ) return false; + wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); // now draw the check mark part - HDC hdc = GetHdcOf(dc); + HDC hdc = GetHdcOf(*impl); int nBmpWidth = ::GetSystemMetrics(SM_CXMENUCHECK), nBmpHeight = ::GetSystemMetrics(SM_CYMENUCHECK); @@ -483,9 +485,19 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event) if ( nItem != wxNOT_FOUND ) { - wxCheckListBoxItem *item = GetItem(nItem); - item->Toggle(); - item->SendEvent(); + // people expect to get "kill focus" event for the currently + // focused control before getting events from the other controls + // and, equally importantly, they may prevent the focus change from + // taking place at all (e.g. because the old control contents is + // invalid and needs to be corrected) in which case we shouldn't + // generate this event at all + SetFocus(); + if ( FindFocus() == this ) + { + wxCheckListBoxItem *item = GetItem(nItem); + item->Toggle(); + item->SendEvent(); + } } //else: it's not an error, just click outside of client zone } @@ -496,20 +508,6 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event) } } -int wxCheckListBox::DoHitTestItem(wxCoord x, wxCoord y) const -{ - int nItem = (int)::SendMessage - ( - (HWND)GetHWND(), - LB_ITEMFROMPOINT, - 0, - MAKELPARAM(x, y) - ); - - return nItem >= (int)m_noItems ? wxNOT_FOUND : nItem; -} - - wxSize wxCheckListBox::DoGetBestSize() const { wxSize best = wxListBox::DoGetBestSize(); @@ -518,4 +516,4 @@ wxSize wxCheckListBox::DoGetBestSize() const return best; } -#endif +#endif // wxUSE_CHECKLISTBOX