Add validity check to Timecode.
authorCarl Hetherington <cth@carlh.net>
Wed, 20 Dec 2023 22:41:49 +0000 (23:41 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 12 Mar 2024 22:41:00 +0000 (23:41 +0100)
src/wx/timecode.cc
src/wx/timecode.h

index 1e6a1930d95f6c358015eb643ffa37b471a6d7c8..64fe8719038a62e5415c017572fa0c0e9644c4d6 100644 (file)
@@ -114,7 +114,7 @@ void
 TimecodeBase::changed ()
 {
        if (_set_button && !_ignore_changed) {
-               _set_button->Enable (true);
+               _set_button->Enable(valid());
        }
 }
 
index 6c5d8ae231cd0d6679e1b56cd2e98b0da34b89d6..22899ddc9ba49bd07f40f8d1acb12229b7d47ea1 100644 (file)
@@ -50,6 +50,7 @@ public:
 protected:
        void changed ();
        void set_clicked ();
+       virtual bool valid() const = 0;
 
        wxSizer* _sizer;
        wxPanel* _editable;
@@ -96,6 +97,11 @@ public:
                _frames->SetHint (std_to_wx(dcp::raw_convert<std::string>(hmsf.f)));
        }
 
+       void set_maximum(dcpomatic::HMSF maximum)
+       {
+               _maximum = std::move(maximum);
+       }
+
        dcpomatic::HMSF get () const
        {
                auto value_or_hint = [](wxTextCtrl const * t) {
@@ -116,6 +122,13 @@ public:
        {
                return T(get(), fps);
        }
+
+private:
+       bool valid() const override {
+               return !_maximum || get() <= *_maximum;
+       }
+
+       boost::optional<dcpomatic::HMSF> _maximum;
 };
 
 #endif