X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ffull_language_tag_dialog.cc;h=5f0aca1e5b53acdececa49d059046d116029e028;hb=5ee919f413a6c1048aecf83676d42ab3fd94e06e;hp=df9a565b4d89c60a74b843fa644a81b5ca75ef93;hpb=313319ba2d8544bc25524e02e634804a503b54f1;p=dcpomatic.git diff --git a/src/wx/full_language_tag_dialog.cc b/src/wx/full_language_tag_dialog.cc index df9a565b4..5f0aca1e5 100644 --- a/src/wx/full_language_tag_dialog.cc +++ b/src/wx/full_language_tag_dialog.cc @@ -20,11 +20,16 @@ #include "full_language_tag_dialog.h" +#include "language_subtag_panel.h" +#include "subtag_list_ctrl.h" #include "lib/dcpomatic_assert.h" #include +#include +LIBDCP_DISABLE_WARNINGS #include #include #include +LIBDCP_ENABLE_WARNINGS #include #include #include @@ -46,148 +51,6 @@ using namespace boost::placeholders; #endif -class SubtagListCtrl : public wxListCtrl -{ -public: - SubtagListCtrl (wxWindow* parent) - : wxListCtrl (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxLC_VIRTUAL) - { - AppendColumn ("", wxLIST_FORMAT_LEFT, 80); - AppendColumn ("", wxLIST_FORMAT_LEFT, 400); - } - - void set (dcp::LanguageTag::SubtagType type, string search, optional subtag = optional()) - { - _all_subtags = dcp::LanguageTag::get_all(type); - set_search (search); - if (subtag) { - auto i = find(_matching_subtags.begin(), _matching_subtags.end(), *subtag); - if (i != _matching_subtags.end()) { - auto item = std::distance(_matching_subtags.begin(), i); - SetItemState (item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); - EnsureVisible (item); - } - } else { - if (GetItemCount() > 0) { - /* The new list sometimes isn't visible without this */ - EnsureVisible (0); - } - } - } - - void set_search (string search) - { - if (search == "") { - _matching_subtags = _all_subtags; - } else { - _matching_subtags.clear (); - - boost::algorithm::to_lower(search); - for (auto const& i: _all_subtags) { - if ( - (boost::algorithm::to_lower_copy(i.subtag).find(search) != string::npos) || - (boost::algorithm::to_lower_copy(i.description).find(search) != string::npos)) { - _matching_subtags.push_back (i); - } - } - } - - SetItemCount (_matching_subtags.size()); - if (GetItemCount() > 0) { - RefreshItems (0, GetItemCount() - 1); - } - } - - optional selected_subtag () const - { - auto selected = GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (selected == -1) { - return {}; - } - - DCPOMATIC_ASSERT (static_cast(selected) < _matching_subtags.size()); - return _matching_subtags[selected]; - } - -private: - wxString OnGetItemText (long item, long column) const override - { - if (column == 0) { - return _matching_subtags[item].subtag; - } else { - return _matching_subtags[item].description; - } - } - - std::vector _all_subtags; - std::vector _matching_subtags; -}; - - -class LanguageSubtagPanel : public wxPanel -{ -public: - LanguageSubtagPanel (wxWindow* parent) - : wxPanel (parent, wxID_ANY) - { -#ifdef __WXGTK3__ - int const height = 30; -#else - int const height = -1; -#endif - - _search = new wxSearchCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, height)); - _list = new SubtagListCtrl (this); - - auto sizer = new wxBoxSizer (wxVERTICAL); - sizer->Add (_search, 0, wxALL, 8); - sizer->Add (_list, 1, wxALL, 8); - SetSizer (sizer); - - _search->Bind (wxEVT_TEXT, boost::bind(&LanguageSubtagPanel::search_changed, this)); - _list->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind(&LanguageSubtagPanel::selection_changed, this)); - _list->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind(&LanguageSubtagPanel::selection_changed, this)); - } - - void set (dcp::LanguageTag::SubtagType type, string search, optional subtag = optional()) - { - _list->set (type, search, subtag); - _search->SetValue (wxString(search)); - } - - optional get () const - { - if (!_list->selected_subtag()) { - return {}; - } - - return dcp::LanguageTag::RegionSubtag(_list->selected_subtag()->subtag); - } - - boost::signals2::signal)> SelectionChanged; - boost::signals2::signal SearchChanged; - -private: - void search_changed () - { - auto search = _search->GetValue(); - _list->set_search (search.ToStdString()); - if (search.Length() > 0 && _list->GetItemCount() > 0) { - _list->EnsureVisible (0); - } - SearchChanged (_search->GetValue().ToStdString()); - } - - void selection_changed () - { - SelectionChanged (_list->selected_subtag()); - } - - wxSearchCtrl* _search; - SubtagListCtrl* _list; -}; - - FullLanguageTagDialog::FullLanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag) : wxDialog (parent, wxID_ANY, _("Language Tag"), wxDefaultPosition, wxSize(-1, 500)) { @@ -424,29 +287,3 @@ FullLanguageTagDialog::setup_sensitivity () _remove->Enable (selected > 0); } - -RegionSubtagDialog::RegionSubtagDialog (wxWindow* parent, dcp::LanguageTag::RegionSubtag region) - : wxDialog (parent, wxID_ANY, _("Region"), wxDefaultPosition, wxSize(-1, 500)) - , _panel (new LanguageSubtagPanel (this)) -{ - auto sizer = new wxBoxSizer (wxVERTICAL); - sizer->Add (_panel, 1); - - auto buttons = CreateSeparatedButtonSizer (wxOK); - if (buttons) { - sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); - } - - SetSizer (sizer); - - _panel->set (dcp::LanguageTag::SubtagType::REGION, "", *dcp::LanguageTag::get_subtag_data(region)); -} - - -optional -RegionSubtagDialog::get () const -{ - return _panel->get (); -} - -