Use wx_ptr for the splash screen.
[dcpomatic.git] / src / wx / wx_util.cc
index 933d303d145bb8e531b75c5216bcddaac8812a35..e600b63c89c4506e4b161b3b1f5a64617df1a8e8 100644 (file)
@@ -29,6 +29,7 @@
 #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"
@@ -160,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 ();
 }
 
 
@@ -178,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 ();
 }
 
 
@@ -188,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;
 }
 
 
@@ -540,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)) {
@@ -557,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 ();
                }