added InitCommandEventWithItems() and call it from wxChoice and wxComboBox code to ensure that per item client data is set correctly in the generated events (replaces patch 1476171; closes bug 1470505)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39064 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -144,6 +144,7 @@ protected:
|
|||||||
virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData) = 0;
|
virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData) = 0;
|
||||||
virtual wxClientData* DoGetItemClientObject(unsigned int n) const = 0;
|
virtual wxClientData* DoGetItemClientObject(unsigned int n) const = 0;
|
||||||
|
|
||||||
|
|
||||||
// the type of the client data for the items
|
// the type of the client data for the items
|
||||||
wxClientDataType m_clientDataItemsType;
|
wxClientDataType m_clientDataItemsType;
|
||||||
};
|
};
|
||||||
@@ -197,6 +198,12 @@ protected:
|
|||||||
// ctors for this to work!
|
// ctors for this to work!
|
||||||
virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
|
virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
|
||||||
|
|
||||||
|
// fill in the client object or data field of the event as appropriate
|
||||||
|
//
|
||||||
|
// calls InitCommandEvent() and, if n != wxNOT_FOUND, also sets the per
|
||||||
|
// item client data
|
||||||
|
void InitCommandEventWithItems(wxCommandEvent& event, int n);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_ABSTRACT_CLASS(wxControlWithItems)
|
DECLARE_ABSTRACT_CLASS(wxControlWithItems)
|
||||||
DECLARE_NO_COPY_CLASS(wxControlWithItems)
|
DECLARE_NO_COPY_CLASS(wxControlWithItems)
|
||||||
|
@@ -741,10 +741,7 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
|||||||
if ( n > -1 )
|
if ( n > -1 )
|
||||||
{
|
{
|
||||||
event.SetString(GetStringSelection());
|
event.SetString(GetStringSelection());
|
||||||
if ( HasClientObjectData() )
|
InitCommandEventWithItems(event, n);
|
||||||
event.SetClientObject( GetClientObject(n) );
|
|
||||||
else if ( HasClientUntypedData() )
|
|
||||||
event.SetClientData( GetClientData(n) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessCommand(event);
|
ProcessCommand(event);
|
||||||
|
@@ -259,9 +259,12 @@ bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
|
|||||||
if ( wParam == VK_RETURN )
|
if ( wParam == VK_RETURN )
|
||||||
{
|
{
|
||||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
|
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
|
||||||
InitCommandEvent(event);
|
|
||||||
|
const int sel = GetSelection();
|
||||||
|
event.SetInt(sel);
|
||||||
event.SetString(GetValue());
|
event.SetString(GetValue());
|
||||||
event.SetInt(GetSelection());
|
InitCommandEventWithItems(event, sel);
|
||||||
|
|
||||||
if ( ProcessCommand(event) )
|
if ( ProcessCommand(event) )
|
||||||
{
|
{
|
||||||
// don't let the event through to the native control
|
// don't let the event through to the native control
|
||||||
@@ -313,9 +316,10 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
|
|||||||
value = GetStringSelection();
|
value = GetStringSelection();
|
||||||
{
|
{
|
||||||
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
|
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetInt(sel);
|
event.SetInt(sel);
|
||||||
event.SetString(value);
|
event.SetString(value);
|
||||||
|
InitCommandEventWithItems(event, sel);
|
||||||
|
|
||||||
ProcessCommand(event);
|
ProcessCommand(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +330,6 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
|
|||||||
case CBN_EDITCHANGE:
|
case CBN_EDITCHANGE:
|
||||||
{
|
{
|
||||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
|
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
|
||||||
event.SetEventObject(this);
|
|
||||||
|
|
||||||
// if sel != -1, value was already initialized above
|
// if sel != -1, value was already initialized above
|
||||||
if ( sel == -1 )
|
if ( sel == -1 )
|
||||||
@@ -335,6 +338,8 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
event.SetString(value);
|
event.SetString(value);
|
||||||
|
InitCommandEventWithItems(event, sel);
|
||||||
|
|
||||||
ProcessCommand(event);
|
ProcessCommand(event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user