592741b4d4f589e92c99a75f943e69c1800e430a
[dcpomatic.git] / src / wx / language_tag_widget.cc
1 /*
2     Copyright (C) 2020 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 LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxSizer* sizer, wxString label, wxString tooltip, dcp::LanguageTag tag)
30         : _parent (parent)
31 {
32         add_label_to_sizer(sizer, parent, label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
33         wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
34         _language = new wxStaticText (parent, wxID_ANY, wxT(""));
35         _language->SetToolTip (tooltip);
36         set (tag);
37         s->Add (_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
38         _edit = new Button (parent, _("Edit..."));
39         s->Add (_edit, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
40         sizer->Add (s, 0, wxEXPAND);
41
42         _edit->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagWidget::edit, this));
43 }
44
45
46 void
47 LanguageTagWidget::edit ()
48 {
49         LanguageTagDialog* d = new LanguageTagDialog(_parent, _tag);
50         d->ShowModal ();
51         set (d->get());
52         Changed (d->get());
53         d->Destroy ();
54 }
55
56
57 void
58 LanguageTagWidget::set (dcp::LanguageTag tag)
59 {
60         _tag = tag;
61         checked_set (_language, std_to_wx(tag.to_string()));
62 }