From 728e98ef7b0962044193d6d7fa3104270e962709 Mon Sep 17 00:00:00 2001 From: "shahzaib.ibrahim" Date: Fri, 28 Jun 2024 12:09:13 +0200 Subject: [PATCH] Scaling combo text according to zoom level Registering the comboDpiChange handler and applying change manually to text, image and arrow and popup --- .../common/org/eclipse/swt/custom/CCombo.java | 17 +++++++++++++++++ .../CommonWidgetsDPIChangeHandlers.java | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java index e24bd918dfe..7cbe83041be 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java @@ -2025,4 +2025,21 @@ public boolean traverse(int event){ } return super.traverse(event); } + +/** + * The method accepts a combo and a callback which takes + * all the child of the CCombo as the argument and executes it. + * All children are refreshed after the execution of the callback. + * + * @noreference This method is not intended to be referenced by clients. + * @param combo + * @param childUpdater + */ +public static void updateAndRefreshChildren(CCombo combo, Consumer childUpdater) { + childUpdater.accept(combo.text); + childUpdater.accept(combo.list); + childUpdater.accept(combo.arrow); + childUpdater.accept(combo.popup); +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/CommonWidgetsDPIChangeHandlers.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/CommonWidgetsDPIChangeHandlers.java index 1ac53b67756..23bf07eae25 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/CommonWidgetsDPIChangeHandlers.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/CommonWidgetsDPIChangeHandlers.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.swt.internal; +import org.eclipse.swt.custom.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; @@ -31,6 +32,7 @@ public class CommonWidgetsDPIChangeHandlers { public static void registerCommonHandlers() { DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleItemDPIChange, Item.class); + DPIZoomChangeRegistry.registerHandler(CommonWidgetsDPIChangeHandlers::handleCComboDPIChange, CCombo.class); } private static void handleItemDPIChange(Widget widget, int newZoom, float scalingFactor) { @@ -43,4 +45,10 @@ private static void handleItemDPIChange(Widget widget, int newZoom, float scalin item.setImage(image); } } -} + private static void handleCComboDPIChange(Widget widget, int newZoom, float scalingFactor) { + if (!(widget instanceof CCombo combo)) { + return; + } + CCombo.updateAndRefreshChildren(combo, childWidget -> DPIZoomChangeRegistry.applyChange(childWidget, newZoom, scalingFactor)); + } +} \ No newline at end of file