Always use addView() and removeView() implementation from ViewGroup

This makes sure, that the index argument is handled correctly everywhere
This commit is contained in:
Julian Winkler
2023-09-01 13:49:42 +02:00
parent a35879c633
commit 3b6e4dc217
10 changed files with 10 additions and 102 deletions

View File

@@ -207,22 +207,6 @@ extern "C" {
JNIEXPORT jlong JNICALL Java_android_widget_FrameLayout_native_1constructor JNIEXPORT jlong JNICALL Java_android_widget_FrameLayout_native_1constructor
(JNIEnv *, jobject, jobject, jobject); (JNIEnv *, jobject, jobject, jobject);
/*
* Class: android_widget_FrameLayout
* Method: native_addView
* Signature: (JJILandroid/view/ViewGroup/LayoutParams;)V
*/
JNIEXPORT void JNICALL Java_android_widget_FrameLayout_native_1addView
(JNIEnv *, jobject, jlong, jlong, jint, jobject);
/*
* Class: android_widget_FrameLayout
* Method: native_removeView
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_widget_FrameLayout_native_1removeView
(JNIEnv *, jobject, jlong, jlong);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -207,22 +207,6 @@ extern "C" {
JNIEXPORT jlong JNICALL Java_android_widget_LinearLayout_native_1constructor JNIEXPORT jlong JNICALL Java_android_widget_LinearLayout_native_1constructor
(JNIEnv *, jobject, jobject, jobject); (JNIEnv *, jobject, jobject, jobject);
/*
* Class: android_widget_LinearLayout
* Method: native_addView
* Signature: (JJILandroid/view/ViewGroup/LayoutParams;)V
*/
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_native_1addView
(JNIEnv *, jobject, jlong, jlong, jint, jobject);
/*
* Class: android_widget_LinearLayout
* Method: native_removeView
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_native_1removeView
(JNIEnv *, jobject, jlong, jlong);
/* /*
* Class: android_widget_LinearLayout * Class: android_widget_LinearLayout
* Method: setOrientation * Method: setOrientation

View File

@@ -207,22 +207,6 @@ extern "C" {
JNIEXPORT jlong JNICALL Java_android_widget_ScrollView_native_1constructor JNIEXPORT jlong JNICALL Java_android_widget_ScrollView_native_1constructor
(JNIEnv *, jobject, jobject, jobject); (JNIEnv *, jobject, jobject, jobject);
/*
* Class: android_widget_ScrollView
* Method: native_addView
* Signature: (JJILandroid/view/ViewGroup/LayoutParams;)V
*/
JNIEXPORT void JNICALL Java_android_widget_ScrollView_native_1addView
(JNIEnv *, jobject, jlong, jlong, jint, jobject);
/*
* Class: android_widget_ScrollView
* Method: native_removeView
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_widget_ScrollView_native_1removeView
(JNIEnv *, jobject, jlong, jlong);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -136,10 +136,18 @@ JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1addView(JNIEnv *env,
Java_android_view_View_setGravity(env, child, child_gravity); Java_android_view_View_setGravity(env, child, child_gravity);
}*/ }*/
} }
gtk_box_append(GTK_BOX(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child)))); // FIXME - ignores index argument GtkWidget *parent = _PTR(widget);
GtkWidget *iter = gtk_widget_get_first_child(parent);
for(int i = 0; i < index; i++) {
iter = gtk_widget_get_next_sibling(iter);
if(iter == NULL)
break;
}
gtk_widget_insert_before(gtk_widget_get_parent(GTK_WIDGET(_PTR(child))), parent, iter);
} }
JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1removeView(JNIEnv *env, jobject this, jlong widget, jlong child) JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1removeView(JNIEnv *env, jobject this, jlong widget, jlong child)
{ {
gtk_box_remove(GTK_BOX(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child)))); gtk_widget_unparent(gtk_widget_get_parent(GTK_WIDGET(_PTR(child))));
} }

View File

@@ -81,15 +81,3 @@ JNIEXPORT jlong JNICALL Java_android_widget_FrameLayout_native_1constructor(JNIE
gtk_widget_set_name(GTK_WIDGET(frame_layout), "FrameLayout"); gtk_widget_set_name(GTK_WIDGET(frame_layout), "FrameLayout");
return _INTPTR(frame_layout); return _INTPTR(frame_layout);
} }
JNIEXPORT void JNICALL Java_android_widget_FrameLayout_native_1addView(JNIEnv *env, jobject this, jlong widget, jlong child, jint index, jobject layout_params)
{
if(index >= 0)
frame_layout_widget_insert_child_at_index(FRAME_LAYOUT_WIDGET(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child))), index);
else
frame_layout_widget_insert_child(FRAME_LAYOUT_WIDGET(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child))));
}
JNIEXPORT void JNICALL Java_android_widget_FrameLayout_native_1removeView(JNIEnv *env, jobject this, jlong widget, jlong child) {
gtk_widget_unparent(gtk_widget_get_parent(GTK_WIDGET(_PTR(child))));
}

View File

@@ -43,16 +43,6 @@ JNIEXPORT jlong JNICALL Java_android_widget_LinearLayout_native_1constructor(JNI
// g_object_set_data(G_OBJECT(wrapper), "background_ninepatch", ninepatch); // g_object_set_data(G_OBJECT(wrapper), "background_ninepatch", ninepatch);
} }
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_native_1addView(JNIEnv *env, jobject this, jlong widget, jlong child, jint index, jobject layout_params)
{
gtk_box_append(GTK_BOX(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child)))); // FIXME - ignores index argument
}
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_native_1removeView(JNIEnv *env, jobject this, jlong widget, jlong child)
{
gtk_box_remove(GTK_BOX(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child))));
}
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_setOrientation(JNIEnv *env, jobject this, jint orientation) JNIEXPORT void JNICALL Java_android_widget_LinearLayout_setOrientation(JNIEnv *env, jobject this, jint orientation)
{ {
gtk_orientable_set_orientation(GTK_ORIENTABLE(_PTR(_GET_LONG_FIELD(this, "widget"))), orientation ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL); gtk_orientable_set_orientation(GTK_ORIENTABLE(_PTR(_GET_LONG_FIELD(this, "widget"))), orientation ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);

View File

@@ -20,16 +20,3 @@ JNIEXPORT jlong JNICALL Java_android_widget_ScrollView_native_1constructor(JNIEn
gtk_widget_set_name(GTK_WIDGET(box), "ScrollView"); gtk_widget_set_name(GTK_WIDGET(box), "ScrollView");
return _INTPTR(box); return _INTPTR(box);
} }
JNIEXPORT void JNICALL Java_android_widget_ScrollView_native_1removeView(JNIEnv *env, jobject this, jlong widget, jlong child)
{
GtkWidget *_child = gtk_widget_get_parent(GTK_WIDGET(_PTR(child)));
gtk_box_remove(GTK_BOX(_PTR(widget)), g_object_ref(_child));
g_object_force_floating(G_OBJECT(_child));
}
JNIEXPORT void JNICALL Java_android_widget_ScrollView_native_1addView(JNIEnv *env, jobject this, jlong widget, jlong child, jint index, jobject layout_params)
{
gtk_box_append(GTK_BOX(_PTR(widget)), gtk_widget_get_parent(GTK_WIDGET(_PTR(child))));
}

View File

@@ -2,9 +2,7 @@ package android.widget;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
public class FrameLayout extends ViewGroup { public class FrameLayout extends ViewGroup {
@@ -22,10 +20,6 @@ public class FrameLayout extends ViewGroup {
@Override @Override
protected native long native_constructor(Context context, AttributeSet attrs); protected native long native_constructor(Context context, AttributeSet attrs);
@Override
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
@Override
protected native void native_removeView(long widget, long child);
@Override @Override
public LayoutParams generateLayoutParams(AttributeSet attrs) { public LayoutParams generateLayoutParams(AttributeSet attrs) {

View File

@@ -2,7 +2,6 @@ package android.widget;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
public class LinearLayout extends ViewGroup { public class LinearLayout extends ViewGroup {
@@ -19,10 +18,6 @@ public class LinearLayout extends ViewGroup {
@Override @Override
protected native long native_constructor(Context context, AttributeSet attrs); protected native long native_constructor(Context context, AttributeSet attrs);
@Override
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
@Override
protected native void native_removeView(long widget, long child);
public native void setOrientation(int orientation); public native void setOrientation(int orientation);
public void setWeightSum(float weightSum) {} public void setWeightSum(float weightSum) {}

View File

@@ -2,9 +2,7 @@ package android.widget;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
public class ScrollView extends ViewGroup { public class ScrollView extends ViewGroup {
public ScrollView(Context context, AttributeSet attrs) { public ScrollView(Context context, AttributeSet attrs) {
@@ -17,10 +15,6 @@ public class ScrollView extends ViewGroup {
@Override @Override
protected native long native_constructor(Context context, AttributeSet attrs); protected native long native_constructor(Context context, AttributeSet attrs);
@Override
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
@Override
protected native void native_removeView(long widget, long child);
public void setFillViewport(boolean fillViewport) {} public void setFillViewport(boolean fillViewport) {}
} }