void SpinControl::SetDigits(unsigned int digits) { if (digits == m_digits) return; m_digits = digits; m_format.Printf(wxT("%6.%%0uf"), m_digits); DoSetValue(m_value); }
void SpinControl::OnSpinButton(bool up) { static const unsigned int SHIFT = 1; static const unsigned int ALT = 2; static const unsigned int META = 4; static const unsigned int CTRLCMD = 8; double increment = 0.0f; wxMouseState mouseState = wxGetMouseState(); unsigned int keys = 0; if (mouseState.ShiftDown()) keys |= SHIFT; if (mouseState.AltDown()) keys |= ALT; if (mouseState.MetaDown()) keys |= META; if (mouseState.ControlDown() || mouseState.CmdDown()) keys |= CTRLCMD; if (keys == 0) increment = m_regularIncrement; else if (keys == SHIFT) increment = m_shiftIncrement; else if (keys == CTRLCMD) increment = m_ctrlIncrement; double newValue = up ? m_value + increment : m_value - increment; newValue = AdjustToRange(newValue); if (DoSetValue(newValue)) DoSendEvent(); m_spin->SetValue(0); }
void SpinControl::SetRange(double min, double max) { assert(min < max); m_minValue = min; m_maxValue = max; DoSetValue(AdjustToRange(m_value)); }
void SpinControl::SetValue(const wxString& textValue) { double doubleValue; if (textValue.ToDouble(&doubleValue) && InRange(doubleValue)) { DoSetValue(doubleValue); } else { m_text->SetValue(textValue); m_text->SetSelection(0, -1); m_text->SetInsertionPointEnd(); } }
bool SpinControl::SyncFromText() { if (!m_text->IsModified()) return false; double textValue; if (m_text->GetValue().ToDouble(&textValue)) textValue = AdjustToRange(textValue); else textValue = m_value; return DoSetValue(textValue); }
void wxSpinCtrlGTKBase::SetValue( const wxString& value ) { wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") ); double n; if ( wxSscanf(value, "%lg", &n) == 1 ) { // a number - set it, let DoSetValue round for int value DoSetValue(n); return; } // invalid number - set text as is (wxMSW compatible) wxSpinCtrlEventDisabler disable(this); gtk_entry_set_text( GTK_ENTRY(m_widget), wxGTK_CONV( value ) ); }
// set property value at a specific time position GError GProperty::SetValue(const GKeyValue& InputValue, const GTimeValue TimePos, const GValueMethod SetMethod) { if (InputValue.KeyType() != HandledType()) return G_INVALID_PARAMETER; GKeyValue tmpKey(InputValue); tmpKey.SetTimePosition(TimePos); // apply ease (time curve) if (gApplyEase && gEaseProperty) { GKeyValue easeValue; GTimeInterval easeValid = G_FOREVER_TIMEINTERVAL; GError err = gEaseProperty->Value(easeValue, easeValid, TimePos, G_ABSOLUTE_VALUE); if (err != G_NO_ERROR) return err; tmpKey.SetTimePosition(easeValue.RealValue()); } return DoSetValue(tmpKey, tmpKey.TimePosition(), SetMethod); }
SpinControl::SpinControl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : wxPanel(parent, id, pos, size, (style & ~wxBORDER_MASK) | wxBORDER_NONE, name), m_text(NULL), m_spin(NULL), m_minValue(std::numeric_limits<double>::min()), m_maxValue(std::numeric_limits<double>::max()), m_regularIncrement(0.0), m_shiftIncrement(0.0), m_ctrlIncrement(0.0), m_value(0.0), m_digits(0), m_format(wxT("%g")) { m_text = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_RIGHT); m_spin = new wxSpinButton(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_VERTICAL); m_text->SetSizeHints(wxDefaultCoord, wxDefaultCoord); m_text->SetToolTip(GetToolTipText()); m_spin->SetToolTip(GetToolTipText()); m_spin->SetSizeHints(wxDefaultCoord, wxDefaultCoord); m_spin->SetRange(-32000, 32000); DoSetValue(m_value); wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_text, 1, wxEXPAND); sizer->Add(m_spin); SetSizerAndFit(sizer); SetInitialSize(size); Move(pos); m_text->Bind(wxEVT_COMMAND_TEXT_ENTER, &SpinControl::OnTextEnter, this); m_text->Bind(wxEVT_KILL_FOCUS, &SpinControl::OnTextKillFocus, this); m_spin->Bind(wxEVT_SPIN_UP, &SpinControl::OnSpinButtonUp, this); m_spin->Bind(wxEVT_SPIN_DOWN, &SpinControl::OnSpinButtonDown, this); Bind(wxEVT_SET_FOCUS, &SpinControl::OnSetFocus, this); }
void SpinControl::SetValue(double doubleValue) { if (InRange(doubleValue)) DoSetValue(doubleValue); }