2 Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <boost/lexical_cast.hpp>
27 using boost::lexical_cast;
29 TimecodeBase::TimecodeBase (wxWindow* parent)
32 wxSize const s = TimecodeBase::size (parent);
34 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
37 wxString n (wxT ("0123456789"));
38 for (size_t i = 0; i < n.Length(); ++i) {
42 validator.SetIncludes (list);
44 _sizer = new wxBoxSizer (wxHORIZONTAL);
46 _editable = new wxPanel (this);
47 wxSizer* editable_sizer = new wxBoxSizer (wxHORIZONTAL);
48 _hours = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
49 _hours->SetMaxLength (2);
50 editable_sizer->Add (_hours);
51 add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
52 _minutes = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
53 _minutes->SetMaxLength (2);
54 editable_sizer->Add (_minutes);
55 add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
56 _seconds = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
57 _seconds->SetMaxLength (2);
58 editable_sizer->Add (_seconds);
59 add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
60 _frames = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
61 _frames->SetMaxLength (2);
62 editable_sizer->Add (_frames);
63 _set_button = new wxButton (_editable, wxID_ANY, _("Set"));
64 editable_sizer->Add (_set_button, 0, wxLEFT | wxRIGHT, 8);
65 _editable->SetSizerAndFit (editable_sizer);
66 _sizer->Add (_editable);
68 _fixed = add_label_to_sizer (_sizer, this, wxT ("42"), false);
70 _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this));
71 _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this));
72 _seconds->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this));
73 _frames->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimecodeBase::changed, this));
74 _set_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimecodeBase::set_clicked, this));
76 _set_button->Enable (false);
80 SetSizerAndFit (_sizer);
84 TimecodeBase::clear ()
86 checked_set (_hours, wxT (""));
87 checked_set (_minutes, wxT (""));
88 checked_set (_seconds, wxT (""));
89 checked_set (_frames, wxT (""));
90 checked_set (_fixed, wxT (""));
94 TimecodeBase::changed ()
96 _set_button->Enable (true);
100 TimecodeBase::set_clicked ()
103 _set_button->Enable (false);
107 TimecodeBase::set_editable (bool e)
115 TimecodeBase::size (wxWindow* parent)
117 wxClientDC dc (parent);
118 wxSize size = dc.GetTextExtent (wxT ("9999"));