reapack

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

commit 89e898fc8af5598ca42e3731f7f82ae538de8a39
parent ae718b3c446f53282def59fef3749c289d520165
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 26 Jun 2016 15:12:51 -0700

dialog: don't restore outside of the screen bounds

Diffstat:
Msrc/dialog.cpp | 29++++++++++++++++++++---------
Msrc/dialog.hpp | 1+
2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -213,19 +213,15 @@ void Dialog::center() GetWindowRect(m_handle, &dialogRect); GetWindowRect(m_parent, &parentRect); - const int screenWidth = GetSystemMetrics(SM_CXSCREEN); const int parentWidth = parentRect.right - parentRect.left; const int dialogWidth = dialogRect.right - dialogRect.left; - int left = (parentWidth - dialogWidth) / 2; - left = min(left + (int)parentRect.left, screenWidth - dialogWidth); + left += parentRect.left; - const int screenHeight = GetSystemMetrics(SM_CYSCREEN); const int parentHeight = parentRect.bottom - parentRect.top; const int dialogHeight = dialogRect.bottom - dialogRect.top; - int top = (parentHeight - dialogHeight) / 2; - top = min(top + (int)parentRect.top, screenHeight - dialogHeight); + top += parentRect.top; const int verticalBias = (int)(parentHeight * 0.1); @@ -235,7 +231,20 @@ void Dialog::center() top += verticalBias; // according to SWELL, top means bottom. #endif - SetWindowPos(m_handle, HWND_TOP, max(0, left), max(0, top), + boundedMove(left, top); +} + +void Dialog::boundedMove(int x, int y) +{ + RECT rect; + GetWindowRect(m_handle, &rect); + + const int width = rect.right - rect.left, height = rect.bottom - rect.top; + + x = min(max(0, x), GetSystemMetrics(SM_CXSCREEN) - width); + y = min(max(0, y), GetSystemMetrics(SM_CYSCREEN) - height); + + SetWindowPos(m_handle, nullptr, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } @@ -338,10 +347,12 @@ void Dialog::restore(Serializer::Data &data) const auto &pos = *it++; const auto &size = *it++; - SetWindowPos(m_handle, HWND_TOP, pos[0], pos[1], - size[0], size[1], SWP_NOZORDER); + SetWindowPos(m_handle, nullptr, 0, 0, + size[0], size[1], SWP_NOZORDER | SWP_NOMOVE); onResize(); + boundedMove(pos[0], pos[1]); + data.erase(data.begin(), it); } diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -99,6 +99,7 @@ public: void close(INT_PTR = 0); void center(); + void boundedMove(int x, int y); bool hasFocus() const; void setFocus(); int startTimer(int elapse, int id = 0);