don't generate EVT_LISTBOX_DCLICK events with incorrect indices [backport of r58405 from trunk] (closes #10429)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-02-08 10:29:09 +00:00
parent e3646f4afd
commit 87908d388c
2 changed files with 20 additions and 16 deletions

View File

@@ -154,6 +154,7 @@ wxMSW:
- Fixed invisible CHM tooltip text bug when window text colour is black. - Fixed invisible CHM tooltip text bug when window text colour is black.
- Automatically adjust toolbar's tool size if the provided bitmaps - Automatically adjust toolbar's tool size if the provided bitmaps
don't fit into the default size. don't fit into the default size.
- Don't generate EVT_LISTBOX_DCLICK events with incorrect indices.
wxMSW/CE: wxMSW/CE:

View File

@@ -544,12 +544,12 @@ wxListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
int wxListBox::DoListHitTest(const wxPoint& point) const int wxListBox::DoListHitTest(const wxPoint& point) const
{ {
LRESULT lRes = ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT, LRESULT lRes = ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT,
0L, MAKELONG(point.x, point.y)); 0, MAKELPARAM(point.x, point.y));
// non zero high-order word means that this item is outside of the client // non zero high-order word means that this item is outside of the client
// area, IOW the point is outside of the listbox // area, IOW the point is outside of the listbox
return HIWORD(lRes) ? wxNOT_FOUND : lRes; return HIWORD(lRes) ? wxNOT_FOUND : LOWORD(lRes);
} }
void wxListBox::SetString(unsigned int n, const wxString& s) void wxListBox::SetString(unsigned int n, const wxString& s)
@@ -702,13 +702,18 @@ wxSize wxListBox::DoGetBestSize() const
bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{ {
wxEventType evtType; wxEventType evtType;
int n;
if ( param == LBN_SELCHANGE ) if ( param == LBN_SELCHANGE )
{ {
evtType = wxEVT_COMMAND_LISTBOX_SELECTED; evtType = wxEVT_COMMAND_LISTBOX_SELECTED;
n = SendMessage(GetHwnd(), LB_GETCARETINDEX, 0, 0);
// NB: conveniently enough, LB_ERR is the same as wxNOT_FOUND
} }
else if ( param == LBN_DBLCLK ) else if ( param == LBN_DBLCLK )
{ {
evtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED; evtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
n = HitTest(ScreenToClient(wxGetMousePosition()));
} }
else else
{ {
@@ -716,23 +721,21 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
return false; return false;
} }
wxCommandEvent event(evtType, m_windowId);
event.SetEventObject( this );
// retrieve the affected item // retrieve the affected item
int n = SendMessage(GetHwnd(), LB_GETCARETINDEX, 0, 0); if ( n == wxNOT_FOUND )
if ( n != LB_ERR ) return false;
{
if ( HasClientObjectData() )
event.SetClientObject( GetClientObject(n) );
else if ( HasClientUntypedData() )
event.SetClientData( GetClientData(n) );
event.SetString(GetString(n)); wxCommandEvent event(evtType, m_windowId);
event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : true ); event.SetEventObject(this);
}
if ( HasClientObjectData() )
event.SetClientObject( GetClientObject(n) );
else if ( HasClientUntypedData() )
event.SetClientData( GetClientData(n) );
event.SetString(GetString(n));
event.SetInt(n); event.SetInt(n);
event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : true );
return GetEventHandler()->ProcessEvent(event); return GetEventHandler()->ProcessEvent(event);
} }