X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftime_picker.cc;h=ee591023bdbda95af34436528e738098ba4e8a78;hb=c27d6f3a7e6c79c60ffac7c616dd3a3431819862;hp=309e5c713b564cea157d8f772270786284e5b292;hpb=1b6cc1e8aa8abd05dfc9a108b35ddd7cbf50dedf;p=dcpomatic.git diff --git a/src/wx/time_picker.cc b/src/wx/time_picker.cc index 309e5c713..ee591023b 100644 --- a/src/wx/time_picker.cc +++ b/src/wx/time_picker.cc @@ -36,82 +36,45 @@ using dcp::locale_convert; TimePicker::TimePicker (wxWindow* parent, wxDateTime time) : wxPanel (parent) - , _block_update (false) { wxClientDC dc (parent); - wxSize size = dc.GetTextExtent (wxT ("9999")); + wxSize size = dc.GetTextExtent (wxT ("9999999")); size.SetHeight (-1); wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); - _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); - _hours->SetMaxLength (2); - sizer->Add (_hours, 0); - _hours_spin = new wxSpinButton (this, wxID_ANY); - sizer->Add (_hours_spin, 0, wxLEFT | wxRIGHT, 2); + _hours = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); + sizer->Add (_hours, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_GAP); sizer->Add (new wxStaticText (this, wxID_ANY, wxT (":")), 0, wxALIGN_CENTER_VERTICAL); - _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); - _minutes->SetMaxLength (2); - sizer->Add (_minutes, 0); - _minutes_spin = new wxSpinButton (this, wxID_ANY); - sizer->Add (_minutes_spin, 0, wxLEFT | wxRIGHT, 2); + _minutes = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); + sizer->Add (_minutes, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP); SetSizerAndFit (sizer); _minutes->MoveAfterInTabOrder (_hours); - _hours_spin->SetValue (time.GetHour ()); - _hours_spin->SetRange (0, 23); - _minutes_spin->SetValue (time.GetMinute ()); - _minutes_spin->SetRange (0, 59); + _hours->SetValue (time.GetHour ()); + _hours->SetRange (0, 23); + _minutes->SetValue (time.GetMinute ()); + _minutes->SetRange (0, 59); - update_text (); - - _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this))); - _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this))); - _hours_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this)); - _minutes_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this)); -} - -void -TimePicker::update_text () -{ - if (_block_update) { - return; - } - - _block_update = true; - - _hours->SetValue (wxString::Format ("%d", _hours_spin->GetValue ())); - _minutes->SetValue (wxString::Format ("%02d", _minutes_spin->GetValue ())); - - _block_update = false; - - Changed (); + _hours->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, (bind (&TimePicker::spin_changed, this))); + _minutes->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, (bind (&TimePicker::spin_changed, this))); } void -TimePicker::update_spin () +TimePicker::spin_changed () { - if (_block_update) { - return; - } - - _block_update = true; - _hours_spin->SetValue (locale_convert (wx_to_std (_hours->GetValue()))); - _minutes_spin->SetValue (locale_convert (wx_to_std (_minutes->GetValue()))); - _block_update = false; - Changed (); } int TimePicker::hours () const { - return _hours_spin->GetValue(); + return _hours->GetValue(); } int TimePicker::minutes () const { - return _minutes_spin->GetValue(); + return _minutes->GetValue(); }