diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-01-14 22:06:05 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-01-14 22:06:05 +0100 |
| commit | 4e4968464eeef1956cb82392e1fc3b27a792ab89 (patch) | |
| tree | 79db245f320df21a075a0fd26de685e02fff6924 /src/wx | |
| parent | 0ecea9f4d1a772e99f396e47364e68abfbfe9f7f (diff) | |
Add wx_ptr and use it instead of ScopeGuard in a lot of places.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/config_dialog.cc | 28 | ||||
| -rw-r--r-- | src/wx/content_advanced_dialog.cc | 6 | ||||
| -rw-r--r-- | src/wx/content_menu.cc | 5 | ||||
| -rw-r--r-- | src/wx/content_panel.cc | 15 | ||||
| -rw-r--r-- | src/wx/controls.cc | 7 | ||||
| -rw-r--r-- | src/wx/editable_list.h | 8 | ||||
| -rw-r--r-- | src/wx/fonts_dialog.cc | 7 | ||||
| -rw-r--r-- | src/wx/language_tag_widget.cc | 4 | ||||
| -rw-r--r-- | src/wx/region_subtag_widget.cc | 4 | ||||
| -rw-r--r-- | src/wx/screen_dialog.cc | 10 | ||||
| -rw-r--r-- | src/wx/screens_panel.cc | 13 | ||||
| -rw-r--r-- | src/wx/text_panel.cc | 4 | ||||
| -rw-r--r-- | src/wx/timing_panel.cc | 4 | ||||
| -rw-r--r-- | src/wx/wx_ptr.h | 80 | ||||
| -rw-r--r-- | src/wx/wx_util.cc | 11 |
15 files changed, 129 insertions, 77 deletions
diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index bf7e295ee..51b6ff2e9 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -25,6 +25,7 @@ #include "dcpomatic_button.h" #include "nag_dialog.h" #include "static_text.h" +#include "wx_ptr.h" #include "lib/constants.h" #include <dcp/file.h> #include <dcp/raw_convert.h> @@ -367,8 +368,7 @@ CertificateChainEditor::add_button (wxWindow* button) void CertificateChainEditor::add_certificate () { - auto d = new wxFileDialog (this, _("Select Certificate File")); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxFileDialog>(this, _("Select Certificate File")); if (d->ShowModal() == wxID_OK) { try { @@ -450,11 +450,10 @@ CertificateChainEditor::export_certificate () default_name = "intermediate.pem"; } - auto d = new wxFileDialog( + auto d = make_wx<wxFileDialog>( this, _("Select Certificate File"), wxEmptyString, default_name, wxT ("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [d]() { d->Destroy(); }; auto j = all.begin (); for (int k = 0; k < i; ++k) { @@ -481,11 +480,10 @@ CertificateChainEditor::export_certificate () void CertificateChainEditor::export_chain () { - auto d = new wxFileDialog ( + auto d = make_wx<wxFileDialog>( this, _("Select Chain File"), wxEmptyString, wxT("certificate_chain.pem"), wxT("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() != wxID_OK) { return; @@ -546,8 +544,7 @@ CertificateChainEditor::remake_certificates () return; } - auto d = new MakeChainDialog (this, _get()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<MakeChainDialog>(this, _get()); if (d->ShowModal () == wxID_OK) { _set (d->get()); @@ -574,8 +571,7 @@ CertificateChainEditor::update_private_key () void CertificateChainEditor::import_private_key () { - auto d = new wxFileDialog (this, _("Select Key File")); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxFileDialog>(this, _("Select Key File")); if (d->ShowModal() == wxID_OK) { try { @@ -608,11 +604,10 @@ CertificateChainEditor::export_private_key () return; } - auto d = new wxFileDialog ( + auto d = make_wx<wxFileDialog>( this, _("Select Key File"), wxEmptyString, wxT("private_key.pem"), wxT("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal () == wxID_OK) { boost::filesystem::path path (wx_to_std(d->GetPath())); @@ -727,11 +722,10 @@ KeysPage::signing_advanced () void KeysPage::export_decryption_chain_and_key () { - auto d = new wxFileDialog ( + auto d = make_wx<wxFileDialog>( _panel, _("Select Export File"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() != wxID_OK) { return; @@ -762,10 +756,9 @@ KeysPage::import_decryption_chain_and_key () return; } - auto d = new wxFileDialog ( + auto d = make_wx<wxFileDialog>( _panel, _("Select File To Import"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom") ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() != wxID_OK) { return; @@ -825,11 +818,10 @@ KeysPage::export_decryption_certificate () } default_name += wxT("_kdm_decryption_cert.pem"); - auto d = new wxFileDialog ( + auto d = make_wx<wxFileDialog>( _panel, _("Select Certificate File"), wxEmptyString, default_name, wxT("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() != wxID_OK) { return; diff --git a/src/wx/content_advanced_dialog.cc b/src/wx/content_advanced_dialog.cc index 35343d78d..752fa565a 100644 --- a/src/wx/content_advanced_dialog.cc +++ b/src/wx/content_advanced_dialog.cc @@ -25,13 +25,13 @@ #include "filter_dialog.h" #include "language_tag_widget.h" #include "static_text.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/content.h" #include "lib/dcp_content.h" #include "lib/filter.h" #include "lib/ffmpeg_content.h" #include "lib/image_content.h" -#include "lib/scope_guard.h" #include "lib/video_content.h" #include <dcp/warnings.h> LIBDCP_DISABLE_WARNINGS @@ -181,9 +181,7 @@ ContentAdvancedDialog::edit_filters () return; } - auto dialog = new FilterDialog(this, _filters_list); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; - + auto dialog = make_wx<FilterDialog>(this, _filters_list); dialog->ActiveChanged.connect(bind(&ContentAdvancedDialog::filters_changed, this, _1)); dialog->ShowModal(); } diff --git a/src/wx/content_menu.cc b/src/wx/content_menu.cc index 80976e5f6..5957ac06d 100644 --- a/src/wx/content_menu.cc +++ b/src/wx/content_menu.cc @@ -27,6 +27,7 @@ #include "repeat_dialog.h" #include "timeline_video_content_view.h" #include "timeline_audio_content_view.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/audio_content.h" #include "lib/config.h" @@ -44,7 +45,6 @@ #include "lib/image_content.h" #include "lib/job_manager.h" #include "lib/playlist.h" -#include "lib/scope_guard.h" #include "lib/video_content.h" #include <dcp/cpl.h> #include <dcp/decrypted_kdm.h> @@ -466,8 +466,7 @@ ContentMenu::advanced () DCPOMATIC_ASSERT(!_content.empty()); auto content = _content.front(); - auto dialog = new ContentAdvancedDialog(_parent, content); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<ContentAdvancedDialog>(_parent, content); if (dialog->ShowModal() == wxID_CANCEL) { return; diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index a25e37a2a..71f32068a 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -30,6 +30,7 @@ #include "timeline_dialog.h" #include "timing_panel.h" #include "video_panel.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/audio_content.h" #include "lib/case_insensitive_sorter.h" @@ -45,7 +46,6 @@ #include "lib/image_content.h" #include "lib/log.h" #include "lib/playlist.h" -#include "lib/scope_guard.h" #include "lib/string_text_file.h" #include "lib/string_text_file_content.h" #include "lib/text_content.h" @@ -595,7 +595,7 @@ ContentPanel::add_file_clicked () /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using non-Latin filenames or paths. */ - auto dialog = new FileDialog( + auto dialog = make_wx<FileDialog>( _splitter, _("Choose a file or files"), wxT("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"), @@ -604,8 +604,6 @@ ContentPanel::add_file_clicked () add_files_override_path() ); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; - if (dialog->show()) { add_files(dialog->paths()); } @@ -615,8 +613,7 @@ ContentPanel::add_file_clicked () void ContentPanel::add_folder_clicked () { - auto d = new DirDialog(_splitter, _("Choose a folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<DirDialog>(_splitter, _("Choose a folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path()); if (d->show()) { add_folder(d->path()); } @@ -643,8 +640,7 @@ ContentPanel::add_folder(boost::filesystem::path folder) for (auto i: content) { auto ic = dynamic_pointer_cast<ImageContent> (i); if (ic) { - auto e = new ImageSequenceDialog (_splitter); - ScopeGuard sg = [e]() { e->Destroy(); }; + auto e = make_wx<ImageSequenceDialog>(_splitter); if (e->ShowModal() != wxID_OK) { return; @@ -660,8 +656,7 @@ ContentPanel::add_folder(boost::filesystem::path folder) void ContentPanel::add_dcp_clicked () { - auto d = new DirDialog(_splitter, _("Choose a DCP folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<DirDialog>(_splitter, _("Choose a DCP folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path()); if (d->show()) { add_dcp(d->path()); } diff --git a/src/wx/controls.cc b/src/wx/controls.cc index 804b59dae..b9eebade5 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -28,6 +28,7 @@ #include "playhead_to_frame_dialog.h" #include "playhead_to_timecode_dialog.h" #include "static_text.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/content_factory.h" #include "lib/cross.h" @@ -381,8 +382,7 @@ Controls::setup_sensitivity () void Controls::timecode_clicked () { - auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate()); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<PlayheadToTimecodeDialog>(this, _viewer.position(), _film->video_frame_rate()); if (dialog->ShowModal() == wxID_OK) { _viewer.seek(dialog->get(), true); @@ -393,8 +393,7 @@ Controls::timecode_clicked () void Controls::frame_number_clicked () { - auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate()); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<PlayheadToFrameDialog>(this, _viewer.position(), _film->video_frame_rate()); if (dialog->ShowModal() == wxID_OK) { _viewer.seek(dialog->get(), true); diff --git a/src/wx/editable_list.h b/src/wx/editable_list.h index f3a0dd957..f8050cac5 100644 --- a/src/wx/editable_list.h +++ b/src/wx/editable_list.h @@ -24,8 +24,8 @@ #include "dcpomatic_button.h" +#include "wx_ptr.h" #include "wx_util.h" -#include "lib/scope_guard.h" #include <dcp/warnings.h> LIBDCP_DISABLE_WARNINGS #include <wx/listctrl.h> @@ -233,8 +233,7 @@ private: void add_clicked () { - S* dialog = new S (this); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<S>(this); if (dialog->ShowModal() == wxID_OK) { auto const v = dialog->get (); @@ -258,8 +257,7 @@ private: std::vector<T> all = _get (); DCPOMATIC_ASSERT (item >= 0 && item < int (all.size ())); - S* dialog = new S (this); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<S>(this); dialog->set (all[item]); if (dialog->ShowModal() == wxID_OK) { auto const v = dialog->get (); diff --git a/src/wx/fonts_dialog.cc b/src/wx/fonts_dialog.cc index b21bb8498..9e38e9e68 100644 --- a/src/wx/fonts_dialog.cc +++ b/src/wx/fonts_dialog.cc @@ -22,6 +22,7 @@ #include "dcpomatic_button.h" #include "fonts_dialog.h" #include "system_font_dialog.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/content.h" #include "lib/font.h" @@ -184,8 +185,7 @@ FontsDialog::set_from_file_clicked () default_dir = "/System/Library/Fonts"; #endif - auto d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf;*.ttc"), wxFD_CHANGE_DIR); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxFileDialog>(this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf;*.ttc"), wxFD_CHANGE_DIR); if (d->ShowModal() != wxID_OK) { return; @@ -204,8 +204,7 @@ FontsDialog::set_from_system_font_clicked() return; } - auto dialog = new SystemFontDialog(this); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<SystemFontDialog>(this); if (dialog->ShowModal() == wxID_OK) { auto font_file = dialog->get_font(); if (font_file) { diff --git a/src/wx/language_tag_widget.cc b/src/wx/language_tag_widget.cc index f28046bd9..d14c43f0c 100644 --- a/src/wx/language_tag_widget.cc +++ b/src/wx/language_tag_widget.cc @@ -22,6 +22,7 @@ #include "dcpomatic_button.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 <dcp/warnings.h> @@ -66,8 +67,7 @@ LanguageTagWidget::~LanguageTagWidget () void LanguageTagWidget::edit () { - auto d = new LanguageTagDialog(_parent, _tag.get_value_or(dcp::LanguageTag("en"))); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<LanguageTagDialog>(_parent, _tag.get_value_or(dcp::LanguageTag("en"))); if (d->ShowModal() == wxID_OK) { set(d->get()); Changed(d->get()); diff --git a/src/wx/region_subtag_widget.cc b/src/wx/region_subtag_widget.cc index 3b0457f13..54c6d9d43 100644 --- a/src/wx/region_subtag_widget.cc +++ b/src/wx/region_subtag_widget.cc @@ -23,6 +23,7 @@ #include "full_language_tag_dialog.h" #include "region_subtag_dialog.h" #include "region_subtag_widget.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/scope_guard.h" #include <dcp/warnings.h> @@ -67,8 +68,7 @@ RegionSubtagWidget::~RegionSubtagWidget() void RegionSubtagWidget::edit() { - auto d = new RegionSubtagDialog(_parent, _tag.get_value_or(dcp::LanguageTag::RegionSubtag("US"))); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<RegionSubtagDialog>(_parent, _tag.get_value_or(dcp::LanguageTag::RegionSubtag("US"))); if (d->ShowModal() == wxID_OK) { set(d->get()); diff --git a/src/wx/screen_dialog.cc b/src/wx/screen_dialog.cc index 6d7fb4f03..3fa17353d 100644 --- a/src/wx/screen_dialog.cc +++ b/src/wx/screen_dialog.cc @@ -25,6 +25,7 @@ #include "screen_dialog.h" #include "static_text.h" #include "table_dialog.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/compose.hpp" #include "lib/scope_guard.h" @@ -64,8 +65,7 @@ public: void load_certificate () { - auto dialog = new FileDialog(this, _("Trusted Device certificate"), wxEmptyString, wxFD_DEFAULT_STYLE, "SelectCertificatePath"); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<FileDialog>(this, _("Trusted Device certificate"), wxEmptyString, wxFD_DEFAULT_STYLE, "SelectCertificatePath"); if (!dialog->show()) { return; } @@ -259,8 +259,7 @@ ScreenDialog::load_recipient (boost::filesystem::path file) void ScreenDialog::get_recipient_from_file () { - auto dialog = new FileDialog(this, _("Select Certificate File"), wxEmptyString, wxFD_DEFAULT_STYLE , "SelectCertificatePath"); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<FileDialog>(this, _("Select Certificate File"), wxEmptyString, wxFD_DEFAULT_STYLE , "SelectCertificatePath"); if (dialog->show()) { load_recipient(dialog->paths()[0]); } @@ -272,8 +271,7 @@ ScreenDialog::get_recipient_from_file () void ScreenDialog::download_recipient () { - auto dialog = new DownloadCertificateDialog (this); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<DownloadCertificateDialog>(this); if (dialog->ShowModal() == wxID_OK) { set_recipient(dialog->certificate()); checked_set(_recipient_file, dialog->url()); diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index 1d94d1acb..ad000d988 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -23,6 +23,7 @@ #include "dcpomatic_button.h" #include "screen_dialog.h" #include "screens_panel.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/cinema.h" #include "lib/config.h" @@ -230,8 +231,7 @@ ScreensPanel::add_screen (shared_ptr<Cinema> cinema, shared_ptr<Screen> screen) void ScreensPanel::add_cinema_clicked () { - auto dialog = new CinemaDialog (GetParent(), _("Add Cinema")); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<CinemaDialog>(GetParent(), _("Add Cinema")); if (dialog->ShowModal() == wxID_OK) { auto cinema = make_shared<Cinema>(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute()); @@ -298,10 +298,9 @@ ScreensPanel::edit_cinema_clicked () return; } - auto dialog = new CinemaDialog( + auto dialog = make_wx<CinemaDialog>( GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute() ); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; if (dialog->ShowModal() == wxID_OK) { cinema->name = dialog->name(); @@ -351,8 +350,7 @@ ScreensPanel::add_screen_clicked () return; } - auto dialog = new ScreenDialog(GetParent(), _("Add Screen")); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<ScreenDialog>(GetParent(), _("Add Screen")); if (dialog->ShowModal () != wxID_OK) { return; @@ -391,7 +389,7 @@ ScreensPanel::edit_screen_clicked () auto edit_screen = _selected_screens[0]; - auto dialog = new ScreenDialog( + auto dialog = make_wx<ScreenDialog>( GetParent(), _("Edit screen"), edit_screen->name, edit_screen->notes, @@ -399,7 +397,6 @@ ScreensPanel::edit_screen_clicked () edit_screen->recipient_file, edit_screen->trusted_devices ); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; if (dialog->ShowModal() != wxID_OK) { return; diff --git a/src/wx/text_panel.cc b/src/wx/text_panel.cc index 8e7d4434e..94ec8506d 100644 --- a/src/wx/text_panel.cc +++ b/src/wx/text_panel.cc @@ -32,6 +32,7 @@ #include "subtitle_appearance_dialog.h" #include "text_panel.h" #include "text_view.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/analyse_subtitles_job.h" #include "lib/dcp_content.h" @@ -370,8 +371,7 @@ TextPanel::dcp_track_changed () optional<DCPTextTrack> track; if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) { - auto d = new DCPTextTrackDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<DCPTextTrackDialog>(this); if (d->ShowModal() == wxID_OK) { track = d->get(); } diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 732cd07d5..47019487f 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -26,6 +26,7 @@ #include "static_text.h" #include "timecode.h" #include "timing_panel.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/audio_content.h" #include "lib/content.h" @@ -507,8 +508,7 @@ TimingPanel::move_to_start_of_reel_clicked () } } - auto d = new MoveToDialog(this, position, _parent->film()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<MoveToDialog>(this, position, _parent->film()); if (d->ShowModal() == wxID_OK) { for (auto i: _parent->selected()) { diff --git a/src/wx/wx_ptr.h b/src/wx/wx_ptr.h new file mode 100644 index 000000000..de18846cc --- /dev/null +++ b/src/wx/wx_ptr.h @@ -0,0 +1,80 @@ +/* + Copyright (C) 2023 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#ifndef DCPOMATIC_WX_PTR_H +#define DCPOMATIC_WX_PTR_H + + +#include <utility> + + +template <class T> +class wx_ptr +{ +public: + explicit wx_ptr(T* wx) + : _wx(wx) + {} + + wx_ptr(wx_ptr&) = delete; + wx_ptr& operator=(wx_ptr&) = delete; + + wx_ptr(wx_ptr&& other) + { + _wx = other._wx; + other._wx = nullptr; + } + + wx_ptr& operator=(wx_ptr&& other) + { + if (this != &other) { + _wx = other._wx; + other._wx = nullptr; + } + return *this; + } + + ~wx_ptr() + { + if (_wx) { + _wx->Destroy(); + } + } + + T* operator->() { + return _wx; + } + +private: + T* _wx; +}; + + + +template <class T, typename... Args> +wx_ptr<T> +make_wx(Args... args) +{ + return wx_ptr<T>(new T(std::forward<Args>(args)...)); +} + + +#endif diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 1f2afb4f5..d264f8b20 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -29,12 +29,12 @@ #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" #include "lib/job.h" #include "lib/job_manager.h" -#include "lib/scope_guard.h" #include "lib/util.h" #include "lib/version.h" #include <dcp/locale_convert.h> @@ -161,8 +161,7 @@ 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); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR); if (e) { wxString em = *e; em[0] = wxToupper (em[0]); @@ -179,8 +178,7 @@ 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); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION); d->ShowModal (); } @@ -189,8 +187,7 @@ 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); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION); return d->ShowModal() == wxID_YES; } |
