39#include <wx/dcbuffer.h>
41#include <wx/graphics.h>
43#include <wx/tooltip.h>
45#include <wx/textctrl.h>
46#include <wx/valtext.h>
47#include <wx/statline.h>
48#include <wx/settings.h>
49#include <wx/popupwin.h>
56#include "../ProjectWindowBase.h"
63#if wxUSE_ACCESSIBILITY
69 ASliderAx(wxWindow * window);
71 virtual ~ ASliderAx();
75 wxAccStatus GetChild(
int childId, wxAccessible** child)
override;
78 wxAccStatus GetChildCount(
int* childCount)
override;
86 wxAccStatus GetDefaultAction(
int childId, wxString *actionName)
override;
89 wxAccStatus GetDescription(
int childId, wxString *description)
override;
95 wxAccStatus GetFocus(
int *childId, wxAccessible **child)
override;
98 wxAccStatus GetHelpText(
int childId, wxString *helpText)
override;
102 wxAccStatus GetKeyboardShortcut(
int childId, wxString *shortcut)
override;
106 wxAccStatus GetLocation(wxRect& rect,
int elementId)
override;
109 wxAccStatus GetName(
int childId, wxString *
name)
override;
112 wxAccStatus GetRole(
int childId, wxAccRole *role)
override;
122 wxAccStatus GetSelections(wxVariant *selections)
override;
125 wxAccStatus GetState(
int childId,
long* state)
override;
129 wxAccStatus GetValue(
int childId, wxString* strValue)
override;
140#define OPTIONAL_SLIDER_TICKS
153 void SetPos(
const wxPoint & pos);
157 void OnPaint(wxPaintEvent & event);
165 DECLARE_EVENT_TABLE()
173: wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
174 wxFRAME_SHAPED | wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
176 SetBackgroundStyle(wxBG_STYLE_PAINT);
177 SetBackgroundColour(wxTransparentColour);
180 mFont.SetFamily(wxFONTFAMILY_SWISS);
181 mFont.SetStyle(wxFONTSTYLE_NORMAL);
182 mFont.SetWeight(wxFONTWEIGHT_NORMAL);
184 mWidth = mHeight = 0;
185 for (
const auto &
label : labels ) {
188 mWidth = std::max( mWidth, width );
189 mHeight = std::max( mHeight, height );
196#if defined(__WXMAC__)
199 wxBitmap shape(mWidth, mHeight);
200 wxMemoryDC dc(shape);
202 dc.SetPen(*wxBLACK_PEN);
203 dc.SetBrush(*wxBLACK_BRUSH);
204 dc.DrawRoundedRectangle(0, 0, mWidth, mHeight, 5);
205 dc.SelectObject(wxNullBitmap);
207 SetShape(wxRegion(shape, *wxWHITE));
209 wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath();
210 path.AddRoundedRectangle(0, 0, mWidth, mHeight, 5);
232 wxAutoBufferedPaintDC dc(
this);
234 dc.SetPen(*wxBLACK_PEN);
241 int textWidth, textHeight;
243 dc.GetTextExtent(visibleLabel, &textWidth, &textHeight);
244 dc.DrawText(visibleLabel, (
mWidth - textWidth) / 2, (
mHeight - textHeight) / 2);
270 mValue = mpOrigin->Get(
false);
273 auto trailing = NumValidatorStyle::TWO_TRAILING_ZEROES;
277 trailing = NumValidatorStyle::ONE_TRAILING_ZERO;
282 S.StartVerticalLay();
287 .Validator<IntegerValidator<float>>(
288 &mValue, NumValidatorStyle::DEFAULT, -100.0, 100.0)
289 .AddTextBox({}, wxEmptyString, 15);
294 .Validator<IntegerValidator<float>>(
295 &mValue, NumValidatorStyle::DEFAULT, -50.0, 50.0)
296 .AddTextBox({}, wxEmptyString, 15);
301 .Validator<IntegerValidator<float>>(
302 &mValue, NumValidatorStyle::DEFAULT, 0.0, 100.0)
303 .AddTextBox({}, wxEmptyString, 15);
308 .Validator<FloatingPointValidator<float>>(
309 prec, &mValue, trailing, mpOrigin->GetMinValue(), mpOrigin->GetMaxValue())
310 .AddTextBox({}, wxEmptyString, 15);
341 mTextCtrl->GetValidator()->TransferToWindow();
353 if (
mTextCtrl->GetValidator()->TransferFromWindow())
378 if (
mTextCtrl->GetValidator()->TransferFromWindow())
395static const wxPoint2DDouble
outer[] =
397 wxPoint2DDouble( 2, 0 ),
398 wxPoint2DDouble( 8, 0 ),
399 wxPoint2DDouble( 10, 2 ),
400 wxPoint2DDouble( 10, 8 ),
401 wxPoint2DDouble( 5, 13 ),
402 wxPoint2DDouble( 0, 8 ),
403 wxPoint2DDouble( 0, 2 ),
404 wxPoint2DDouble( 2, 0 )
410 wxPoint2DDouble( 2, 1 ),
411 wxPoint2DDouble( 1, 2 ),
412 wxPoint2DDouble( 1, 8 ),
413 wxPoint2DDouble( 4, 4 ),
414 wxPoint2DDouble( 4, 7 )
418 wxPoint2DDouble( 8, 1 ),
419 wxPoint2DDouble( 1, 8 ),
420 wxPoint2DDouble( 5, 12 ),
421 wxPoint2DDouble( 6, 4 ),
422 wxPoint2DDouble( 6, 7 )
428 wxPoint2DDouble( 9, 2 ),
429 wxPoint2DDouble( 9, 8 ),
430 wxPoint2DDouble( 4, 5 ),
431 wxPoint2DDouble( 4, 8 ),
435 wxPoint2DDouble( 9, 8 ),
436 wxPoint2DDouble( 6, 11 ),
437 wxPoint2DDouble( 6, 5 ),
438 wxPoint2DDouble( 6, 8 )
444 wxPoint2DDouble( 3, 2 ),
445 wxPoint2DDouble( 5, 2 ),
446 wxPoint2DDouble( 7, 2 ),
447 wxPoint2DDouble( 2, 3 ),
448 wxPoint2DDouble( 2, 5 ),
449 wxPoint2DDouble( 2, 7 ),
453 wxPoint2DDouble( 8, 7 ),
454 wxPoint2DDouble( 8, 5 ),
455 wxPoint2DDouble( 8, 3 ),
456 wxPoint2DDouble( 7, 8 ),
457 wxPoint2DDouble( 6, 9 ),
458 wxPoint2DDouble( 5, 10 ),
464 wxPoint2DDouble( 9, 2 ),
465 wxPoint2DDouble( 9, 8 ),
469 wxPoint2DDouble( 9, 8 ),
470 wxPoint2DDouble( 6, 11 ),
491 Init(parent,
name, pos,
size, minValue, maxValue, stepValue,
492 canUseShift,
style, showlabels, drawticks, drawtrack,
493 alwayshidetip, heavyweight, popup, 1.0, orientation);
510 wxString leftLabel, rightLabel;
512 float minValue, maxValue, stepValue;
521 orientation = wxHORIZONTAL;
556 Init(parent,
name, pos,
size, minValue, maxValue, stepValue,
557 true,
style, showlabels, drawticks, drawtrack, alwayshidetip,
558 heavyweight, popup, speed, orientation);
740 dc.SetBackground( *wxTRANSPARENT_BRUSH );
745 const auto &thumbBitmap =
749 dc.DrawBitmap(thumbBitmap,
mLeft+thumbPos,
mTop+thumbOrtho,
true);
754 dc.DrawBitmap(thumbBitmap,
mLeft+thumbOrtho-5,
mTop+thumbPos,
true);
785 mBitmap = std::make_unique<wxBitmap>();
788#if defined(__WXMAC__)
797 dc.SetBackground(wxBrush(
mParent->GetBackgroundColour()));
826 wxFont labelFont(7, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
827 dc.SetFont(labelFont);
833 dc.DrawText(
_(
"L"),
mLeftX, 0);
836 dc.DrawText(
_(
"R"),
mRightX - dc.GetTextExtent(
_(
"R")).GetWidth(), 0);
867 bool bTicks = TickColour != wxColour(60,60,60);
877 upp = divs / (double)(
mWidthX-1);
885#ifdef OPTIONAL_SLIDER_TICKS
889 for(
int p = 0; p <= kMax; p++)
891 if (((
int)d) > int_d)
894 int tickLength = ((int_d == 0) || (int_d == divs)) ? 5: 3;
922 dc.SelectObject(wxNullBitmap);
1014 val =
XO(
"%+.1f dB").Format( value );
1024 const auto v = 100.0f * fabsf(value);
1027 val =
XO(
"%.0f%% Left").Format( v );
1030 val =
XO(
"%.0f%% Right").Format( v );
1036 val =
XO(
"%.2fx").Format( value );
1077 results.push_back(
GetTip( -1.99f ) );
1078 results.push_back(
GetTip( +1.99f ) );
1082 results.push_back(
GetTip(1.0f));
1085 results.push_back(
GetTip( -99.9f ) );
1086 results.push_back(
GetTip( +99.9f ) );
1092 results.push_back(
GetTip( 0.f ) );
1093 results.push_back(
GetTip( +1.f ) );
1094 results.push_back(
GetTip( -1.f ) );
1098 results.push_back(
GetTip( 9.99f ) );
1102 results.push_back(
GetTip( 999.f ) );
1127 bool changed =
false;
1141 if (pos == wxPoint(-1, -1)) {
1145 changed = (dlg.ShowModal() == wxID_OK);
1163 if (event.Entering())
1172 else if (event.Leaving())
1190 if ((event.RightDown() && !event.RightIsDown()) ||
1191 (event.RightUp() && event.GetPosition() == wxPoint(-1, -1)))
1214 wxRect tolerantThumbRect = r;
1215 tolerantThumbRect.Inflate(3, 3);
1218 if( event.ButtonDClick() &&
mPopup )
1223 else if( event.ButtonDown() )
1230 if( event.RightDown() ) {
1238 if( tolerantThumbRect.Contains( event.GetPosition() ) )
1251 (
mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y,
1261 else if( event.ButtonUp() )
1273 if (event.m_y < (r.y - 2 * r.height) ||
1274 event.m_y > (r.y + 3 * r.height)) {
1287 if (event.m_x < (r.x - 2 * r.width) ||
1288 event.m_x > (r.x + 3 * r.width)) {
1300 else if( event.m_wheelRotation != 0 )
1304 double steps =
event.m_wheelRotation /
1305 (
event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
1326 switch( event.GetKeyCode() )
1329 mParent->Navigate(event.ShiftDown()
1330 ? wxNavigationKeyEvent::IsBackward
1331 : wxNavigationKeyEvent::IsForward);
1371 case WXK_NUMPAD_ENTER:
1373 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(
mParent), wxTopLevelWindow);
1374 wxWindow *def = tlw->GetDefaultItem();
1375 if (def && def->IsEnabled()) {
1378 cevent.SetEventObject( def );
1379 mParent->GetEventHandler()->ProcessEvent(cevent);
1420 wxCommandEvent e( wxEVT_COMMAND_SLIDER_UPDATED,
mID );
1423 e.SetInt( intValue );
1424 mParent->GetEventHandler()->ProcessEvent(e);
1494 float val = (pos / (float)nSpan)
1574 if ( stepValue == 0.0 )
1597 if ( stepValue == 0.0 )
1660BEGIN_EVENT_TABLE(
ASlider, wxPanel)
1676 const wxPoint & pos,
1677 const wxSize &
size,
1679: wxPanel( parent,
id, pos,
size, wxWANTS_CHARS )
1684 mLWSlider = std::make_unique<LWSlider>(
this,
1692 options.alwaysHideTip,
1695 options.orientation);
1696 mLWSlider->mStepValue = options.stepValue;
1697 mLWSlider->SetId(
id );
1700 mSliderIsFocused =
false;
1701 mStyle = options.style;
1703 mTimer.SetOwner(
this);
1705#if wxUSE_ACCESSIBILITY
1706 SetAccessible(
safenew ASliderAx(
this ) );
1709 mLWSlider->SetScroll( options.line, options.page );
1721 auto res = wxPanel::SetBackgroundColour(colour);
1734 if ( event.GetId() ==
mLWSlider->GetId() )
1736#if wxUSE_ACCESSIBILITY
1737 GetAccessible()->NotifyEvent( wxACC_EVENT_OBJECT_VALUECHANGE,
1759 wxBufferedPaintDC dc(
this);
1762 GetClientRect().Contains(
1764 ::wxGetMousePosition() ) );
1779 if (event.Entering())
1783 else if (event.Leaving())
1793 wxMouseEvent e(wxEVT_LEFT_UP);
1872 wxWindow::Enable(enable);
1885 s_AcceptsFocus =
true;
1898#if wxUSE_ACCESSIBILITY
1900ASliderAx::ASliderAx( wxWindow * window ) :
1905ASliderAx::~ASliderAx()
1911wxAccStatus ASliderAx::GetChild(
int childId, wxAccessible** child )
1913 if ( childId == wxACC_SELF )
1926wxAccStatus ASliderAx::GetChildCount(
int* childCount)
1939wxAccStatus ASliderAx::GetDefaultAction(
int WXUNUSED(childId), wxString *actionName )
1941 actionName->clear();
1947wxAccStatus ASliderAx::GetDescription(
int WXUNUSED(childId), wxString *description )
1949 description->clear();
1958wxAccStatus ASliderAx::GetFocus(
int* childId, wxAccessible** child)
1967wxAccStatus ASliderAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText )
1976wxAccStatus ASliderAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut )
1985wxAccStatus ASliderAx::GetLocation( wxRect& rect,
int WXUNUSED(elementId) )
1989 rect = as->GetRect();
1990 rect.SetPosition( as->GetParent()->ClientToScreen( rect.GetPosition() ) );
1996wxAccStatus ASliderAx::GetName(
int WXUNUSED(childId), wxString*
name)
2000 *
name = as->GetName();
2006wxAccStatus ASliderAx::GetRole(
int childId, wxAccRole* role)
2011 *role = wxROLE_SYSTEM_SLIDER;
2016 *role = wxROLE_SYSTEM_PUSHBUTTON;
2020 *role = wxROLE_SYSTEM_INDICATOR;
2035wxAccStatus ASliderAx::GetSelections( wxVariant * WXUNUSED(selections) )
2037 return wxACC_NOT_IMPLEMENTED;
2041wxAccStatus ASliderAx::GetState(
int childId,
long* state)
2048 *state = wxACC_STATE_SYSTEM_FOCUSABLE;
2054 *state = wxACC_STATE_SYSTEM_INVISIBLE;
2061 *state = wxACC_STATE_SYSTEM_INVISIBLE;
2075wxAccStatus ASliderAx::GetValue(
int childId, wxString* strValue)
2081 *strValue = as->
mLWSlider->GetStringValue();
2084 return wxACC_NOT_SUPPORTED;
static const wxPoint2DDouble enabledLeftEnd[]
static const wxPoint2DDouble disabledRightEnd[]
static const wxPoint2DDouble enabledLeftBegin[]
static const wxPoint2DDouble disabledRightBegin[]
static const wxPoint2DDouble disabledStripesBegin[]
static const wxPoint2DDouble enabledRightBegin[]
static const wxPoint2DDouble enabledRightEnd[]
static const wxPoint2DDouble disabledStripesEnd[]
static const wxPoint2DDouble outer[]
wxEVT_COMMAND_BUTTON_CLICKED
const TranslatableString name
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
static wxBrush tooltipBrush
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
static void DrawFocus(wxDC &dc, wxRect &r)
ASlider is a custom slider, allowing for a slicker look and feel.
static TempAllowFocus TemporarilyAllowFocus()
void OnSetFocus(wxFocusEvent &event)
void SetFocusFromKbd() override
void SetSpeed(float speed)
void GetScroll(float &line, float &page)
bool ShowDialog(wxPoint pos=wxPoint(-1, -1))
std::unique_ptr< LWSlider > mLWSlider
void OnKeyDown(wxKeyEvent &event)
void OnTimer(wxTimerEvent &event)
std::unique_ptr< bool, Resetter > TempAllowFocus
void OnKillFocus(wxFocusEvent &event)
void Increase(float steps)
void OnCaptureLost(wxMouseCaptureLostEvent &event)
void Decrease(float steps)
void OnSlider(wxCommandEvent &event)
void SetToolTipTemplate(const TranslatableString &tip)
void OnMouseEvent(wxMouseEvent &event)
static bool s_AcceptsFocus
bool Enable(bool enable=true) override
void OnPaint(wxPaintEvent &event)
bool SetBackgroundColour(const wxColour &colour) override
void OnErase(wxEraseEvent &event)
void SetScroll(float line, float page)
void OnSize(wxSizeEvent &event)
float Get(bool convert=true)
Lightweight version of ASlider. In other words it does not have a window permanently associated with ...
void DrawToBitmap(wxDC &dc)
void OnPaint(wxDC &dc, bool highlighted)
float GetMinValue() const
std::unique_ptr< wxBitmap > mThumbBitmap
void SetEnabled(bool enabled)
void Init(wxWindow *parent, const TranslatableString &name, const wxPoint &pos, const wxSize &size, float minValue, float maxValue, float stepValue, bool canUseShift, int style, bool showlabels, bool drawticks, bool drawtrack, bool alwayshidetip, bool heavyweight, bool popup, float speed, int orientation=wxHORIZONTAL)
TranslatableString mTipTemplate
void OnMouseEvent(wxMouseEvent &event)
void Decrease(float steps)
void AdjustSize(const wxSize &sz)
void Increase(float steps)
float Get(bool convert=true)
void SetDefaultValue(float value)
wxString GetStringValue() const
void OnKeyDown(wxKeyEvent &event)
int ValueToPosition(float val)
TranslatableStrings GetWidestTips() const
std::unique_ptr< wxBitmap > mBitmap
void GetScroll(float &line, float &page)
void SetSpeed(float speed)
void SetDefaultShortcut(bool value)
std::unique_ptr< wxBitmap > mThumbBitmapHilited
float GetMaxValue() const
void SendUpdate(float newValue)
void SetName(const TranslatableString &name)
float DragPositionToValue(int fromPos, bool shiftDown)
void SetScroll(float line, float page)
bool DoShowDialog(wxPoint pos)
void OnSize(wxSizeEvent &event)
void SetId(wxWindowID id)
void SetToolTipTemplate(const TranslatableString &tip)
void Move(const wxPoint &newpos)
void SetParent(wxWindow *parent)
LWSlider(wxWindow *parent, const TranslatableString &name, const wxPoint &pos, const wxSize &size, float minValue, float maxValue, float stepValue, bool canUseShift, int style, bool showlabels=true, bool drawticks=true, bool drawtrack=true, bool alwayshidetip=false, bool heavyweight=false, bool popup=true, int orientation=wxHORIZONTAL)
float ClickPositionToValue(int fromPos, bool shiftDown)
wxWeakRef< TipWindow > mTipPanel
TranslatableString GetTip(float value) const
static ProjectStatus & Get(AudacityProject &project)
void Set(const TranslatableString &msg, StatusBarField field=MainStatusBarField())
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Pop up dialog used with an LWSlider.
bool TransferDataFromWindow() override
void OnSlider(wxCommandEvent &event)
void OnTextChange(wxCommandEvent &event)
bool TransferDataToWindow() override
wxColour & Colour(int iIndex)
wxBitmap & Bitmap(int iIndex)
A wxPopupWindow used to give the numerical value of an LWSlider or ASlider.
void OnPaint(wxPaintEvent &event)
TipWindow(wxWindow *parent, const TranslatableStrings &labels)
void SetLabel(const TranslatableString &label)
TranslatableString mLabel
void SetPos(const wxPoint &pos)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
__finl float __vecc rint(float a)