1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-21 14:50:06 +02:00

Fix Mac tabbing to sliders and meters, analogously to buttons...

... And make sure they don't steal focus when clicked or double clicked
This commit is contained in:
Paul Licameli 2016-06-25 00:06:22 -04:00
parent d31e96aa57
commit 57788c8d7a
7 changed files with 71 additions and 10 deletions

View File

@ -137,6 +137,8 @@ simplifies construction of menu items.
#include "tracks/ui/Scrubbing.h"
#include "prefs/TracksPrefs.h"
#include "widgets/Meter.h"
enum {
kAlignStartZero = 0,
kAlignStartSelStart,
@ -2752,10 +2754,12 @@ void AudacityProject::OnSetRightSelection()
void AudacityProject::NextOrPrevFrame(bool forward)
{
// Focus won't take in a dock unless at least one descendant window
// accepts focus. Tell all AButtons to take focus for the duration of this
// accepts focus. Tell controls to take focus for the duration of this
// function, only. Outside of this, they won't steal the focus when
// clicked.
auto temp = AButton::TemporarilyAllowFocus();
auto temp1 = AButton::TemporarilyAllowFocus();
auto temp2 = ASlider::TemporarilyAllowFocus();
auto temp3 = Meter::TemporarilyAllowFocus();
// Define the set of windows we rotate among.

View File

@ -247,7 +247,7 @@ void AButton::UseDisabledAsDownHiliteImage(bool flag)
// this bypasses that limitation
void AButton::SetFocusFromKbd()
{
auto temp = AButton::TemporarilyAllowFocus();
auto temp = TemporarilyAllowFocus();
SetFocus();
}
@ -574,6 +574,11 @@ void AButton::SetControl(bool control)
mWasControlDown = control;
}
auto AButton::TemporarilyAllowFocus() -> TempAllowFocus {
s_AcceptsFocus = true;
return std::move(TempAllowFocus{ &s_AcceptsFocus });
}
#if wxUSE_ACCESSIBILITY
AButtonAx::AButtonAx( wxWindow *window ):

View File

@ -144,10 +144,7 @@ class AButton final : public wxWindow {
using TempAllowFocus = std::unique_ptr<bool, Resetter>;
public:
static TempAllowFocus TemporarilyAllowFocus() {
s_AcceptsFocus = true;
return std::move(TempAllowFocus{ &s_AcceptsFocus });
}
static TempAllowFocus TemporarilyAllowFocus();
private:

View File

@ -1783,6 +1783,22 @@ bool ASlider::IsEnabled() const
return mLWSlider->GetEnabled();
}
bool ASlider::s_AcceptsFocus{ false };
auto ASlider::TemporarilyAllowFocus() -> TempAllowFocus {
s_AcceptsFocus = true;
return std::move(TempAllowFocus{ &s_AcceptsFocus });
}
// This compensates for a but in wxWidgets 3.0.2 for mac:
// Couldn't set focus from keyboard when AcceptsFocus returns false;
// this bypasses that limitation
void ASlider::SetFocusFromKbd()
{
auto temp = TemporarilyAllowFocus();
SetFocus();
}
#if wxUSE_ACCESSIBILITY
ASliderAx::ASliderAx( wxWindow * window ) :

View File

@ -15,6 +15,7 @@
#include "../Experimental.h"
#include "../MemoryX.h"
#include <wx/defs.h>
#include <wx/window.h>
#include <wx/dialog.h>
@ -264,7 +265,10 @@ class ASlider /* not final */ : public wxPanel
int orientation = wxHORIZONTAL);
virtual ~ASlider();
bool AcceptsFocus() const override { return false; }
bool AcceptsFocus() const override { return s_AcceptsFocus; }
bool AcceptsFocusFromKeyboard() const override { return true; }
void SetFocusFromKbd() override;
void GetScroll(float & line, float & page);
void SetScroll(float line, float page);
@ -298,6 +302,14 @@ class ASlider /* not final */ : public wxPanel
bool Enable(bool enable = true);
bool IsEnabled() const;
private:
static bool s_AcceptsFocus;
struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
using TempAllowFocus = std::unique_ptr<bool, Resetter>;
public:
static TempAllowFocus TemporarilyAllowFocus();
private:
LWSlider *mLWSlider;
bool mSliderIsFocused;

View File

@ -2083,6 +2083,23 @@ wxString Meter::Key(const wxString & key) const
return wxT("/Meter/Output/") + key;
}
bool Meter::s_AcceptsFocus{ false };
auto Meter::TemporarilyAllowFocus() -> TempAllowFocus {
s_AcceptsFocus = true;
return std::move(TempAllowFocus{ &s_AcceptsFocus });
}
// This compensates for a but in wxWidgets 3.0.2 for mac:
// Couldn't set focus from keyboard when AcceptsFocus returns false;
// this bypasses that limitation
void Meter::SetFocusFromKbd()
{
auto temp = TemporarilyAllowFocus();
SetFocus();
}
#if wxUSE_ACCESSIBILITY
MeterAx::MeterAx(wxWindow *window):

View File

@ -113,8 +113,10 @@ class Meter final : public wxPanel
~Meter();
bool AcceptsFocus() const override { return false; };
bool AcceptsFocusFromKeyboard() const override { return true; };
bool AcceptsFocus() const override { return s_AcceptsFocus; }
bool AcceptsFocusFromKeyboard() const override { return true; }
void SetFocusFromKbd() override;
void UpdatePrefs();
void Clear();
@ -179,6 +181,14 @@ class Meter final : public wxPanel
void *SaveState();
void RestoreState(void *state);
private:
static bool s_AcceptsFocus;
struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
using TempAllowFocus = std::unique_ptr<bool, Resetter>;
public:
static TempAllowFocus TemporarilyAllowFocus();
private:
//
// Event handlers