From: Carl Hetherington Date: Mon, 8 Jun 2020 23:18:03 +0000 (+0200) Subject: Assorted GTK3 layout tidying in KDM dialogs. X-Git-Tag: v2.15.78~8 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=22ee15e4c6fb91414997adf1a010b563e5dad6e3 Assorted GTK3 layout tidying in KDM dialogs. --- diff --git a/src/wx/kdm_timing_panel.cc b/src/wx/kdm_timing_panel.cc index e0e5ac44f..51a99627c 100644 --- a/src/wx/kdm_timing_panel.cc +++ b/src/wx/kdm_timing_panel.cc @@ -33,13 +33,29 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent) { wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); +#ifdef __WXGTK3__ + /* wxDatePickerCtrl is too small with the GTK3 backend so we need to make it bigger with some fudge factors */ + wxClientDC dc (parent); + wxSize size = dc.GetTextExtent (wxT("99/99/9999")); + size.SetWidth (size.GetWidth() * 1.75); + size.SetHeight (-1); +#else + wxSize size = wxDefaultSize; +#endif + wxSizer* table = new wxBoxSizer (wxHORIZONTAL); add_label_to_sizer (table, this, _("From"), true); wxDateTime from; from.SetToCurrent (); - _from_date = new wxDatePickerCtrl (this, wxID_ANY, from); + _from_date = new wxDatePickerCtrl (this, wxID_ANY, from, wxDefaultPosition, size); table->Add (_from_date, 0, wxALIGN_CENTER_VERTICAL); - _from_time = new TimePicker (this, from); + +#ifdef __WXGTK3__ + _from_time = new TimePickerText (this, from); +#else + _from_time = new TimePickerSpin (this, from); +#endif + #ifdef DCPOMATIC_OSX /* Hack to tweak alignment, which I can't get right by "proper" means for some reason */ table->Add (_from_time, 0, wxALIGN_CENTER_VERTICAL | wxTOP, 4); @@ -51,9 +67,15 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent) wxDateTime to = from; /* 1 week from now */ to.Add (wxDateSpan (0, 0, 1, 0)); - _until_date = new wxDatePickerCtrl (this, wxID_ANY, to); + _until_date = new wxDatePickerCtrl (this, wxID_ANY, to, wxDefaultPosition, size); table->Add (_until_date, 0, wxALIGN_CENTER_VERTICAL); - _until_time = new TimePicker (this, to); + +#ifdef __WXGTK3__ + _until_time = new TimePickerText (this, to); +#else + _until_time = new TimePickerSpin (this, to); +#endif + #ifdef DCPOMATIC_OSX table->Add (_until_time, 0, wxALIGN_CENTER_VERTICAL | wxTOP, 4); #else diff --git a/src/wx/recipients_panel.cc b/src/wx/recipients_panel.cc index e4559742f..8bb78750e 100644 --- a/src/wx/recipients_panel.cc +++ b/src/wx/recipients_panel.cc @@ -43,8 +43,17 @@ RecipientsPanel::RecipientsPanel (wxWindow* parent) { wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL); - _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (200, -1)); +#ifdef __WXGTK3__ + int const height = 30; +#else + int const height = -1; +#endif + + _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (200, height)); +#ifndef __WXGTK3__ + /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */ _search->ShowCancelButton (true); +#endif sizer->Add (_search, 0, wxBOTTOM, DCPOMATIC_SIZER_GAP); wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL); diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index 8db7a1035..5541d46d4 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -44,8 +44,17 @@ ScreensPanel::ScreensPanel (wxWindow* parent) { wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL); - _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (200, -1)); +#ifdef __WXGTK3__ + int const height = 30; +#else + int const height = -1; +#endif + + _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, height)); +#ifndef __WXGTK3__ + /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */ _search->ShowCancelButton (true); +#endif sizer->Add (_search, 0, wxBOTTOM, DCPOMATIC_SIZER_GAP); wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL); diff --git a/src/wx/time_picker.cc b/src/wx/time_picker.cc index 295bbd52d..dc57d8b2e 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. @@ -35,9 +35,17 @@ 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); @@ -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 | wxALIGN_CENTER_VERTICAL, 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 | wxALIGN_CENTER_VERTICAL, 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()))); +} + + + diff --git a/src/wx/time_picker.h b/src/wx/time_picker.h index 53e31a06a..9e83c0043 100644 --- a/src/wx/time_picker.h +++ b/src/wx/time_picker.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2020 Carl Hetherington This file is part of DCP-o-matic. @@ -23,19 +23,46 @@ class wxSpinCtrl; + class TimePicker : public wxPanel { public: - TimePicker (wxWindow* parent, wxDateTime time); + TimePicker (wxWindow* parent); - int hours () const; - int minutes () const; + virtual int hours () const = 0; + virtual int minutes () const = 0; boost::signals2::signal Changed; +}; + + +class TimePickerSpin : public TimePicker +{ +public: + TimePickerSpin (wxWindow* parent, wxDateTime time); + + int hours () const; + int minutes () const; private: - void spin_changed (); + void changed (); wxSpinCtrl* _hours; wxSpinCtrl* _minutes; }; + + +class TimePickerText : public TimePicker +{ +public: + TimePickerText (wxWindow* parent, wxDateTime time); + + int hours () const; + int minutes () const; + +private: + void changed (); + + wxTextCtrl* _hours; + wxTextCtrl* _minutes; +};