reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit d5ba3d78e265548c23843ba5cafde2bda748db78
parent 5eb0cde59a5ee9a83ba949e6e13b31999a00f40b
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Wed, 15 Jan 2020 21:01:24 -0500

optimize mass selecting/filtering in listviews on macOS

WM_SETREDRAW was added to SWELL for Cocoa ListViews in justinfrankel/WDL@7b09c43c4b6cc118f8c6a0355e7d0f0fa93664f9

Diffstat:
Msrc/control.cpp | 18+++++++++++-------
Msrc/control.hpp | 24++++--------------------
Msrc/listview.cpp | 12++++++++++++
Msrc/listview.hpp | 4++--
4 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/control.cpp b/src/control.cpp @@ -17,13 +17,16 @@ #include "control.hpp" -std::map<HWND, InhibitControl *> InhibitControl::s_lock; +#include <map> -void InhibitControl::inhibitRedraw(const bool inhibit) +void InhibitControl::setRedraw(const bool inhibit) { -#ifdef _WIN32 - if(s_lock.count(m_handle)) { - if(inhibit || s_lock[m_handle] != this) + static std::map<HWND, InhibitControl *> s_lock; + + auto owner = s_lock.find(m_handle); + + if(owner != s_lock.end()) { + if(inhibit || owner->second != this) return; } else if(!inhibit) @@ -34,9 +37,10 @@ void InhibitControl::inhibitRedraw(const bool inhibit) if(inhibit) s_lock.insert({m_handle, this}); else { - s_lock.erase(m_handle); + s_lock.erase(owner); +#ifdef _WIN32 RedrawWindow(m_handle, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); - } #endif + } } diff --git a/src/control.hpp b/src/control.hpp @@ -18,8 +18,6 @@ #ifndef REAPACK_CONTROL_HPP #define REAPACK_CONTROL_HPP -#include <map> - #ifdef _WIN32 # include <windows.h> #else @@ -47,26 +45,12 @@ private: class InhibitControl { public: - InhibitControl(Control *ctrl) : m_handle(ctrl->handle()) - { - inhibitRedraw(true); - } - - InhibitControl(HWND handle) - : m_handle(handle) - { - inhibitRedraw(true); - } - - ~InhibitControl() - { - inhibitRedraw(false); - } + InhibitControl(Control *ctrl) : InhibitControl(ctrl->handle()) {} + InhibitControl(HWND handle) : m_handle(handle) { setRedraw(true); } + ~InhibitControl() { setRedraw(false); } private: - static std::map<HWND, InhibitControl *> s_lock; - - void inhibitRedraw(const bool inhibit); + void setRedraw(const bool inhibit); HWND m_handle; }; diff --git a/src/listview.cpp b/src/listview.cpp @@ -342,6 +342,18 @@ void ListView::setSelected(const int index, const bool select) select ? LVIS_SELECTED : 0, LVIS_SELECTED); } +void ListView::selectAll() +{ + InhibitControl inhibit(this); + select(-1); +} + +void ListView::unselectAll() +{ + InhibitControl inhibit(this); + unselect(-1); +} + int ListView::visibleRowCount() const { return ListView_GetItemCount(handle()); diff --git a/src/listview.hpp b/src/listview.hpp @@ -130,8 +130,8 @@ public: void setSelected(int index, bool select); void select(int index) { setSelected(index, true); } void unselect(int index) { setSelected(index, false); } - void selectAll() { select(-1); } - void unselectAll() { unselect(-1); } + void selectAll(); + void unselectAll(); int selectionSize() const; bool hasSelection() const { return selectionSize() > 0; } std::vector<int> selection(bool sort = true) const;