[Java-gnome-developer] GtkContainer::children()
Brought to you by:
afcowie
|
From: Julian F. <jfi...@ho...> - 2001-03-22 04:05:29
|
I needed to use the children() method of GtkContainer but the code being
generated returned a GStringList and it was set to null.
Because we needed it, we wrote the method but I don't even know where to
being trying to fix the generator so it generates appropriate code and I
don't think I have the spare time to figure it out. I thought I'd include
our code in case it helps you to have something to model off of or
something.
I'm not 100% sure of the Signature in the comment block... my understanding
is a GtkWidget[] has the same type as a GtkWidget but...
Julian
------------snip------------------
/*
* Class: gnu.gtk.GtkContainer
* Method: children
* Signature: ()Lgnu/gtk/GtkWidget;
*/
JNIEXPORT jobjectArray JNICALL Java_gnu_gtk_GtkContainer_children
(JNIEnv
*env, jobject obj)
{
GtkContainer *cptr = peerOfBaseObject (env, obj);
GList* children = gtk_container_children (cptr);
int childrenLength = g_list_length(children);
jclass widget_cls = (*env)->FindClass(env, "gnu/gtk/GtkWidget");
jobjectArray array;
jclass result_jc;
jobject widget;
GtkWidget *native_widget;
char classname[100];
if (childrenLength > 0)
{
int i;
native_widget = (GtkWidget*)g_list_nth_data(children, 0);
sprintf(classname, "gnu/gtk/%s",
gtk_type_name(GTK_OBJECT_TYPE(native_widget)));
result_jc = (*env)->FindClass (env, classname);
widget = makeBaseObjectSubclass (env, result_jc,
native_widget);
array = (*env)->NewObjectArray(env, childrenLength, widget_cls,
widget);
for (i = 1;i < childrenLength;i++)
{
native_widget = (GtkWidget*)g_list_nth_data(children, i);
sprintf(classname, "gnu/gtk/%s",
gtk_type_name(GTK_OBJECT_TYPE(native_widget)));
result_jc = (*env)->FindClass (env, classname);
widget = makeBaseObjectSubclass (env, result_jc,
native_widget);
(*env)->SetObjectArrayElement(env, array, i, widget);
}
}
return array;
}
|