diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index 7bdf21ece94..c8070feabdb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -271,8 +271,8 @@ public class Display extends Device implements Executor { boolean textUseDarkthemeIcons = false; /* Custom icons */ - long hIconSearch; - long hIconCancel; + private HashMap sizeToSearchIconHandle = new HashMap<>(); + private HashMap sizeToCancelIconHandle = new HashMap<>(); /* Focus */ int focusEvent; @@ -1188,6 +1188,26 @@ static Image createIcon (Image image) { return Image.win32_new (device, SWT.ICON, hIcon); } +long getTextSearchIcon(int size) { + if (!sizeToSearchIconHandle.containsKey(size)) { + int searchIconResource = textUseDarkthemeIcons ? Text.IDI_SEARCH_DARKTHEME : Text.IDI_SEARCH; + long iconHandle = OS.LoadImage (OS.GetLibraryHandle (), searchIconResource, OS.IMAGE_ICON, size, size, 0); + if (iconHandle == 0) error(SWT.ERROR_NO_HANDLES); + sizeToSearchIconHandle.put(size, iconHandle); + } + return sizeToSearchIconHandle.get(size); +} + +long getTextCancelIcon(int size) { + if (!sizeToCancelIconHandle.containsKey(size)) { + int searchIconResource = textUseDarkthemeIcons ? Text.IDI_CANCEL_DARKTHEME : Text.IDI_CANCEL; + long iconHandle = OS.LoadImage (OS.GetLibraryHandle (), searchIconResource, OS.IMAGE_ICON, size, size, 0); + if (iconHandle == 0) error(SWT.ERROR_NO_HANDLES); + sizeToCancelIconHandle.put(size, iconHandle); + } + return sizeToCancelIconHandle.get(size); +} + static void deregister (Display display) { synchronized (Device.class) { for (int i=0; i OS.DestroyIcon(handle)); + sizeToCancelIconHandle.values().forEach(handle -> OS.DestroyIcon(handle)); + sizeToSearchIconHandle.clear(); + sizeToCancelIconHandle.clear(); /* Release XP Themes */ resetThemes(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java index af693c6ed77..8d9a4609724 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java @@ -337,24 +337,7 @@ void createHandle () { state |= THEME_BACKGROUND; } } - addIcons(); -} - -private void addIcons() { if ((style & SWT.SEARCH) != 0) { - if (display.hIconSearch == 0) { - long [] phicon = new long [1]; - - int searchIconResource = display.textUseDarkthemeIcons ? IDI_SEARCH_DARKTHEME : IDI_SEARCH; - int hresult = OS.LoadIconMetric (OS.GetLibraryHandle (), searchIconResource, OS.LIM_SMALL, phicon); - if (hresult != OS.S_OK) error (SWT.ERROR_NO_HANDLES); - display.hIconSearch = phicon [0]; - - int cancelIconResource = display.textUseDarkthemeIcons ? IDI_CANCEL_DARKTHEME : IDI_CANCEL; - hresult = OS.LoadIconMetric (OS.GetLibraryHandle (), cancelIconResource, OS.LIM_SMALL, phicon); - if (hresult != OS.S_OK) error (SWT.ERROR_NO_HANDLES); - display.hIconCancel = phicon [0]; - } if ((style & SWT.ICON_SEARCH) != 0) { long hwndSearch = OS.CreateWindowEx ( 0, @@ -2770,7 +2753,10 @@ LRESULT WM_DRAWITEM (long wParam, long lParam) { int state = OS.GetKeyState (OS.VK_LBUTTON) < 0 ? OS.PBS_PRESSED : OS.PBS_HOT; OS.DrawThemeBackground (display.hButtonThemeAuto (), struct.hDC, OS.BP_PUSHBUTTON, state, rect, null); } - long hIcon = (struct.CtlID == SWT.ICON_SEARCH) ? display.hIconSearch : display.hIconCancel; + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + int size = Math.min(width, height); + long hIcon = (struct.CtlID == SWT.ICON_SEARCH) ? display.getTextSearchIcon(size) : display.getTextCancelIcon(size); int y = (rect.bottom - rect.right) / 2; OS.DrawIconEx (struct.hDC, 0, y, hIcon, 0, 0, 0, 0, OS.DI_NORMAL); return LRESULT.ONE; @@ -3167,7 +3153,6 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac if (!(widget instanceof Text text)) { return; } - text.addIcons(); text.setMargins(); } }