Skip to content

Commit 10635b5

Browse files
joel-majanoakurtakov
authored andcommitted
Bug 576120 - [GTK4] Replace GTK3/4 specific gtk_widget_size_allocate
This patch contains a new function in Widget called gtk_widget_size_allocate which replaces the need to use GTK3 and GTK4 specific calls to the same function. There are other places that use specific calls, but all if(GTK.GTK4) wrapped calls have been replaced. Change-Id: Ia815181528c38a7663a104a4c99fe08079e76640 Signed-off-by: jmajano <[email protected]> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/185622 Tested-by: Platform Bot <[email protected]> Reviewed-by: Alexander Kurtakov <[email protected]>
1 parent bb5417b commit 10635b5

File tree

7 files changed

+17
-33
lines changed

7 files changed

+17
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
10051005
Point sizes = resizeCalculationsGTK3(boxHandle, boxWidth, boxHeight);
10061006
allocation.width = sizes.x;
10071007
allocation.height = sizes.y;
1008-
GTK3.gtk_widget_size_allocate (boxHandle, allocation);
1008+
gtk_widget_size_allocate(boxHandle, allocation, -1);
10091009
}
10101010
return result;
10111011
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,7 @@ void adjustChildClipping (long widget) {
472472
// Call gtk_widget_get_preferred_size() to prevent warnings
473473
GTK.gtk_widget_get_preferred_size(widget, minimumSize, naturalSize);
474474
// Allocate and queue a resize event
475-
if (GTK.GTK4) {
476-
GTK4.gtk_widget_size_allocate(widget, allocation, -1);
477-
} else {
478-
GTK3.gtk_widget_size_allocate(widget, allocation);
479-
}
475+
gtk_widget_size_allocate(widget, allocation, -1);
480476
GTK.gtk_widget_queue_resize(widget);
481477
}
482478
}
@@ -1400,11 +1396,7 @@ void moveChildren(int oldWidth) {
14001396
gtk_widget_get_preferred_size (topHandle, requisition);
14011397
allocation.x = x;
14021398
allocation.y = y;
1403-
if (GTK.GTK4) {
1404-
GTK4.gtk_widget_size_allocate (topHandle, allocation, -1);
1405-
} else {
1406-
GTK3.gtk_widget_size_allocate (topHandle, allocation);
1407-
}
1399+
gtk_widget_size_allocate(topHandle, allocation, -1);
14081400
Control control = child.findBackgroundControl ();
14091401
if (control != null && control.backgroundImage != null) {
14101402
if (child.isVisible ()) child.redrawWidget (0, 0, 0, 0, true, true, true);

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -882,11 +882,7 @@ void forceResize () {
882882
gtk_widget_get_preferred_size (topHandle, requisition);
883883
GtkAllocation allocation = new GtkAllocation ();
884884
GTK.gtk_widget_get_allocation(topHandle, allocation);
885-
if (GTK.GTK4) {
886-
GTK4.gtk_widget_size_allocate (topHandle, allocation, -1);
887-
} else {
888-
GTK3.gtk_widget_size_allocate (topHandle, allocation);
889-
}
885+
gtk_widget_size_allocate(topHandle, allocation, -1);
890886
}
891887

892888
/**
@@ -1153,11 +1149,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
11531149
Control focusControl = display.getFocusControl();
11541150
GTK.gtk_widget_show(topHandle);
11551151
gtk_widget_get_preferred_size (topHandle, requisition);
1156-
if (GTK.GTK4) {
1157-
GTK4.gtk_widget_size_allocate (topHandle, allocation, -1);
1158-
} else {
1159-
GTK3.gtk_widget_size_allocate (topHandle, allocation);
1160-
}
1152+
gtk_widget_size_allocate(topHandle, allocation, -1);
11611153
GTK.gtk_widget_hide(topHandle);
11621154
/* Bug 540002: Showing and hiding widget causes original focused control to loose focus,
11631155
* Reset focus to original focused control after dealing with allocation.
@@ -5875,11 +5867,7 @@ public boolean setParent (Composite parent) {
58755867
allocation.y = y;
58765868
allocation.width = width;
58775869
allocation.height = height;
5878-
if (GTK.GTK4) {
5879-
GTK4.gtk_widget_size_allocate (topHandle, allocation, -1);
5880-
} else {
5881-
GTK3.gtk_widget_size_allocate (topHandle, allocation);
5882-
}
5870+
gtk_widget_size_allocate(topHandle, allocation, -1);
58835871
this.parent = parent;
58845872
setZOrder (null, false, true);
58855873
reskin (SWT.ALL);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
585585
GTK.gtk_widget_get_allocation(labelHandle, allocation);
586586
allocation.width = labelWidth;
587587
allocation.height = labelHeight;
588-
GTK3.gtk_widget_size_allocate (labelHandle, allocation);
588+
gtk_widget_size_allocate(labelHandle, allocation, -1);
589589
}
590590
return result;
591591
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,11 +1156,7 @@ void forceResize (int width, int height) {
11561156
}
11571157
}
11581158

1159-
if (GTK.GTK4) {
1160-
GTK4.gtk_widget_size_allocate(vboxHandle, allocation, -1);
1161-
} else {
1162-
GTK3.gtk_widget_size_allocate(vboxHandle, allocation);
1163-
}
1159+
gtk_widget_size_allocate(vboxHandle, allocation, -1);
11641160

11651161
if ((style & SWT.MIRRORED) != 0) moveChildren(clientWidth);
11661162
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ void resizeHandle(int width, int height) {
10381038
GTK.gtk_widget_get_allocation (handle, allocation);
10391039
allocation.width = width;
10401040
allocation.height = height;
1041-
GTK3.gtk_widget_size_allocate (handle, allocation);
1041+
gtk_widget_size_allocate(handle, allocation, -1);
10421042
}
10431043

10441044
void selectRadio () {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,4 +2510,12 @@ void setToolTipText(long tipWidget, String string) {
25102510

25112511
GTK.gtk_widget_set_tooltip_text(tipWidget, buffer);
25122512
}
2513+
2514+
void gtk_widget_size_allocate (long widget, GtkAllocation allocation, int baseline) {
2515+
if (GTK.GTK4) {
2516+
GTK4.gtk_widget_size_allocate(widget, allocation, baseline);
2517+
} else {
2518+
GTK3.gtk_widget_size_allocate(widget, allocation);
2519+
}
2520+
}
25132521
}

0 commit comments

Comments
 (0)