2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "language_subtag_panel.h"
23 #include <dcp/warnings.h>
24 LIBDCP_DISABLE_WARNINGS
25 #include <wx/srchctrl.h>
27 LIBDCP_ENABLE_WARNINGS
31 using boost::optional;
34 LanguageSubtagPanel::LanguageSubtagPanel(wxWindow* parent)
35 : wxPanel (parent, wxID_ANY)
38 int const height = 30;
40 int const height = -1;
43 _search = new wxSearchCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, height));
44 _list = new SubtagListCtrl(this);
46 auto sizer = new wxBoxSizer(wxVERTICAL);
47 sizer->Add(_search, 0, wxALL, 8);
48 sizer->Add(_list, 1, wxALL, 8);
51 _search->Bind(wxEVT_TEXT, boost::bind(&LanguageSubtagPanel::search_changed, this));
52 _list->Bind(wxEVT_LIST_ITEM_SELECTED, boost::bind(&LanguageSubtagPanel::selection_changed, this));
53 _list->Bind(wxEVT_LIST_ITEM_DESELECTED, boost::bind(&LanguageSubtagPanel::selection_changed, this));
58 LanguageSubtagPanel::set(dcp::LanguageTag::SubtagType type, string search, optional<dcp::LanguageTag::SubtagData> subtag)
60 _list->set(type, search, subtag);
61 _search->SetValue(wxString(search));
65 optional<dcp::LanguageTag::RegionSubtag>
66 LanguageSubtagPanel::get() const
68 if (!_list->selected_subtag()) {
72 return dcp::LanguageTag::RegionSubtag(_list->selected_subtag()->subtag);
77 LanguageSubtagPanel::search_changed()
79 auto search = _search->GetValue();
80 _list->set_search(search.ToStdString());
81 if (search.Length() > 0 && _list->GetItemCount() > 0) {
82 _list->EnsureVisible (0);
84 SearchChanged(_search->GetValue().ToStdString());
89 LanguageSubtagPanel::selection_changed()
91 SelectionChanged(_list->selected_subtag());