diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java | 449 |
1 files changed, 279 insertions, 170 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index 4d5c2d3294..8be1e4314e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -123,16 +123,16 @@ import org.eclipse.swt.internal.win32.*; public class Shell extends Decorations { Menu activeMenu; ToolTip [] toolTips; - long /*int*/ hIMC, hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle, menuItemToolTipHandle; - int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT; - long /*int*/ [] brushes; + long hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle, menuItemToolTipHandle; + int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT, maxWidth = SWT.DEFAULT, maxHeight = SWT.DEFAULT; + long [] brushes; boolean showWithParent, fullScreen, wasMaximized, modified, center; String toolTitle, balloonTitle; - long /*int*/ toolIcon, balloonIcon; - long /*int*/ windowProc; + long toolIcon, balloonIcon; + long windowProc; Control lastActive; - static /*final*/ long /*int*/ ToolTipProc; - static final long /*int*/ DialogProc; + static /*final*/ long ToolTipProc; + static final long DialogProc; static final TCHAR DialogClass = new TCHAR (0, "#32770", true); final static int [] SYSTEM_COLORS = { OS.COLOR_BTNFACE, @@ -279,7 +279,7 @@ public Shell (Display display, int style) { this (display, null, style, 0, false); } -Shell (Display display, Shell parent, int style, long /*int*/ handle, boolean embedded) { +Shell (Display display, Shell parent, int style, long handle, boolean embedded) { super (); checkSubclass (); if (display == null) display = Display.getCurrent (); @@ -398,7 +398,7 @@ public Shell (Shell parent, int style) { * * @noreference This method is not intended to be referenced by clients. */ -public static Shell win32_new (Display display, long /*int*/ handle) { +public static Shell win32_new (Display display, long handle) { return new Shell (display, null, SWT.NO_TRIM, handle, true); } @@ -421,7 +421,7 @@ public static Shell win32_new (Display display, long /*int*/ handle) { * * @since 3.3 */ -public static Shell internal_new (Display display, long /*int*/ handle) { +public static Shell internal_new (Display display, long handle) { return new Shell (display, null, SWT.NO_TRIM, handle, false); } @@ -473,13 +473,13 @@ public void addShellListener (ShellListener listener) { addListener (SWT.Deactivate, typedListener); } -long /*int*/ balloonTipHandle () { +long balloonTipHandle () { if (balloonTipHandle == 0) createBalloonTipHandle (); return balloonTipHandle; } @Override -long /*int*/ callWindowProc (long /*int*/ hwnd, int msg, long /*int*/ wParam, long /*int*/ lParam) { +long callWindowProc (long hwnd, int msg, long wParam, long lParam) { if (handle == 0) return 0; if (hwnd == toolTipHandle || hwnd == balloonTipHandle || hwnd == menuItemToolTipHandle) { return OS.CallWindowProc (ToolTipProc, hwnd, msg, wParam, lParam); @@ -575,6 +575,24 @@ void createBalloonTipHandle () { OS.SetWindowLongPtr (balloonTipHandle, OS.GWLP_WNDPROC, display.windowProc); } +void setTitleColoring() { + int attributeID = 0; + if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_2004) { + // Documented since build 20348, but was already present since build 19041 + final int DWMWA_USE_IMMERSIVE_DARK_MODE = 20; + attributeID = DWMWA_USE_IMMERSIVE_DARK_MODE; + } else if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1809) { + // Undocumented value + attributeID = 19; + } else { + // Not supported + return; + } + + int[] value = new int[] {1}; + OS.DwmSetWindowAttribute (handle, attributeID, value, 4); +} + @Override void createHandle () { boolean embedded = handle != 0 && (state & FOREIGN_HANDLE) == 0; @@ -607,6 +625,10 @@ void createHandle () { // if ((style & SWT.ON_TOP) != 0) display.lockActiveWindow = false; if (!embedded) { + if (display.useShellTitleColoring) { + setTitleColoring(); + } + int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); bits &= ~(OS.WS_OVERLAPPED | OS.WS_CAPTION); bits |= OS.WS_POPUP; @@ -625,10 +647,6 @@ void createHandle () { int flags = OS.SWP_DRAWFRAME | OS.SWP_NOMOVE | OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE; OS.SetWindowPos (handle, 0, 0, 0, 0, 0, flags); } - if (OS.IsDBLocale) { - hIMC = OS.ImmCreateContext (); - if (hIMC != 0) OS.ImmAssociateContext (handle, hIMC); - } } void createMenuItemToolTipHandle() { @@ -659,8 +677,8 @@ void createToolTipHandle () { toolTipHandle = createToolTipHandle (handle); } -long /*int*/ createToolTipHandle (long /*int*/ parent) { - long /*int*/ toolTipHandle = OS.CreateWindowEx ( +long createToolTipHandle (long parent) { + long toolTipHandle = OS.CreateWindowEx ( 0, new TCHAR (0, OS.TOOLTIPS_CLASS, true), null, @@ -712,36 +730,6 @@ void destroyToolTip (ToolTip toolTip) { void destroyWidget () { fixActiveShell (); super.destroyWidget (); - - /* - * Destroy context only after the controls that used it were destroyed. - * Technically, that shouldn't be necessary, because 'Control.releaseWidget' - * clears up association by calling 'OS.ImmAssociateContext (handle, 0)'. - * However, there's a bug in Windows 10 (see bug 526758), and this is the workaround. - */ - if (OS.IsDBLocale) { - if (hIMC != 0) OS.ImmDestroyContext (hIMC); - } -} - -@Override -public void dispose () { - /* - * This code is intentionally commented. On some - * platforms, the owner window is repainted right - * away when a dialog window exits. This behavior - * is currently unspecified. - */ -// /* -// * Note: It is valid to attempt to dispose a widget -// * more than once. If this happens, fail silently. -// */ -// if (!isValidWidget ()) return; -// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); -// Display oldDisplay = display; - super.dispose (); - // widget is disposed at this point -// if (oldDisplay != null) oldDisplay.update (); } @Override @@ -759,18 +747,17 @@ void enableWidget (boolean enabled) { } @Override -long /*int*/ findBrush (long /*int*/ value, int lbStyle) { +long findBrush (long value, int lbStyle) { if (lbStyle == OS.BS_SOLID) { - for (int i=0; i<SYSTEM_COLORS.length; i++) { - if (value == OS.GetSysColor (SYSTEM_COLORS [i])) { - return OS.GetSysColorBrush (SYSTEM_COLORS [i]); + for (int element : SYSTEM_COLORS) { + if (value == OS.GetSysColor (element)) { + return OS.GetSysColorBrush (element); } } } - if (brushes == null) brushes = new long /*int*/ [BRUSHES_SIZE]; + if (brushes == null) brushes = new long [BRUSHES_SIZE]; LOGBRUSH logBrush = new LOGBRUSH (); - for (int i=0; i<brushes.length; i++) { - long /*int*/ hBrush = brushes [i]; + for (long hBrush : brushes) { if (hBrush == 0) break; OS.GetObject (hBrush, LOGBRUSH.sizeof, logBrush); switch (logBrush.lbStyle) { @@ -787,12 +774,12 @@ long /*int*/ findBrush (long /*int*/ value, int lbStyle) { } } int length = brushes.length; - long /*int*/ hBrush = brushes [--length]; + long hBrush = brushes [--length]; if (hBrush != 0) OS.DeleteObject (hBrush); System.arraycopy (brushes, 0, brushes, 1, length); switch (lbStyle) { case OS.BS_SOLID: - hBrush = OS.CreateSolidBrush ((int)/*64*/value); + hBrush = OS.CreateSolidBrush ((int)value); break; case OS.BS_PATTERN: hBrush = OS.CreatePatternBrush (value); @@ -832,7 +819,7 @@ void fixActiveShell () { * application). The fix is to activate the disabled parent * shell before disposing or hiding the active shell. */ - long /*int*/ hwndParent = OS.GetParent (handle); + long hwndParent = OS.GetParent (handle); if (hwndParent != 0 && handle == OS.GetActiveWindow ()) { if (!OS.IsWindowEnabled (hwndParent) && OS.IsWindowVisible (hwndParent)) { OS.SetActiveWindow (hwndParent); @@ -960,13 +947,13 @@ ToolTip getCurrentToolTip () { return null; } -ToolTip getCurrentToolTip (long /*int*/ hwndToolTip) { +ToolTip getCurrentToolTip (long hwndToolTip) { if (hwndToolTip == 0) return null; if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) { TOOLINFO lpti = new TOOLINFO (); lpti.cbSize = TOOLINFO.sizeof; if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) { - if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) return findToolTip ((int)/*64*/lpti.uId); + if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) return findToolTip ((int)lpti.uId); } } return null; @@ -1017,7 +1004,7 @@ public boolean getFullScreen () { public int getImeInputMode () { checkWidget (); if (!OS.IsDBLocale) return 0; - long /*int*/ hIMC = OS.ImmGetContext (handle); + long hIMC = OS.ImmGetContext (handle); int [] lpfdwConversion = new int [1], lpfdwSentence = new int [1]; boolean open = OS.ImmGetOpenStatus (hIMC); if (open) open = OS.ImmGetConversionStatus (hIMC, lpfdwConversion, lpfdwSentence); @@ -1045,6 +1032,47 @@ public boolean getMaximized () { } /** + * Returns a point describing the maximum receiver's size. The + * x coordinate of the result is the maximum width of the receiver. + * The y coordinate of the result is the maximum height of the + * receiver. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.116 + */ +public Point getMaximumSize () { + checkWidget (); + return DPIUtil.autoScaleDown(getMaximumSizeInPixels()); +} + +Point getMaximumSizeInPixels () { + int width = Math.min (Integer.MAX_VALUE, maxWidth); + int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; + if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { + width = Math.min (width, OS.GetSystemMetrics (OS.SM_CXMAXTRACK)); + } + int height = Math.min (Integer.MAX_VALUE, maxHeight); + if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { + if ((style & SWT.RESIZE) != 0) { + height = Math.min (height, OS.GetSystemMetrics (OS.SM_CYMAXTRACK)); + } else { + RECT rect = new RECT (); + int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); + int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); + OS.AdjustWindowRectEx (rect, bits1, false, bits2); + height = Math.min (height, rect.bottom - rect.top); + } + } + return new Point (width, height); +} + +/** * Returns a point describing the minimum receiver's size. The * x coordinate of the result is the minimum width of the receiver. * The y coordinate of the result is the minimum height of the @@ -1153,22 +1181,22 @@ public Shell [] getShells () { checkWidget (); int count = 0; Shell [] shells = display.getShells (); - for (int i=0; i<shells.length; i++) { - Control shell = shells [i]; + for (Shell activeshell : shells) { + Control shell = activeshell; do { - shell = shell.parent; + shell = shell.getParent (); } while (shell != null && shell != this); if (shell == this) count++; } int index = 0; Shell [] result = new Shell [count]; - for (int i=0; i<shells.length; i++) { - Control shell = shells [i]; + for (Shell activeshell : shells) { + Control shell = activeshell; do { - shell = shell.parent; + shell = shell.getParent (); } while (shell != null && shell != this); if (shell == this) { - result [index++] = shells [i]; + result [index++] = activeshell; } } return result; @@ -1212,7 +1240,7 @@ public boolean isVisible () { return getVisible (); } -long /*int*/ hwndMDIClient () { +long hwndMDIClient () { if (hwndMDIClient == 0) { int widgetStyle = OS.MDIS_ALLCHILDSTYLES | OS.WS_CHILD | OS.WS_CLIPCHILDREN | OS.WS_CLIPSIBLINGS; hwndMDIClient = OS.CreateWindowEx ( @@ -1230,7 +1258,7 @@ long /*int*/ hwndMDIClient () { return hwndMDIClient; } -long /*int*/ menuItemToolTipHandle () { +long menuItemToolTipHandle () { if (menuItemToolTipHandle == 0) createMenuItemToolTipHandle (); return menuItemToolTipHandle; } @@ -1325,8 +1353,8 @@ void register () { void releaseBrushes () { if (brushes != null) { - for (int i=0; i<brushes.length; i++) { - if (brushes [i] != 0) OS.DeleteObject (brushes [i]); + for (long brush : brushes) { + if (brush != 0) OS.DeleteObject (brush); } } brushes = null; @@ -1334,16 +1362,13 @@ void releaseBrushes () { @Override void releaseChildren (boolean destroy) { - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; + for (Shell shell : getShells ()) { if (shell != null && !shell.isDisposed ()) { shell.release (false); } } if (toolTips != null) { - for (int i=0; i<toolTips.length; i++) { - ToolTip toolTip = toolTips [i]; + for (ToolTip toolTip : toolTips) { if (toolTip != null && !toolTip.isDisposed ()) { toolTip.release (false); } @@ -1371,7 +1396,7 @@ void releaseWidget () { activeMenu = null; display.clearModal (this); if (lpstrTip != 0) { - long /*int*/ hHeap = OS.GetProcessHeap (); + long hHeap = OS.GetProcessHeap (); OS.HeapFree (hHeap, 0, lpstrTip); } lpstrTip = 0; @@ -1421,36 +1446,19 @@ public void requestLayout () { @Override void reskinChildren (int flags) { - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; + for (Shell shell : getShells ()) { if (shell != null) shell.reskin (flags); } if (toolTips != null) { - for (int i=0; i<toolTips.length; i++) { - ToolTip toolTip = toolTips [i]; + for (ToolTip toolTip : toolTips) { if (toolTip != null) toolTip.reskin (flags); } } super.reskinChildren (flags); } -LRESULT selectPalette (long /*int*/ hPalette) { - long /*int*/ hDC = OS.GetDC (handle); - long /*int*/ hOld = OS.SelectPalette (hDC, hPalette, false); - int result = OS.RealizePalette (hDC); - if (result > 0) { - OS.InvalidateRect (handle, null, true); - } else { - OS.SelectPalette (hDC, hOld, true); - OS.RealizePalette (hDC); - } - OS.ReleaseDC (handle, hDC); - return (result > 0) ? LRESULT.ONE : LRESULT.ZERO; -} - @Override -boolean sendKeyEvent (int type, int msg, long /*int*/ wParam, long /*int*/ lParam, Event event) { +boolean sendKeyEvent (int type, int msg, long wParam, long lParam, Event event) { if (!isEnabled () || !isActive ()) return false; return super.sendKeyEvent (type, msg, wParam, lParam, event); } @@ -1594,8 +1602,9 @@ public void setEnabled (boolean enabled) { * to either the maximized or normal states. * <p> * Note: The result of intermixing calls to <code>setFullScreen(true)</code>, - * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will - * vary by platform. Typically, the behavior will match the platform user's + * <code>setMaximized(true)</code>, <code>setMinimized(true)</code> and + * <code>setMaximumSize</code> will vary by platform. + * Typically, the behavior will match the platform user's * expectations, but not always. This should be avoided if possible. * </p> * @@ -1626,6 +1635,9 @@ public void setFullScreen (boolean fullScreen) { } if (fullScreen) wasMaximized = getMaximized (); boolean visible = isVisible (); + if (!visible && !wasMaximized) { + swFlags = stateFlags; + } OS.SetWindowLong (handle, OS.GWL_STYLE, styleFlags); if (wasMaximized) { OS.ShowWindow (handle, OS.SW_HIDE); @@ -1656,7 +1668,7 @@ public void setImeInputMode (int mode) { checkWidget (); if (!OS.IsDBLocale) return; boolean imeOn = mode != SWT.NONE; - long /*int*/ hIMC = OS.ImmGetContext (handle); + long hIMC = OS.ImmGetContext (handle); OS.ImmSetOpenStatus (hIMC, imeOn); if (imeOn) { int [] lpfdwConversion = new int [1], lpfdwSentence = new int [1]; @@ -1674,7 +1686,7 @@ public void setImeInputMode (int mode) { } boolean fullShape = (mode & SWT.DBCS) != 0; if ((mode & SWT.NATIVE) != 0) { - long /*int*/ hkl = OS.GetKeyboardLayout (0); + long hkl = OS.GetKeyboardLayout (0); int langid = OS.PRIMARYLANGID (OS.LOWORD (hkl)); if (langid == OS.LANG_JAPANESE) { fullShape = true; @@ -1699,6 +1711,85 @@ public void setImeInputMode (int mode) { } /** + * Sets the receiver's maximum size to the size specified by the arguments. + * If the new maximum size is smaller than the current size of the receiver, + * the receiver is resized to the new maximum size. + * <p> + * Note: The result of intermixing calls to <code>setMaximumSize</code> and + * <code>setFullScreen(true)</code> will vary by platform. + * Typically, the behavior will match the platform user's + * expectations, but not always. This should be avoided if possible. + * </p> + * @param width the new maximum width for the receiver + * @param height the new maximum height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.116 + */ +public void setMaximumSize (int width, int height) { + checkWidget (); + setMaximumSizeInPixels(DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height)); +} + +/** + * Sets the receiver's maximum size to the size specified by the argument. + * If the new maximum size is smaller than the current size of the receiver, + * the receiver is resized to the new maximum size. + * <p> + * Note: The result of intermixing calls to <code>setMaximumSize</code> and + * <code>setFullScreen(true)</code> will vary by platform. + * Typically, the behavior will match the platform user's + * expectations, but not always. This should be avoided if possible. + * </p> + * @param size the new maximum size for the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.116 + */ +public void setMaximumSize (Point size) { + checkWidget (); + if (size == null) error (SWT.ERROR_NULL_ARGUMENT); + size = DPIUtil.autoScaleUp(size); + setMaximumSizeInPixels(size.x, size.y); +} + +void setMaximumSizeInPixels (int width, int height) { + int widthLimit = 0, heightLimit = 0; + int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; + if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { + widthLimit = OS.GetSystemMetrics (OS.SM_CXMAXTRACK); + if ((style & SWT.RESIZE) != 0) { + heightLimit = OS.GetSystemMetrics (OS.SM_CYMAXTRACK); + } else { + RECT rect = new RECT (); + int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); + int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); + OS.AdjustWindowRectEx (rect, bits1, false, bits2); + heightLimit = rect.bottom - rect.top; + } + } + maxWidth = Math.min (widthLimit, width); + maxHeight = Math.min (heightLimit, height); + Point size = getSizeInPixels (); + int newWidth = Math.min (size.x, maxWidth); + int newHeight = Math.min (size.y, maxHeight); + if (maxWidth >= widthLimit) maxWidth = SWT.DEFAULT; + if (maxHeight >= heightLimit) maxHeight = SWT.DEFAULT; + if (newWidth != size.x || newHeight != size.y) setSizeInPixels (newWidth, newHeight); +} + +/** * Sets the receiver's minimum size to the size specified by the arguments. * If the new minimum size is larger than the current size of the receiver, * the receiver is resized to the new minimum size. @@ -1785,7 +1876,7 @@ public void setModified (boolean modified) { } void setItemEnabled (int cmd, boolean enabled) { - long /*int*/ hMenu = OS.GetSystemMenu (handle, false); + long hMenu = OS.GetSystemMenu (handle, false); if (hMenu == 0) return; int flags = OS.MF_ENABLED; if (!enabled) flags = OS.MF_DISABLED | OS.MF_GRAYED; @@ -1832,21 +1923,22 @@ public void setRegion (Region region) { super.setRegion (region); } -void setToolTipText (long /*int*/ hwnd, String text) { +void setToolTipText (long hwnd, String text) { TOOLINFO lpti = new TOOLINFO (); lpti.cbSize = TOOLINFO.sizeof; lpti.hwnd = handle; lpti.uId = hwnd; - long /*int*/ hwndToolTip = toolTipHandle (); + long hwndToolTip = toolTipHandle (); + maybeEnableDarkSystemTheme(hwndToolTip); if (text == null) { OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, lpti); - } else { - if (OS.SendMessage (hwndToolTip, OS.TTM_GETTOOLINFO, 0, lpti) != 0) { + } else if (OS.SendMessage (hwndToolTip, OS.TTM_GETTOOLINFO, 0, lpti) == 0) { + lpti.uFlags = OS.TTF_IDISHWND | OS.TTF_SUBCLASS; + lpti.lpszText = OS.LPSTR_TEXTCALLBACK; + OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti); + } else if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) { + if (lpti.uId == hwnd) { OS.SendMessage (hwndToolTip, OS.TTM_UPDATE, 0, 0); - } else { - lpti.uFlags = OS.TTF_IDISHWND | OS.TTF_SUBCLASS; - lpti.lpszText = OS.LPSTR_TEXTCALLBACK; - OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti); } } } @@ -1859,7 +1951,7 @@ void setToolTipText (NMTTDISPINFO lpnmtdi, char [] buffer) { * shell trimmings. */ if (!hasCursor ()) return; - long /*int*/ hHeap = OS.GetProcessHeap (); + long hHeap = OS.GetProcessHeap (); if (lpstrTip != 0) OS.HeapFree (hHeap, 0, lpstrTip); int byteCount = buffer.length * 2; lpstrTip = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); @@ -1867,7 +1959,7 @@ void setToolTipText (NMTTDISPINFO lpnmtdi, char [] buffer) { lpnmtdi.lpszText = lpstrTip; } -void setToolTipTitle (long /*int*/ hwndToolTip, String text, int icon) { +void setToolTipTitle (long hwndToolTip, String text, int icon) { /* * Bug in Windows. For some reason, when TTM_SETTITLE * is used to set the title of a tool tip, Windows leaks @@ -1940,7 +2032,7 @@ public void setVisible (boolean visible) { bringToTop (); if (isDisposed ()) return; } - long /*int*/ hwndShell = OS.GetActiveWindow (); + long hwndShell = OS.GetActiveWindow (); if (hwndShell == 0) { if (parent != null) hwndShell = parent.handle; } @@ -1981,7 +2073,7 @@ public void setVisible (boolean visible) { /* Make the foreign window parent appear in the task bar */ if (visible) { if (parent != null && (parent.state & FOREIGN_HANDLE) != 0) { - long /*int*/ hwndParent = parent.handle; + long hwndParent = parent.handle; int style = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE); if ((style & OS.WS_EX_TOOLWINDOW) != 0) { OS.SetWindowLong (hwndParent, OS.GWL_EXSTYLE, style & ~OS.WS_EX_TOOLWINDOW); @@ -2001,7 +2093,7 @@ public void setVisible (boolean visible) { void subclass () { super.subclass (); if (ToolTipProc != 0) { - long /*int*/ newProc = display.windowProc; + long newProc = display.windowProc; if (toolTipHandle != 0) { OS.SetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC, newProc); } @@ -2014,7 +2106,7 @@ void subclass () { } } -long /*int*/ toolTipHandle () { +long toolTipHandle () { if (toolTipHandle == 0) createToolTipHandle (); return toolTipHandle; } @@ -2064,7 +2156,7 @@ CREATESTRUCT widgetCreateStruct () { } @Override -long /*int*/ widgetParent () { +long widgetParent () { if (handle != 0) return handle; return parent != null ? parent.handle : 0; } @@ -2103,7 +2195,7 @@ TCHAR windowClass () { } @Override -long /*int*/ windowProc () { +long windowProc () { if (windowProc != 0) return windowProc; if ((style & SWT.TOOL) != 0) { int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE; @@ -2112,8 +2204,39 @@ long /*int*/ windowProc () { return parent != null ? DialogProc : super.windowProc (); } +Rectangle getClientRectInWindow () { + RECT windowRect = new RECT (); + OS.GetWindowRect (handle, windowRect); + + POINT clientWindowLT = new POINT (); + OS.ClientToScreen (handle, clientWindowLT); + clientWindowLT.x -= windowRect.left; + clientWindowLT.y -= windowRect.top; + + RECT clientRect = new RECT (); + OS.GetClientRect (handle, clientRect); + + return new Rectangle( + clientWindowLT.x + clientRect.left, + clientWindowLT.y + clientRect.top, + clientRect.right - clientRect.left, + clientRect.bottom - clientRect.top); +} + +void overpaintMenuBorder () { + if ((menuBar == null) || (display.menuBarBorderPen == 0)) return; + + Rectangle clientArea = getClientRectInWindow(); + long dc = OS.GetWindowDC (handle); + long oldPen = OS.SelectObject (dc, display.menuBarBorderPen); + OS.MoveToEx (dc, clientArea.x, clientArea.y - 1, 0); + OS.LineTo (dc, clientArea.x + clientArea.width, clientArea.y - 1); + OS.SelectObject (dc, oldPen); + OS.ReleaseDC (handle, dc); +} + @Override -long /*int*/ windowProc (long /*int*/ hwnd, int msg, long /*int*/ wParam, long /*int*/ lParam) { +long windowProc (long hwnd, int msg, long wParam, long lParam) { if (handle == 0) return 0; if((style & SWT.NO_MOVE) != 0 && msg == OS.WM_NCLBUTTONDOWN && wParam == OS.HTCAPTION) return 0; if (hwnd == toolTipHandle || hwnd == balloonTipHandle || hwnd == menuItemToolTipHandle) { @@ -2138,7 +2261,7 @@ long /*int*/ windowProc (long /*int*/ hwnd, int msg, long /*int*/ wParam, long / return callWindowProc (hwnd, msg, wParam, lParam); } if (hwnd == handle) { - if ((int)/*64*/msg == Display.TASKBARBUTTONCREATED) { + if (msg == Display.TASKBARBUTTONCREATED) { if (display.taskBar != null) { for (TaskItem item : display.taskBar.items) { if (item != null && item.shell == this) { @@ -2149,6 +2272,17 @@ long /*int*/ windowProc (long /*int*/ hwnd, int msg, long /*int*/ wParam, long / } } } + + switch (msg) { + case OS.WM_NCACTIVATE: + case OS.WM_NCPAINT: + { + long ret = super.windowProc (hwnd, msg, wParam, lParam); + overpaintMenuBorder(); + return ret; + } + } + return super.windowProc (hwnd, msg, wParam, lParam); } @@ -2175,19 +2309,7 @@ int widgetStyle () { } @Override -LRESULT WM_ACTIVATE (long /*int*/ wParam, long /*int*/ lParam) { - /* - * Bug in Windows XP. When a Shell is deactivated, the - * IME composition window does not go away. This causes - * repaint issues. The fix is to commit the composition - * string. - */ - if (OS.LOWORD (wParam) == 0 && OS.IsDBLocale && hIMC != 0) { - if (OS.ImmGetOpenStatus (hIMC)) { - OS.ImmNotifyIME (hIMC, OS.NI_COMPOSITIONSTR, OS.CPS_COMPLETE, 0); - } - } - +LRESULT WM_ACTIVATE (long wParam, long lParam) { /* Process WM_ACTIVATE */ LRESULT result = super.WM_ACTIVATE (wParam, lParam); if (OS.LOWORD (wParam) == 0) { @@ -2201,7 +2323,7 @@ LRESULT WM_ACTIVATE (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_DESTROY (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_DESTROY (long wParam, long lParam) { LRESULT result = super.WM_DESTROY (wParam, lParam); /* * When the shell is a WS_CHILD window of a non-SWT @@ -2218,7 +2340,7 @@ LRESULT WM_DESTROY (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_ERASEBKGND (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_ERASEBKGND (long wParam, long lParam) { LRESULT result = super.WM_ERASEBKGND (wParam, lParam); if (result != null) return result; /* @@ -2237,7 +2359,7 @@ LRESULT WM_ERASEBKGND (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_ENTERIDLE (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_ENTERIDLE (long wParam, long lParam) { LRESULT result = super.WM_ENTERIDLE (wParam, lParam); if (result != null) return result; Display display = this.display; @@ -2246,14 +2368,17 @@ LRESULT WM_ENTERIDLE (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_GETMINMAXINFO (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_GETMINMAXINFO (long wParam, long lParam) { LRESULT result = super.WM_GETMINMAXINFO (wParam, lParam); if (result != null) return result; - if (minWidth != SWT.DEFAULT || minHeight != SWT.DEFAULT) { + if (minWidth != SWT.DEFAULT || minHeight != SWT.DEFAULT + || maxWidth != SWT.DEFAULT || maxHeight != SWT.DEFAULT) { MINMAXINFO info = new MINMAXINFO (); OS.MoveMemory (info, lParam, MINMAXINFO.sizeof); if (minWidth != SWT.DEFAULT) info.ptMinTrackSize_x = minWidth; if (minHeight != SWT.DEFAULT) info.ptMinTrackSize_y = minHeight; + if (maxWidth != SWT.DEFAULT) info.ptMaxTrackSize_x = maxWidth; + if (maxHeight != SWT.DEFAULT) info.ptMaxTrackSize_y = maxHeight; OS.MoveMemory (lParam, info, MINMAXINFO.sizeof); return LRESULT.ZERO; } @@ -2261,7 +2386,7 @@ LRESULT WM_GETMINMAXINFO (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_MOUSEACTIVATE (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_MOUSEACTIVATE (long wParam, long lParam) { LRESULT result = super.WM_MOUSEACTIVATE (wParam, lParam); if (result != null) return result; @@ -2312,7 +2437,7 @@ LRESULT WM_MOUSEACTIVATE (long /*int*/ wParam, long /*int*/ lParam) { int pos = OS.GetMessagePos (); OS.POINTSTOPOINT (pt, pos); } - long /*int*/ hwnd = OS.WindowFromPoint (pt); + long hwnd = OS.WindowFromPoint (pt); if (hwnd == 0) return null; Control control = display.findControl (hwnd); @@ -2333,13 +2458,13 @@ LRESULT WM_MOUSEACTIVATE (long /*int*/ wParam, long /*int*/ lParam) { } } - long /*int*/ code = callWindowProc (handle, OS.WM_MOUSEACTIVATE, wParam, lParam); + long code = callWindowProc (handle, OS.WM_MOUSEACTIVATE, wParam, lParam); setActiveControl (control, SWT.MouseDown); return new LRESULT (code); } @Override -LRESULT WM_MOVE (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_MOVE (long wParam, long lParam) { LRESULT result = super.WM_MOVE (wParam, lParam); if (result != null) return result; ToolTip tip = getCurrentToolTip (); @@ -2348,16 +2473,16 @@ LRESULT WM_MOVE (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_NCHITTEST (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_NCHITTEST (long wParam, long lParam) { if (!OS.IsWindowEnabled (handle)) return null; if (!isEnabled () || !isActive ()) { if (!Display.TrimEnabled) return new LRESULT (OS.HTNOWHERE); - long /*int*/ hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); + long hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); if (hittest == OS.HTCLIENT || hittest == OS.HTMENU) hittest = OS.HTBORDER; return new LRESULT (hittest); } if (menuBar != null && !menuBar.getEnabled ()) { - long /*int*/ hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); + long hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); if (hittest == OS.HTMENU) hittest = OS.HTBORDER; return new LRESULT (hittest); } @@ -2365,7 +2490,7 @@ LRESULT WM_NCHITTEST (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_NCLBUTTONDOWN (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_NCLBUTTONDOWN (long wParam, long lParam) { LRESULT result = super.WM_NCLBUTTONDOWN (wParam, lParam); if (result != null) return result; /* @@ -2378,7 +2503,7 @@ LRESULT WM_NCLBUTTONDOWN (long /*int*/ wParam, long /*int*/ lParam) { if (!display.ignoreRestoreFocus) return result; Display display = this.display; display.lockActiveWindow = true; - long /*int*/ code = callWindowProc (handle, OS.WM_NCLBUTTONDOWN, wParam, lParam); + long code = callWindowProc (handle, OS.WM_NCLBUTTONDOWN, wParam, lParam); display.lockActiveWindow = false; Control focusControl = display.lastHittestControl; if (focusControl != null && !focusControl.isDisposed ()) { @@ -2390,23 +2515,7 @@ LRESULT WM_NCLBUTTONDOWN (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_PALETTECHANGED (long /*int*/ wParam, long /*int*/ lParam) { - if (wParam != handle) { - long /*int*/ hPalette = display.hPalette; - if (hPalette != 0) return selectPalette (hPalette); - } - return super.WM_PALETTECHANGED (wParam, lParam); -} - -@Override -LRESULT WM_QUERYNEWPALETTE (long /*int*/ wParam, long /*int*/ lParam) { - long /*int*/ hPalette = display.hPalette; - if (hPalette != 0) return selectPalette (hPalette); - return super.WM_QUERYNEWPALETTE (wParam, lParam); -} - -@Override -LRESULT WM_SETCURSOR (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_SETCURSOR (long wParam, long lParam) { /* * Feature in Windows. When the shell is disabled * by a Windows standard dialog (like a MessageBox @@ -2420,14 +2529,14 @@ LRESULT WM_SETCURSOR (long /*int*/ wParam, long /*int*/ lParam) { if (!Display.TrimEnabled) { Shell modalShell = display.getModalShell (); if (modalShell != null && !isActive ()) { - long /*int*/ hwndModal = modalShell.handle; + long hwndModal = modalShell.handle; if (OS.IsWindowEnabled (hwndModal)) { OS.SetActiveWindow (hwndModal); } } } if (!OS.IsWindowEnabled (handle)) { - long /*int*/ hwndPopup = OS.GetLastActivePopup (handle); + long hwndPopup = OS.GetLastActivePopup (handle); if (hwndPopup != 0 && hwndPopup != handle) { if (display.getControl (hwndPopup) == null) { if (OS.IsWindowEnabled (hwndPopup)) { @@ -2477,7 +2586,7 @@ LRESULT WM_SETCURSOR (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_SHOWWINDOW (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_SHOWWINDOW (long wParam, long lParam) { LRESULT result = super.WM_SHOWWINDOW (wParam, lParam); if (result != null) return result; /* @@ -2500,7 +2609,7 @@ LRESULT WM_SHOWWINDOW (long /*int*/ wParam, long /*int*/ lParam) { } @Override -LRESULT WM_WINDOWPOSCHANGING (long /*int*/ wParam, long /*int*/ lParam) { +LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) { LRESULT result = super.WM_WINDOWPOSCHANGING (wParam,lParam); if (result != null) return result; WINDOWPOS lpwp = new WINDOWPOS (); |