Refactor listbox event sending code to avoid duplication.
wxMSW wxListBox implementation contained the same code as the private LBSendEvent() function in lboxcmn.cpp, so make this function a (protected) member of wxListBoxBase and reuse it instead. Also change its and CalcAndSendEvent() return type to bool to be able to return whether the event was processed or not. As the result of this refactoring, the "is selected" flag is now set correctly for the selection events under MSW (it was always off before). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64496 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -647,16 +647,13 @@ wxSize wxListBox::DoGetBestClientSize() const
|
||||
|
||||
bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
||||
{
|
||||
if ((param == LBN_SELCHANGE) && HasMultipleSelection())
|
||||
{
|
||||
CalcAndSendEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
wxEventType evtType;
|
||||
int n;
|
||||
if ( param == LBN_SELCHANGE )
|
||||
{
|
||||
if ( HasMultipleSelection() )
|
||||
return CalcAndSendEvent();
|
||||
|
||||
evtType = wxEVT_COMMAND_LISTBOX_SELECTED;
|
||||
n = SendMessage(GetHwnd(), LB_GETCARETINDEX, 0, 0);
|
||||
|
||||
@@ -673,22 +670,8 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
||||
return false;
|
||||
}
|
||||
|
||||
// retrieve the affected item
|
||||
if ( n == wxNOT_FOUND )
|
||||
return false;
|
||||
|
||||
wxCommandEvent event(evtType, m_windowId);
|
||||
event.SetEventObject(this);
|
||||
|
||||
if ( HasClientObjectData() )
|
||||
event.SetClientObject( GetClientObject(n) );
|
||||
else if ( HasClientUntypedData() )
|
||||
event.SetClientData( GetClientData(n) );
|
||||
|
||||
event.SetString(GetString(n));
|
||||
event.SetInt(n);
|
||||
|
||||
return HandleWindowEvent(event);
|
||||
// only send an event if we have a valid item
|
||||
return n != wxNOT_FOUND && SendEvent(evtType, n, true /* selection */);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user