Lots of #include <iostream>s for Arch.
[dcpomatic.git] / src / wx / timecode.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "lib/util.h"
21 #include "timecode.h"
22 #include "wx_util.h"
23 #include <boost/lexical_cast.hpp>
24 #include <iostream>
25
26 using std::string;
27 using std::cout;
28 using boost::lexical_cast;
29
30 TimecodeBase::TimecodeBase (wxWindow* parent)
31         : wxPanel (parent)
32 {
33         wxSize const s = TimecodeBase::size (parent);
34
35         wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
36         wxArrayString list;
37
38         wxString n (wxT ("0123456789"));
39         for (size_t i = 0; i < n.Length(); ++i) {
40                 list.Add (n[i]);
41         }
42
43         validator.SetIncludes (list);
44
45         _sizer = new wxBoxSizer (wxHORIZONTAL);
46
47         _editable = new wxPanel (this);
48         wxSizer* editable_sizer = new wxBoxSizer (wxHORIZONTAL);
49         _hours = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
50         _hours->SetMaxLength (2);
51         editable_sizer->Add (_hours);
52         add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
53         _minutes = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
54         _minutes->SetMaxLength (2);
55         editable_sizer->Add (_minutes);
56         add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
57         _seconds = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
58         _seconds->SetMaxLength (2);
59         editable_sizer->Add (_seconds);
60         add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
61         _frames = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
62         _frames->SetMaxLength (2);
63         editable_sizer->Add (_frames);
64         _set_button = new wxButton (_editable, wxID_ANY, _("Set"));
65         editable_sizer->Add (_set_button, 0, wxLEFT | wxRIGHT, 8);
66         _editable->SetSizerAndFit (editable_sizer);
67         _sizer->Add (_editable);
68
69         _fixed = add_label_to_sizer (_sizer, this, wxT ("42"), false);
70
71         _hours->Bind      (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
72         _minutes->Bind    (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
73         _seconds->Bind    (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
74         _frames->Bind     (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
75         _set_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimecodeBase::set_clicked, this));
76
77         _set_button->Enable (false);
78
79         set_editable (true);
80
81         SetSizerAndFit (_sizer);
82 }
83
84 void
85 TimecodeBase::clear ()
86 {
87         checked_set (_hours, wxT (""));
88         checked_set (_minutes, wxT (""));
89         checked_set (_seconds, wxT (""));
90         checked_set (_frames, wxT (""));
91         checked_set (_fixed, wxT (""));
92 }
93
94 void
95 TimecodeBase::changed ()
96 {
97         _set_button->Enable (true);
98 }
99
100 void
101 TimecodeBase::set_clicked ()
102 {
103         Changed ();
104         _set_button->Enable (false);
105 }
106
107 void
108 TimecodeBase::set_editable (bool e)
109 {
110         _editable->Show (e);
111         _fixed->Show (!e);
112         _sizer->Layout ();
113 }
114
115 wxSize
116 TimecodeBase::size (wxWindow* parent)
117 {
118         wxClientDC dc (parent);
119         wxSize size = dc.GetTextExtent (wxT ("9999"));
120         size.SetHeight (-1);
121         return size;
122 }
123
124