Skip to content

Commit fe59a75

Browse files
committed
Do not call 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 Since these 2 classes are not in the same package as other subclasses of Widget, I had to resort to expanding the functionality in TypedListener. Fixes #2733
1 parent 9e2bdb5 commit fe59a75

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

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

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

175175
initAccessible();
176-
addListener(SWT.ZoomChanged, this::handleDPIChange);
176+
addTypedListener((ZoomChangedListener) this::handleDPIChange, SWT.ZoomChanged);
177177
}
178178
static int checkStyle (int style) {
179179
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ 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+
addTypedListener((ZoomChangedListener) this::handleDPIChange, SWT.ZoomChanged);
762762
}
763763
/**
764764
* Adds an extended modify listener. An ExtendedModify event is sent by the
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Vector Informatik GmbH and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Vector Informatik GmbH - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.events;
15+
16+
import java.util.*;
17+
18+
import org.eclipse.swt.*;
19+
import org.eclipse.swt.widgets.*;
20+
21+
/**
22+
* Interface for typed listeners that react to events of type {@code SWT.ZoomChanged}.
23+
*
24+
* @implNote This API is currently only implemented on Windows and GTK.
25+
* SWT doesn't send zoom events events on Cocoa.
26+
* </p>
27+
* @see {@linkplain SWT#ZoomChanged}
28+
* @since 3.132
29+
*
30+
*/
31+
@FunctionalInterface
32+
public interface ZoomChangedListener extends EventListener {
33+
void zoomChanged(Event e);
34+
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ public void handleEvent (Event e) {
313313
e.doit = event.doit;
314314
break;
315315
}
316+
case SWT.ZoomChanged: {
317+
((ZoomChangedListener) eventListener).zoomChanged(e);
318+
break;
319+
}
316320
}
317321
}
318322

0 commit comments

Comments
 (0)