Skip to content
Merged
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 @@ -3527,6 +3527,26 @@ NSTouch findTouchWithId(NSArray touches, NSObject identity) {
return null;
}

/**
* Sets the autoscaling mode for this widget. The capability is not supported on
* every platform, such that calling this method may not have an effect on
* unsupported platforms. The return value indicates if the autoscale mode was
* set properly. With {@link #isAutoScalable()}, the autoscale enablement can
* also be evaluated at any later point in time.
* <p>
* Currently, this is only supported on Windows.
* </p>
*
* @param autoscalingMode the autoscaling mode to set
*
* @return {@code false} if the operation was called on an unsupported platform
*
* @since 3.133
*/
public boolean setAutoscalingMode(AutoscalingMode autoscalingMode) {
return false;
}

void setBackground () {
if (!drawsBackground()) return;
Control control = findBackgroundControl ();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.eclipse.swt.graphics;

/**
* Defines the autoscaling behavior used when rendering or computing layout for
* controls that support DPI‑aware scaling.
* <p>
* This mode determines whether SWT takes care of the scaling of widgets with
* respect to the zoom level of the monitor.
* </p>
*
* <ul>
* <li><b>{@link #ENABLED}</b> – Autoscaling is explicitly enabled. Values (such
* as coordinates, dimensions, or layout metrics) will be adjusted according to
* the effective scaling factor.</li>
*
* <li><b>{@link #DISABLED}</b> – Autoscaling is explicitly disabled. Values
* will be used as‑is without applying any scaling transformations.</li>
*
* <li><b>{@link #DISABLED_INHERITED}</b> – Autoscaling is disabled for this
* control and this is inherited by its children. Child controls will also be
* initialized with DISABLED_INHERITED AutoscalingMode.</li>
* </ul>
*
* @since 3.133
*/
public enum AutoscalingMode {
ENABLED, DISABLED, DISABLED_INHERITED
}
Original file line number Diff line number Diff line change
Expand Up @@ -5143,6 +5143,26 @@ void gtk_label_set_align(long label, float xAlign, float yAlign) {
GTK.gtk_label_set_yalign(label, yAlign);
}

/**
* Sets the autoscaling mode for this widget. The capability is not supported on
* every platform, such that calling this method may not have an effect on
* unsupported platforms. The return value indicates if the autoscale mode was
* set properly. With {@link #isAutoScalable()}, the autoscale enablement can
* also be evaluated at any later point in time.
* <p>
* Currently, this is only supported on Windows.
* </p>
*
* @param autoscalingMode the autoscaling mode to set
*
* @return {@code false} if the operation was called on an unsupported platform
*
* @since 3.133
*/
public boolean setAutoscalingMode(AutoscalingMode autoscalingMode) {
return false;
}

void setBackground () {
if ((state & BACKGROUND) == 0 && backgroundImage == null) {
if ((state & PARENT_BACKGROUND) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,24 @@ public abstract class Control extends Widget implements Drawable {
Region region;
Font font;
int drawCount, foreground, background, backgroundAlpha = 255;
boolean autoScaleDisabled = false;
AutoscalingMode autoscalingMode = AutoscalingMode.ENABLED;

/**
* @deprecated use {@link Shell#getZoom(AutoscalingMode)} instead to obtain the zoom of the shell.
*/
@Deprecated(since = "2026-03", forRemoval = true)
private static final String DATA_SHELL_ZOOM = "SHELL_ZOOM";

/**
* @deprecated use {@link Control#setAutoscalingMode(AutoscalingMode)} instead to set the autoscaling mode directly.
*/
@Deprecated(since = "2026-03", forRemoval = true)
private static final String DATA_AUTOSCALE_DISABLED = "AUTOSCALE_DISABLED";

/**
* @deprecated use {@link Control#setAutoscalingMode(AutoscalingMode)} instead to set the autoscaling mode directly.
*/
@Deprecated(since = "2026-03", forRemoval = true)
private static final String PROPOGATE_AUTOSCALE_DISABLED = "PROPOGATE_AUTOSCALE_DISABLED";
/**
* Prevents uninitialized instances from being created outside the package.
Expand Down Expand Up @@ -124,11 +136,11 @@ public abstract class Control extends Widget implements Drawable {
public Control (Composite parent, int style) {
super (parent, style);
this.parent = parent;
Boolean parentPropagateAutoscaleDisabled = (Boolean) parent.getData(PROPOGATE_AUTOSCALE_DISABLED);
if (parentPropagateAutoscaleDisabled == null || parentPropagateAutoscaleDisabled) {
this.autoScaleDisabled = parent.autoScaleDisabled;
AutoscalingMode parentAutoscaleMode = parent.autoscalingMode;
if (parentAutoscaleMode == AutoscalingMode.DISABLED_INHERITED) {
this.autoscalingMode = parent.autoscalingMode;
}
if (!autoScaleDisabled) {
if (!isAutoscalingDisabled()) {
this.nativeZoom = getShellZoom();
}
createWidget ();
Expand Down Expand Up @@ -1286,13 +1298,28 @@ public Object getData(String key) {
@Override
public void setData(String key, Object value) {
super.setData(key, value);
if (DATA_AUTOSCALE_DISABLED.equals(key)) {
autoScaleDisabled = Boolean.parseBoolean(value.toString());
if (autoScaleDisabled) {
this.nativeZoom = 100;
} else {
this.nativeZoom = getShellZoom();
}
if (DATA_AUTOSCALE_DISABLED.equals(key) || PROPOGATE_AUTOSCALE_DISABLED.equals(key)) {
updateAutoScalingModeFromData();
}
}

/**
* @deprecated use {@link Control#setAutoscalingMode(AutoscalingMode)} instead.
* These hidden data objects will be removed in a future release and one has to
* migrate to the new API for that purpose.
*/
@Deprecated(since = "2026-03", forRemoval = true)
private void updateAutoScalingModeFromData() {
Object propagateAutoscaleDisabled = getData(PROPOGATE_AUTOSCALE_DISABLED);
boolean propagateAutoscaling = propagateAutoscaleDisabled != null && Boolean.parseBoolean(propagateAutoscaleDisabled.toString());
Object autoscaleDisabled = getData(DATA_AUTOSCALE_DISABLED);
boolean isAutoscaleDisabled = autoscaleDisabled != null && Boolean.parseBoolean(autoscaleDisabled.toString());
if (isAutoscaleDisabled) {
autoscalingMode = propagateAutoscaling ? AutoscalingMode.DISABLED_INHERITED : AutoscalingMode.DISABLED;
this.nativeZoom = 100;
} else {
autoscalingMode = AutoscalingMode.ENABLED;
this.nativeZoom = getShellZoom();
}
}

Expand Down Expand Up @@ -1874,6 +1901,11 @@ boolean isActive () {
return shell.getEnabled ();
}

@Override
public boolean isAutoScalable() {
return autoscalingMode == AutoscalingMode.ENABLED;
}

/**
* Returns <code>true</code> if the receiver is enabled and all
* ancestors up to and including the receiver's nearest ancestor
Expand Down Expand Up @@ -3353,6 +3385,32 @@ private void fitInParentBounds(Rectangle boundsInPixels, int zoom) {
}
}

/**
* Sets the autoscaling mode for this widget. The capability is not supported on
* every platform, such that calling this method may not have an effect on
* unsupported platforms. The return value indicates if the autoscale mode was
* set properly. With {@link #isAutoScalable()}, the autoscale enablement can
* also be evaluated at any later point in time.
* <p>
* Currently, this is only supported on Windows.
* </p>
*
* @param autoscalingMode the autoscaling mode to set
*
* @return {@code false} if the operation was called on an unsupported platform
*
* @since 3.133
*/
public boolean setAutoscalingMode(AutoscalingMode autoscalingMode) {
this.autoscalingMode = autoscalingMode;
if (isAutoscalingDisabled()) {
this.nativeZoom = 100;
} else {
this.nativeZoom = getShellZoom();
}
return true;
}

void setBoundsInPixels (Rectangle rect) {
setBoundsInPixels (rect.x, rect.y, rect.width, rect.height);
}
Expand Down Expand Up @@ -4866,15 +4924,15 @@ public boolean setParent (Composite parent) {
@Override
GC createNewGC(long hDC, GCData data) {
data.nativeZoom = nativeZoom;
if (autoScaleDisabled && data.font != null) {
if (isAutoscalingDisabled() && data.font != null) {
data.font = SWTFontProvider.getFont(display, data.font.getFontData()[0], 100);
}
return GC.win32_new(hDC, data);
}

@Override
int getAutoscalingZoom() {
if (autoScaleDisabled) {
if (isAutoscalingDisabled()) {
return 100;
}
return super.getAutoscalingZoom();
Expand All @@ -4888,7 +4946,7 @@ int getShellZoom() {
}

int computeGetBoundsZoom() {
if (parent != null && !autoScaleDisabled) {
if (parent != null && !isAutoscalingDisabled()) {
return parent.getAutoscalingZoom();
}
return getAutoscalingZoom();
Expand Down Expand Up @@ -6076,10 +6134,14 @@ void sendZoomChangedEvent(Event event, Shell shell) {
}
}

private boolean isAutoscalingDisabled() {
return autoscalingMode != AutoscalingMode.ENABLED;
}

@Override
void handleDPIChange(Event event, float scalingFactor) {
super.handleDPIChange(event, scalingFactor);
if (this.autoScaleDisabled) {
if (isAutoscalingDisabled()) {
this.nativeZoom = 100;
}
resizeFont(this, nativeZoom);
Expand Down
Loading