/*
- Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2016-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
+
+#include "static_text.h"
#include "time_picker.h"
#include "wx_util.h"
-#include <dcp/raw_convert.h>
+#include <dcp/locale_convert.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
#include <wx/spinctrl.h>
-#include <boost/bind.hpp>
+LIBDCP_ENABLE_WARNINGS
+#include <boost/bind/bind.hpp>
#include <iomanip>
+
+using std::cout;
+using std::max;
+using std::min;
using std::setfill;
using std::setw;
-using std::min;
-using std::max;
using std::string;
-using std::cout;
using boost::bind;
-using dcp::raw_convert;
+using dcp::locale_convert;
+
-TimePicker::TimePicker (wxWindow* parent, wxDateTime time)
+TimePicker::TimePicker (wxWindow* parent)
: wxPanel (parent)
- , _block_update (false)
+{
+
+}
+
+
+TimePickerSpin::TimePickerSpin (wxWindow* parent, wxDateTime time)
+ : TimePicker (parent)
{
wxClientDC dc (parent);
- wxSize size = dc.GetTextExtent (wxT ("9999"));
+ wxSize size = dc.GetTextExtent (wxT ("9999999"));
size.SetHeight (-1);
wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
- _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
- _hours->SetMaxLength (2);
- sizer->Add (_hours, 0);
- _hours_spin = new wxSpinButton (this, wxID_ANY);
- sizer->Add (_hours_spin, 0, wxLEFT | wxRIGHT, 2);
- sizer->Add (new wxStaticText (this, wxID_ANY, wxT (":")), 0, wxALIGN_CENTER_VERTICAL);
- _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
- _minutes->SetMaxLength (2);
- sizer->Add (_minutes, 0);
- _minutes_spin = new wxSpinButton (this, wxID_ANY);
- sizer->Add (_minutes_spin, 0, wxLEFT | wxRIGHT, 2);
+ _hours = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
+ sizer->Add (_hours, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
+ sizer->Add (new StaticText(this, wxT(":")), 0, wxALIGN_CENTER_VERTICAL);
+ _minutes = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
+ sizer->Add (_minutes, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
SetSizerAndFit (sizer);
_minutes->MoveAfterInTabOrder (_hours);
- _hours_spin->SetValue (time.GetHour ());
- _hours_spin->SetRange (0, 23);
- _minutes_spin->SetValue (time.GetMinute ());
- _minutes_spin->SetRange (0, 59);
-
- update_text ();
+ _hours->SetValue (time.GetHour ());
+ _hours->SetRange (0, 23);
+ _minutes->SetValue (time.GetMinute ());
+ _minutes->SetRange (0, 59);
- _hours->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
- _minutes->Bind (wxEVT_COMMAND_TEXT_UPDATED, (bind (&TimePicker::update_spin, this)));
- _hours_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
- _minutes_spin->Bind (wxEVT_SPIN, bind (&TimePicker::update_text, this));
+ _hours->Bind (wxEVT_SPINCTRL, (bind (&TimePickerSpin::changed, this)));
+ _minutes->Bind (wxEVT_SPINCTRL, (bind (&TimePickerSpin::changed, this)));
}
+
void
-TimePicker::update_text ()
+TimePickerSpin::changed ()
{
- if (_block_update) {
- return;
- }
+ Changed ();
+}
- _block_update = true;
- _hours->SetValue (wxString::Format ("%d", _hours_spin->GetValue ()));
- _minutes->SetValue (wxString::Format ("%02d", _minutes_spin->GetValue ()));
+int
+TimePickerSpin::hours () const
+{
+ return _hours->GetValue();
+}
- _block_update = false;
- Changed ();
+int
+TimePickerSpin::minutes () const
+{
+ return _minutes->GetValue();
}
-void
-TimePicker::update_spin ()
+
+TimePickerText::TimePickerText (wxWindow* parent, wxDateTime time)
+ : TimePicker (parent)
{
- if (_block_update) {
- return;
- }
+ wxClientDC dc (parent);
+ wxSize size = dc.GetTextExtent (wxT("99999"));
+ size.SetHeight (-1);
+
+ wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+ _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
+ sizer->Add (_hours, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_GAP);
+ sizer->Add (new StaticText (this, wxT (":")), 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 4);
+ _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
+ sizer->Add (_minutes, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
+
+ SetSizerAndFit (sizer);
+
+ _minutes->MoveAfterInTabOrder (_hours);
+
+ _hours->SetValue (wxString::Format("%d", time.GetHour()));
+ _minutes->SetValue (wxString::Format("%d", time.GetMinute()));
+
+ _hours->Bind (wxEVT_TEXT, (bind(&TimePickerText::changed, this)));
+ _minutes->Bind (wxEVT_TEXT, (bind(&TimePickerText::changed, this)));
+}
- _block_update = true;
- _hours_spin->SetValue (raw_convert<int> (wx_to_std (_hours->GetValue())));
- _minutes_spin->SetValue (raw_convert<int> (wx_to_std (_minutes->GetValue())));
- _block_update = false;
+void
+TimePickerText::changed ()
+{
Changed ();
}
+
int
-TimePicker::hours () const
+TimePickerText::hours () const
{
- return _hours_spin->GetValue();
+ return max(0, min(23, wxAtoi(_hours->GetValue())));
}
+
int
-TimePicker::minutes () const
+TimePickerText::minutes () const
{
- return _minutes_spin->GetValue();
+ return max(0, min(59, wxAtoi(_minutes->GetValue())));
}
+
+
+