BOOST_FOREACH.
[dcpomatic.git] / src / wx / language_tag_dialog.cc
index 0d0203e90a7af71a3c8237a9e5f1504035a08361..d9add6dcae38b4ff942a673f26444997a085f625 100644 (file)
 #include <wx/srchctrl.h>
 #include <wx/wx.h>
 #include <boost/algorithm/string.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
+#include <boost/bind/bind.hpp>
 #include <boost/optional.hpp>
-#include <boost/shared_ptr.hpp>
 #include <boost/signals2.hpp>
 #include <iostream>
 #include <iterator>
@@ -42,8 +40,8 @@ using std::pair;
 using std::string;
 using std::vector;
 using boost::optional;
-using boost::shared_ptr;
-using boost::weak_ptr;
+using std::shared_ptr;
+using std::weak_ptr;
 #if BOOST_VERSION >= 106100
 using namespace boost::placeholders;
 #endif
@@ -70,6 +68,11 @@ public:
                                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);
+                       }
                }
        }
 
@@ -81,7 +84,7 @@ public:
                        _matching_subtags.clear ();
 
                        boost::algorithm::to_lower(search);
-                       BOOST_FOREACH (dcp::LanguageTag::SubtagData const& i, _all_subtags) {
+                       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)) {
@@ -219,18 +222,7 @@ LanguageTagDialog::LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag)
 
        SetSizerAndFit (overall_sizer);
 
-       bool have_language = false;
-       vector<pair<dcp::LanguageTag::SubtagType, dcp::LanguageTag::SubtagData> > subtags = tag.subtags();
-       for (vector<pair<dcp::LanguageTag::SubtagType, dcp::LanguageTag::SubtagData> >::const_iterator i = subtags.begin(); i != subtags.end(); ++i) {
-               add_to_current_tag (i->first, i->second);
-               if (i->first == dcp::LanguageTag::LANGUAGE) {
-                       have_language = true;
-               }
-       }
-
-       if (!have_language) {
-               add_to_current_tag (dcp::LanguageTag::LANGUAGE, dcp::LanguageTag::SubtagData("en", "English"));
-       }
+       set (tag);
 
        _add_script->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::add_to_current_tag, this, dcp::LanguageTag::SCRIPT, boost::optional<dcp::LanguageTag::SubtagData>()));
        _add_region->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::add_to_current_tag, this, dcp::LanguageTag::REGION, boost::optional<dcp::LanguageTag::SubtagData>()));
@@ -269,7 +261,7 @@ dcp::LanguageTag LanguageTagDialog::get () const
        vector<dcp::LanguageTag::VariantSubtag> variants;
        vector<dcp::LanguageTag::ExtlangSubtag> extlangs;
 
-       BOOST_FOREACH (Subtag i, _current_tag_subtags) {
+       for (auto i: _current_tag_subtags) {
                if (!i.subtag) {
                        continue;
                }
@@ -298,6 +290,27 @@ dcp::LanguageTag LanguageTagDialog::get () const
 }
 
 
+void
+LanguageTagDialog::set (dcp::LanguageTag tag)
+{
+       _current_tag_subtags.clear ();
+       _current_tag_list->DeleteAllItems ();
+
+       bool have_language = false;
+       vector<pair<dcp::LanguageTag::SubtagType, dcp::LanguageTag::SubtagData> > subtags = tag.subtags();
+       for (vector<pair<dcp::LanguageTag::SubtagType, dcp::LanguageTag::SubtagData> >::const_iterator i = subtags.begin(); i != subtags.end(); ++i) {
+               add_to_current_tag (i->first, i->second);
+               if (i->first == dcp::LanguageTag::LANGUAGE) {
+                       have_language = true;
+               }
+       }
+
+       if (!have_language) {
+               add_to_current_tag (dcp::LanguageTag::LANGUAGE, dcp::LanguageTag::SubtagData("en", "English"));
+       }
+}
+
+
 string LanguageTagDialog::subtag_type_name (dcp::LanguageTag::SubtagType type)
 {
        switch (type) {
@@ -387,7 +400,7 @@ LanguageTagDialog::setup_sensitivity ()
        _add_region->Enable ();
        _add_variant->Enable ();
        _add_external->Enable ();
-       BOOST_FOREACH (Subtag const& i, _current_tag_subtags) {
+       for (auto const& i: _current_tag_subtags) {
                switch (i.type) {
                        case dcp::LanguageTag::SCRIPT:
                                _add_script->Enable (false);