Skip to content

Commit 6a6af6d

Browse files
committed
WIP
1 parent 1eb32bc commit 6a6af6d

File tree

32 files changed

+344
-420
lines changed

32 files changed

+344
-420
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ public CCombo (Composite parent, int style) {
173173
}
174174

175175
initAccessible();
176+
addListener(SWT.ZoomChanged, event -> {
177+
handleCComboDPIChange(event);
178+
});
176179
}
177180
static int checkStyle (int style) {
178181
int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT | SWT.LEAD | SWT.CENTER | SWT.TRAIL;
@@ -2026,19 +2029,24 @@ public boolean traverse(int event){
20262029
return super.traverse(event);
20272030
}
20282031

2032+
private void handleCComboDPIChange(Event event) {
2033+
updateAndRefreshChildren(childWidget -> {
2034+
childWidget.notifyListeners(SWT.ZoomChanged, event);
2035+
});
2036+
}
2037+
20292038
/**
20302039
* The method accepts a combo and a callback which takes
20312040
* all the child of the CCombo as the argument and executes it.
20322041
* All children are refreshed after the execution of the callback.
20332042
*
2034-
* @noreference This method is not intended to be referenced by clients.
20352043
* @param combo the Combo to get the children widget from
20362044
* @param childUpdater the callback which works with the child widgets
20372045
*/
2038-
public static void updateAndRefreshChildren(CCombo combo, Consumer<Widget> childUpdater) {
2039-
childUpdater.accept(combo.text);
2040-
childUpdater.accept(combo.list);
2041-
childUpdater.accept(combo.arrow);
2042-
childUpdater.accept(combo.popup);
2046+
private void updateAndRefreshChildren(Consumer<Widget> childUpdater) {
2047+
childUpdater.accept(text);
2048+
childUpdater.accept(list);
2049+
childUpdater.accept(arrow);
2050+
childUpdater.accept(popup);
20432051
}
20442052
}

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020

2121
import java.util.*;
22-
import java.util.function.*;
2322
import java.util.stream.*;
2423

2524
import org.eclipse.swt.*;
@@ -759,6 +758,9 @@ public StyledText(Composite parent, int style) {
759758
initializeAccessible();
760759
setData("DEFAULT_DROP_TARGET_EFFECT", new StyledTextDropTargetEffect(this));
761760
if (IS_MAC) setData(STYLEDTEXT_KEY);
761+
addListener(SWT.ZoomChanged, event -> {
762+
handleStyledTextDPIChange(event);
763+
});
762764
}
763765
/**
764766
* Adds an extended modify listener. An ExtendedModify event is sent by the
@@ -10901,29 +10903,21 @@ void updateSelection(int startOffset, int replacedLength, int newLength) {
1090110903
setCaretLocations();
1090210904
}
1090310905

10904-
/**
10905-
* The method accepts a StyledText and a callback which takes
10906-
* all the carets of the StyledText as the argument and executes it.
10907-
* The caret is refreshed after the execution of the callback.
10908-
*
10909-
* @param styledText the StyledText to get the carets from
10910-
* @param caretUpdater the callback which works with the carets
10911-
*
10912-
* @noreference This method is not intended to be referenced by clients.
10913-
*/
10914-
public static void updateAndRefreshCarets(StyledText styledText, Consumer<Caret> caretUpdater) {
10906+
private void handleStyledTextDPIChange(Event event) {
1091510907
Set<Caret> caretSet = new HashSet<>();
10916-
caretSet.add(styledText.getCaret());
10917-
caretSet.add(styledText.defaultCaret);
10918-
if (styledText.carets != null) {
10919-
for (Caret caret : styledText.carets) {
10908+
caretSet.add(getCaret());
10909+
caretSet.add(defaultCaret);
10910+
if (carets != null) {
10911+
for (Caret caret : carets) {
1092010912
caretSet.add(caret);
1092110913
}
1092210914
}
10923-
caretSet.stream().filter(Objects::nonNull).forEach(caretUpdater);
10924-
10925-
styledText.updateCaretVisibility();
10926-
styledText.setCaretLocations();
10915+
caretSet.stream().filter(Objects::nonNull).forEach(caretToRefresh -> {
10916+
((Caret) caretToRefresh).notifyListeners(SWT.ZoomChanged, event);
10917+
Caret.win32_setHeight(caretToRefresh, getLineHeight());
10918+
});
10919+
updateCaretVisibility();
10920+
setCaretLocations();
1092710921

1092810922
}
1092910923

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DPITestUtil.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.internal;
1515

16+
import org.eclipse.swt.*;
1617
import org.eclipse.swt.widgets.*;
1718

1819
public final class DPITestUtil {
@@ -22,8 +23,12 @@ private DPITestUtil() {
2223

2324
public static void changeDPIZoom (Shell shell, int nativeZoom) {
2425
DPIUtil.setDeviceZoom(nativeZoom);
25-
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(nativeZoom) / DPIUtil.getZoomForAutoscaleProperty(shell.nativeZoom);
26-
DPIZoomChangeRegistry.applyChange(shell, nativeZoom, scalingFactor);
26+
Event event = new Event();
27+
event.type = SWT.ZoomChanged;
28+
event.widget = shell;
29+
event.detail = nativeZoom;
30+
event.doit = true;
31+
shell.notifyListeners(SWT.ZoomChanged, event);
2732
}
2833

2934
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.eclipse.swt.events;
2+
3+
import java.util.concurrent.atomic.*;
4+
5+
import org.eclipse.swt.*;
6+
import org.eclipse.swt.widgets.*;
7+
8+
/**
9+
* @since 3.131
10+
*/
11+
public class ZoomChangedEvent extends Event {
12+
13+
private AtomicInteger handleDPIChangedScheduledTasksCount;
14+
private Shell shell;
15+
private float scalingFactor;
16+
17+
public ZoomChangedEvent(Shell shell, Widget widget, int zoom, float scalingFactor) {
18+
this(shell, widget, zoom, scalingFactor, new AtomicInteger(0));
19+
}
20+
21+
private ZoomChangedEvent(Shell shell, Widget widget, int zoom, float scalingFactor, AtomicInteger handleDPIChangedScheduledTasksCount) {
22+
this.shell = shell;
23+
this.widget = widget;
24+
this.handleDPIChangedScheduledTasksCount = handleDPIChangedScheduledTasksCount;
25+
this.scalingFactor = scalingFactor;
26+
this.detail = zoom;
27+
this.doit = true;
28+
this.type = SWT.ZoomChanged;
29+
}
30+
31+
public AtomicInteger getHandleDPIChangedScheduledTasksCount() {
32+
return handleDPIChangedScheduledTasksCount;
33+
}
34+
35+
public Shell getShell() {
36+
return shell;
37+
}
38+
39+
public float getScalingFactor() {
40+
return scalingFactor;
41+
}
42+
43+
public ZoomChangedEvent createFor(Widget widget) {
44+
ZoomChangedEvent event = new ZoomChangedEvent(shell, widget, detail, scalingFactor, handleDPIChangedScheduledTasksCount);
45+
return event;
46+
}
47+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public abstract class Item extends Widget {
7575
public Item (Widget parent, int style) {
7676
super (parent, style);
7777
text = "";
78+
this.addListener(SWT.ZoomChanged, event -> {
79+
handleItemDPIChange(event);
80+
});
7881
}
7982

8083
/**
@@ -224,4 +227,13 @@ boolean updateTextDirection(int textDirection) {
224227
return textDirection == AUTO_TEXT_DIRECTION;
225228
}
226229

230+
231+
private void handleItemDPIChange(Event event) {
232+
// Refresh the image
233+
Image image = getImage();
234+
if (image != null) {
235+
setImage(image);
236+
}
237+
}
238+
227239
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/CommonWidgetsDPIChangeHandlers.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeHandler.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public class Button extends Control {
6565
WNDCLASS lpWndClass = new WNDCLASS ();
6666
OS.GetClassInfo (0, ButtonClass, lpWndClass);
6767
ButtonProc = lpWndClass.lpfnWndProc;
68-
69-
DPIZoomChangeRegistry.registerHandler(Button::handleDPIChange, Button.class);
7068
}
7169

7270
/**
@@ -1561,16 +1559,15 @@ LRESULT wmDrawChild (long wParam, long lParam) {
15611559
return null;
15621560
}
15631561

1564-
private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
1565-
if (!(widget instanceof Button button)) {
1566-
return;
1567-
}
1562+
@Override
1563+
void handleDPIChange(Event event, float scalingFactor) {
1564+
super.handleDPIChange(event, scalingFactor);
15681565
//Refresh the CheckSize
1569-
button.refreshCheckSize(newZoom);
1566+
refreshCheckSize(event.detail);
15701567
// Refresh the image
1571-
if (button.image != null) {
1572-
button._setImage(button.image);
1573-
button.updateImageList();
1568+
if (image != null) {
1569+
_setImage(image);
1570+
updateImageList();
15741571
}
15751572
}
15761573
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public class Caret extends Widget {
4949
Font font;
5050
LOGFONT oldFont;
5151

52-
static {
53-
DPIZoomChangeRegistry.registerHandler(Caret::handleDPIChange, Caret.class);
54-
}
55-
5652
/**
5753
* Constructs a new instance of this class given its parent
5854
* and a style value describing its behavior and appearance.
@@ -669,18 +665,16 @@ public static void win32_setHeight(Caret caret, int height) {
669665
if(caret.isVisible && caret.hasFocus()) caret.resize();
670666
}
671667

672-
private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
673-
if (!(widget instanceof Caret caret)) {
674-
return;
675-
}
676-
677-
Image image = caret.getImage();
668+
@Override
669+
void handleDPIChange(Event event, float scalingFactor) {
670+
super.handleDPIChange(event, scalingFactor);
671+
Image image = getImage();
678672
if (image != null) {
679-
caret.setImage(image);
673+
setImage(image);
680674
}
681675

682-
if (caret.font != null) {
683-
caret.setFont(caret.font);
676+
if (font != null) {
677+
setFont(font);
684678
}
685679
}
686680
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public class Combo extends Composite {
104104
WNDCLASS lpWndClass = new WNDCLASS ();
105105
OS.GetClassInfo (0, ComboClass, lpWndClass);
106106
ComboProc = lpWndClass.lpfnWndProc;
107-
DPIZoomChangeRegistry.registerHandler(Combo::handleDPIChange, Combo.class);
108107
}
109108

110109
/* Undocumented values. Remained the same at least between Win7 and Win10 */
@@ -3359,13 +3358,12 @@ LRESULT wmSysKeyDown (long hwnd, long wParam, long lParam) {
33593358
return result;
33603359
}
33613360

3362-
private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
3363-
if (!(widget instanceof Combo combo)) {
3364-
return;
3365-
}
3366-
if ((combo.style & SWT.H_SCROLL) != 0) {
3367-
combo.scrollWidth = 0;
3368-
combo.setScrollWidth();
3361+
@Override
3362+
void handleDPIChange(Event event, float scalingFactor) {
3363+
super.handleDPIChange(event, scalingFactor);
3364+
if ((style & SWT.H_SCROLL) != 0) {
3365+
scrollWidth = 0;
3366+
setScrollWidth();
33693367
}
33703368
}
33713369
}

0 commit comments

Comments
 (0)