X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Fwx%2Flanguage_tag_widget.cc;h=88923da15c87b7a29340dd02c0483766ec5ef4e4;hp=a032545adcfca1b7376c4b6ced9967e367bb2611;hb=a399d7c7b9239e055ba08a82b18eb68a511d1025;hpb=5d02ff3376c62b05f3f1bebe5277704474a39526 diff --git a/src/wx/language_tag_widget.cc b/src/wx/language_tag_widget.cc index a032545ad..88923da15 100644 --- a/src/wx/language_tag_widget.cc +++ b/src/wx/language_tag_widget.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -20,19 +20,35 @@ #include "dcpomatic_button.h" -#include "full_language_tag_dialog.h" +#include "language_tag_dialog.h" #include "language_tag_widget.h" +#include "wx_ptr.h" #include "wx_util.h" +#include "lib/scope_guard.h" +#include +LIBDCP_DISABLE_WARNINGS #include +LIBDCP_ENABLE_WARNINGS -LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxString tooltip, dcp::LanguageTag tag) +using boost::optional; + + +LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxString tooltip, optional tag, optional size_to_fit) : _parent (parent) , _sizer (new wxBoxSizer(wxHORIZONTAL)) { - _language = new wxStaticText (parent, wxID_ANY, wxT("")); + _language = new wxStaticText (parent, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END); _language->SetToolTip (tooltip); set (tag); + + if (size_to_fit) { + int w; + int h; + _language->GetTextExtent (*size_to_fit, &w, &h); + _language->SetMinSize (wxSize(w, -1)); + } + _sizer->Add (_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP); _edit = new Button (parent, _("Edit...")); _sizer->Add (_edit, 0, wxLEFT, DCPOMATIC_SIZER_GAP); @@ -41,22 +57,33 @@ LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxString tooltip, dcp::L } +LanguageTagWidget::~LanguageTagWidget() +{ + _language->Destroy(); + _edit->Destroy(); +} + + void LanguageTagWidget::edit () { - auto d = new FullLanguageTagDialog(_parent, _tag); - d->ShowModal (); - set (d->get()); - Changed (d->get()); - d->Destroy (); + auto d = make_wx(_parent, _tag.get_value_or(dcp::LanguageTag("en"))); + if (d->ShowModal() == wxID_OK) { + set(d->get()); + Changed(d->get()); + } } void -LanguageTagWidget::set (dcp::LanguageTag tag) +LanguageTagWidget::set (optional tag) { _tag = tag; - checked_set (_language, std_to_wx(tag.to_string())); + if (tag) { + checked_set (_language, std_to_wx(tag->to_string())); + } else { + checked_set (_language, wxT("")); + } }