From 825159ba0f9701ef373f2ca361ebfa5a81666ceb Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Fri, 12 Dec 2025 13:59:45 +0100 Subject: [PATCH] Adjusted computation of horizontal toolbar size. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first part ensures the toolbar becomes tall enough to fit controls like Combo or Text, whose height is often larger than the native toolbar button height returned by TB_GETITEMRECT. Without this check, the toolbar height is based only on Windows’ button metrics, which are smaller, causing embedded controls to be clipped. By taking the max of the toolbar height and each control’s actual height, the final toolbar size always accommodates the tallest embedded control. In the second part, the original code centered the control vertically, but when the control (like a combo box) was taller than the toolbar item height, the centering calculation produced a negative offset, shifting the control upward and causing clipping. Your fix uses Math.max(0, …) to prevent negative offsets, ensuring the control is never positioned above the item’s top. As a result, taller controls are aligned safely without being cut off. --- .../Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java | 6 ++++++ .../Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java index 076bc0272f4..b06f16b0453 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java @@ -255,6 +255,12 @@ Point computeSizeInPixels (Point hintInPoints, int zoom, boolean changed) { OS.SendMessage (handle, OS.TB_GETITEMRECT, count - 1, rect); width = Math.max (width, rect.right); height = Math.max (height, rect.bottom); + // Adjust height for embedded controls (Combo, Text, etc.) + for (ToolItem item : items) { + if (item != null && item.getControl() != null) { + height = Math.max(height, item.getControl().getBoundsInPixels().height); + } + } } OS.SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags); if (redraw) OS.ValidateRect (handle, null); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java index 59fa20c511f..75a9ee8b067 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java @@ -583,7 +583,7 @@ void resizeControl () { control.setSize (itemRect.width, itemRect.height); Rectangle rect = control.getBounds (); rect.x = itemRect.x + (itemRect.width - rect.width) / 2; - rect.y = itemRect.y + (itemRect.height - rect.height) / 2; + rect.y = itemRect.y + Math.max(0, itemRect.height - rect.height) / 2; control.setLocation (rect.x, rect.y); } }