Skip to content

Commit bfcadf9

Browse files
committed
[GTK] Stop using DPIUtil (take 2)
Handles remaining widgets code. Continuation of #2058
1 parent 981e760 commit bfcadf9

File tree

8 files changed

+118
-142
lines changed

8 files changed

+118
-142
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -266,7 +266,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
266266
if (layout != null) {
267267
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
268268
changed |= (state & LAYOUT_CHANGED) != 0;
269-
size = DPIUtil.autoScaleUp(layout.computeSize (this, DPIUtil.autoScaleDown(wHint), DPIUtil.autoScaleDown(hHint), changed));
269+
size = layout.computeSize (this, wHint, hHint, changed);
270270
state &= ~LAYOUT_CHANGED;
271271
} else {
272272
size = new Point (wHint, hHint);
@@ -278,7 +278,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
278278
}
279279
if (wHint != SWT.DEFAULT) size.x = wHint;
280280
if (hHint != SWT.DEFAULT) size.y = hHint;
281-
Rectangle trim = DPIUtil.autoScaleUp (computeTrim (0, 0, DPIUtil.autoScaleDown(size.x), DPIUtil.autoScaleDown(size.y)));
281+
Rectangle trim = computeTrim (0, 0, size.x, size.y);
282282
return new Point (trim.width, trim.height);
283283
}
284284

@@ -550,9 +550,7 @@ void deregister () {
550550
*/
551551
public void drawBackground (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) {
552552
checkWidget();
553-
Rectangle rect = DPIUtil.autoScaleUp(new Rectangle (x, y, width, height));
554-
offsetX = DPIUtil.autoScaleUp(offsetX);
555-
offsetY = DPIUtil.autoScaleUp(offsetY);
553+
Rectangle rect = new Rectangle (x, y, width, height);
556554
drawBackgroundInPixels(gc, rect.x, rect.y, rect.width, rect.height, offsetX, offsetY);
557555
}
558556

@@ -591,7 +589,7 @@ void drawBackgroundInPixels (GC gc, int x, int y, int width, int height, int off
591589
Cairo.cairo_fill (cairo);
592590
Cairo.cairo_restore (cairo);
593591
} else {
594-
gc.fillRectangle(DPIUtil.autoScaleDown(new Rectangle(x, y, width, height)));
592+
gc.fillRectangle(new Rectangle(x, y, width, height));
595593

596594
}
597595
}
@@ -1427,10 +1425,10 @@ Point minimumSize (int wHint, int hHint, boolean changed) {
14271425
* Since getClientArea can be overridden by subclasses, we cannot
14281426
* call getClientAreaInPixels directly.
14291427
*/
1430-
Rectangle clientArea = DPIUtil.autoScaleUp(getClientArea ());
1428+
Rectangle clientArea = getClientArea ();
14311429
int width = 0, height = 0;
14321430
for (int i=0; i<children.length; i++) {
1433-
Rectangle rect = DPIUtil.autoScaleUp(children [i].getBounds ());
1431+
Rectangle rect = children [i].getBounds ();
14341432
width = Math.max (width, rect.x - clientArea.x + rect.width);
14351433
height = Math.max (height, rect.y - clientArea.y + rect.height);
14361434
}
@@ -1446,7 +1444,7 @@ long parentingHandle () {
14461444
void printWidget (GC gc, long drawable, int depth, int x, int y) {
14471445
Region oldClip = new Region (gc.getDevice ());
14481446
Region newClip = new Region (gc.getDevice ());
1449-
Point loc = DPIUtil.autoScaleDown(new Point (x, y));
1447+
Point loc = new Point (x, y);
14501448
gc.getClipping (oldClip);
14511449
Rectangle rect = getBounds ();
14521450
newClip.add (oldClip);
@@ -1457,7 +1455,7 @@ void printWidget (GC gc, long drawable, int depth, int x, int y) {
14571455
Point pt = display.mapInPixels (this, parent, clientRect.x, clientRect.y);
14581456
clientRect.x = x + pt.x - rect.x;
14591457
clientRect.y = y + pt.y - rect.y;
1460-
newClip.intersect (DPIUtil.autoScaleDown(clientRect));
1458+
newClip.intersect (clientRect);
14611459
gc.setClipping (newClip);
14621460
Control [] children = _getChildren ();
14631461
for (int i=children.length-1; i>=0; --i) {

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

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
832832
checkWidget();
833833
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
834834
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
835-
wHint = DPIUtil.autoScaleUp(wHint);
836-
hHint = DPIUtil.autoScaleUp(hHint);
837-
return DPIUtil.autoScaleDown (computeSizeInPixels (wHint, hHint, changed));
835+
return computeSizeInPixels (wHint, hHint, changed);
838836
}
839837

840838
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@@ -933,7 +931,7 @@ Accessible _getAccessible () {
933931
*/
934932
public Rectangle getBounds () {
935933
checkWidget();
936-
return DPIUtil.autoScaleDown(getBoundsInPixels());
934+
return getBoundsInPixels();
937935
}
938936

939937
Rectangle getBoundsInPixels () {
@@ -975,7 +973,6 @@ Rectangle getBoundsInPixels () {
975973
public void setBounds (Rectangle rect) {
976974
checkWidget ();
977975
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
978-
rect = DPIUtil.autoScaleUp(rect);
979976
setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true);
980977
}
981978

@@ -1015,7 +1012,7 @@ void setBoundsInPixels (Rectangle rect) {
10151012
*/
10161013
public void setBounds (int x, int y, int width, int height) {
10171014
checkWidget();
1018-
Rectangle rect = DPIUtil.autoScaleUp(new Rectangle (x, y, width, height));
1015+
Rectangle rect = new Rectangle (x, y, width, height);
10191016
setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true);
10201017
}
10211018

@@ -1234,7 +1231,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
12341231
*/
12351232
public Point getLocation () {
12361233
checkWidget();
1237-
return DPIUtil.autoScaleDown(getLocationInPixels());
1234+
return getLocationInPixels();
12381235
}
12391236

12401237
Point getLocationInPixels () {
@@ -1271,7 +1268,6 @@ Point getLocationInPixels () {
12711268
public void setLocation (Point location) {
12721269
checkWidget ();
12731270
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
1274-
location = DPIUtil.autoScaleUp(location);
12751271
setBounds (location.x, location.y, 0, 0, true, false);
12761272
}
12771273

@@ -1301,7 +1297,7 @@ void setLocationInPixels (Point location) {
13011297
*/
13021298
public void setLocation(int x, int y) {
13031299
checkWidget();
1304-
Point loc = DPIUtil.autoScaleUp(new Point (x, y));
1300+
Point loc = new Point (x, y);
13051301
setBounds (loc.x, loc.y, 0, 0, true, false);
13061302
}
13071303

@@ -1325,7 +1321,7 @@ void setLocationInPixels(int x, int y) {
13251321
*/
13261322
public Point getSize () {
13271323
checkWidget();
1328-
return DPIUtil.autoScaleDown(getSizeInPixels());
1324+
return getSizeInPixels();
13291325
}
13301326

13311327
Point getSizeInPixels () {
@@ -1364,7 +1360,6 @@ Point getSizeInPixels () {
13641360
public void setSize (Point size) {
13651361
checkWidget ();
13661362
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
1367-
size = DPIUtil.autoScaleUp(size);
13681363
setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true);
13691364
}
13701365

@@ -1483,7 +1478,7 @@ void setRelations () {
14831478
*/
14841479
public void setSize (int width, int height) {
14851480
checkWidget();
1486-
Point size = DPIUtil.autoScaleUp(new Point (width, height));
1481+
Point size = new Point (width, height);
14871482
setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true);
14881483
}
14891484

@@ -1667,9 +1662,9 @@ public Point toControl(int x, int y) {
16671662
GDK.gdk_window_get_origin(window, origin_x, origin_y);
16681663
}
16691664

1670-
x -= DPIUtil.autoScaleDown(origin_x[0]);
1671-
y -= DPIUtil.autoScaleDown(origin_y[0]);
1672-
if ((style & SWT.MIRRORED) != 0) x = DPIUtil.autoScaleDown(getClientWidth()) - x;
1665+
x -= origin_x[0];
1666+
y -= origin_y[0];
1667+
if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
16731668

16741669
return new Point(x, y);
16751670
}
@@ -1732,9 +1727,9 @@ public Point toDisplay(int x, int y) {
17321727
GDK.gdk_window_get_origin(window, origin_x, origin_y);
17331728
}
17341729

1735-
if ((style & SWT.MIRRORED) != 0) x = DPIUtil.autoScaleDown(getClientWidth()) - x;
1736-
x += DPIUtil.autoScaleDown(origin_x[0]);
1737-
y += DPIUtil.autoScaleDown(origin_y[0]);
1730+
if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
1731+
x += origin_x[0];
1732+
y += origin_y[0];
17381733

17391734
return new Point(x, y);
17401735
}
@@ -3018,7 +3013,7 @@ GdkRGBA getBaseGdkRGBA () {
30183013
* </ul>
30193014
*/
30203015
public int getBorderWidth () {
3021-
return DPIUtil.autoScaleDown(getBorderWidthInPixels());
3016+
return getBorderWidthInPixels();
30223017
}
30233018

30243019
int getBorderWidthInPixels () {
@@ -3557,8 +3552,7 @@ long gtk_button_press_event (long widget, long event, boolean sendMouseDown) {
35573552
// See comment in #dragDetect()
35583553
if (OS.isX11()) {
35593554
if (dragging) {
3560-
Point scaledEvent = DPIUtil.autoScaleDown(new Point((int)eventX[0], (int) eventY[0]));
3561-
sendDragEvent (eventButton[0], eventState[0], scaledEvent.x, scaledEvent.y, false);
3555+
sendDragEvent (eventButton[0], eventState[0], (int)eventX[0], (int)eventY[0], false);
35623556
if (isDisposed ()) return 1;
35633557
}
35643558
}
@@ -3885,8 +3879,8 @@ long gtk_draw (long widget, long cairo) {
38853879
if (!hooksPaint ()) return 0;
38863880
Event event = new Event ();
38873881
event.count = 1;
3888-
Rectangle eventBounds = DPIUtil.autoScaleDown (new Rectangle (rect.x, rect.y, rect.width, rect.height));
3889-
if ((style & SWT.MIRRORED) != 0) eventBounds.x = DPIUtil.autoScaleDown (getClientWidth ()) - eventBounds.width - eventBounds.x;
3882+
Rectangle eventBounds = new Rectangle (rect.x, rect.y, rect.width, rect.height);
3883+
if ((style & SWT.MIRRORED) != 0) eventBounds.x = getClientWidth () - eventBounds.width - eventBounds.x;
38903884
event.setBounds (eventBounds);
38913885
GCData data = new GCData ();
38923886
/*
@@ -4175,7 +4169,7 @@ long gtk_motion_notify_event (long widget, long event) {
41754169
int eventType = GDK.gdk_event_get_event_type(event);
41764170
if (eventType == GDK.GDK_3BUTTON_PRESS) return 0;
41774171

4178-
Point scaledEvent = DPIUtil.autoScaleDown(new Point((int)eventX[0], (int) eventY[0]));
4172+
Point scaledEvent = new Point((int)eventX[0], (int) eventY[0]);
41794173

41804174
int [] eventButton = new int [1];
41814175
int [] eventState = new int [1];
@@ -4708,8 +4702,7 @@ void redraw (boolean all) {
47084702
*/
47094703
public void redraw (int x, int y, int width, int height, boolean all) {
47104704
checkWidget();
4711-
Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height));
4712-
redrawInPixels(rect.x, rect.y, rect.width, rect.height, all);
4705+
redrawInPixels(x, y, width, height, all);
47134706
}
47144707

47154708
void redrawInPixels (int x, int y, int width, int height, boolean all) {
@@ -4894,7 +4887,7 @@ boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateM
48944887
event.button = button;
48954888
Rectangle eventRect = new Rectangle (x, y, 0, 0);
48964889
event.setBounds (eventRect);
4897-
if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown(getClientWidth ()) - event.x;
4890+
if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x;
48984891
if (isStateMask) {
48994892
event.stateMask = stateMask;
49004893
} else {
@@ -5062,7 +5055,7 @@ boolean sendMouseEvent (int type, int button, int count, int detail, boolean sen
50625055
if (is_hint) {
50635056
// coordinates are already window-relative, see #gtk_motion_notify_event(..) and bug 94502
50645057
Rectangle eventRect = new Rectangle ((int)x, (int)y, 0, 0);
5065-
event.setBounds (DPIUtil.autoScaleDown (eventRect));
5058+
event.setBounds (eventRect);
50665059
} else {
50675060
int [] origin_x = new int [1], origin_y = new int [1];
50685061
Rectangle eventRect;
@@ -5071,15 +5064,15 @@ boolean sendMouseEvent (int type, int button, int count, int detail, boolean sen
50715064
// GDK.gdk_surface_get_origin (surface, origin_x, origin_y);
50725065
// eventRect = new Rectangle ((int)x - origin_x [0], (int)y - origin_y [0], 0, 0);
50735066
eventRect = new Rectangle ((int)x, (int)y, 0, 0);
5074-
event.setBounds (DPIUtil.autoScaleDown (eventRect));
5067+
event.setBounds (eventRect);
50755068
} else {
50765069
long window = eventWindow ();
50775070
GDK.gdk_window_get_origin (window, origin_x, origin_y);
50785071
eventRect = new Rectangle ((int)x - origin_x [0], (int)y - origin_y [0], 0, 0);
5079-
event.setBounds (DPIUtil.autoScaleDown (eventRect));
5072+
event.setBounds (eventRect);
50805073
}
50815074
}
5082-
if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (getClientWidth ()) - event.x;
5075+
if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x;
50835076
setInputState (event, state);
50845077

50855078
/**
@@ -6309,7 +6302,7 @@ boolean showMenu (int x, int y) {
63096302
boolean showMenu (int x, int y, int detail) {
63106303
Event event = new Event ();
63116304
Rectangle eventRect = new Rectangle (x, y, 0, 0);
6312-
event.setBounds (DPIUtil.autoScaleDown (eventRect));
6305+
event.setBounds (eventRect);
63136306
event.detail = detail;
63146307
sendEvent (SWT.MenuDetect, event);
63156308
//widget could be disposed at this point
@@ -6332,7 +6325,7 @@ boolean showMenu (int x, int y, int detail) {
63326325

63336326
return true;
63346327
} else {
6335-
Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ());
6328+
Rectangle rect = event.getBounds ();
63366329
if (rect.x != x || rect.y != y) {
63376330
menu.setLocationInPixels (rect.x, rect.y);
63386331
}

0 commit comments

Comments
 (0)