15#include <wx/textctrl.h>
19#include <wx/spinctrl.h>
22#include <wx/spinbutt.h>
27#if wxUSE_ACCESSIBILITY
30class SpinControl::SpinControlAx final
34 explicit SpinControlAx(
SpinControl* owner, wxWindow* control)
40 wxAccStatus GetName(
int childId, wxString*
name)
override
42 if (childId != wxACC_SELF)
43 return wxACC_NOT_IMPLEMENTED;
45 *
name = mName.StrippedTranslation();
52 mName = std::move(
name);
64 wxWindow* parent, wxWindowID winid ,
double value ,
65 double min ,
double max ,
double step ,
66 bool allowFractional ,
const wxPoint& pos ,
69 : wxControl(parent, winid, pos,
size, wxBORDER_NONE)
71 , mFractionalAllowed(allowFractional)
146#if wxUSE_ACCESSIBILITY
147 if (mWindowAccessible ==
nullptr)
153 mWindowAccessible->SetName(
name);
169 constexpr auto minGtkSize = 16;
170 const auto editorHeight = std::max(minGtkSize * 2,
mTextControl->GetSize().y);
173 auto boxSizer =
safenew wxBoxSizer(wxHORIZONTAL);
175 boxSizer->Add(
mTextControl, wxSizerFlags().Border(wxALL, 0));
178 mSpinButton =
safenew wxSpinButton(
this);
179 mSpinButton->SetMaxSize({ -1, editorHeight });
183 mSpinButton->SetValue(50);
185 boxSizer->Add(mSpinButton, wxSizerFlags().Border(wxALL, 0));
187 auto buttonsSizer =
safenew wxBoxSizer(wxVERTICAL);
189 const auto buttonSize = wxSize { editorHeight / 2, editorHeight / 2 };
191 mUpButton =
safenew wxButton(
this, wxID_ANY, L
"+", wxDefaultPosition, buttonSize);
194 buttonsSizer->Add(
mUpButton, wxSizerFlags().Border(wxALL, 0));
199 buttonsSizer->Add(
mDownButton, wxSizerFlags().Border(wxALL, 0));
201 boxSizer->Add(buttonsSizer, wxSizerFlags().Border(wxALL, 0));
204 const auto width = GetSize().x;
209 auto spinWidth = mSpinButton->GetSize().x;
210 const auto editorWidth = std::max(10, width - spinWidth);
211 mTextControl->SetMaxSize({ editorWidth, editorHeight });
213 const auto editorWidth = std::max(10, width - editorHeight / 2);
215 mTextControl->SetMinSize({ editorWidth, editorHeight });
216 mTextControl->SetMaxSize({ editorWidth, editorHeight });
221 SetSizerAndFit(boxSizer);
246 const auto delta = evt.GetWheelDelta();
247 const auto rotation = evt.GetWheelRotation();
249 if (rotation >= delta)
250 DoSteps(evt.ShiftDown() ? 10 : 1);
251 else if (rotation <= delta)
252 DoSteps(evt.ShiftDown() ? -10 : -1);
292 auto validator = wxFloatingPointValidator<ValueType>(
293 mPrecision,
nullptr, wxNUM_VAL_NO_TRAILING_ZEROES);
302 auto validator = wxIntegerValidator<int>();
304 validator.SetMin(
static_cast<int>(std::ceil(
mMinValue)));
305 validator.SetMax(
static_cast<int>(std::floor(
mMaxValue)));
322 const auto keyCode = evt.GetKeyCode();
324 if (keyCode == WXK_UP || keyCode == WXK_NUMPAD_UP)
325 DoSteps(evt.ShiftDown() ? 10.0 : 1.0);
326 else if (keyCode == WXK_PAGEUP || keyCode == WXK_NUMPAD_PAGEUP)
328 else if (keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN)
329 DoSteps(evt.ShiftDown() ? -10.0 : -1.0);
330 else if (keyCode == WXK_PAGEDOWN || keyCode == WXK_NUMPAD_PAGEDOWN)
332 else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER)
360 wxCommandEvent e(wxEVT_SPINCTRL, GetId());
361 e.SetEventObject(
this);
362 ProcessWindowEvent(e);
void SetMaxValue(double value)
bool GetFractionalAllowed()
void UpdatePrefs() override
void DoSteps(double direction)
void NotifyValueChanged()
wxTextCtrl * mTextControl
void SetStep(double step)
void SetFractionalAllowed(bool allow)
void CommitTextControlValue()
void OnCharHook(wxKeyEvent &evt)
void SetMinValue(double value)
void SetValue(double value)
SpinControl(wxWindow *parent, wxWindowID winid=wxID_ANY, ValueType value=0.0, ValueType min=0.0f, ValueType max=100.0, ValueType step=1.0, bool allowFractional=false, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const TranslatableString &name={})
void SetName(const TranslatableString &name)
double GetMaxValue() const
double GetMinValue() const
Holds a msgid for the translation catalog; may also bind format arguments.
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...