Skip to content

Commit b48f0d1

Browse files
committed
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path
Fixes #1300
1 parent d9fbab8 commit b48f0d1

30 files changed

+182
-495
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ public Point getCaretLocation () {
10921092
PangoRectangle pos = new PangoRectangle ();
10931093
OS.pango_layout_index_to_pos (layout, index, pos);
10941094
Point thickness = getThickness (entryHandle);
1095-
int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidthInPixels () - thickness.x;
1095+
int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidth() - thickness.x;
10961096
int y = offset_y [0] + OS.PANGO_PIXELS (pos.y) - thickness.y;
10971097
return new Point (x, y);
10981098
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ public void setBounds(int x, int y, int width, int height) {
17451745
* Usually called when control is resized or first initialized.
17461746
*/
17471747
private void setDropDownButtonSize() {
1748-
Rectangle rect = getClientAreaInPixels();
1748+
Rectangle rect = getClientArea();
17491749
int parentWidth = rect.width;
17501750
int parentHeight = rect.height;
17511751
Point buttonSize = down.computeSize(SWT.DEFAULT, parentHeight);

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,8 @@ public boolean getExpanded() {
232232
*/
233233
public int getHeaderHeight () {
234234
checkWidget ();
235-
return DPIUtil.autoScaleDown (getHeaderHeightInPixels ());
236-
}
237-
238-
int getHeaderHeightInPixels() {
239-
checkWidget();
240-
241235
GtkAllocation allocation = new GtkAllocation();
242236
GTK.gtk_widget_get_allocation(GTK.gtk_expander_get_label_widget(handle), allocation);
243-
244237
return allocation.height;
245238
}
246239

@@ -256,7 +249,7 @@ int getHeaderHeightInPixels() {
256249
*/
257250
public int getHeight() {
258251
checkWidget();
259-
return DPIUtil.autoScaleDown(height);
252+
return height;
260253
}
261254

262255
/**
@@ -506,11 +499,6 @@ void setForegroundRGBA (GdkRGBA rgba) {
506499
* </ul>
507500
*/
508501
public void setHeight (int height) {
509-
checkWidget ();
510-
setHeightInPixels(DPIUtil.autoScaleUp(height));
511-
}
512-
513-
void setHeightInPixels (int height) {
514502
checkWidget ();
515503
if (height < 0) return;
516504
this.height = height;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ long clientHandle () {
110110
}
111111

112112
@Override
113-
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
114-
Point size = super.computeSizeInPixels(wHint, hHint, changed);
113+
public Point computeSize(int wHint, int hHint, boolean changed) {
114+
Point size = super.computeSize(wHint, hHint, changed);
115115
int width = computeNativeSize (handle, SWT.DEFAULT, SWT.DEFAULT, false).x;
116116
size.x = Math.max (size.x, width);
117117
return size;
118118
}
119119
@Override
120-
Rectangle computeTrimInPixels (int x, int y, int width, int height) {
120+
public Rectangle computeTrim(int x, int y, int width, int height) {
121121
checkWidget();
122122
forceResize ();
123123
GtkAllocation allocation = new GtkAllocation();
@@ -132,8 +132,8 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
132132
}
133133

134134
@Override
135-
Rectangle getClientAreaInPixels () {
136-
Rectangle clientRectangle = super.getClientAreaInPixels ();
135+
public Rectangle getClientArea() {
136+
Rectangle clientRectangle = super.getClientArea();
137137
/*
138138
* Bug 453827 Child position fix.
139139
* SWT's calls to gtk_widget_size_allocate and gtk_widget_set_allocation

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Point computeNativeSize (long h, int wHint, int hHint, boolean changed) {
139139
}
140140
}
141141
@Override
142-
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
142+
public Point computeSize(int wHint, int hHint, boolean changed) {
143143
checkWidget ();
144144
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
145145
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
@@ -369,7 +369,7 @@ public int getAlignment () {
369369
}
370370

371371
@Override
372-
int getBorderWidthInPixels () {
372+
public int getBorderWidth() {
373373
checkWidget();
374374
if (frameHandle != 0) {
375375
return getThickness (frameHandle).x;

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.eclipse.swt.accessibility.*;
1919
import org.eclipse.swt.events.*;
2020
import org.eclipse.swt.graphics.*;
21-
import org.eclipse.swt.internal.*;
2221
import org.eclipse.swt.internal.gtk.*;
2322
import org.eclipse.swt.internal.gtk3.*;
2423
import org.eclipse.swt.internal.gtk4.*;
@@ -121,7 +120,7 @@ public void addSelectionListener (SelectionListener listener) {
121120
}
122121

123122
@Override
124-
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
123+
public Point computeSize(int wHint, int hHint, boolean changed) {
125124
checkWidget ();
126125
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
127126
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
@@ -130,19 +129,19 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
130129
//TEMPORARY CODE
131130
if (wHint == 0) {
132131
layout.setWidth (1);
133-
Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds ());
132+
Rectangle rect = layout.getBounds ();
134133
width = 0;
135134
height = rect.height;
136135
} else {
137-
layout.setWidth (DPIUtil.autoScaleDown(wHint));
138-
Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds ());
136+
layout.setWidth(wHint);
137+
Rectangle rect = layout.getBounds ();
139138
width = rect.width;
140139
height = rect.height;
141140
}
142141
layout.setWidth (layoutWidth);
143142
if (wHint != SWT.DEFAULT) width = wHint;
144143
if (hHint != SWT.DEFAULT) height = hHint;
145-
int border = getBorderWidthInPixels ();
144+
int border = getBorderWidth();
146145
width += border * 2;
147146
height += border * 2;
148147
return new Point (width, height);
@@ -191,9 +190,9 @@ void drawWidget(GC gc) {
191190
if ((state & DISABLED) != 0) gc.setForeground (disabledColor);
192191
layout.draw (gc, 0, 0, selStart, selEnd, null, null);
193192
if (hasFocus () && focusIndex != -1) {
194-
Rectangle [] rects = getRectanglesInPixels (focusIndex);
193+
Rectangle [] rects = getRectangles(focusIndex);
195194
for (int i = 0; i < rects.length; i++) {
196-
Rectangle rect = DPIUtil.autoScaleDown(rects [i]);
195+
Rectangle rect = rects [i];
197196
gc.drawFocus (rect.x, rect.y, rect.width, rect.height);
198197
}
199198
}
@@ -292,7 +291,7 @@ String getNameText () {
292291
return getText ();
293292
}
294293

295-
Rectangle [] getRectanglesInPixels (int linkIndex) {
294+
Rectangle [] getRectangles(int linkIndex) {
296295
int lineCount = layout.getLineCount ();
297296
Rectangle [] rects = new Rectangle [lineCount];
298297
int [] lineOffsets = layout.getLineOffsets ();
@@ -303,13 +302,13 @@ String getNameText () {
303302
while (point.y > lineOffsets [lineEnd]) lineEnd++;
304303
int index = 0;
305304
if (lineStart == lineEnd) {
306-
rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, point.y));
305+
rects [index++] = layout.getBounds (point.x, point.y);
307306
} else {
308-
rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (point.x, lineOffsets [lineStart]-1));
309-
rects [index++] = DPIUtil.autoScaleUp (layout.getBounds (lineOffsets [lineEnd-1], point.y));
307+
rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
308+
rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
310309
if (lineEnd - lineStart > 1) {
311310
for (int i = lineStart; i < lineEnd - 1; i++) {
312-
rects [index++] = DPIUtil.autoScaleUp (layout.getLineBounds (i));
311+
rects [index++] = layout.getLineBounds (i);
313312
}
314313
}
315314
}
@@ -365,7 +364,7 @@ long gtk_button_press_event (long widget, long event) {
365364
int x = (int) eventX[0];
366365
int y = (int) eventY[0];
367366
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
368-
int offset = DPIUtil.autoScaleUp(layout.getOffset (x, y, null));
367+
int offset = layout.getOffset (x, y, null);
369368
int oldSelectionX = selection.x;
370369
int oldSelectionY = selection.y;
371370
selection.x = offset;
@@ -376,11 +375,11 @@ long gtk_button_press_event (long widget, long event) {
376375
oldSelectionX = oldSelectionY;
377376
oldSelectionY = temp;
378377
}
379-
Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds (oldSelectionX, oldSelectionY));
380-
redrawInPixels (rect.x, rect.y, rect.width, rect.height, false);
378+
Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY);
379+
redraw(rect.x, rect.y, rect.width, rect.height, false);
381380
}
382381
for (int j = 0; j < offsets.length; j++) {
383-
Rectangle [] rects = getRectanglesInPixels (j);
382+
Rectangle [] rects = getRectangles(j);
384383
for (int i = 0; i < rects.length; i++) {
385384
Rectangle rect = rects [i];
386385
if (rect.contains (x, y)) {
@@ -419,7 +418,7 @@ long gtk_button_release_event (long widget, long event) {
419418
int x = (int) eventX[0];
420419
int y = (int) eventY[0];
421420
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
422-
Rectangle [] rects = getRectanglesInPixels (focusIndex);
421+
Rectangle [] rects = getRectangles(focusIndex);
423422
for (int i = 0; i < rects.length; i++) {
424423
Rectangle rect = rects [i];
425424
if (rect.contains (x, y)) {
@@ -544,7 +543,7 @@ long gtk_motion_notify_event (long widget, long event) {
544543
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
545544
if ((state[0] & GDK.GDK_BUTTON1_MASK) != 0) {
546545
int oldSelection = selection.y;
547-
selection.y = DPIUtil.autoScaleUp(layout.getOffset (x, y, null));
546+
selection.y = layout.getOffset (x, y, null);
548547
if (selection.y != oldSelection) {
549548
int newSelection = selection.y;
550549
if (oldSelection > newSelection) {
@@ -553,11 +552,11 @@ long gtk_motion_notify_event (long widget, long event) {
553552
newSelection = temp;
554553
}
555554
Rectangle rect = layout.getBounds (oldSelection, newSelection);
556-
redrawInPixels (rect.x, rect.y, rect.width, rect.height, false);
555+
redraw(rect.x, rect.y, rect.width, rect.height, false);
557556
}
558557
} else {
559558
for (int j = 0; j < offsets.length; j++) {
560-
Rectangle [] rects = getRectanglesInPixels (j);
559+
Rectangle [] rects = getRectangles(j);
561560
for (int i = 0; i < rects.length; i++) {
562561
Rectangle rect = rects [i];
563562
if (rect.contains (x, y)) {
@@ -810,7 +809,7 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuilder result) {
810809
int setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
811810
int result = super.setBounds (x, y, width,height, move, resize);
812811
if ((result & RESIZED) != 0) {
813-
layout.setWidth (DPIUtil.autoScaleDown((width > 0 ? width : -1)));
812+
layout.setWidth(width > 0 ? width : -1);
814813
redraw ();
815814
}
816815
return result;

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ int applyThemeBackground () {
269269
}
270270

271271
@Override
272-
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
272+
public Point computeSize(int wHint, int hHint, boolean changed) {
273273
checkWidget ();
274274
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
275275
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
@@ -282,7 +282,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
282282
* based on the number of items in the table
283283
*/
284284
if (size.y == 0 && hHint == SWT.DEFAULT) {
285-
size.y = getItemCount() * getItemHeightInPixels();
285+
size.y = getItemCount() * getItemHeight();
286286
}
287287

288288
/*
@@ -291,7 +291,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
291291
* so need to assign default height
292292
*/
293293
if (size.y == 0 && hHint == SWT.DEFAULT) size.y = DEFAULT_HEIGHT;
294-
Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y);
294+
Rectangle trim = computeTrim(0, 0, size.x, size.y);
295295
size.x = trim.width;
296296
size.y = trim.height;
297297
return size;
@@ -543,12 +543,6 @@ public int getItemCount () {
543543
*/
544544
public int getItemHeight () {
545545
checkWidget();
546-
return DPIUtil.autoScaleDown(getItemHeightInPixels());
547-
}
548-
549-
int getItemHeightInPixels() {
550-
checkWidget();
551-
552546
final int BASE_ITEM_PADDING = 1;
553547

554548
int[] h = new int [1];

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,6 @@ public void setEnabled(boolean enabled) {
11981198
*/
11991199
public void setLocation (int x, int y) {
12001200
checkWidget ();
1201-
setLocation (new Point (x, y));
1202-
}
1203-
1204-
void setLocationInPixels (int x, int y) {
1205-
checkWidget();
12061201
if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
12071202
this.x = x;
12081203
this.y = y;
@@ -1235,13 +1230,8 @@ void setLocationInPixels (int x, int y) {
12351230
*/
12361231
public void setLocation (Point location) {
12371232
checkWidget ();
1238-
setLocationInPixels (DPIUtil.autoScaleUp (location));
1239-
}
1240-
1241-
void setLocationInPixels (Point location) {
1242-
checkWidget();
12431233
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
1244-
setLocationInPixels (location.x, location.y);
1234+
setLocation(location.x, location.y);
12451235
}
12461236

12471237
/**

0 commit comments

Comments
 (0)