1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 06:09:47 +02:00

Bug 1639 - Left and Right arrow keys don't work in docked toolbars, if bound to some action.

This fix works by detecting whether the focus window is the TrackPanel, in which case all keys are handled normally.  If it isn't the TrackPanel, then the problematic keys do not get sent to our own CommandHandler and proceed on to wxWidgets.

A problem that then follows is that the menu accelerators (which normally don't get a look in) may then convert the event to a menu event and stop it going any further.So it does not get to the focus window.

The fix/workaround for that is to NOT provide accelerators for up, down, left and right arrow in the menus.  I'd much rather be able to turn off those accelerators completely, yet still show them to users as hints.
This commit is contained in:
James Crook 2017-05-01 19:00:59 +01:00
parent ae24cab8fe
commit 57b200884e
3 changed files with 64 additions and 4 deletions

View File

@ -2326,8 +2326,10 @@ void AudacityProject::OnMenu(wxCommandEvent & event)
if (handled)
event.Skip(false);
else
else{
event.ResumePropagation( 999 );
event.Skip(true);
}
}
void AudacityProject::OnUpdateUI(wxUpdateUIEvent & WXUNUSED(event))

View File

@ -410,7 +410,7 @@ private:
UInt32 mDeadKeyState;
#endif
} monitor;
}monitor;
///
/// Standard Constructor
@ -719,7 +719,7 @@ void CommandManager::AddItem(const wxChar *name,
{
CommandListEntry *entry = NewIdentifier(name, label_in, accel, CurrentMenu(), callback, false, 0, 0);
int ID = entry->id;
wxString label = GetLabel(entry);
wxString label = GetLabelWithDisabledAccel(entry);
if (flags != NoFlagsSpecifed || mask != NoFlagsSpecifed) {
SetCommandFlags(name, flags, mask);
@ -966,6 +966,34 @@ wxString CommandManager::GetLabel(const CommandListEntry *entry) const
return label;
}
// A label that may have its accelerator disabled.
// The problem is that as soon as we show accelerators in the menu, the menu might
// catch them in normal wxWidgets processing, rather than passing the key presses on
// to the controls that had the focus. We would like all the menu accelerators to be
// disabled, in fact.
wxString CommandManager::GetLabelWithDisabledAccel(const CommandListEntry *entry) const
{
wxString label = entry->label;
#if 1
do{
if (!entry->key.IsEmpty())
{
if( entry->key.StartsWith("Left" )) break;
if( entry->key.StartsWith("Right")) break;
if( entry->key.StartsWith("Up" )) break;
if( entry->key.StartsWith("Down")) break;
//if( entry->key.StartsWith("Space" )) break;
// These ones appear ot be illegal and mess up accelerator processing.
if( entry->key.StartsWith("NUMPAD_ENTER" )) break;
if( entry->key.StartsWith("Backspace" )) break;
if( entry->key.StartsWith("Delete" )) break;
label += wxT("\t") + entry->key;
//wxLogDebug("Added Accel:[%s][%s]", entry->label, entry->key );
}
} while (false );
#endif
return label;
}
///Enables or disables a menu item based on its name (not the
///label in the menu bar, but the name of the command.)
///If you give it the name of a multi-item (one that was
@ -1147,13 +1175,42 @@ bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent &
wxKeyEvent temp = evt;
// Possibly let wxWidgets do its normal key handling IF it is one of
// the standard navigation keys.
if((type == wxEVT_KEY_DOWN) || (type == wxEVT_KEY_UP ))
{
wxWindow * pWnd = wxWindow::FindFocus();
wxWindow * pTrackPanel = (wxWindow*)GetActiveProject()->GetTrackPanel();
//wxLogDebug("Focus: %p TrackPanel: %p", pWnd, pTrackPanel );
// We allow the keystrokes below to be handled by wxWidgets controls IF we are
// in some sub window rather than in the TrackPanel itself.
// Otherwise they will go to our command handler and if it handles them
// they will NOT be available to wxWidgets.
if( pWnd != pTrackPanel ){
switch( evt.GetKeyCode() ){
case WXK_LEFT:
case WXK_RIGHT:
case WXK_UP:
case WXK_DOWN:
case WXK_SPACE:
case WXK_TAB:
case WXK_BACK:
case WXK_HOME:
case WXK_END:
case WXK_RETURN:
case WXK_NUMPAD_ENTER:
case WXK_DELETE:
return false;
}
}
}
if (type == wxEVT_KEY_DOWN)
{
if (entry->skipKeydown)
{
return true;
}
return HandleCommandEntry(entry, flags, NoFlagsSpecifed, &temp);
}

View File

@ -305,6 +305,7 @@ protected:
wxMenu * CurrentSubMenu() const;
wxMenu * CurrentMenu() const;
wxString GetLabel(const CommandListEntry *entry) const;
wxString GetLabelWithDisabledAccel(const CommandListEntry *entry) const;
//
// Loading/Saving