X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftime_picker.cc;h=966671be9ac100f8c876707a4ad8b8ff038068b3;hb=56e0452ce0f436e7c54a49c68b272797f92a7ffe;hp=295bbd52d327c6a0c3db226c9756bf3c96733bc8;hpb=9c1bb2e5ca7c80c4e26b1b2e41159aa171360a94;p=dcpomatic.git diff --git a/src/wx/time_picker.cc b/src/wx/time_picker.cc index 295bbd52d..966671be9 100644 --- a/src/wx/time_picker.cc +++ b/src/wx/time_picker.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2018 Carl Hetherington + Copyright (C) 2016-2020 Carl Hetherington This file is part of DCP-o-matic. @@ -23,7 +23,7 @@ #include "static_text.h" #include #include -#include +#include #include using std::setfill; @@ -35,19 +35,27 @@ using std::cout; using boost::bind; using dcp::locale_convert; -TimePicker::TimePicker (wxWindow* parent, wxDateTime time) + +TimePicker::TimePicker (wxWindow* parent) : wxPanel (parent) { + +} + + +TimePickerSpin::TimePickerSpin (wxWindow* parent, wxDateTime time) + : TimePicker (parent) +{ wxClientDC dc (parent); wxSize size = dc.GetTextExtent (wxT ("9999999")); size.SetHeight (-1); wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); _hours = new wxSpinCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size); - sizer->Add (_hours, 1, wxEXPAND | wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP); - sizer->Add (new StaticText (this, wxT (":")), 0, wxALIGN_CENTER_VERTICAL); + 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, wxEXPAND | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP); + sizer->Add (_minutes, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP); SetSizerAndFit (sizer); @@ -58,24 +66,77 @@ TimePicker::TimePicker (wxWindow* parent, wxDateTime time) _minutes->SetValue (time.GetMinute ()); _minutes->SetRange (0, 59); - _hours->Bind (wxEVT_SPINCTRL, (bind (&TimePicker::spin_changed, this))); - _minutes->Bind (wxEVT_SPINCTRL, (bind (&TimePicker::spin_changed, this))); + _hours->Bind (wxEVT_SPINCTRL, (bind (&TimePickerSpin::changed, this))); + _minutes->Bind (wxEVT_SPINCTRL, (bind (&TimePickerSpin::changed, this))); } + void -TimePicker::spin_changed () +TimePickerSpin::changed () { Changed (); } + int -TimePicker::hours () const +TimePickerSpin::hours () const { return _hours->GetValue(); } + int -TimePicker::minutes () const +TimePickerSpin::minutes () const { return _minutes->GetValue(); } + + +TimePickerText::TimePickerText (wxWindow* parent, wxDateTime time) + : TimePicker (parent) +{ + 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))); +} + + +void +TimePickerText::changed () +{ + Changed (); +} + + +int +TimePickerText::hours () const +{ + return max(0, min(23, wxAtoi(_hours->GetValue()))); +} + + +int +TimePickerText::minutes () const +{ + return max(0, min(59, wxAtoi(_minutes->GetValue()))); +} + + +