Skip to content

Commit 9cacd32

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Replace nativeZoom of control with disabled autoscaling with 100
The nativeZoom of some controls currently always has the original native zoom value, even if autoscaling is disabled for that control such that they behave as if their native zoom is effectively 100. With this change the behavior of those control will be fixed as per autoscale disabled value.
1 parent 905fdb9 commit 9cacd32

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ public abstract class Control extends Widget implements Drawable {
7878
Region region;
7979
Font font;
8080
int drawCount, foreground, background, backgroundAlpha = 255;
81+
boolean autoScaleDisabled = false;
8182

8283
/** Cache for currently processed DPI change event to be able to cancel it if a new one is triggered */
8384
Event currentDpiChangeEvent;
8485

8586
private static final String DATA_SHELL_ZOOM = "SHELL_ZOOM";
87+
88+
private static final String DATA_AUTOSCALE_DISABLED = "AUTOSCALE_DISABLED";
8689
/**
8790
* Prevents uninitialized instances from being created outside the package.
8891
*/
@@ -122,6 +125,7 @@ public abstract class Control extends Widget implements Drawable {
122125
public Control (Composite parent, int style) {
123126
super (parent, style);
124127
this.parent = parent;
128+
this.autoScaleDisabled = parent.autoScaleDisabled;
125129
createWidget ();
126130
}
127131

@@ -1283,6 +1287,19 @@ public Object getData(String key) {
12831287
return super.getData(key);
12841288
}
12851289

1290+
@Override
1291+
public void setData(String key, Object value) {
1292+
super.setData(key, value);
1293+
if (DATA_AUTOSCALE_DISABLED.equals(key)) {
1294+
autoScaleDisabled = Boolean.parseBoolean(value.toString());
1295+
if (autoScaleDisabled) {
1296+
this.nativeZoom = 100;
1297+
} else {
1298+
this.nativeZoom = (int) getData(DATA_SHELL_ZOOM);
1299+
}
1300+
}
1301+
}
1302+
12861303
/**
12871304
* Returns <code>true</code> if the receiver is detecting
12881305
* drag gestures, and <code>false</code> otherwise.
@@ -3547,7 +3564,7 @@ public void setLayoutData (Object layoutData) {
35473564
*/
35483565
public void setLocation (int x, int y) {
35493566
checkWidget ();
3550-
int zoom = getZoom();
3567+
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
35513568
x = DPIUtil.pointToPixel(x, zoom);
35523569
y = DPIUtil.pointToPixel(y, zoom);
35533570
setLocationInPixels(x, y);
@@ -3804,7 +3821,7 @@ public void setRegion (Region region) {
38043821
*/
38053822
public void setSize (int width, int height) {
38063823
checkWidget ();
3807-
int zoom = getZoom();
3824+
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
38083825
width = DPIUtil.pointToPixel(width, zoom);
38093826
height = DPIUtil.pointToPixel(height, zoom);
38103827
setSizeInPixels(width, height);
@@ -4798,6 +4815,23 @@ public boolean setParent (Composite parent) {
47984815
return true;
47994816
}
48004817

4818+
@Override
4819+
GC createNewGC(long hDC, GCData data) {
4820+
data.nativeZoom = getNativeZoom();
4821+
if (autoScaleDisabled && data.font != null) {
4822+
data.font = SWTFontProvider.getFont(display, data.font.getFontData()[0], 100);
4823+
}
4824+
return GC.win32_new(hDC, data);
4825+
}
4826+
4827+
@Override
4828+
int getZoom() {
4829+
if (autoScaleDisabled) {
4830+
return 100;
4831+
}
4832+
return super.getZoom();
4833+
}
4834+
48014835
abstract TCHAR windowClass ();
48024836

48034837
abstract long windowProc ();
@@ -5972,6 +6006,9 @@ void sendZoomChangedEvent(Event event, Shell shell) {
59726006
@Override
59736007
void handleDPIChange(Event event, float scalingFactor) {
59746008
super.handleDPIChange(event, scalingFactor);
6009+
if (this.autoScaleDisabled) {
6010+
this.nativeZoom = 100;
6011+
}
59756012
resizeFont(this, getNativeZoom());
59766013

59776014
Image image = backgroundImage;

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ 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;
6968
int style, state;
7069
Display display;
7170
EventTable eventTable;
@@ -133,8 +132,6 @@ public abstract class Widget {
133132
/* Bidi flag and for auto text direction */
134133
static final int AUTO_TEXT_DIRECTION = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
135134

136-
private static final String DATA_AUTOSCALE_DISABLED = "AUTOSCALE_DISABLED";
137-
138135
/* Initialize the Common Controls DLL */
139136
static {
140137
INITCOMMONCONTROLSEX icce = new INITCOMMONCONTROLSEX ();
@@ -184,7 +181,6 @@ public Widget (Widget parent, int style) {
184181
checkParent (parent);
185182
this.style = style;
186183
this.nativeZoom = parent != null ? parent.nativeZoom : DPIUtil.getNativeDeviceZoom();
187-
this.autoScaleDisabled = parent.autoScaleDisabled;
188184
display = parent.display;
189185
reskinWidget ();
190186
notifyCreationTracker();
@@ -1470,10 +1466,6 @@ public void setData (String key, Object value) {
14701466
}
14711467
}
14721468
if (key.equals(SWT.SKIN_CLASS) || key.equals(SWT.SKIN_ID)) this.reskin(SWT.ALL);
1473-
1474-
if (DATA_AUTOSCALE_DISABLED.equals(key)) {
1475-
autoScaleDisabled = Boolean.parseBoolean(value.toString());
1476-
}
14771469
}
14781470

14791471
boolean sendFocusEvent (int type) {
@@ -2704,23 +2696,14 @@ void notifyDisposalTracker() {
27042696

27052697
GC createNewGC(long hDC, GCData data) {
27062698
data.nativeZoom = getNativeZoom();
2707-
if (autoScaleDisabled && data.font != null) {
2708-
data.font = SWTFontProvider.getFont(display, data.font.getFontData()[0], 100);
2709-
}
27102699
return GC.win32_new(hDC, data);
27112700
}
27122701

27132702
int getNativeZoom() {
2714-
if (autoScaleDisabled) {
2715-
return 100;
2716-
}
27172703
return nativeZoom;
27182704
}
27192705

27202706
int getZoom() {
2721-
if (autoScaleDisabled) {
2722-
return 100;
2723-
}
27242707
return DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
27252708
}
27262709

0 commit comments

Comments
 (0)