https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d2626f0c2a4d39a5d3f08…
commit d2626f0c2a4d39a5d3f08594b422f8042003ce33
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Wed Jan 9 22:27:41 2019 +0100
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Thu Jan 10 19:55:39 2019 +0100
[WIN32K:NTUSER] Find a better position for a menu that is off-screen
Previously, we would just stick the menu on the edge of the screen.
We should actually try to flip the menu around the point of origin,
and only when that fails move it to the edge of the screen.
CORE-15001
CORE-9037
---
win32ss/user/ntuser/menu.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/win32ss/user/ntuser/menu.c b/win32ss/user/ntuser/menu.c
index 0dc6bac375..b8177594df 100644
--- a/win32ss/user/ntuser/menu.c
+++ b/win32ss/user/ntuser/menu.c
@@ -2911,9 +2911,22 @@ static BOOL FASTCALL MENU_ShowPopup(PWND pwndOwner, PMENU menu,
UINT id, UINT fl
x -= width - xanchor;
if( x + width > monitor->rcMonitor.right)
- x = monitor->rcMonitor.right - width;
+ {
+ /* If we would flip around our origin, would we go off screen on the other
side? */
+ if (x - width < monitor->rcMonitor.left)
+ x = monitor->rcMonitor.right - width;
+ else
+ x -= width;
+ }
+ }
+ if( x < monitor->rcMonitor.left )
+ {
+ /* If we would flip around our origin, would we go off screen on the other side?
*/
+ if (x + width > monitor->rcMonitor.right)
+ x = monitor->rcMonitor.left;
+ else
+ x += width;
}
- if( x < monitor->rcMonitor.left ) x = monitor->rcMonitor.left;
if( y + height > monitor->rcMonitor.bottom)
{
@@ -2921,9 +2934,22 @@ static BOOL FASTCALL MENU_ShowPopup(PWND pwndOwner, PMENU menu,
UINT id, UINT fl
y -= height + yanchor;
if( y + height > monitor->rcMonitor.bottom)
- y = monitor->rcMonitor.bottom - height;
+ {
+ /* If we would flip around our origin, would we go off screen on the other
side? */
+ if (y - height < monitor->rcMonitor.top)
+ y = monitor->rcMonitor.bottom - height;
+ else
+ y -= height;
+ }
+ }
+ if( y < monitor->rcMonitor.top )
+ {
+ /* If we would flip around our origin, would we go off screen on the other side?
*/
+ if (y + height > monitor->rcMonitor.bottom)
+ y = monitor->rcMonitor.top;
+ else
+ y += height;
}
- if( y < monitor->rcMonitor.top ) y = monitor->rcMonitor.top;
pWnd = ValidateHwndNoErr( menu->hWnd );