Rename Choice::add to Choice::add_entry.
[dcpomatic.git] / src / wx / dcpomatic_choice.cc
index 168d76430bfc3822fce2a2685c6980fbf74d6142..5e5a1e2575444dfa4dc0361b9ef3d6c2ce8c10b4 100644 (file)
@@ -40,14 +40,14 @@ Choice::Choice(wxWindow* parent)
 
 
 void
-Choice::add(string const& entry)
+Choice::add_entry(string const& entry)
 {
-       add(std_to_wx(entry));
+       add_entry(std_to_wx(entry));
 }
 
 
 void
-Choice::add(wxString const& entry)
+Choice::add_entry(wxString const& entry)
 {
        if (_needs_clearing) {
                Clear();
@@ -59,7 +59,7 @@ Choice::add(wxString const& entry)
 
 
 void
-Choice::add(wxString const& entry, wxClientData* data)
+Choice::add_entry(wxString const& entry, wxClientData* data)
 {
        if (_needs_clearing) {
                Clear();
@@ -70,6 +70,18 @@ Choice::add(wxString const& entry, wxClientData* data)
 }
 
 
+void
+Choice::add_entry(wxString const& entry, wxString const& data)
+{
+       if (_needs_clearing) {
+               Clear();
+               _needs_clearing = false;
+       }
+
+       Append(entry, new wxStringClientData(data));
+}
+
+
 void
 Choice::set(int index)
 {
@@ -77,6 +89,20 @@ Choice::set(int index)
 }
 
 
+void
+Choice::set_by_data(wxString const& data)
+{
+       for (unsigned int i = 0; i < GetCount(); ++i) {
+               if (auto client_data = dynamic_cast<wxStringClientData*>(GetClientObject(i))) {
+                       if (client_data->GetData() == data) {
+                               set(i);
+                               return;
+                       }
+               }
+       }
+}
+
+
 optional<int>
 Choice::get() const
 {
@@ -88,3 +114,15 @@ Choice::get() const
        return sel;
 }
 
+
+optional<wxString>
+Choice::get_data() const
+{
+       auto index = get();
+       if (!index) {
+               return {};
+       }
+
+       return dynamic_cast<wxStringClientData*>(GetClientObject(*index))->GetData();
+}
+