-#include <boost/algorithm/string.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/optional.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/signals2.hpp>
-#include <iostream>
-#include <iterator>
-#include <string>
-#include <vector>
-
-
-using std::pair;
-using std::string;
-using std::vector;
-using boost::optional;
-using boost::shared_ptr;
-using boost::weak_ptr;
-#if BOOST_VERSION >= 106100
-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<dcp::LanguageTag::SubtagData> subtag = optional<dcp::LanguageTag::SubtagData>())
- {
- _all_subtags = dcp::LanguageTag::get_all(type);
- set_search (search);
- if (subtag) {
- vector<dcp::LanguageTag::SubtagData>::iterator i = find(_matching_subtags.begin(), _matching_subtags.end(), *subtag);
- if (i != _matching_subtags.end()) {
- long item = std::distance(_matching_subtags.begin(), i);
- SetItemState (item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
- EnsureVisible (item);
- }
- }
- }
-
- void set_search (string search)
- {
- if (search == "") {
- _matching_subtags = _all_subtags;
- } else {
- _matching_subtags.clear ();
-
- boost::algorithm::to_lower(search);
- BOOST_FOREACH (dcp::LanguageTag::SubtagData 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<dcp::LanguageTag::SubtagData> selected_subtag () const
- {
- long int selected = GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
- if (selected == -1) {
- return optional<dcp::LanguageTag::SubtagData>();
- }
-
- DCPOMATIC_ASSERT (static_cast<size_t>(selected) < _matching_subtags.size());
- return _matching_subtags[selected];
- }