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>
51#include <wx/display.h>
57#include "../ProjectWindowBase.h"
64#if wxUSE_ACCESSIBILITY
70 ASliderAx(wxWindow * window);
72 virtual ~ ASliderAx();
76 wxAccStatus GetChild(
int childId, wxAccessible** child)
override;
79 wxAccStatus GetChildCount(
int* childCount)
override;
87 wxAccStatus GetDefaultAction(
int childId, wxString *actionName)
override;
90 wxAccStatus GetDescription(
int childId, wxString *description)
override;
96 wxAccStatus GetFocus(
int *childId, wxAccessible **child)
override;
99 wxAccStatus GetHelpText(
int childId, wxString *helpText)
override;
103 wxAccStatus GetKeyboardShortcut(
int childId, wxString *shortcut)
override;
107 wxAccStatus GetLocation(wxRect& rect,
int elementId)
override;
110 wxAccStatus GetName(
int childId, wxString *
name)
override;
113 wxAccStatus GetRole(
int childId, wxAccRole *role)
override;
123 wxAccStatus GetSelections(wxVariant *selections)
override;
126 wxAccStatus GetState(
int childId,
long* state)
override;
130 wxAccStatus GetValue(
int childId, wxString* strValue)
override;
141#define OPTIONAL_SLIDER_TICKS
154 void SetPos(
const wxPoint & pos);
158 void OnPaint(wxPaintEvent & event);
166 DECLARE_EVENT_TABLE()
174: wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
175 wxFRAME_SHAPED | wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
177 SetBackgroundStyle(wxBG_STYLE_PAINT);
178 SetBackgroundColour(wxTransparentColour);
181 mFont.SetFamily(wxFONTFAMILY_SWISS);
182 mFont.SetStyle(wxFONTSTYLE_NORMAL);
183 mFont.SetWeight(wxFONTWEIGHT_NORMAL);
185 mWidth = mHeight = 0;
186 for (
const auto &
label : labels ) {
189 mWidth = std::max( mWidth, width );
190 mHeight = std::max( mHeight, height );
197#if defined(__WXMAC__)
200 wxBitmap shape(mWidth, mHeight);
201 wxMemoryDC dc(shape);
203 dc.SetPen(*wxBLACK_PEN);
204 dc.SetBrush(*wxBLACK_BRUSH);
205 dc.DrawRoundedRectangle(0, 0, mWidth, mHeight, 5);
206 dc.SelectObject(wxNullBitmap);
208 SetShape(wxRegion(shape, *wxWHITE));
210 wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath();
211 path.AddRoundedRectangle(0, 0, mWidth, mHeight, 5);
233 wxAutoBufferedPaintDC dc(
this);
235 dc.SetPen(*wxBLACK_PEN);
242 int textWidth, textHeight;
244 dc.GetTextExtent(visibleLabel, &textWidth, &textHeight);
245 dc.DrawText(visibleLabel, (
mWidth - textWidth) / 2, (
mHeight - textHeight) / 2);
271 mValue = mpOrigin->Get(
false);
274 auto trailing = NumValidatorStyle::TWO_TRAILING_ZEROES;
278 trailing = NumValidatorStyle::ONE_TRAILING_ZERO;
283 trailing = NumValidatorStyle::THREE_TRAILING_ZEROES;
288 S.StartVerticalLay();
293 .Validator<IntegerValidator<float>>(
294 &mValue, NumValidatorStyle::DEFAULT, -100.0, 100.0)
295 .AddTextBox({}, wxEmptyString, 15);
300 .Validator<IntegerValidator<float>>(
301 &mValue, NumValidatorStyle::DEFAULT, -50.0, 50.0)
302 .AddTextBox({}, wxEmptyString, 15);
307 .Validator<IntegerValidator<float>>(
308 &mValue, NumValidatorStyle::DEFAULT, 0.0, 100.0)
309 .AddTextBox({}, wxEmptyString, 15);
314 .Validator<FloatingPointValidator<float>>(
315 prec, &mValue, trailing, mpOrigin->GetMinValue(), mpOrigin->GetMaxValue())
316 .AddTextBox({}, wxEmptyString, 15);
347 mTextCtrl->GetValidator()->TransferToWindow();
359 if (
mTextCtrl->GetValidator()->TransferFromWindow())
384 if (
mTextCtrl->GetValidator()->TransferFromWindow())
401static const wxPoint2DDouble
outer[] =
403 wxPoint2DDouble( 2, 0 ),
404 wxPoint2DDouble( 8, 0 ),
405 wxPoint2DDouble( 10, 2 ),
406 wxPoint2DDouble( 10, 8 ),
407 wxPoint2DDouble( 5, 13 ),
408 wxPoint2DDouble( 0, 8 ),
409 wxPoint2DDouble( 0, 2 ),
410 wxPoint2DDouble( 2, 0 )
416 wxPoint2DDouble( 2, 1 ),
417 wxPoint2DDouble( 1, 2 ),
418 wxPoint2DDouble( 1, 8 ),
419 wxPoint2DDouble( 4, 4 ),
420 wxPoint2DDouble( 4, 7 )
424 wxPoint2DDouble( 8, 1 ),
425 wxPoint2DDouble( 1, 8 ),
426 wxPoint2DDouble( 5, 12 ),
427 wxPoint2DDouble( 6, 4 ),
428 wxPoint2DDouble( 6, 7 )
434 wxPoint2DDouble( 9, 2 ),
435 wxPoint2DDouble( 9, 8 ),
436 wxPoint2DDouble( 4, 5 ),
437 wxPoint2DDouble( 4, 8 ),
441 wxPoint2DDouble( 9, 8 ),
442 wxPoint2DDouble( 6, 11 ),
443 wxPoint2DDouble( 6, 5 ),
444 wxPoint2DDouble( 6, 8 )
450 wxPoint2DDouble( 3, 2 ),
451 wxPoint2DDouble( 5, 2 ),
452 wxPoint2DDouble( 7, 2 ),
453 wxPoint2DDouble( 2, 3 ),
454 wxPoint2DDouble( 2, 5 ),
455 wxPoint2DDouble( 2, 7 ),
459 wxPoint2DDouble( 8, 7 ),
460 wxPoint2DDouble( 8, 5 ),
461 wxPoint2DDouble( 8, 3 ),
462 wxPoint2DDouble( 7, 8 ),
463 wxPoint2DDouble( 6, 9 ),
464 wxPoint2DDouble( 5, 10 ),
470 wxPoint2DDouble( 9, 2 ),
471 wxPoint2DDouble( 9, 8 ),
475 wxPoint2DDouble( 9, 8 ),
476 wxPoint2DDouble( 6, 11 ),
497 Init(parent,
name, pos,
size, minValue, maxValue, stepValue,
498 canUseShift,
style, showlabels, drawticks, drawtrack,
499 alwayshidetip, heavyweight, popup, 1.0, orientation);
516 wxString leftLabel, rightLabel;
518 float minValue, maxValue, stepValue;
527 orientation = wxHORIZONTAL;
562 Init(parent,
name, pos,
size, minValue, maxValue, stepValue,
563 true,
style, showlabels, drawticks, drawtrack, alwayshidetip,
564 heavyweight, popup, speed, orientation);
746 dc.SetBackground( *wxTRANSPARENT_BRUSH );
751 const auto &thumbBitmap =
755 dc.DrawBitmap(thumbBitmap,
mLeft+thumbPos,
mTop+thumbOrtho,
true);
760 dc.DrawBitmap(thumbBitmap,
mLeft+thumbOrtho-5,
mTop+thumbPos,
true);
791 mBitmap = std::make_unique<wxBitmap>();
794#if defined(__WXMAC__)
803 dc.SetBackground(wxBrush(
mParent->GetBackgroundColour()));
832 wxFont labelFont(7, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
833 dc.SetFont(labelFont);
839 dc.DrawText(
_(
"L"),
mLeftX, 0);
842 dc.DrawText(
_(
"R"),
mRightX - dc.GetTextExtent(
_(
"R")).GetWidth(), 0);
873 bool bTicks = TickColour != wxColour(60,60,60);
883 upp = divs / (double)(
mWidthX-1);
891#ifdef OPTIONAL_SLIDER_TICKS
895 for(
int p = 0; p <= kMax; p++)
897 if (((
int)d) > int_d)
900 int tickLength = ((int_d == 0) || (int_d == divs)) ? 5: 3;
928 dc.SelectObject(wxNullBitmap);
1020 val =
XO(
"%+.1f dB").Format( value );
1030 const auto v = 100.0f * fabsf(value);
1033 val =
XO(
"%.0f%% Left").Format( v );
1036 val =
XO(
"%.0f%% Right").Format( v );
1042 val =
XO(
"%.3fx").Format( value );
1083 results.push_back(
GetTip( -1.99f ) );
1084 results.push_back(
GetTip( +1.99f ) );
1088 results.push_back(
GetTip(1.0f));
1091 results.push_back(
GetTip( -99.9f ) );
1092 results.push_back(
GetTip( +99.9f ) );
1098 results.push_back(
GetTip( 0.f ) );
1099 results.push_back(
GetTip( +1.f ) );
1100 results.push_back(
GetTip( -1.f ) );
1104 results.push_back(
GetTip( 9.99f ) );
1108 results.push_back(
GetTip( 999.f ) );
1133 bool changed =
false;
1147 if (pos == wxPoint(-1, -1)) {
1150 wxRect screenRect = wxDisplay(wxDisplay::GetFromPoint(pos)).GetClientArea();
1151 int screenOffset = 8;
1152 int dlgWidth = dlg.GetSize().GetWidth();
1153 int dlgHeight = dlg.GetSize().GetHeight();
1155 if (pos.x + dlgWidth > screenRect.GetRight()) {
1156 pos.x = screenRect.GetRight() - dlgWidth - screenOffset;
1158 if (pos.x < screenRect.GetLeft()) {
1159 pos.x = screenRect.GetLeft() + screenOffset;
1161 if (pos.y + dlgHeight > screenRect.GetBottom()) {
1162 pos.y = screenRect.GetBottom() - dlgHeight - screenOffset;
1164 if (pos.y < screenRect.GetTop()) {
1165 pos.y = screenRect.GetTop() + screenOffset;
1167 dlg.SetPosition(pos);
1169 changed = (dlg.ShowModal() == wxID_OK);
1187 if (event.Entering())
1196 else if (event.Leaving())
1214 if ((event.RightDown() && !event.RightIsDown()) ||
1215 (event.RightUp() && event.GetPosition() == wxPoint(-1, -1)))
1238 wxRect tolerantThumbRect = r;
1239 tolerantThumbRect.Inflate(3, 3);
1242 if( event.ButtonDClick() &&
mPopup )
1247 else if( event.ButtonDown() )
1254 if( event.RightDown() ) {
1262 if( tolerantThumbRect.Contains( event.GetPosition() ) )
1275 (
mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y,
1285 else if( event.ButtonUp() )
1297 if (event.m_y < (r.y - 2 * r.height) ||
1298 event.m_y > (r.y + 3 * r.height)) {
1311 if (event.m_x < (r.x - 2 * r.width) ||
1312 event.m_x > (r.x + 3 * r.width)) {
1324 else if( event.m_wheelRotation != 0 )
1328 double steps =
event.m_wheelRotation /
1329 (
event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
1350 switch( event.GetKeyCode() )
1353 mParent->Navigate(event.ShiftDown()
1354 ? wxNavigationKeyEvent::IsBackward
1355 : wxNavigationKeyEvent::IsForward);
1395 case WXK_NUMPAD_ENTER:
1397 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(
mParent), wxTopLevelWindow);
1398 wxWindow *def = tlw->GetDefaultItem();
1399 if (def && def->IsEnabled()) {
1402 cevent.SetEventObject( def );
1403 mParent->GetEventHandler()->ProcessEvent(cevent);
1444 wxCommandEvent e( wxEVT_COMMAND_SLIDER_UPDATED,
mID );
1447 e.SetInt( intValue );
1448 mParent->GetEventHandler()->ProcessEvent(e);
1518 float val = (pos / (float)nSpan)
1598 if ( stepValue == 0.0 )
1621 if ( stepValue == 0.0 )
1684BEGIN_EVENT_TABLE(
ASlider, wxPanel)
1700 const wxPoint & pos,
1701 const wxSize &
size,
1703: wxPanel( parent,
id, pos,
size, wxWANTS_CHARS )
1708 mLWSlider = std::make_unique<LWSlider>(
this,
1716 options.alwaysHideTip,
1719 options.orientation);
1720 mLWSlider->mStepValue = options.stepValue;
1721 mLWSlider->SetId(
id );
1722 SetName(
name.Translation() );
1724 mSliderIsFocused =
false;
1725 mStyle = options.style;
1727 mTimer.SetOwner(
this);
1729#if wxUSE_ACCESSIBILITY
1730 SetAccessible(
safenew ASliderAx(
this ) );
1733 mLWSlider->SetScroll( options.line, options.page );
1745 auto res = wxPanel::SetBackgroundColour(colour);
1758 if ( event.GetId() ==
mLWSlider->GetId() )
1760#if wxUSE_ACCESSIBILITY
1761 GetAccessible()->NotifyEvent( wxACC_EVENT_OBJECT_VALUECHANGE,
1783 wxBufferedPaintDC dc(
this);
1786 GetClientRect().Contains(
1788 ::wxGetMousePosition() ) );
1803 if (event.Entering())
1807 else if (event.Leaving())
1817 wxMouseEvent e(wxEVT_LEFT_UP);
1896 wxWindow::Enable(enable);
1909 s_AcceptsFocus =
true;
1922#if wxUSE_ACCESSIBILITY
1924ASliderAx::ASliderAx( wxWindow * window ) :
1929ASliderAx::~ASliderAx()
1935wxAccStatus ASliderAx::GetChild(
int childId, wxAccessible** child )
1937 if ( childId == wxACC_SELF )
1950wxAccStatus ASliderAx::GetChildCount(
int* childCount)
1963wxAccStatus ASliderAx::GetDefaultAction(
int WXUNUSED(childId), wxString *actionName )
1965 actionName->clear();
1971wxAccStatus ASliderAx::GetDescription(
int WXUNUSED(childId), wxString *description )
1973 description->clear();
1982wxAccStatus ASliderAx::GetFocus(
int* childId, wxAccessible** child)
1991wxAccStatus ASliderAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText )
2000wxAccStatus ASliderAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut )
2009wxAccStatus ASliderAx::GetLocation( wxRect& rect,
int WXUNUSED(elementId) )
2013 rect = as->GetRect();
2014 rect.SetPosition( as->GetParent()->ClientToScreen( rect.GetPosition() ) );
2020wxAccStatus ASliderAx::GetName(
int WXUNUSED(childId), wxString*
name)
2024 *
name = as->GetName();
2030wxAccStatus ASliderAx::GetRole(
int childId, wxAccRole* role)
2035 *role = wxROLE_SYSTEM_SLIDER;
2040 *role = wxROLE_SYSTEM_PUSHBUTTON;
2044 *role = wxROLE_SYSTEM_INDICATOR;
2059wxAccStatus ASliderAx::GetSelections( wxVariant * WXUNUSED(selections) )
2061 return wxACC_NOT_IMPLEMENTED;
2065wxAccStatus ASliderAx::GetState(
int childId,
long* state)
2072 *state = wxACC_STATE_SYSTEM_FOCUSABLE;
2078 *state = wxACC_STATE_SYSTEM_INVISIBLE;
2085 *state = wxACC_STATE_SYSTEM_INVISIBLE;
2099wxAccStatus ASliderAx::GetValue(
int childId, wxString* strValue)
2105 *strValue = as->
mLWSlider->GetStringValue();
2108 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
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)