Store controls and use the vector to tidy some things up.
authorCarl Hetherington <cth@carlh.net>
Wed, 15 Jan 2025 20:57:05 +0000 (21:57 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 Jan 2025 20:57:05 +0000 (21:57 +0100)
src/wx/timecode.cc
src/wx/timecode.h

index 42491c48e25b9202a28f41970912193b72c2a3b5..8560939190fbdb7818801704269e9afc2c1e8087 100644 (file)
@@ -46,27 +46,21 @@ TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button)
 
        _sizer = new wxBoxSizer (wxHORIZONTAL);
 
-       std::vector<wxTextCtrl*> controls;
-
        _editable = new wxPanel (this);
        auto editable_sizer = new wxBoxSizer (wxHORIZONTAL);
-       _hours = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator);
-       controls.push_back(_hours);
-       _minutes = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator);
-       controls.push_back(_minutes);
-       _seconds = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator);
-       controls.push_back(_seconds);
-       _frames = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator);
-       controls.push_back(_frames);
+       _controls.push_back(_hours = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator));
+       _controls.push_back(_minutes = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator));
+       _controls.push_back(_seconds = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator));
+       _controls.push_back(_frames = new wxTextCtrl(_editable, wxID_ANY, {}, wxDefaultPosition, s, 0, validator));
 
        if (parent->GetLayoutDirection() == wxLayout_RightToLeft) {
-               std::reverse(controls.begin(), controls.end());
+               std::reverse(_controls.begin(), _controls.end());
        }
 
-       for (auto i = controls.begin(); i != controls.end(); ++i) {
+       for (auto i = _controls.begin(); i != _controls.end(); ++i) {
                (*i)->SetMaxLength(2);
                editable_sizer->Add(*i);
-               if (std::next(i) != controls.end()) {
+               if (std::next(i) != _controls.end()) {
                        add_label_to_sizer(editable_sizer, _editable, char_to_wx(":"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
                }
        }
@@ -80,10 +74,9 @@ 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);
 
-       _hours->Bind      (wxEVT_TEXT,   boost::bind (&TimecodeBase::changed, this));
-       _minutes->Bind    (wxEVT_TEXT,   boost::bind (&TimecodeBase::changed, this));
-       _seconds->Bind    (wxEVT_TEXT,   boost::bind (&TimecodeBase::changed, this));
-       _frames->Bind     (wxEVT_TEXT,   boost::bind (&TimecodeBase::changed, this));
+       for (auto control: _controls) {
+               control->Bind(wxEVT_TEXT, boost::bind(&TimecodeBase::changed, this));
+       }
        if (_set_button) {
                _set_button->Bind (wxEVT_BUTTON, boost::bind (&TimecodeBase::set_clicked, this));
                _set_button->Enable (false);
@@ -103,10 +96,9 @@ TimecodeBase::set_focus ()
 void
 TimecodeBase::clear ()
 {
-       checked_set(_hours, wxString{});
-       checked_set(_minutes, wxString{});
-       checked_set(_seconds, wxString{});
-       checked_set(_frames, wxString{});
+       for (auto control: _controls) {
+               checked_set(control, wxString{});
+       }
        checked_set(_fixed, wxString{});
 }
 
@@ -127,17 +119,10 @@ TimecodeBase::set_clicked ()
        }
 
        _ignore_changed = true;
-       if (_hours->GetValue().IsEmpty()) {
-               _hours->SetValue(char_to_wx("0"));
-       }
-       if (_minutes->GetValue().IsEmpty()) {
-               _minutes->SetValue(char_to_wx("0"));
-       }
-       if (_seconds->GetValue().IsEmpty()) {
-               _seconds->SetValue(char_to_wx("0"));
-       }
-       if (_frames->GetValue().IsEmpty()) {
-               _frames->SetValue(char_to_wx("0"));
+       for (auto control: _controls) {
+               if (control->GetValue().IsEmpty()) {
+                       control->SetValue(char_to_wx("0"));
+               }
        }
        _ignore_changed = false;
 }
index 1116e9d87f45f0d9e9356b672c958c42ff1d745a..64d2e311bf0fa22216284fa3a83cf62ced4c346f 100644 (file)
@@ -62,6 +62,8 @@ protected:
        wxButton* _set_button;
        wxStaticText* _fixed;
 
+       std::vector<wxTextCtrl*> _controls;
+
        bool _ignore_changed = false;
 };