reapack

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

commit 7c50a0b1a85717149189755c8d9f5cae104ebff6
parent 5962c2d0c43013ab8194730a7d0e0e9a3ba9ca7f
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 20 Jun 2016 16:42:54 -0700

listview: fix context menu position when using Shift+F10 on Windows

Diffstat:
Msrc/about.cpp | 5+++--
Msrc/about.hpp | 2+-
Msrc/browser.cpp | 12++++++------
Msrc/browser.hpp | 2+-
Msrc/dialog.cpp | 12+++++++-----
Msrc/listview.cpp | 28++++++++++++++++++++++++----
Msrc/listview.hpp | 4++--
Msrc/manager.cpp | 6+++---
Msrc/manager.hpp | 2+-
9 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -61,7 +61,8 @@ void About::onInit() m_packages->sortByColumn(0); m_packages->onActivate(bind(&About::packageHistory, this)); - m_packages->onContextMenu(bind(&About::fillContextMenu, this, placeholders::_1)); + m_packages->onContextMenu(bind(&About::fillContextMenu, + this, placeholders::_1, placeholders::_2)); m_installedFiles = getControl(IDC_LIST); @@ -110,7 +111,7 @@ void About::onCommand(const int id, int) } } -bool About::fillContextMenu(Menu &menu) const +bool About::fillContextMenu(Menu &menu, const int) const { if(m_packages->currentIndex() < 0) return false; diff --git a/src/about.hpp b/src/about.hpp @@ -44,7 +44,7 @@ protected: void onCommand(int, int) override; private: - bool fillContextMenu(Menu &) const; + bool fillContextMenu(Menu &, int index) const; void populate(); void updatePackages(); void updateInstalledFiles(); diff --git a/src/browser.cpp b/src/browser.cpp @@ -90,11 +90,12 @@ void Browser::onInit() m_list->onActivate([=] { history(m_list->itemUnderMouse()); }); m_list->onSelect([=] { setEnabled(m_list->hasSelection(), m_actionsBtn); }); - m_list->onContextMenu(bind(&Browser::fillContextMenu, this, placeholders::_1)); - m_list->sortByColumn(1); + m_list->onContextMenu(bind(&Browser::fillContextMenu, + this, placeholders::_1, placeholders::_2)); const auto config = m_reapack->config()->browser(); - m_list->restore(config->list, 1); + if(!m_list->restore(config->list, 1)) + m_list->sortByColumn(1); updateDisplayLabel(); refresh(); @@ -231,10 +232,9 @@ void Browser::onTimer(const int id) checkFilter(); } -bool Browser::fillContextMenu(Menu &menu) +bool Browser::fillContextMenu(Menu &menu, const int index) { - m_currentIndex = m_list->itemUnderMouse(); - + m_currentIndex = index; fillMenu(menu); return true; diff --git a/src/browser.hpp b/src/browser.hpp @@ -99,7 +99,7 @@ private: Entry makeEntry(const Package *, const Registry::Entry &) const; - bool fillContextMenu(Menu &); + bool fillContextMenu(Menu &, int index); void populate(); void transferActions(); bool match(const Entry &) const; diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -330,11 +330,8 @@ void Dialog::onNotify(LPNMHDR info, LPARAM lParam) it->second->onNotify(info, lParam); } -void Dialog::onContextMenu(HWND, int x, int y) +void Dialog::onContextMenu(HWND target, const int x, const int y) { - // target HWND is not always accurate: - // on OS X it does not match the listview when hovering the column header - for(const auto &pair : m_controls) { Control *ctrl = pair.second; @@ -349,7 +346,12 @@ void Dialog::onContextMenu(HWND, int x, int y) swap(rect.top, rect.bottom); #endif - if(y >= rect.top && y <= rect.bottom && x >= rect.left && x <= rect.right) { + // target HWND is not always accurate: + // on OS X it does not match the listview when hovering the column header + const bool inRect = y >= rect.top && y <= rect.bottom + && x >= rect.left && x <= rect.right; + + if(target == ctrl->handle() || inRect) { if(ctrl->onContextMenu(m_handle, x, y)) return; } diff --git a/src/listview.cpp b/src/listview.cpp @@ -265,12 +265,27 @@ bool ListView::onContextMenu(HWND dialog, int x, int y) { SetFocus(handle()); + int index = itemUnderMouse(); + +#ifdef ListView_GetItemPosition // unsuported by SWELL + if(x == 0xffff) { + index = max(0, currentIndex()); + + POINT point{}; + ListView_GetItemPosition(handle(), translate(index), &point); + ClientToScreen(handle(), &point); + x = point.x; + y = point.y; + } +#endif + Menu menu; - if(!m_onContextMenu(menu)) + if(!m_onContextMenu(menu, index)) return false; menu.show(x, y, dialog); + return true; } @@ -348,11 +363,14 @@ int ListView::adjustWidth(const int points) #endif } -void ListView::restore(const string &data, const int userVersion) +bool ListView::restore(const string &data, const int userVersion) { m_userVersion = userVersion; // for save() setExStyle(LVS_EX_HEADERDRAGDROP, true); // enable column reordering + if(data.empty()) + return false; + int col = -2; vector<int> order(m_columnSize); istringstream stream(data); @@ -372,13 +390,13 @@ void ListView::restore(const string &data, const int userVersion) right = stoi(second.c_str()); } catch(logic_error &) { - return; // data is invalid! aborting. + return false; // data is invalid! aborting. } switch(col) { case -2: // version if(left != userVersion || right != VERSION) - return; + return false; break; case -1: // sort if(left < m_columnSize) @@ -400,6 +418,8 @@ void ListView::restore(const string &data, const int userVersion) order[col] = col; ListView_SetColumnOrderArray(handle(), m_columnSize, &order[0]); + + return true; } string ListView::save() const diff --git a/src/listview.hpp b/src/listview.hpp @@ -36,7 +36,7 @@ public: typedef std::vector<auto_string> Row; typedef boost::signals2::signal<void ()> VoidSignal; - typedef boost::signals2::signal<bool (Menu &)> MenuSignal; + typedef boost::signals2::signal<bool (Menu &, int index)> MenuSignal; ListView(const Columns &, HWND handle); @@ -64,7 +64,7 @@ public: int columnCount() const { return m_columnSize; } bool empty() const { return rowCount() < 1; } - void restore(const std::string &, int userVersion); + bool restore(const std::string &, int userVersion); std::string save() const; void onSelect(const VoidSignal::slot_type &slot) { m_onSelect.connect(slot); } diff --git a/src/manager.cpp b/src/manager.cpp @@ -52,7 +52,8 @@ void Manager::onInit() }); m_list->onActivate([=] { about(m_list->currentIndex()); }); - m_list->onContextMenu(bind(&Manager::fillContextMenu, this, placeholders::_1)); + m_list->onContextMenu(bind(&Manager::fillContextMenu, + this, placeholders::_1, placeholders::_2)); refresh(); @@ -135,9 +136,8 @@ void Manager::onCommand(const int id, int) } } -bool Manager::fillContextMenu(Menu &menu) const +bool Manager::fillContextMenu(Menu &menu, const int index) const { - const int index = m_list->itemUnderMouse(); const Remote &remote = getRemote(index); if(!remote) { diff --git a/src/manager.hpp b/src/manager.hpp @@ -47,7 +47,7 @@ private: ListView::Row makeRow(const Remote &) const; Remote getRemote(int index) const; - bool fillContextMenu(Menu &) const; + bool fillContextMenu(Menu &, int index) const; void setRemoteEnabled(bool); bool isRemoteEnabled(const Remote &) const; void uninstall();