Skip to content

Commit 1c281f5

Browse files
committed
[GTK4] Implement correct moveAbove()/moveBelow() control behavior
Regardless of which control are given as input parameters, the controls are currently always added as last child to their parents. Underlying issue seems to be that the swt_fixed_restack() method does not handle the GTK4 widgets correctly. As a solution, perform the movement using the proper API. To understand the combination in which GTK methods need to be called, consider the expected behavior based on the GTK and SWT documentation: [GTK4 Documentation] - gtk_widget_insert_after(widget, parent, previous_sibling) It will be placed after previous_sibling, or at the beginning if previous_sibling is NULL. - gtk_widget_insert_before(widget, parent, next_sibling) It will be placed before next_sibling, or at the end if next_sibling is NULL. [SWT Documentation] - moveAbove(control) Moves the receiver above the specified control in the drawing order. If the argument is null, then the receiver is moved to the top of the drawing order This means that if the specified control is NULL, gtk_widget_insert_after(...) needs to be called, otherwise gtk_widget_insert_before(...). - moveBelow(control) Moves the receiver below the specified control in the drawing order. If the argument is null, then the receiver is moved to the bottom of the drawing order. Here the inverse applies. If the specified control is NULL, gtk_widget_insert_before(...) needs to be called, otherwise gtk_widget_insert_after(...).
1 parent 0071da4 commit 1c281f5

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,26 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1widget_1get_1root)
20352035
}
20362036
#endif
20372037

2038+
#ifndef NO_gtk_1widget_1insert_1after
2039+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1insert_1after)
2040+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
2041+
{
2042+
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1insert_1after_FUNC);
2043+
gtk_widget_insert_after((GtkWidget *)arg0, (GtkWidget *)arg1, (GtkWidget *)arg2);
2044+
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1insert_1after_FUNC);
2045+
}
2046+
#endif
2047+
2048+
#ifndef NO_gtk_1widget_1insert_1before
2049+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1insert_1before)
2050+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
2051+
{
2052+
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1insert_1before_FUNC);
2053+
gtk_widget_insert_before((GtkWidget *)arg0, (GtkWidget *)arg1, (GtkWidget *)arg2);
2054+
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1insert_1before_FUNC);
2055+
}
2056+
#endif
2057+
20382058
#ifndef NO_gtk_1widget_1measure
20392059
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1measure)
20402060
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2, jintArray arg3, jintArray arg4, jintArray arg5, jintArray arg6)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ typedef enum {
169169
gtk_1widget_1get_1prev_1sibling_FUNC,
170170
gtk_1widget_1get_1receives_1default_FUNC,
171171
gtk_1widget_1get_1root_FUNC,
172+
gtk_1widget_1insert_1after_FUNC,
173+
gtk_1widget_1insert_1before_FUNC,
172174
gtk_1widget_1measure_FUNC,
173175
gtk_1widget_1set_1cursor_FUNC,
174176
gtk_1widget_1set_1focusable_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,18 @@ public class GTK4 {
631631
* @param allocation cast=(GtkAllocation *),flags=no_out
632632
*/
633633
public static final native void gtk_widget_size_allocate(long widget, GtkAllocation allocation, int baseline);
634+
/**
635+
* @param widget cast=(GtkWidget *)
636+
* @param parent cast=(GtkWidget *)
637+
* @param previous_sibling cast=(GtkWidget *)
638+
*/
639+
public static final native void gtk_widget_insert_after(long widget, long parent, long previous_sibling);
640+
/**
641+
* @param widget cast=(GtkWidget *)
642+
* @param parent cast=(GtkWidget *)
643+
* @param next_sibling cast=(GtkWidget *)
644+
*/
645+
public static final native void gtk_widget_insert_before(long widget, long parent, long next_sibling);
634646

635647
/* GtkComboBox */
636648
/** @param combo_box cast=(GtkComboBox *) */

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,15 @@ void markLayout (boolean changed, boolean all) {
13531353
void moveAbove (long child, long sibling) {
13541354
if (child == sibling) return;
13551355
long parentHandle = parentingHandle ();
1356-
OS.swt_fixed_restack (parentHandle, child, sibling, true);
1356+
if (GTK.GTK4) {
1357+
if (sibling == 0) {
1358+
GTK4.gtk_widget_insert_after(child, parentHandle, 0L);
1359+
} else {
1360+
GTK4.gtk_widget_insert_before(child, parentHandle, sibling);
1361+
}
1362+
} else {
1363+
OS.swt_fixed_restack (parentHandle, child, sibling, true);
1364+
}
13571365
return;
13581366
}
13591367

@@ -1364,7 +1372,15 @@ void moveBelow (long child, long sibling) {
13641372
moveAbove (child, scrolledHandle != 0 ? scrolledHandle : handle);
13651373
return;
13661374
}
1367-
OS.swt_fixed_restack (parentHandle, child, sibling, false);
1375+
if (GTK.GTK4) {
1376+
if (sibling == 0) {
1377+
GTK4.gtk_widget_insert_before(child, parentHandle, 0L);
1378+
} else {
1379+
GTK4.gtk_widget_insert_after(child, parentHandle, sibling);
1380+
}
1381+
} else {
1382+
OS.swt_fixed_restack (parentHandle, child, sibling, false);
1383+
}
13681384
return;
13691385
}
13701386

0 commit comments

Comments
 (0)