commit 056935e7102225c8aebd93501aad32cabc153f9b
parent a9099d64c8d4b806c327a3a3c109f2c8a55a2634
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 12 Jan 2020 15:57:45 -0500
use smart pointers for dialog control ownership
Diffstat:
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/src/dialog.cpp b/src/dialog.cpp
@@ -21,7 +21,6 @@
#include "win32.hpp"
#include <algorithm>
-#include <boost/range/adaptor/map.hpp>
#include <boost/algorithm/string/join.hpp>
#include <reaper_plugin_functions.h>
@@ -117,12 +116,8 @@ Dialog::~Dialog()
{
plugin_register("-accelerator", &m_accel);
- const std::set<int> timers = m_timers; // make an immutable copy
- for(const int id : timers)
- stopTimer(id);
-
- for(Control *control : m_controls | boost::adaptors::map_values)
- delete control;
+ for(const int id : m_timers)
+ KillTimer(m_handle, id); // not using stopTimer to avoid modifying m_timers
// Unregistering the instance right now before DestroyWindow prevents WM_DESTROY
// from calling the default implementation of onClose (because we're in the
@@ -429,7 +424,9 @@ void Dialog::onNotify(LPNMHDR info, LPARAM lParam)
void Dialog::onContextMenu(HWND target, const int x, const int y)
{
- for(Control *ctrl : m_controls | boost::adaptors::map_values) {
+ for(const auto &[id, ctrl] : m_controls) {
+ (void)id;
+
if(!IsWindowVisible(ctrl->handle()))
continue;
diff --git a/src/dialog.hpp b/src/dialog.hpp
@@ -124,10 +124,8 @@ protected:
if(m_controls.count(id))
return nullptr;
- HWND handle = getControl(id);
-
- T *ctrl = new T(handle, args...);
- m_controls[id] = ctrl;
+ T *ctrl = new T(getControl(id), args...);
+ m_controls.emplace(id, ctrl);
return ctrl;
}
@@ -154,7 +152,8 @@ private:
HWND m_parent;
HWND m_handle;
- std::map<int, Control *> m_controls;
+ using ControlPtr = std::unique_ptr<Control>;
+ std::map<int, ControlPtr> m_controls;
std::set<int> m_timers;
CloseHandler m_closeHandler;