X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fdcpomatic_choice.cc;h=2f1a6f0e9b782b34d006912afd71b9cc5350fc13;hb=a3a0e7a567b73dac9ba29a1ab28e58757cc21411;hp=168d76430bfc3822fce2a2685c6980fbf74d6142;hpb=d9b398b33716d5f28fd8d6e22cb723c2fbb635a0;p=dcpomatic.git diff --git a/src/wx/dcpomatic_choice.cc b/src/wx/dcpomatic_choice.cc index 168d76430..2f1a6f0e9 100644 --- a/src/wx/dcpomatic_choice.cc +++ b/src/wx/dcpomatic_choice.cc @@ -70,6 +70,18 @@ Choice::add(wxString const& entry, wxClientData* data) } +void +Choice::add(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(GetClientObject(i))) { + if (client_data->GetData() == data) { + set(i); + return; + } + } + } +} + + optional Choice::get() const { @@ -88,3 +114,15 @@ Choice::get() const return sel; } + +optional +Choice::get_data() const +{ + auto index = get(); + if (!index) { + return {}; + } + + return dynamic_cast(GetClientObject(*index))->GetData(); +} +