Don't use --target-macos-arm64 any more, since it's not supported.
[dcpomatic.git] / src / wx / time_picker.cc
1 /*
2     Copyright (C) 2016-2020 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
22 #include "static_text.h"
23 #include "time_picker.h"
24 #include "wx_util.h"
25 #include <dcp/locale_convert.h>
26 #include <dcp/warnings.h>
27 LIBDCP_DISABLE_WARNINGS
28 #include <wx/spinctrl.h>
29 LIBDCP_ENABLE_WARNINGS
30 #include <boost/bind/bind.hpp>
31 #include <iomanip>
32
33
34 using std::cout;
35 using std::max;
36 using std::min;
37 using std::setfill;
38 using std::setw;
39 using std::string;
40 using boost::bind;
41 using dcp::locale_convert;
42
43
44 TimePicker::TimePicker (wxWindow* parent)
45         : wxPanel (parent)
46 {
47
48 }
49
50
51 TimePickerSpin::TimePickerSpin (wxWindow* parent, wxDateTime time)
52         : TimePicker (parent)
53 {
54         wxClientDC dc (parent);
55         wxSize size = dc.GetTextExtent (wxT ("9999999"));
56         size.SetHeight (-1);
57
58         wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
59         _hours = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
60         sizer->Add (_hours, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
61         sizer->Add (new StaticText(this, wxT(":")), 0, wxALIGN_CENTER_VERTICAL);
62         _minutes = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
63         sizer->Add (_minutes, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
64
65         SetSizerAndFit (sizer);
66
67         _minutes->MoveAfterInTabOrder (_hours);
68
69         _hours->SetValue (time.GetHour ());
70         _hours->SetRange (0, 23);
71         _minutes->SetValue (time.GetMinute ());
72         _minutes->SetRange (0, 59);
73
74         _hours->Bind (wxEVT_SPINCTRL, (bind (&TimePickerSpin::changed, this)));
75         _minutes->Bind (wxEVT_SPINCTRL, (bind (&TimePickerSpin::changed, this)));
76 }
77
78
79 void
80 TimePickerSpin::changed ()
81 {
82         Changed ();
83 }
84
85
86 int
87 TimePickerSpin::hours () const
88 {
89         return _hours->GetValue();
90 }
91
92
93 int
94 TimePickerSpin::minutes () const
95 {
96         return _minutes->GetValue();
97 }
98
99
100 TimePickerText::TimePickerText (wxWindow* parent, wxDateTime time)
101         : TimePicker (parent)
102 {
103         wxClientDC dc (parent);
104         wxSize size = dc.GetTextExtent (wxT("99999"));
105         size.SetHeight (-1);
106
107         wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
108         _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
109         sizer->Add (_hours, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_GAP);
110         sizer->Add (new StaticText (this, wxT (":")), 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 4);
111         _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
112         sizer->Add (_minutes, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
113
114         SetSizerAndFit (sizer);
115
116         _minutes->MoveAfterInTabOrder (_hours);
117
118         _hours->SetValue (wxString::Format("%d", time.GetHour()));
119         _minutes->SetValue (wxString::Format("%d", time.GetMinute()));
120
121         _hours->Bind (wxEVT_TEXT, (bind(&TimePickerText::changed, this)));
122         _minutes->Bind (wxEVT_TEXT, (bind(&TimePickerText::changed, this)));
123 }
124
125
126 void
127 TimePickerText::changed ()
128 {
129         Changed ();
130 }
131
132
133 int
134 TimePickerText::hours () const
135 {
136         return max(0, min(23, wxAtoi(_hours->GetValue())));
137 }
138
139
140 int
141 TimePickerText::minutes () const
142 {
143         return max(0, min(59, wxAtoi(_minutes->GetValue())));
144 }
145
146
147