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"
22 #include "lib/raw_convert.h"
23 #include <wx/spinctrl.h>
24 #include <boost/bind.hpp>
35 TimePicker::TimePicker (wxWindow* parent, wxDateTime time)
37 , _block_update (false)
39 wxClientDC dc (parent);
40 wxSize size = dc.GetTextExtent (wxT ("9999"));
43 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
44 _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
45 _hours->SetMaxLength (2);
46 sizer->Add (_hours, 0);
47 _hours_spin = new wxSpinButton (this, wxID_ANY);
48 sizer->Add (_hours_spin, 0, wxLEFT | wxRIGHT, 2);
49 sizer->Add (new wxStaticText (this, wxID_ANY, wxT (":")), 0, wxALIGN_CENTER_VERTICAL);
50 _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
51 _minutes->SetMaxLength (2);
52 sizer->Add (_minutes, 0);
53 _minutes_spin = new wxSpinButton (this, wxID_ANY);
54 sizer->Add (_minutes_spin, 0, wxLEFT | wxRIGHT, 2);
56 SetSizerAndFit (sizer);
58 _minutes->MoveAfterInTabOrder (_hours);
60 _hours_spin->SetValue (time.GetHour ());
61 _hours_spin->SetRange (0, 23);
62 _minutes_spin->SetValue (time.GetMinute ());
63 _minutes_spin->SetRange (0, 59);
67 _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
68 _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
69 _hours_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
70 _minutes_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
74 TimePicker::update_text ()
82 _hours->SetValue (wxString (raw_convert<string> (_hours_spin->GetValue ())));
85 m << setfill('0') << setw(2) << _minutes_spin->GetValue();
86 _minutes->SetValue (wxString (m.str()));
88 _block_update = false;
94 TimePicker::update_spin ()
100 _block_update = true;
101 _hours_spin->SetValue (raw_convert<int> (_hours->GetValue().ToStdString()));
102 _minutes_spin->SetValue (raw_convert<int> (_minutes->GetValue().ToStdString()));
103 _block_update = false;
109 TimePicker::hours () const
111 return _hours_spin->GetValue();
115 TimePicker::minutes () const
117 return _minutes_spin->GetValue();