Skip to content

Commit 709f323

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 3e8da4a commit 709f323

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
@@ -2083,6 +2083,26 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1widget_1get_1root)
20832083
}
20842084
#endif
20852085

2086+
#ifndef NO_gtk_1widget_1insert_1after
2087+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1insert_1after)
2088+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
2089+
{
2090+
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1insert_1after_FUNC);
2091+
gtk_widget_insert_after((GtkWidget *)arg0, (GtkWidget *)arg1, (GtkWidget *)arg2);
2092+
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1insert_1after_FUNC);
2093+
}
2094+
#endif
2095+
2096+
#ifndef NO_gtk_1widget_1insert_1before
2097+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1insert_1before)
2098+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
2099+
{
2100+
GTK4_NATIVE_ENTER(env, that, gtk_1widget_1insert_1before_FUNC);
2101+
gtk_widget_insert_before((GtkWidget *)arg0, (GtkWidget *)arg1, (GtkWidget *)arg2);
2102+
GTK4_NATIVE_EXIT(env, that, gtk_1widget_1insert_1before_FUNC);
2103+
}
2104+
#endif
2105+
20862106
#ifndef NO_gtk_1widget_1measure
20872107
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1widget_1measure)
20882108
(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
@@ -173,6 +173,8 @@ typedef enum {
173173
gtk_1widget_1get_1prev_1sibling_FUNC,
174174
gtk_1widget_1get_1receives_1default_FUNC,
175175
gtk_1widget_1get_1root_FUNC,
176+
gtk_1widget_1insert_1after_FUNC,
177+
gtk_1widget_1insert_1before_FUNC,
176178
gtk_1widget_1measure_FUNC,
177179
gtk_1widget_1set_1cursor_FUNC,
178180
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
@@ -649,6 +649,18 @@ public class GTK4 {
649649
* @param allocation cast=(GtkAllocation *),flags=no_out
650650
*/
651651
public static final native void gtk_widget_size_allocate(long widget, GtkAllocation allocation, int baseline);
652+
/**
653+
* @param widget cast=(GtkWidget *)
654+
* @param parent cast=(GtkWidget *)
655+
* @param previous_sibling cast=(GtkWidget *)
656+
*/
657+
public static final native void gtk_widget_insert_after(long widget, long parent, long previous_sibling);
658+
/**
659+
* @param widget cast=(GtkWidget *)
660+
* @param parent cast=(GtkWidget *)
661+
* @param next_sibling cast=(GtkWidget *)
662+
*/
663+
public static final native void gtk_widget_insert_before(long widget, long parent, long next_sibling);
652664

653665
/* GtkComboBox */
654666
/** @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)