Add indent option to wxGridBagSizer version of add_label_to_sizer
[dcpomatic.git] / src / wx / wx_util.cc
index d02eb3ca5d3b3e68a6f5d26b87e1fd19ac14480d..7a41f66e7cfa226c1bccb139f7fb88b3dc141082 100644 (file)
 
 
 #include "file_picker_ctrl.h"
+#include "language_tag_widget.h"
 #include "password_entry.h"
+#include "region_subtag_widget.h"
 #include "static_text.h"
+#include "wx_ptr.h"
 #include "wx_util.h"
 #include "lib/config.h"
 #include "lib/cross.h"
@@ -122,14 +125,14 @@ add_label_to_sizer (wxSizer* s, wxStaticText* t, bool, int prop, int flags)
 
 
 wxStaticText *
-add_label_to_sizer (wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span)
+add_label_to_sizer(wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span, bool indent)
 {
-       int flags = wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT;
+       int flags = wxALIGN_CENTER_VERTICAL | wxLEFT;
 #ifdef __WXOSX__
        setup_osx_flags (s, left, flags);
 #endif
        auto m = create_label (p, t, left);
-       s->Add (m, pos, span, flags);
+       s->Add(m, pos, span, flags, indent ? DCPOMATIC_SIZER_X_GAP : 0);
        return m;
 }
 
@@ -158,14 +161,13 @@ add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool, wxGBPosition pos,
 void
 error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
 {
-       auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
+       auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
        if (e) {
                wxString em = *e;
                em[0] = wxToupper (em[0]);
                d->SetExtendedMessage (em);
        }
        d->ShowModal ();
-       d->Destroy ();
 }
 
 
@@ -176,9 +178,8 @@ error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
 void
 message_dialog (wxWindow* parent, wxString m)
 {
-       auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION);
+       auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION);
        d->ShowModal ();
-       d->Destroy ();
 }
 
 
@@ -186,10 +187,8 @@ message_dialog (wxWindow* parent, wxString m)
 bool
 confirm_dialog (wxWindow* parent, wxString m)
 {
-       auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION);
-       int const r = d->ShowModal ();
-       d->Destroy ();
-       return r == wxID_YES;
+       auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION);
+       return d->ShowModal() == wxID_YES;
 }
 
 
@@ -304,7 +303,7 @@ checked_set (wxChoice* widget, vector<pair<string, string>> items)
                current.push_back (
                        make_pair(
                                wx_to_std(widget->GetString(i)),
-                               string_client_data(widget->GetClientObject(i))
+                               widget->GetClientData() ? string_client_data(widget->GetClientObject(i)) : ""
                                )
                        );
        }
@@ -383,6 +382,33 @@ checked_set (wxRadioButton* widget, bool value)
 }
 
 
+void
+checked_set(LanguageTagWidget* widget, dcp::LanguageTag value)
+{
+       if (widget->get() != value) {
+               widget->set(value);
+       }
+}
+
+
+void
+checked_set(LanguageTagWidget* widget, optional<dcp::LanguageTag> value)
+{
+       if (widget->get() != value) {
+               widget->set(value);
+       }
+}
+
+
+void
+checked_set(RegionSubtagWidget* widget, optional<dcp::LanguageTag::RegionSubtag> value)
+{
+       if (widget->get() != value) {
+               widget->set(value);
+       }
+}
+
+
 void
 dcpomatic_setup_i18n ()
 {
@@ -511,10 +537,11 @@ setup_audio_channels_choice (wxChoice* choice, int minimum)
 }
 
 
-wxSplashScreen *
+wx_ptr<wxSplashScreen>
 maybe_show_splash ()
 {
-       wxSplashScreen* splash = nullptr;
+       wx_ptr<wxSplashScreen> splash;
+
        try {
                wxBitmap bitmap;
                if (bitmap.LoadFile(bitmap_path("splash.png"), wxBITMAP_TYPE_PNG)) {
@@ -528,9 +555,9 @@ maybe_show_splash ()
                        }
 #ifdef DCPOMATIC_WINDOWS
                        /* Having wxSTAY_ON_TOP means error dialogues hide behind the splash screen on Windows, no matter what I try */
-                       splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
+                       splash.reset(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
 #else
-                       splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1);
+                       splash.reset(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1);
 #endif
                        wxYield ();
                }
@@ -651,6 +678,13 @@ bitmap_path (string name)
 }
 
 
+wxString
+icon_path(string name)
+{
+       return gui_is_dark() ? bitmap_path(String::compose("%1_white.png", name)) : bitmap_path(String::compose("%1_black.png", name));
+}
+
+
 wxSize
 small_button_size (wxWindow* parent, wxString text)
 {
@@ -724,3 +758,4 @@ report_config_load_failure(wxWindow* parent, Config::LoadFailure what)
                break;
        }
 }
+