Skip to content

Commit cbf014c

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] Allow disablement of autoscale per Widget
This commit introduces the data attribute AUTOSCALE_DISABLED for the windows implementation for Widget. This will disable autoscaling for this Widget and all of its children. This is a necessary requirement for some complex usages utilizing GC. Without disabling autoscaling rendering artifacts will be introduced when only parts of the GC are redrawn. This commit serves as starting point to harden this feature before considering extracting an API out of it.
1 parent 1b7b9bb commit cbf014c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,8 @@ void setBoundsInPixels (int x, int y, int width, int height, int flags, boolean
32573257
public void setBounds (Rectangle rect) {
32583258
checkWidget ();
32593259
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
3260-
setBoundsInPixels(DPIUtil.scaleUp(rect, getZoom()));
3260+
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
3261+
setBoundsInPixels(DPIUtil.scaleUp(rect, zoom));
32613262
}
32623263

32633264
void setBoundsInPixels (Rectangle rect) {

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public abstract class Widget {
6565
* @noreference This field is not intended to be referenced by clients.
6666
*/
6767
public int nativeZoom;
68+
boolean autoScaleDisabled = false;
6869
int style, state;
6970
Display display;
7071
EventTable eventTable;
@@ -132,6 +133,9 @@ public abstract class Widget {
132133
/* Bidi flag and for auto text direction */
133134
static final int AUTO_TEXT_DIRECTION = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
134135

136+
private static final String DATA_AUTOSCALE_DISABLED = "AUTOSCALE_DISABLED";
137+
private static final String DATA_NATIVE_ZOOM = "NATIVE_ZOOM";
138+
135139
/* Initialize the Common Controls DLL */
136140
static {
137141
INITCOMMONCONTROLSEX icce = new INITCOMMONCONTROLSEX ();
@@ -182,9 +186,11 @@ public Widget (Widget parent, int style) {
182186
checkParent (parent);
183187
this.style = style;
184188
this.nativeZoom = parent != null ? parent.nativeZoom : DPIUtil.getNativeDeviceZoom();
189+
this.autoScaleDisabled = parent.autoScaleDisabled;
185190
display = parent.display;
186191
reskinWidget ();
187192
notifyCreationTracker();
193+
this.setData(DATA_NATIVE_ZOOM, this.nativeZoom);
188194
}
189195

190196
void _addListener (int eventType, Listener listener) {
@@ -1457,6 +1463,10 @@ public void setData (String key, Object value) {
14571463
}
14581464
}
14591465
if (key.equals(SWT.SKIN_CLASS) || key.equals(SWT.SKIN_ID)) this.reskin(SWT.ALL);
1466+
1467+
if (DATA_AUTOSCALE_DISABLED.equals(key)) {
1468+
autoScaleDisabled = Boolean.parseBoolean(value.toString());
1469+
}
14601470
}
14611471

14621472
boolean sendFocusEvent (int type) {
@@ -2686,20 +2696,30 @@ void notifyDisposalTracker() {
26862696
}
26872697

26882698
GC createNewGC(long hDC, GCData data) {
2689-
data.nativeZoom = nativeZoom;
2699+
data.nativeZoom = getNativeZoom();
2700+
if (autoScaleDisabled && data.font != null) {
2701+
data.font = SWTFontProvider.getFont(display, data.font.getFontData()[0], 100);
2702+
}
26902703
return GC.win32_new(hDC, data);
26912704
}
26922705

26932706
int getNativeZoom() {
2707+
if (autoScaleDisabled) {
2708+
return 100;
2709+
}
26942710
return nativeZoom;
26952711
}
26962712

26972713
int getZoom() {
2714+
if (autoScaleDisabled) {
2715+
return 100;
2716+
}
26982717
return DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
26992718
}
27002719

27012720
private static void handleDPIChange(Widget widget, int newZoom, float scalingFactor) {
27022721
widget.nativeZoom = newZoom;
2722+
widget.setData(DATA_NATIVE_ZOOM, newZoom);
27032723
}
27042724

27052725
int getSystemMetrics(int nIndex) {

0 commit comments

Comments
 (0)