1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 00:21:16 +02:00

Ignore the key up events after showing the context menu (on Windows only)

This commit is contained in:
lllucius 2015-01-09 15:27:58 +00:00
parent cdde320f0d
commit a6ace4a606
2 changed files with 26 additions and 3 deletions

View File

@ -710,6 +710,9 @@ void Meter::OnMouse(wxMouseEvent &evt)
void Meter::OnContext(wxContextMenuEvent &evt) void Meter::OnContext(wxContextMenuEvent &evt)
{ {
#if defined(__WXMSW__)
if (mHadKeyDown)
#endif
if (mStyle != MixerTrackCluster) // MixerTrackCluster style has no menu. if (mStyle != MixerTrackCluster) // MixerTrackCluster style has no menu.
{ {
ShowMenu(wxPoint(mIconRect.x + 1, mIconRect.y + mIconRect.height + 1)); ShowMenu(wxPoint(mIconRect.x + 1, mIconRect.y + mIconRect.height + 1));
@ -718,19 +721,30 @@ void Meter::OnContext(wxContextMenuEvent &evt)
{ {
evt.Skip(); evt.Skip();
} }
#if defined(__WXMSW__)
mHadKeyDown = false;
#endif
} }
void Meter::OnKeyDown(wxKeyEvent &evt) void Meter::OnKeyDown(wxKeyEvent &evt)
{ {
switch (evt.GetKeyCode()) switch (evt.GetKeyCode())
{ {
// These are handled in the OnKeyUp handler because, on Windows at least, the
// key up event will be passed on to the menu if we show it here. This causes
// the default sound to be heard if assigned.
//
// But, again on Windows, when the user selects a menu item, it is handled by
// the menu and the key up event is passed along to our OnKeyUp() handler, so
// we have to ignore it, otherwise we'd just show the menu again.
case WXK_RETURN: case WXK_RETURN:
case WXK_NUMPAD_ENTER: case WXK_NUMPAD_ENTER:
// Ignore them...will be handled in OnKeyUp
break;
case WXK_WINDOWS_MENU: case WXK_WINDOWS_MENU:
case WXK_MENU: case WXK_MENU:
// Ignore them...will be handled in OnContext #if defined(__WXMSW__)
mHadKeyDown = true;
#endif
break; break;
case WXK_RIGHT: case WXK_RIGHT:
Navigate(wxNavigationKeyEvent::IsForward); Navigate(wxNavigationKeyEvent::IsForward);
@ -756,10 +770,16 @@ void Meter::OnKeyUp(wxKeyEvent &evt)
{ {
case WXK_RETURN: case WXK_RETURN:
case WXK_NUMPAD_ENTER: case WXK_NUMPAD_ENTER:
#if defined(__WXMSW__)
if (mHadKeyDown)
#endif
if (mStyle != MixerTrackCluster) // MixerTrackCluster style has no menu. if (mStyle != MixerTrackCluster) // MixerTrackCluster style has no menu.
{ {
ShowMenu(wxPoint(mIconRect.x + 1, mIconRect.y + mIconRect.height + 1)); ShowMenu(wxPoint(mIconRect.x + 1, mIconRect.y + mIconRect.height + 1));
} }
#if defined(__WXMSW__)
mHadKeyDown = false;
#endif
break; break;
default: default:
evt.Skip(); evt.Skip();

View File

@ -270,6 +270,9 @@ class Meter : public wxPanel
bool mIsFocused; bool mIsFocused;
wxRect mFocusRect; wxRect mFocusRect;
#if defined(__WXMSW__)
bool mHadKeyDown;
#endif
friend class MeterAx; friend class MeterAx;