diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-01-15 01:25:27 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-01-15 01:25:27 +0100 |
| commit | 963c7649da903b87637975e8c2d634da887d3109 (patch) | |
| tree | ab59391e9f4fd5a35f4bec052b97d4e703b007cd /src/wx | |
| parent | fcaf62b405f6379e7030ddc2a38426c5f9ffb081 (diff) | |
Use wx_ptr for the splash screen.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/wx_ptr.h | 25 | ||||
| -rw-r--r-- | src/wx/wx_util.cc | 9 | ||||
| -rw-r--r-- | src/wx/wx_util.h | 3 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/wx/wx_ptr.h b/src/wx/wx_ptr.h index 96459183e..24bccb043 100644 --- a/src/wx/wx_ptr.h +++ b/src/wx/wx_ptr.h @@ -62,11 +62,34 @@ public: } } - T* operator->() { + wx_ptr& operator=(T* ptr) + { + if (_wx) { + _wx->Destroy(); + } + _wx = ptr; + return *this; + } + + T* operator->() + { DCPOMATIC_ASSERT(_wx); return _wx; } + operator bool() const + { + return _wx != nullptr; + } + + void reset() + { + if (_wx) { + _wx->Destroy(); + _wx = nullptr; + } + } + template <typename... Args> void reset(Args&&... args) { diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index d264f8b20..e600b63c8 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -537,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)) { @@ -554,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 (); } diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h index 5ef221b15..be3be0d1a 100644 --- a/src/wx/wx_util.h +++ b/src/wx/wx_util.h @@ -28,6 +28,7 @@ #define DCPOMATIC_WX_UTIL_H +#include "wx_ptr.h" #include "lib/config.h" #include "lib/dcpomatic_time.h" #include <dcp/warnings.h> @@ -116,7 +117,7 @@ extern wxString context_translation (wxString); extern std::string string_client_data (wxClientData* o); extern wxString time_to_timecode (dcpomatic::DCPTime t, double fps); extern void setup_audio_channels_choice (wxChoice* choice, int minimum); -extern wxSplashScreen* maybe_show_splash (); +extern wx_ptr<wxSplashScreen> maybe_show_splash(); extern double calculate_mark_interval (double start); extern bool display_progress (wxString title, wxString task); extern bool report_errors_from_last_job (wxWindow* parent); |
