Skip to content

Commit ad8479c

Browse files
committed
Delay call to addListener in constructors of CCombo and StyledText #2733
The method is not final, which may cause issues if a subclass overrides it because it ends up being called upon instantiation, when the object is not fully initialized. Fixes #2733
1 parent 136b375 commit ad8479c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,18 @@ public CCombo (Composite parent, int style) {
173173
}
174174

175175
initAccessible();
176-
addListener(SWT.ZoomChanged, this::handleDPIChange);
176+
177+
// Add listener asynchronously in order to delay execution. This works because
178+
// other DPI changes are also executed asynchronously but if we choose to revert
179+
// back to synchronous execution of the listeners then this async call may be
180+
// executed too late and zoom change events may happen too early and not get
181+
// propagated.
182+
// See https://github.com/eclipse-platform/eclipse.platform.swt/issues/2733
183+
getDisplay().asyncExec(() -> {
184+
if (!isDisposed()) {
185+
addListener(SWT.ZoomChanged, this::handleDPIChange);
186+
}
187+
});
177188
}
178189
static int checkStyle (int style) {
179190
int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT | SWT.LEAD | SWT.CENTER | SWT.TRAIL;

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,18 @@ public StyledText(Composite parent, int style) {
758758
initializeAccessible();
759759
setData("DEFAULT_DROP_TARGET_EFFECT", new StyledTextDropTargetEffect(this));
760760
if (IS_MAC) setData(STYLEDTEXT_KEY);
761-
addListener(SWT.ZoomChanged, this::handleDPIChange);
761+
762+
// Add listener asynchronously in order to delay execution. This works because
763+
// other DPI changes are also executed asynchronously but if we choose to revert
764+
// back to synchronous execution of the listeners then this async call may be
765+
// executed too late and zoom change events may happen too early and not get
766+
// propagated.
767+
// See https://github.com/eclipse-platform/eclipse.platform.swt/issues/2733
768+
getDisplay().asyncExec(() -> {
769+
if (!isDisposed()) {
770+
addListener(SWT.ZoomChanged, this::handleDPIChange);
771+
}
772+
});
762773
}
763774
/**
764775
* Adds an extended modify listener. An ExtendedModify event is sent by the

0 commit comments

Comments
 (0)