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 "lib/raw_convert.h"
24 #include <wx/spinctrl.h>
25 #include <boost/bind.hpp>
36 TimePicker::TimePicker (wxWindow* parent, wxDateTime time)
38 , _block_update (false)
40 wxClientDC dc (parent);
41 wxSize size = dc.GetTextExtent (wxT ("9999"));
44 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
45 _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
46 _hours->SetMaxLength (2);
47 sizer->Add (_hours, 0);
48 _hours_spin = new wxSpinButton (this, wxID_ANY);
49 sizer->Add (_hours_spin, 0, wxLEFT | wxRIGHT, 2);
50 sizer->Add (new wxStaticText (this, wxID_ANY, wxT (":")), 0, wxALIGN_CENTER_VERTICAL);
51 _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
52 _minutes->SetMaxLength (2);
53 sizer->Add (_minutes, 0);
54 _minutes_spin = new wxSpinButton (this, wxID_ANY);
55 sizer->Add (_minutes_spin, 0, wxLEFT | wxRIGHT, 2);
57 SetSizerAndFit (sizer);
59 _minutes->MoveAfterInTabOrder (_hours);
61 _hours_spin->SetValue (time.GetHour ());
62 _hours_spin->SetRange (0, 23);
63 _minutes_spin->SetValue (time.GetMinute ());
64 _minutes_spin->SetRange (0, 59);
68 _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
69 _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
70 _hours_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
71 _minutes_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
75 TimePicker::update_text ()
83 _hours->SetValue (std_to_wx (raw_convert<string> (_hours_spin->GetValue ())));
86 m << setfill('0') << setw(2) << _minutes_spin->GetValue();
87 _minutes->SetValue (std_to_wx (m.str()));
89 _block_update = false;
95 TimePicker::update_spin ()
101 _block_update = true;
102 _hours_spin->SetValue (raw_convert<int> (wx_to_std (_hours->GetValue())));
103 _minutes_spin->SetValue (raw_convert<int> (wx_to_std (_minutes->GetValue())));
104 _block_update = false;
110 TimePicker::hours () const
112 return _hours_spin->GetValue();
116 TimePicker::minutes () const
118 return _minutes_spin->GetValue();