Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public CCombo (Composite parent, int style) {
}

initAccessible();
addListener(SWT.ZoomChanged, event -> {
handleCComboDPIChange(event);
});
}
static int checkStyle (int style) {
int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT | SWT.LEAD | SWT.CENTER | SWT.TRAIL;
Expand Down Expand Up @@ -2026,19 +2029,24 @@ public boolean traverse(int event){
return super.traverse(event);
}

private void handleCComboDPIChange(Event event) {
updateAndRefreshChildren(childWidget -> {
childWidget.notifyListeners(SWT.ZoomChanged, 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 the Combo to get the children widget from
* @param childUpdater the callback which works with the child widgets
*/
public static void updateAndRefreshChildren(CCombo combo, Consumer<Widget> childUpdater) {
childUpdater.accept(combo.text);
childUpdater.accept(combo.list);
childUpdater.accept(combo.arrow);
childUpdater.accept(combo.popup);
private void updateAndRefreshChildren(Consumer<Widget> childUpdater) {
childUpdater.accept(text);
childUpdater.accept(list);
childUpdater.accept(arrow);
childUpdater.accept(popup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import org.eclipse.swt.*;
Expand Down Expand Up @@ -759,6 +758,9 @@ public StyledText(Composite parent, int style) {
initializeAccessible();
setData("DEFAULT_DROP_TARGET_EFFECT", new StyledTextDropTargetEffect(this));
if (IS_MAC) setData(STYLEDTEXT_KEY);
addListener(SWT.ZoomChanged, event -> {
handleStyledTextDPIChange(event);
});
}
/**
* Adds an extended modify listener. An ExtendedModify event is sent by the
Expand Down Expand Up @@ -10901,30 +10903,20 @@ void updateSelection(int startOffset, int replacedLength, int newLength) {
setCaretLocations();
}

/**
* The method accepts a StyledText and a callback which takes
* all the carets of the StyledText as the argument and executes it.
* The caret is refreshed after the execution of the callback.
*
* @param styledText the StyledText to get the carets from
* @param caretUpdater the callback which works with the carets
*
* @noreference This method is not intended to be referenced by clients.
*/
public static void updateAndRefreshCarets(StyledText styledText, Consumer<Caret> caretUpdater) {
private void handleStyledTextDPIChange(Event event) {
updateCaretVisibility();
setCaretLocations();
Set<Caret> caretSet = new HashSet<>();
caretSet.add(styledText.getCaret());
caretSet.add(styledText.defaultCaret);
if (styledText.carets != null) {
for (Caret caret : styledText.carets) {
caretSet.add(getCaret());
caretSet.add(defaultCaret);
if (carets != null) {
for (Caret caret : carets) {
caretSet.add(caret);
}
}
caretSet.stream().filter(Objects::nonNull).forEach(caretUpdater);

styledText.updateCaretVisibility();
styledText.setCaretLocations();

caretSet.stream().filter(Objects::nonNull).forEach(caretToRefresh -> {
((Caret) caretToRefresh).notifyListeners(SWT.ZoomChanged, event);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.swt.internal;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

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

public static void changeDPIZoom (Shell shell, int nativeZoom) {
DPIUtil.setDeviceZoom(nativeZoom);
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(nativeZoom) / DPIUtil.getZoomForAutoscaleProperty(shell.nativeZoom);
DPIZoomChangeRegistry.applyChange(shell, nativeZoom, scalingFactor);
Event event = new Event();
event.type = SWT.ZoomChanged;
event.widget = shell;
event.detail = nativeZoom;
event.doit = true;
shell.notifyListeners(SWT.ZoomChanged, event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public abstract class Item extends Widget {
public Item (Widget parent, int style) {
super (parent, style);
text = "";
this.addListener(SWT.ZoomChanged, event -> {
handleItemDPIChange(event);
});
}

/**
Expand Down Expand Up @@ -224,4 +227,13 @@ boolean updateTextDirection(int textDirection) {
return textDirection == AUTO_TEXT_DIRECTION;
}


private void handleItemDPIChange(Event event) {
// Refresh the image
Image image = getImage();
if (image != null) {
setImage(image);
}
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public class Button extends Control {
WNDCLASS lpWndClass = new WNDCLASS ();
OS.GetClassInfo (0, ButtonClass, lpWndClass);
ButtonProc = lpWndClass.lpfnWndProc;

DPIZoomChangeRegistry.registerHandler(Button::handleDPIChange, Button.class);
}

/**
Expand Down Expand Up @@ -1561,16 +1559,15 @@ LRESULT wmDrawChild (long wParam, long lParam) {
return null;
}

private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
if (!(widget instanceof Button button)) {
return;
}
@Override
void handleDPIChange(Event event, float scalingFactor) {
super.handleDPIChange(event, scalingFactor);
//Refresh the CheckSize
button.refreshCheckSize(newZoom);
refreshCheckSize(event.detail);
// Refresh the image
if (button.image != null) {
button._setImage(button.image);
button.updateImageList();
if (image != null) {
_setImage(image);
updateImageList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ public class Caret extends Widget {
Font font;
LOGFONT oldFont;

static {
DPIZoomChangeRegistry.registerHandler(Caret::handleDPIChange, Caret.class);
}

/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
Expand Down Expand Up @@ -669,19 +665,18 @@ public static void win32_setHeight(Caret caret, int height) {
if(caret.isVisible && caret.hasFocus()) caret.resize();
}

private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
if (!(widget instanceof Caret caret)) {
return;
}

Image image = caret.getImage();
@Override
void handleDPIChange(Event event, float scalingFactor) {
super.handleDPIChange(event, scalingFactor);
Image image = getImage();
if (image != null) {
caret.setImage(image);
setImage(image);
}

if (caret.font != null) {
caret.setFont(caret.font);
if (font != null) {
setFont(font);
}
resize();
}
}

Loading
Loading