2 Copyright (C) 2016 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/>.
21 #include "time_picker.h"
23 #include <dcp/locale_convert.h>
24 #include <wx/spinctrl.h>
25 #include <boost/bind.hpp>
35 using dcp::locale_convert;
37 TimePicker::TimePicker (wxWindow* parent, wxDateTime time)
39 , _block_update (false)
41 wxClientDC dc (parent);
42 wxSize size = dc.GetTextExtent (wxT ("9999"));
45 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
46 _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
47 _hours->SetMaxLength (2);
48 sizer->Add (_hours, 0);
49 _hours_spin = new wxSpinButton (this, wxID_ANY);
50 sizer->Add (_hours_spin, 0, wxLEFT | wxRIGHT, 2);
51 sizer->Add (new wxStaticText (this, wxID_ANY, wxT (":")), 0, wxALIGN_CENTER_VERTICAL);
52 _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
53 _minutes->SetMaxLength (2);
54 sizer->Add (_minutes, 0);
55 _minutes_spin = new wxSpinButton (this, wxID_ANY);
56 sizer->Add (_minutes_spin, 0, wxLEFT | wxRIGHT, 2);
58 SetSizerAndFit (sizer);
60 _minutes->MoveAfterInTabOrder (_hours);
62 _hours_spin->SetValue (time.GetHour ());
63 _hours_spin->SetRange (0, 23);
64 _minutes_spin->SetValue (time.GetMinute ());
65 _minutes_spin->SetRange (0, 59);
69 _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
70 _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
71 _hours_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
72 _minutes_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
76 TimePicker::update_text ()
84 _hours->SetValue (wxString::Format ("%d", _hours_spin->GetValue ()));
85 _minutes->SetValue (wxString::Format ("%02d", _minutes_spin->GetValue ()));
87 _block_update = false;
93 TimePicker::update_spin ()
100 _hours_spin->SetValue (locale_convert<int> (wx_to_std (_hours->GetValue())));
101 _minutes_spin->SetValue (locale_convert<int> (wx_to_std (_minutes->GetValue())));
102 _block_update = false;
108 TimePicker::hours () const
110 return _hours_spin->GetValue();
114 TimePicker::minutes () const
116 return _minutes_spin->GetValue();