Audacity 3.2.0
SpinControl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 @file SpinControl.h
7
8 Dmitry Vedenko
9
10 **********************************************************************/
11#pragma once
12
13#include <numeric>
14
15#include <wx/control.h>
16
17#include "TranslatableString.h"
18#include "Prefs.h"
19
20class wxTextCtrl;
21class wxKeyEvent;
22
23#ifndef __WXGTK__
24class wxSpinButton;
25#else
26class wxButton;
27#endif
28
29class WX_WRAPPERS_API SpinControl final
30 : public wxControl
31 , private PrefsListener
32{
33public:
34 using ValueType = double;
35
37 wxWindow* parent, wxWindowID winid = wxID_ANY, ValueType value = 0.0,
38 ValueType min = 0.0f, ValueType max = 100.0, ValueType step = 1.0,
39 bool allowFractional = false, const wxPoint& pos = wxDefaultPosition,
40 const wxSize& size = wxDefaultSize, const TranslatableString& name = {});
41
42 void SetValue(double value);
43 double GetValue() const;
44
45 void SetMinValue(double value);
46 double GetMinValue() const;
47
48 void SetMaxValue(double value);
49 double GetMaxValue() const;
50
51 void SetStep(double step);
52 double GetStep() const;
53
54 void SetFractionalAllowed(bool allow);
55 bool GetFractionalAllowed();
56
57 void SetName(const TranslatableString& name);
58
59private:
60 void UpdatePrefs() override;
61
62 void CreateUI();
63 void SetupControls();
64 void CommitTextControlValue();
65 void OnCharHook(wxKeyEvent& evt);
66
67 void SetValue(double value, bool silent);
68
69 void DoSteps(double direction);
70
71 void NotifyValueChanged();
72
73 ValueType mValue { std::numeric_limits<ValueType>::quiet_NaN() };
74 ValueType mMinValue { -std::numeric_limits<ValueType>::infinity() };
75 ValueType mMaxValue { std::numeric_limits<ValueType>::infinity() };
77 int mPrecision { 2 };
78
80
81 wxTextCtrl* mTextControl { nullptr };
82#ifndef __WXGTK__
83 wxSpinButton* mSpinButton { nullptr };
84#else
85 wxButton* mUpButton { nullptr };
86 wxButton* mDownButton { nullptr };
87#endif
88
89#if wxUSE_ACCESSIBILITY
90 class SpinControlAx;
91 // As usual, wxWidgets manages the lifetime
92 SpinControlAx* mWindowAccessible { nullptr };
93#endif
94};
int min(int a, int b)
wxString name
Definition: TagsEditor.cpp:166
A listener notified of changes in preferences.
Definition: Prefs.h:652
virtual void UpdatePrefs()=0
Definition: Prefs.cpp:154
ValueType mStep
Definition: SpinControl.h:76
bool mFractionalAllowed
Definition: SpinControl.h:79
Holds a msgid for the translation catalog; may also bind format arguments.