C++11 tidying.
[dcpomatic.git] / src / wx / language_tag_widget.cc
1 /*
2     Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "dcpomatic_button.h"
23 #include "language_tag_dialog.h"
24 #include "language_tag_widget.h"
25 #include "wx_util.h"
26 #include <wx/wx.h>
27
28
29 using boost::optional;
30
31
32 LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxString tooltip, optional<dcp::LanguageTag> tag, optional<wxString> size_to_fit)
33         : _parent (parent)
34         , _sizer (new wxBoxSizer(wxHORIZONTAL))
35 {
36         _language = new wxStaticText (parent, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
37         _language->SetToolTip (tooltip);
38         set (tag);
39
40         if (size_to_fit) {
41                 int w;
42                 int h;
43                 _language->GetTextExtent (*size_to_fit, &w, &h);
44                 _language->SetMinSize (wxSize(w, -1));
45         }
46
47         _sizer->Add (_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
48         _edit = new Button (parent, _("Edit..."));
49         _sizer->Add (_edit, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
50
51         _edit->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagWidget::edit, this));
52 }
53
54
55 LanguageTagWidget::~LanguageTagWidget ()
56 {
57         _language->Destroy ();
58         _edit->Destroy ();
59 }
60
61
62 void
63 LanguageTagWidget::edit ()
64 {
65         auto d = new LanguageTagDialog(_parent, _tag.get_value_or(dcp::LanguageTag("en")));
66         d->ShowModal ();
67         set (d->get());
68         Changed (d->get());
69         d->Destroy ();
70 }
71
72
73 void
74 LanguageTagWidget::set (optional<dcp::LanguageTag> tag)
75 {
76         _tag = tag;
77         if (tag) {
78                 checked_set (_language, std_to_wx(tag->to_string()));
79         } else {
80                 checked_set (_language, wxT(""));
81         }
82 }
83
84
85 void
86 LanguageTagWidget::enable (bool e)
87 {
88         _language->Enable (e);
89         _edit->Enable (e);
90 }