Move onto next timecode control after typing two characters.
authorCarl Hetherington <cth@carlh.net>
Wed, 15 Jan 2025 20:58:07 +0000 (21:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 Jan 2025 20:58:07 +0000 (21:58 +0100)
src/wx/timecode.cc
src/wx/timecode.h

index 8560939190fbdb7818801704269e9afc2c1e8087..63c119a18c6625345aa0e81b1559495adda3ac0f 100644 (file)
@@ -26,6 +26,9 @@
 
 
 using std::string;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
 
 
 TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button)
@@ -75,7 +78,7 @@ TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button)
        _fixed = add_label_to_sizer(_sizer, this, char_to_wx("42"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
 
        for (auto control: _controls) {
-               control->Bind(wxEVT_TEXT, boost::bind(&TimecodeBase::changed, this));
+               control->Bind(wxEVT_TEXT, boost::bind(&TimecodeBase::changed, this, _1));
        }
        if (_set_button) {
                _set_button->Bind (wxEVT_BUTTON, boost::bind (&TimecodeBase::set_clicked, this));
@@ -103,11 +106,25 @@ TimecodeBase::clear ()
 }
 
 void
-TimecodeBase::changed ()
+TimecodeBase::changed(wxCommandEvent& ev)
 {
-       if (_set_button && !_ignore_changed) {
+       if (_ignore_changed) {
+               return;
+       }
+
+       if (_set_button) {
                _set_button->Enable(valid());
        }
+
+       auto iter = std::find(_controls.begin(), _controls.end(), ev.GetEventObject());
+       DCPOMATIC_ASSERT(iter != _controls.end());
+
+       if ((*iter)->GetValue().Length() == 2) {
+               auto next = std::next(iter);
+               if (next != _controls.end()) {
+                       (*next)->SetFocus();
+               }
+       }
 }
 
 void
index 64d2e311bf0fa22216284fa3a83cf62ced4c346f..ed78f942833388d1032ed5bdbc11b20f39e6d076 100644 (file)
@@ -49,7 +49,7 @@ public:
        static wxSize size (wxWindow* parent);
 
 protected:
-       void changed ();
+       void changed(wxCommandEvent& ev);
        void set_clicked ();
        virtual bool valid() const = 0;