fixed event generation for wxChoice: it now sends one and exactly one wxEVT_COMMAND_CHOICE_SELECTED irrespectively of how the item was chosen and only does it after the dropdown is closed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38042 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -633,23 +633,61 @@ WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
|
|||||||
|
|
||||||
bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
The native control provides a great variety in the events it sends in
|
||||||
|
the different selection scenarios (undoubtedly for greater amusement of
|
||||||
|
the programmers using it). For the reference, here are the cases when
|
||||||
|
the final selection is accepted (things are quite interesting when it
|
||||||
|
is cancelled too):
|
||||||
|
|
||||||
|
A. Selecting with just the arrows without opening the dropdown:
|
||||||
|
1. CBN_SELENDOK
|
||||||
|
2. CBN_SELCHANGE
|
||||||
|
|
||||||
|
B. Opening dropdown with F4 and selecting with arrows:
|
||||||
|
1. CBN_DROPDOWN
|
||||||
|
2. many CBN_SELCHANGE while changing selection in the list
|
||||||
|
3. CBN_SELENDOK
|
||||||
|
4. CBN_CLOSEUP
|
||||||
|
|
||||||
|
C. Selecting with the mouse:
|
||||||
|
1. CBN_DROPDOWN
|
||||||
|
-- no intermediate CBN_SELCHANGEs --
|
||||||
|
2. CBN_SELENDOK
|
||||||
|
3. CBN_CLOSEUP
|
||||||
|
4. CBN_SELCHANGE
|
||||||
|
|
||||||
|
Admire the different order of messages in all of those cases, it must
|
||||||
|
surely have taken a lot of effort to Microsoft developers to achieve
|
||||||
|
such originality.
|
||||||
|
*/
|
||||||
switch ( param )
|
switch ( param )
|
||||||
{
|
{
|
||||||
case CBN_DROPDOWN:
|
case CBN_DROPDOWN:
|
||||||
// we don't want to track selection using CB_GETCURSEL while the
|
// we use this value both because we don't want to track selection
|
||||||
// dropdown is opened
|
// using CB_GETCURSEL while the dropdown is opened and because we
|
||||||
|
// need to reset the selection back to it if it's eventually
|
||||||
|
// cancelled by user
|
||||||
m_lastAcceptedSelection = GetCurrentSelection();
|
m_lastAcceptedSelection = GetCurrentSelection();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CBN_CLOSEUP:
|
case CBN_CLOSEUP:
|
||||||
// it should be safe to use CB_GETCURSEL again
|
// if the selection was accepted by the user, it should have been
|
||||||
|
// reset to wxID_NONE by CBN_SELENDOK, otherwise the selection was
|
||||||
|
// cancelled and we must restore the old one
|
||||||
|
if ( m_lastAcceptedSelection != wxID_NONE )
|
||||||
|
{
|
||||||
|
SetSelection(m_lastAcceptedSelection);
|
||||||
m_lastAcceptedSelection = wxID_NONE;
|
m_lastAcceptedSelection = wxID_NONE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CBN_SELCHANGE:
|
case CBN_SELENDOK:
|
||||||
// don't generate any events while the dropdown is opened as the
|
// reset it to prevent CBN_CLOSEUP from undoing the selection (it's
|
||||||
// selection is not final yet
|
// ok to reset it now as GetCurrentSelection() will now return the
|
||||||
if ( m_lastAcceptedSelection == wxID_NONE )
|
// same thing anyhow)
|
||||||
|
m_lastAcceptedSelection = wxID_NONE;
|
||||||
|
|
||||||
{
|
{
|
||||||
const int n = GetSelection();
|
const int n = GetSelection();
|
||||||
|
|
||||||
@@ -668,10 +706,19 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
|||||||
|
|
||||||
ProcessCommand(event);
|
ProcessCommand(event);
|
||||||
}
|
}
|
||||||
return true;
|
break;
|
||||||
|
|
||||||
|
// don't handle CBN_SELENDCANCEL: just leave m_lastAcceptedSelection
|
||||||
|
// valid and the selection will be undone in CBN_CLOSEUP above
|
||||||
|
|
||||||
|
// don't handle CBN_SELCHANGE neither, we don't want to generate events
|
||||||
|
// while the dropdown is opened -- but do add it if we ever need this
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd)
|
WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd)
|
||||||
|
Reference in New Issue
Block a user