Skip to content

Commit dec0c6e

Browse files
Adjusted computation of horizontal toolbar size.
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.
1 parent f005865 commit dec0c6e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ Point computeSizeInPixels (Point hintInPoints, int zoom, boolean changed) {
255255
OS.SendMessage (handle, OS.TB_GETITEMRECT, count - 1, rect);
256256
width = Math.max (width, rect.right);
257257
height = Math.max (height, rect.bottom);
258+
// Adjust height for embedded controls (Combo, Text, etc.)
259+
for (ToolItem item : items) {
260+
if (item != null && item.getControl() != null) {
261+
height = Math.max(height, item.getControl().getBoundsInPixels().height);
262+
}
263+
}
258264
}
259265
OS.SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags);
260266
if (redraw) OS.ValidateRect (handle, null);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ void resizeControl () {
583583
control.setSize (itemRect.width, itemRect.height);
584584
Rectangle rect = control.getBounds ();
585585
rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
586-
rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
586+
rect.y = itemRect.y + Math.max(0, itemRect.height - rect.height) / 2;
587587
control.setLocation (rect.x, rect.y);
588588
}
589589
}

0 commit comments

Comments
 (0)