commit 17a55d66e80f5562e3aa1dda1652b149107052fc
parent c548e6fab31a6fac82124b5552e571ab2ab2a5eb
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 22 Sep 2016 19:46:25 -0700
make flicker protection more robust in stacked usage
Diffstat:
2 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/src/control.cpp b/src/control.cpp
@@ -0,0 +1,43 @@
+/* ReaPack: Package manager for REAPER
+ * Copyright (C) 2015-2016 Christian Fillion
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "control.hpp"
+
+using namespace std;
+
+map<HWND, InhibitControl *> InhibitControl::s_lock;
+
+void InhibitControl::inhibitRedraw(const bool inhibit)
+{
+#ifdef WM_SETREDRAW // not supported by SWELL
+ if(s_lock.count(m_handle)) {
+ if(inhibit || s_lock[m_handle] != this)
+ return;
+ }
+ else if(!inhibit)
+ return;
+
+ SendMessage(m_handle, WM_SETREDRAW, !inhibit, 0);
+
+ if(inhibit)
+ s_lock.insert({m_handle, this});
+ else {
+ s_lock.erase(m_handle);
+ InvalidateRect(m_handle, nullptr, true);
+ }
+#endif
+}
diff --git a/src/control.hpp b/src/control.hpp
@@ -18,6 +18,8 @@
#ifndef REAPACK_CONTROL_HPP
#define REAPACK_CONTROL_HPP
+#include <map>
+
#ifdef _WIN32
#include <windows.h>
#else
@@ -28,17 +30,6 @@ class Dialog;
class Control {
public:
- static void inhibitRedraw(HWND handle, const bool inhibit)
- {
-#ifdef WM_SETREDRAW
- // not supported by SWELL
- SendMessage(handle, WM_SETREDRAW, !inhibit, 0);
-
- if(!inhibit)
- InvalidateRect(handle, nullptr, true);
-#endif
- }
-
Control(HWND handle) : m_handle(handle) {}
virtual ~Control() {}
@@ -46,6 +37,7 @@ public:
protected:
friend Dialog;
+
virtual void onNotify(LPNMHDR, LPARAM) {}
virtual bool onContextMenu(HWND, int, int) { return false; }
@@ -55,27 +47,27 @@ private:
class InhibitControl {
public:
- InhibitControl(Control *ctrl)
- : m_handle(ctrl->handle())
+ InhibitControl(Control *ctrl) : m_handle(ctrl->handle())
{
- block();
+ inhibitRedraw(true);
}
InhibitControl(HWND handle)
: m_handle(handle)
{
- block();
+ inhibitRedraw(true);
}
~InhibitControl()
{
- unblock();
+ inhibitRedraw(false);
}
- void block() { Control::inhibitRedraw(m_handle, true); }
- void unblock() { Control::inhibitRedraw(m_handle, false); }
-
private:
+ static std::map<HWND, InhibitControl *> s_lock;
+
+ void inhibitRedraw(const bool inhibit);
+
HWND m_handle;
};