Skip to content

Commit 6a2b931

Browse files
amartya4256HeikoKlare
authored andcommitted
Fill unpainted region in Window in win32 #62
This commit contributes to filling the unpainted region unoccupied by the menu bar and the client area in a window, including the MenuItem hover overlay remains in the area after hovering over them as sometimes MenuItems have their height more than the height of the menu bar, leading to painting in the unmanaged region - hence, contributing to an artifact line. contributes to #62 and #127
1 parent b836500 commit 6a2b931

File tree

1 file changed

+42
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+42
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java

+42
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,37 @@ void overpaintMenuBorder () {
23032303
OS.ReleaseDC (handle, dc);
23042304
}
23052305

2306+
/**
2307+
* Fills the remaining area which are not painted by MenuBar and ClientArea
2308+
* inside the shell window.
2309+
*/
2310+
private void fillUnpaintedRegionInShellWindow() {
2311+
if (menuBar == null) return;
2312+
Rectangle clientArea = getClientRectInWindow();
2313+
Rectangle menuArea = menuBar.getBounds();
2314+
Rectangle windowBounds = getBoundsInPixels();
2315+
menuArea.x = menuArea.x - windowBounds.x;
2316+
menuArea.y = menuArea .y - windowBounds.y;
2317+
long windowRegion = OS.CreateRectRgn (0, 0, windowBounds.width, windowBounds.height);
2318+
long menuRegion = OS.CreateRectRgn (menuArea.x, menuArea.y, menuArea.x + menuArea.width, menuArea.y + menuArea.height);
2319+
long clientRegion = OS.CreateRectRgn (clientArea.x, clientArea.y, clientArea.x + clientArea.width, clientArea.y + clientArea.height);
2320+
OS.CombineRgn (windowRegion, windowRegion, menuRegion, OS.RGN_DIFF);
2321+
OS.CombineRgn (windowRegion, windowRegion, clientRegion, OS.RGN_DIFF);
2322+
OS.DeleteObject (menuRegion);
2323+
OS.DeleteObject (clientRegion);
2324+
int dwRop = display.useDarkModeExplorerTheme ? OS.BLACKNESS : OS.PATCOPY;
2325+
long dc = OS.GetWindowDC (handle);
2326+
POINT pt = null;
2327+
pt = new POINT();
2328+
OS.GetWindowOrgEx(dc, pt);
2329+
OS.OffsetRgn(windowRegion, -pt.x, -pt.y);
2330+
OS.SelectClipRgn(dc, windowRegion);
2331+
OS.OffsetRgn(windowRegion, pt.x, pt.y);
2332+
OS.PatBlt(dc, 0, 0, windowBounds.width, windowBounds.height, dwRop);
2333+
OS.DeleteObject (windowRegion);
2334+
OS.ReleaseDC (handle, dc);
2335+
}
2336+
23062337
@Override
23072338
long windowProc (long hwnd, int msg, long wParam, long lParam) {
23082339
if (handle == 0) return 0;
@@ -2347,6 +2378,7 @@ long windowProc (long hwnd, int msg, long wParam, long lParam) {
23472378
{
23482379
long ret = super.windowProc (hwnd, msg, wParam, lParam);
23492380
overpaintMenuBorder();
2381+
fillUnpaintedRegionInShellWindow();
23502382
return ret;
23512383
}
23522384
}
@@ -2534,6 +2566,16 @@ LRESULT WM_NCHITTEST (long wParam, long lParam) {
25342566
if (hittest == OS.HTMENU) hittest = OS.HTBORDER;
25352567
return new LRESULT (hittest);
25362568
}
2569+
/*
2570+
* In quarter zoom levels, sometimes the MenuItem in the MenuBar has more height
2571+
* than the MenuBar, which leads to a gap between the client area and the menu
2572+
* bar leaving it unpainted and unmanaged. On hovering over the MenuItem, it
2573+
* leaves the gap area painted with remains of the MenuItem hover overlay. The
2574+
* event WM_NCHITTEST is sent on hovering over MenuItem and hence the overlay
2575+
* remains can be cleaned by calling
2576+
* fillUnpaintedRegionBetweenMenuBarAndClientArea on this event.
2577+
*/
2578+
fillUnpaintedRegionInShellWindow();
25372579
return null;
25382580
}
25392581

0 commit comments

Comments
 (0)