14
14
package org .eclipse .swt .widgets ;
15
15
16
16
17
+ import java .util .*;
18
+
17
19
import org .eclipse .swt .*;
18
20
import org .eclipse .swt .graphics .*;
19
21
import org .eclipse .swt .internal .*;
@@ -1752,37 +1754,30 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
1752
1754
var seperatorWidth = new int [toolItems .length ];
1753
1755
int itemCount = toolItems .length ;
1754
1756
1757
+ record ToolItemData (ToolItem toolItem , TBBUTTON button ) {
1758
+ }
1759
+
1755
1760
// Remove and re-add all button the let Windows resize the tool bar
1756
- ToolItem [] items = new ToolItem [itemCount ];
1757
- TBBUTTON [] buttondata = new TBBUTTON [itemCount ];
1761
+ Stack <ToolItemData > buttondata = new Stack <>();
1758
1762
for (int i = itemCount - 1 ; i >= 0 ; i --) {
1763
+ TBBUTTON lpButton = new TBBUTTON ();
1764
+ OS .SendMessage (toolBar .handle , OS .TB_GETBUTTON , i , lpButton );
1759
1765
ToolItem item = toolItems [i ];
1760
1766
if ((item .style & SWT .SEPARATOR ) != 0 && item .getControl () != null ) {
1761
1767
// Take note of widths of separators with control, so they can be resized
1762
1768
// at the end
1763
1769
seperatorWidth [i ] = item .getWidth ();
1764
1770
}
1765
1771
DPIZoomChangeRegistry .applyChange (item , newZoom , scalingFactor );
1766
-
1767
- TBBUTTON lpButton = new TBBUTTON ();
1768
- OS .SendMessage (toolBar .handle , OS .TB_GETBUTTON , i , lpButton );
1769
- buttondata [lpButton .idCommand ] = lpButton ;
1770
- items [lpButton .idCommand ] = item ;
1772
+ buttondata .push (new ToolItemData (item , lpButton ));
1771
1773
OS .SendMessage (toolBar .handle , OS .TB_DELETEBUTTON , i , 0 );
1772
1774
}
1773
-
1774
- // Refresh the image lists so the image list for the correct zoom is used
1775
- toolBar .setImageList (toolBar .getImageList ());
1776
- toolBar .setDisabledImageList (toolBar .getDisabledImageList ());
1777
- toolBar .setHotImageList (toolBar .getHotImageList ());
1778
-
1779
1775
OS .SendMessage (toolBar .handle , OS .TB_BUTTONSTRUCTSIZE , TBBUTTON .sizeof , 0 );
1780
- for (int i = 0 ; i < buttondata .length ; i ++) {
1781
- TBBUTTON button = buttondata [i ];
1782
- if (button != null ) {
1783
- OS .SendMessage (toolBar .handle , OS .TB_ADDBUTTONS , 1 , button );
1784
- ToolItem item = items [i ];
1785
-
1776
+ while (!buttondata .isEmpty ()) {
1777
+ ToolItemData itemData = buttondata .pop ();
1778
+ OS .SendMessage (toolBar .handle , OS .TB_ADDBUTTONS , 1 , itemData .button );
1779
+ ToolItem item = itemData .toolItem ;
1780
+ if (item != null ) {
1786
1781
// The text is not retained correctly, so we need to reset it
1787
1782
String text = item .getText ();
1788
1783
if (text != null ) {
@@ -1791,8 +1786,6 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
1791
1786
}
1792
1787
}
1793
1788
}
1794
- OS .SendMessage (toolBar .handle , OS .TB_AUTOSIZE , 0 , 0 );
1795
-
1796
1789
for (int i = 0 ; i < itemCount ; i ++) {
1797
1790
ToolItem item = toolItems [i ];
1798
1791
// If the separator is used with a control, we must reset the size to the cached value,
@@ -1801,6 +1794,12 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
1801
1794
item .setWidth (seperatorWidth [i ]);
1802
1795
}
1803
1796
}
1797
+
1798
+ // Refresh the image lists so the image list for the correct zoom is used
1799
+ toolBar .setImageList (toolBar .getImageList ());
1800
+ toolBar .setDisabledImageList (toolBar .getDisabledImageList ());
1801
+ toolBar .setHotImageList (toolBar .getHotImageList ());
1802
+ OS .SendMessage (toolBar .handle , OS .TB_AUTOSIZE , 0 , 0 );
1804
1803
toolBar .layout (true );
1805
1804
}
1806
1805
}
0 commit comments