2 Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
23 #include "dcpomatic_button.h"
30 TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button)
34 auto const s = TimecodeBase::size (parent);
36 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
39 wxString n (wxT ("0123456789"));
40 for (size_t i = 0; i < n.Length(); ++i) {
44 validator.SetIncludes (list);
46 _sizer = new wxBoxSizer (wxHORIZONTAL);
48 _editable = new wxPanel (this);
49 auto editable_sizer = new wxBoxSizer (wxHORIZONTAL);
50 _hours = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
51 _hours->SetMaxLength (2);
52 editable_sizer->Add (_hours);
53 add_label_to_sizer (editable_sizer, _editable, wxT(":"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
54 _minutes = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
55 _minutes->SetMaxLength (2);
56 editable_sizer->Add (_minutes);
57 add_label_to_sizer (editable_sizer, _editable, wxT (":"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
58 _seconds = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
59 _seconds->SetMaxLength (2);
60 editable_sizer->Add (_seconds);
61 add_label_to_sizer (editable_sizer, _editable, wxT (":"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
62 _frames = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
63 _frames->SetMaxLength (2);
64 editable_sizer->Add (_frames);
67 _set_button = new Button (_editable, _("Set"), wxDefaultPosition, small_button_size(parent, _("Set")));
68 editable_sizer->Add (_set_button, 0, wxLEFT | wxRIGHT, 8);
70 _editable->SetSizerAndFit (editable_sizer);
71 _sizer->Add (_editable);
73 _fixed = add_label_to_sizer (_sizer, this, wxT ("42"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
75 _hours->Bind (wxEVT_TEXT, boost::bind (&TimecodeBase::changed, this));
76 _minutes->Bind (wxEVT_TEXT, boost::bind (&TimecodeBase::changed, this));
77 _seconds->Bind (wxEVT_TEXT, boost::bind (&TimecodeBase::changed, this));
78 _frames->Bind (wxEVT_TEXT, boost::bind (&TimecodeBase::changed, this));
80 _set_button->Bind (wxEVT_BUTTON, boost::bind (&TimecodeBase::set_clicked, this));
81 _set_button->Enable (false);
86 SetSizerAndFit (_sizer);
90 TimecodeBase::set_focus ()
96 TimecodeBase::clear ()
98 checked_set (_hours, wxT (""));
99 checked_set (_minutes, wxT (""));
100 checked_set (_seconds, wxT (""));
101 checked_set (_frames, wxT (""));
102 checked_set (_fixed, wxT (""));
106 TimecodeBase::changed ()
109 _set_button->Enable (true);
114 TimecodeBase::set_clicked ()
118 _set_button->Enable (false);
123 TimecodeBase::set_editable (bool e)
131 TimecodeBase::size (wxWindow* parent)
133 wxClientDC dc (parent);
135 auto size = dc.GetTextExtent(wxT("999"));
137 auto size = dc.GetTextExtent(wxT("99999"));