Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / wx / time_picker.cc
1 /*
2     Copyright (C) 2016-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "time_picker.h"
22 #include "wx_util.h"
23 #include "static_text.h"
24 #include <dcp/locale_convert.h>
25 #include <wx/spinctrl.h>
26 #include <boost/bind.hpp>
27 #include <iomanip>
28
29 using std::setfill;
30 using std::setw;
31 using std::min;
32 using std::max;
33 using std::string;
34 using std::cout;
35 using boost::bind;
36 using dcp::locale_convert;
37
38 TimePicker::TimePicker (wxWindow* parent, wxDateTime time)
39         : wxPanel (parent)
40 {
41         wxClientDC dc (parent);
42         wxSize size = dc.GetTextExtent (wxT ("9999999"));
43         size.SetHeight (-1);
44
45         wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
46         _hours = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
47         sizer->Add (_hours, 1, wxEXPAND | wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
48         sizer->Add (new StaticText (this, wxT (":")), 0, wxALIGN_CENTER_VERTICAL);
49         _minutes = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
50         sizer->Add (_minutes, 1, wxEXPAND | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
51
52         SetSizerAndFit (sizer);
53
54         _minutes->MoveAfterInTabOrder (_hours);
55
56         _hours->SetValue (time.GetHour ());
57         _hours->SetRange (0, 23);
58         _minutes->SetValue (time.GetMinute ());
59         _minutes->SetRange (0, 59);
60
61         _hours->Bind (wxEVT_SPINCTRL, (bind (&TimePicker::spin_changed, this)));
62         _minutes->Bind (wxEVT_SPINCTRL, (bind (&TimePicker::spin_changed, this)));
63 }
64
65 void
66 TimePicker::spin_changed ()
67 {
68         Changed ();
69 }
70
71 int
72 TimePicker::hours () const
73 {
74         return _hours->GetValue();
75 }
76
77 int
78 TimePicker::minutes () const
79 {
80         return _minutes->GetValue();
81 }