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 <wx/srchctrl.h>
28 using boost::optional;
31 LanguageSubtagPanel::LanguageSubtagPanel(wxWindow* parent)
32 : wxPanel (parent, wxID_ANY)
35 int const height = 30;
37 int const height = -1;
40 _search = new wxSearchCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, height));
41 _list = new SubtagListCtrl(this);
43 auto sizer = new wxBoxSizer(wxVERTICAL);
44 sizer->Add(_search, 0, wxALL, 8);
45 sizer->Add(_list, 1, wxALL, 8);
48 _search->Bind(wxEVT_TEXT, boost::bind(&LanguageSubtagPanel::search_changed, this));
49 _list->Bind(wxEVT_LIST_ITEM_SELECTED, boost::bind(&LanguageSubtagPanel::selection_changed, this));
50 _list->Bind(wxEVT_LIST_ITEM_DESELECTED, boost::bind(&LanguageSubtagPanel::selection_changed, this));
55 LanguageSubtagPanel::set(dcp::LanguageTag::SubtagType type, string search, optional<dcp::LanguageTag::SubtagData> subtag)
57 _list->set(type, search, subtag);
58 _search->SetValue(wxString(search));
62 optional<dcp::LanguageTag::RegionSubtag>
63 LanguageSubtagPanel::get() const
65 if (!_list->selected_subtag()) {
69 return dcp::LanguageTag::RegionSubtag(_list->selected_subtag()->subtag);
74 LanguageSubtagPanel::search_changed()
76 auto search = _search->GetValue();
77 _list->set_search(search.ToStdString());
78 if (search.Length() > 0 && _list->GetItemCount() > 0) {
79 _list->EnsureVisible (0);
81 SearchChanged(_search->GetValue().ToStdString());
86 LanguageSubtagPanel::selection_changed()
88 SelectionChanged(_list->selected_subtag());