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

Bug1623: Update play, record button images when modal dialog closes

This commit is contained in:
Paul Licameli 2017-07-22 19:06:27 -04:00
parent e2c0b2d00c
commit d9c3a02542

View File

@ -30,6 +30,7 @@
#include <wx/dcclient.h> #include <wx/dcclient.h>
#include <wx/dcmemory.h> #include <wx/dcmemory.h>
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
#include <wx/eventfilter.h>
#include <wx/image.h> #include <wx/image.h>
#include <wx/timer.h> #include <wx/timer.h>
@ -51,72 +52,33 @@ END_EVENT_TABLE()
// LL: An alternative to this might be to just use the wxEVT_KILL_FOCUS // LL: An alternative to this might be to just use the wxEVT_KILL_FOCUS
// or wxEVT_ACTIVATE events. // or wxEVT_ACTIVATE events.
class AButton::Listener final class AButton::Listener final
: public wxEvtHandler : public wxEventFilter
{ {
public: public:
Listener (AButton *button); Listener (AButton *button);
~Listener(); ~Listener();
void OnKeyDown(wxKeyEvent & event); int FilterEvent(wxEvent &event) override;
void OnKeyUp(wxKeyEvent & event);
void OnTimer(wxTimerEvent & event);
DECLARE_CLASS(AButton::Listener) void OnEvent();
DECLARE_EVENT_TABLE()
private: private:
AButton *mButton; AButton *mButton;
wxTimer mShiftKeyTimer;
}; };
IMPLEMENT_CLASS(AButton::Listener, wxEvtHandler);
BEGIN_EVENT_TABLE(AButton::Listener, wxEvtHandler)
EVT_TIMER(wxID_ANY, AButton::Listener::OnTimer)
END_EVENT_TABLE()
AButton::Listener::Listener (AButton *button) AButton::Listener::Listener (AButton *button)
: mButton(button) : mButton(button)
{ {
mShiftKeyTimer.SetOwner(this); wxEvtHandler::AddFilter(this);
wxTheApp->Connect( wxEVT_KEY_DOWN,
wxKeyEventHandler( AButton::Listener::OnKeyDown ),
NULL,
this );
wxTheApp->Connect( wxEVT_KEY_UP,
wxKeyEventHandler( AButton::Listener::OnKeyUp ),
NULL,
this );
} }
AButton::Listener::~Listener () AButton::Listener::~Listener ()
{ {
wxTheApp->Disconnect( wxEVT_KEY_DOWN, wxEvtHandler::RemoveFilter(this);
wxKeyEventHandler( AButton::Listener::OnKeyDown ),
NULL,
this );
wxTheApp->Disconnect( wxEVT_KEY_UP,
wxKeyEventHandler( AButton::Listener::OnKeyUp ),
NULL,
this );
} }
void AButton::Listener::OnKeyDown(wxKeyEvent & event) void AButton::Listener::OnEvent()
{ {
// Really, it's all the same check for changes of key states.
OnKeyUp(event);
// See comments in OnTimer()
mShiftKeyTimer.Start(100);
}
void AButton::Listener::OnKeyUp(wxKeyEvent & event)
{
event.Skip();
if (!mButton->IsDown()) if (!mButton->IsDown())
{ {
int idx = 0; int idx = 0;
@ -136,22 +98,17 @@ void AButton::Listener::OnKeyUp(wxKeyEvent & event)
} }
} }
void AButton::Listener::OnTimer(wxTimerEvent & event) int AButton::Listener::FilterEvent(wxEvent &event)
{ {
event.Skip(); if (event.GetEventType() == wxEVT_KEY_DOWN ||
event.GetEventType() == wxEVT_KEY_UP)
// bug 307 fix: OnEvent();
// Shift key-up events get swallowed if a command with a Shift in its keyboard else if (event.GetEventType() == wxEVT_SET_FOCUS)
// shortcut opens a dialog, and OnKeyUp() doesn't get called. // A modal dialog might have eaten the modifier key-up with its own
// With CTRL now causing the button to change appearance, presumably similar // filter before we saw it; this is adequate to fix the button image
// can happen with that key. // when the dialog disappears.
if (!wxGetKeyState(WXK_SHIFT) || OnEvent();
!wxGetKeyState(WXK_CONTROL)) return Event_Skip;
{
wxKeyEvent dummy;
this->OnKeyUp(dummy);
mShiftKeyTimer.Stop();
}
} }
AButton::AButton(wxWindow * parent, AButton::AButton(wxWindow * parent,