Skip to content

Commit d1859ce

Browse files
committed
[GTK] Remove more *InPixels method
They are not needed at all, double some calls (like checkWidget()), and overall complicate debugging and understanding the codebase. Continuation of #2100
1 parent af044d9 commit d1859ce

16 files changed

+23
-213
lines changed

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 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
@@ -317,12 +317,6 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b
317317
* as to why it's unneeded is left as a TODO. See bug 546274.
318318
*/
319319
if (GTK.GTK4) return;
320-
Point destination = new Point (destX, destY);
321-
Rectangle srcRect = new Rectangle (x, y, width, height);
322-
scrollInPixels(destination.x, destination.y, srcRect.x, srcRect.y, srcRect.width, srcRect.height, all);
323-
}
324-
325-
void scrollInPixels (int destX, int destY, int x, int y, int width, int height, boolean all) {
326320
if ((style & SWT.MIRRORED) != 0) {
327321
int clientWidth = getClientWidth ();
328322
x = clientWidth - width - x;

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

+5-50
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ private void drawInCellEditor(long window) {
141141
* </ul>
142142
*/
143143
public Rectangle getBounds () {
144-
checkWidget();
145-
return getBoundsInPixels();
146-
}
147-
148-
Rectangle getBoundsInPixels () {
149144
checkWidget();
150145
if (image != null) {
151146
Rectangle rect = image.getBoundsInPixels ();
@@ -201,11 +196,6 @@ public Image getImage () {
201196
* </ul>
202197
*/
203198
public Point getLocation () {
204-
checkWidget();
205-
return getLocationInPixels();
206-
}
207-
208-
Point getLocationInPixels () {
209199
checkWidget();
210200
return new Point (x, y);
211201
}
@@ -236,11 +226,6 @@ public Canvas getParent () {
236226
* </ul>
237227
*/
238228
public Point getSize () {
239-
checkWidget();
240-
return getSizeInPixels();
241-
}
242-
243-
Point getSizeInPixels () {
244229
checkWidget();
245230
if (image != null) {
246231
Rectangle rect = image.getBoundsInPixels ();
@@ -348,11 +333,6 @@ void releaseWidget () {
348333
* </ul>
349334
*/
350335
public void setBounds (int x, int y, int width, int height) {
351-
checkWidget();
352-
setBounds (new Rectangle (x, y, width, height));
353-
}
354-
355-
void setBoundsInPixels (int x, int y, int width, int height) {
356336
checkWidget();
357337
if (this.x == x && this.y == y && this.width == width && this.height == height) return;
358338
boolean isFocus = isFocusCaret ();
@@ -377,14 +357,9 @@ void setBoundsInPixels (int x, int y, int width, int height) {
377357
* </ul>
378358
*/
379359
public void setBounds (Rectangle rect) {
380-
checkWidget();
381-
setBoundsInPixels(rect);
382-
}
383-
384-
void setBoundsInPixels (Rectangle rect) {
385360
checkWidget();
386361
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
387-
setBoundsInPixels (rect.x, rect.y, rect.width, rect.height);
362+
setBounds (rect.x, rect.y, rect.width, rect.height);
388363
}
389364

390365
void setFocus () {
@@ -457,12 +432,7 @@ public void setImage (Image image) {
457432
*/
458433
public void setLocation (int x, int y) {
459434
checkWidget();
460-
setLocation (new Point (x, y));
461-
}
462-
463-
void setLocationInPixels (int x, int y) {
464-
checkWidget();
465-
setBoundsInPixels (x, y, width, height);
435+
setBounds (x, y, width, height);
466436
}
467437

468438
/**
@@ -478,14 +448,9 @@ void setLocationInPixels (int x, int y) {
478448
* </ul>
479449
*/
480450
public void setLocation (Point location) {
481-
checkWidget();
482-
setLocationInPixels (location);
483-
}
484-
485-
void setLocationInPixels (Point location) {
486451
checkWidget();
487452
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
488-
setLocationInPixels (location.x, location.y);
453+
setLocation (location.x, location.y);
489454
}
490455

491456
/**
@@ -501,12 +466,7 @@ void setLocationInPixels (Point location) {
501466
*/
502467
public void setSize (int width, int height) {
503468
checkWidget();
504-
setSize (new Point (width,height));
505-
}
506-
507-
void setSizeInPixels (int width, int height) {
508-
checkWidget();
509-
setBoundsInPixels (x, y, width, height);
469+
setBounds (x, y, width, height);
510470
}
511471

512472
/**
@@ -523,14 +483,9 @@ void setSizeInPixels (int width, int height) {
523483
* </ul>
524484
*/
525485
public void setSize (Point size) {
526-
checkWidget();
527-
setSizeInPixels(size);
528-
}
529-
530-
void setSizeInPixels (Point size) {
531486
checkWidget();
532487
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
533-
setSizeInPixels (size.x, size.y);
488+
setSize (size.x, size.y);
534489
}
535490

536491
/**

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

+1-13
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,6 @@ long eventSurface () {
10801080
* @since 3.8
10811081
*/
10821082
public Point getCaretLocation () {
1083-
checkWidget ();
1084-
return getCaretLocationInPixels();
1085-
}
1086-
1087-
1088-
Point getCaretLocationInPixels () {
10891083
checkWidget ();
10901084
if ((style & SWT.READ_ONLY) != 0) {
10911085
return new Point (0, 0);
@@ -1389,12 +1383,6 @@ String getText (int start, int stop) {
13891383
* </ul>
13901384
*/
13911385
public int getTextHeight () {
1392-
checkWidget();
1393-
return getTextHeightInPixels();
1394-
}
1395-
1396-
1397-
int getTextHeightInPixels () {
13981386
checkWidget();
13991387
GtkRequisition requisition = new GtkRequisition ();
14001388
gtk_widget_get_preferred_size (handle, requisition);
@@ -2275,7 +2263,7 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) {
22752263
@Override
22762264
int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
22772265
int newHeight = height;
2278-
if (resize) newHeight = Math.max (getTextHeightInPixels (), height);
2266+
if (resize) newHeight = Math.max (getTextHeight (), height);
22792267
return super.setBounds (x, y, width, newHeight, move, resize);
22802268
}
22812269

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6320,14 +6320,14 @@ boolean showMenu (int x, int y, int detail) {
63206320
if (temp != 0) OS.g_object_unref(temp);
63216321

63226322

6323-
menu.setLocationInPixels(x, y);
6323+
menu.setLocation(x, y);
63246324
menu.setVisible(true);
63256325

63266326
return true;
63276327
} else {
63286328
Rectangle rect = event.getBounds ();
63296329
if (rect.x != x || rect.y != y) {
6330-
menu.setLocationInPixels (rect.x, rect.y);
6330+
menu.setLocation (rect.x, rect.y);
63316331
}
63326332
menu.setVisible (true);
63336333
return true;

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

-5
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,6 @@ void setOrientation (boolean create) {
483483
* </ul>
484484
*/
485485
public void setSpacing (int spacing) {
486-
checkWidget ();
487-
setSpacingInPixels(spacing);
488-
}
489-
490-
void setSpacingInPixels (int spacing) {
491486
checkWidget ();
492487
if (spacing < 0) return;
493488
if (spacing == this.spacing) return;

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

-10
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,6 @@ public boolean getExpanded() {
232232
*/
233233
public int getHeaderHeight () {
234234
checkWidget ();
235-
return getHeaderHeightInPixels ();
236-
}
237-
238-
int getHeaderHeightInPixels() {
239-
checkWidget();
240235

241236
GtkAllocation allocation = new GtkAllocation();
242237
GTK.gtk_widget_get_allocation(GTK.gtk_expander_get_label_widget(handle), allocation);
@@ -506,11 +501,6 @@ void setForegroundRGBA (GdkRGBA rgba) {
506501
* </ul>
507502
*/
508503
public void setHeight (int height) {
509-
checkWidget ();
510-
setHeightInPixels(height);
511-
}
512-
513-
void setHeightInPixels (int height) {
514504
checkWidget ();
515505
if (height < 0) return;
516506
this.height = height;

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
275275
* based on the number of items in the table
276276
*/
277277
if (size.y == 0 && hHint == SWT.DEFAULT) {
278-
size.y = getItemCount() * getItemHeightInPixels();
278+
size.y = getItemCount() * getItemHeight();
279279
}
280280

281281
/*
@@ -536,11 +536,6 @@ public int getItemCount () {
536536
*/
537537
public int getItemHeight () {
538538
checkWidget();
539-
return getItemHeightInPixels();
540-
}
541-
542-
int getItemHeightInPixels() {
543-
checkWidget();
544539

545540
final int BASE_ITEM_PADDING = 1;
546541

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

+1-11
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 (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
/**

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

-5
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@ public int getSelection () {
288288
* </ul>
289289
*/
290290
public Point getSize () {
291-
checkWidget ();
292-
return getSizeInPixels ();
293-
}
294-
295-
Point getSizeInPixels () {
296291
checkWidget ();
297292
if (handle == 0) return new Point (0,0);
298293
GtkRequisition requisition = new GtkRequisition ();

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

+9-40
Original file line numberDiff line numberDiff line change
@@ -1295,11 +1295,6 @@ public boolean getMaximized () {
12951295
* @since 3.1
12961296
*/
12971297
public Point getMinimumSize () {
1298-
checkWidget ();
1299-
return getMinimumSizeInPixels ();
1300-
}
1301-
1302-
Point getMinimumSizeInPixels () {
13031298
checkWidget ();
13041299
int width = Math.max (1, geometry.getMinWidth() + trimWidth ());
13051300
int height = Math.max (1, geometry.getMinHeight() + trimHeight ());
@@ -1323,12 +1318,6 @@ Point getMinimumSizeInPixels () {
13231318
*/
13241319
public Point getMaximumSize () {
13251320
checkWidget ();
1326-
return getMaximumSizeInPixels ();
1327-
}
1328-
1329-
Point getMaximumSizeInPixels () {
1330-
checkWidget ();
1331-
13321321
int width = Math.min (Integer.MAX_VALUE, geometry.getMaxWidth() + trimWidth ());
13331322
int height = Math.min (Integer.MAX_VALUE, geometry.getMaxHeight() + trimHeight ());
13341323
return new Point (width, height);
@@ -2661,11 +2650,6 @@ public void setMinimized (boolean minimized) {
26612650
* @since 3.1
26622651
*/
26632652
public void setMinimumSize (int width, int height) {
2664-
checkWidget ();
2665-
setMinimumSize (new Point (width, height));
2666-
}
2667-
2668-
void setMinimumSizeInPixels (int width, int height) {
26692653
checkWidget ();
26702654
geometry.setMinWidth(Math.max (width, trimWidth ()) - trimWidth ());
26712655
geometry.setMinHeight(Math.max (height, trimHeight ()) - trimHeight ());
@@ -2700,14 +2684,9 @@ void setMinimumSizeInPixels (int width, int height) {
27002684
* @since 3.1
27012685
*/
27022686
public void setMinimumSize (Point size) {
2703-
checkWidget ();
2704-
setMinimumSizeInPixels (size);
2705-
}
2706-
2707-
void setMinimumSizeInPixels (Point size) {
27082687
checkWidget ();
27092688
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
2710-
setMinimumSizeInPixels (size.x, size.y);
2689+
setMinimumSize (size.x, size.y);
27112690
}
27122691

27132692
/**
@@ -2732,7 +2711,13 @@ void setMinimumSizeInPixels (Point size) {
27322711
*/
27332712
public void setMaximumSize (int width, int height) {
27342713
checkWidget ();
2735-
setMaximumSize (new Point (width, height));
2714+
geometry.setMaxWidth(Math.max (width, trimWidth ()) - trimWidth ());
2715+
geometry.setMaxHeight(Math.max (height, trimHeight ()) - trimHeight ());
2716+
int hint = GDK.GDK_HINT_MAX_SIZE;
2717+
if (geometry.getMinWidth() > 0 || geometry.getMinHeight() > 0) {
2718+
hint = hint | GDK.GDK_HINT_MIN_SIZE;
2719+
}
2720+
GTK3.gtk_window_set_geometry_hints (shellHandle, 0, (GdkGeometry) geometry, hint);
27362721
}
27372722

27382723
/**
@@ -2758,25 +2743,9 @@ public void setMaximumSize (int width, int height) {
27582743
* @since 3.116
27592744
*/
27602745
public void setMaximumSize (Point size) {
2761-
checkWidget ();
2762-
setMaximumSizeInPixels (size);
2763-
}
2764-
2765-
void setMaximumSizeInPixels (Point size) {
27662746
checkWidget ();
27672747
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
2768-
setMaximumSizeInPixels (size.x, size.y);
2769-
}
2770-
2771-
void setMaximumSizeInPixels (int width, int height) {
2772-
checkWidget ();
2773-
geometry.setMaxWidth(Math.max (width, trimWidth ()) - trimWidth ());
2774-
geometry.setMaxHeight(Math.max (height, trimHeight ()) - trimHeight ());
2775-
int hint = GDK.GDK_HINT_MAX_SIZE;
2776-
if (geometry.getMinWidth() > 0 || geometry.getMinHeight() > 0) {
2777-
hint = hint | GDK.GDK_HINT_MIN_SIZE;
2778-
}
2779-
GTK3.gtk_window_set_geometry_hints (shellHandle, 0, (GdkGeometry) geometry, hint);
2748+
setMaximumSize (size.x, size.y);
27802749
}
27812750

27822751
/**

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

-5
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ void destroyWidget () {
160160
*/
161161
public Rectangle getBounds () {
162162
checkWidget ();
163-
return getBoundsInPixels ();
164-
}
165-
166-
Rectangle getBoundsInPixels () {
167-
checkWidget();
168163
GtkAllocation allocation = new GtkAllocation ();
169164
GTK.gtk_widget_get_allocation (handle, allocation);
170165
int x = allocation.x;

0 commit comments

Comments
 (0)