--- ../gtk-orig/gst-gtk.c Thu Sep 4 06:49:06 2003 +++ gst-gtk.c Tue Dec 16 21:27:40 2003 @@ -58,7 +58,7 @@ VMProxy *_blox_vm_proxy; static GQuark q_gst_object = 0; -static GHashTable *h_callback = NULL; +/*static GHashTable *h_callback = NULL;*/ static int pending_quit_count = 0; static void blox_gtk_init (); @@ -109,9 +109,9 @@ /* Create a GClosure that invokes the selector, SELECTOR, on the given object. DATA is inserted as the second parameter (or is passed as the only one is the closure's arity is 0). */ -static GClosure * create_smalltalk_closure(OOP receiver, - const char *selector, - OOP data); +static GClosure * create_smalltalk_closure(OOP receiver, + OOP selector, + OOP data); /* The finalization notifier for Smalltalk GClosures. Unregisters the receiver and user data for the CLOSURE. */ @@ -128,9 +128,10 @@ /* A wrapper around g_signal_connect_closure that looks up the selector and creates a Smalltalk GClosure. */ -static void connect_signal (OOP widget, - const char *event_name, - OOP event_handler, +static void connect_signal (OOP widget, + char *event_name, + OOP receiver, + OOP selector, OOP user_data); /* A wrapper around g_object_get_property that replaces GValues with OOPs. */ @@ -428,9 +429,9 @@ } GClosure * -create_smalltalk_closure(OOP receiver, - const char *selector, - OOP data) +create_smalltalk_closure(OOP receiver, + OOP selector, + OOP data) { GClosure *closure = g_closure_new_simple (sizeof (SmalltalkClosure), NULL); SmalltalkClosure *stc = (SmalltalkClosure *) closure; @@ -439,7 +440,7 @@ _blox_vm_proxy->registerOOP (data); stc->receiver = receiver; - stc->selector = _blox_vm_proxy->symbolToOOP(selector); + stc->selector = selector; stc->data = data; g_closure_set_marshal (closure, invoke_smalltalk_closure); @@ -457,6 +458,7 @@ _blox_vm_proxy->unregisterOOP (stc->data); } +/* MA version */ void invoke_smalltalk_closure(GClosure *closure, GValue *return_value, @@ -465,93 +467,54 @@ gpointer invocation_hint, gpointer marshal_data) { - OOP *args = alloca (sizeof (OOP) * MIN(2, 1 + n_param_values)); + OOP *args = alloca (sizeof (OOP) * (1 + n_param_values)); SmalltalkClosure *stc = (SmalltalkClosure *) closure; OOP resultOOP; int i; + /* Maintain the Gtk order of parameters, even if we end up discarding + the sender (first parameter, usually) most of the time */ for (i = 0; i < n_param_values; i++) { OOP oop = convert_g_value_to_oop (¶m_values[i]); if (!oop) - { - fprintf (stderr, "Invalid type, signal discarded.\n"); - - if (return_value->g_type == G_TYPE_NONE) + { + fprintf (stderr, "Invalid type, signal discarded.\n"); + + if (return_value->g_type == G_TYPE_NONE) return; - else + else abort (); } - - args[i + 1] = oop; + args[i] = oop; } + args[n_param_values] = stc->data; - /* Put the user data after the first parameter, if any. */ - if (n_param_values) - { - args[0] = args[1]; - args[1] = stc->data; - } - else - args[0] = stc->data; - - /* Go! */ resultOOP = _blox_vm_proxy->nvmsgSend(stc->receiver, stc->selector, args, 1 + n_param_values); + /* FIXME Need to init return_value's type? */ if (return_value) fill_g_value_from_oop (return_value, resultOOP); } -/* Signal implementation. */ +/* MA version */ void -connect_signal (OOP widget, const char *event_name, OOP event_handler, OOP user_data) +connect_signal (OOP widget, + char *event_name, + OOP receiver, + OOP selector, + OOP user_data) { GtkWidget *cWidget = _blox_vm_proxy->OOPToCObject (widget); - GQuark widgetClassQuark; - const char *selector; - GtkType currentType; GClosure *closure; - guint signalId; - GQuark detail; associate_oop_to_g_object (G_OBJECT (cWidget), widget); - currentType = G_OBJECT_TYPE (cWidget); - if (!g_signal_parse_name (event_name, currentType, &signalId, &detail, true)) - return; - - /* Discard the detail, if any. */ - event_name = g_signal_name (signalId); - - for (;;) - { - GHashTable *signalHash; - widgetClassQuark = g_type_qname (currentType); - signalHash = g_hash_table_lookup (h_callback, (gconstpointer) widgetClassQuark); - if (signalHash) - { - selector = g_hash_table_lookup (signalHash, event_name); - if (selector) - break; - } - - /* All signals should be registered in the table. */ - if (G_TYPE_IS_FUNDAMENTAL (currentType)) - { - fprintf (stderr, "Unknown signal %s:%s\n", g_type_name (G_OBJECT_TYPE (cWidget)), - event_name); - abort (); - } - - currentType = g_type_parent (currentType); - } - - closure = create_smalltalk_closure (event_handler, selector, user_data); - g_signal_connect_closure_by_id (cWidget, signalId, detail, closure, FALSE); + closure = create_smalltalk_closure (receiver, selector, user_data); + g_signal_connect_closure (cWidget, event_name, closure, FALSE); } - /* Event loop. */ void my_gtk_main_iteration () @@ -607,7 +570,7 @@ object_get_property(GObject *anObject, const char *aProperty) { GParamSpec *spec; - GValue result; + GValue result = {0,}; GObject *obj; obj = G_OBJECT (anObject); @@ -622,7 +585,7 @@ { GParamSpec *spec; GObject *obj; - GValue value; + GValue value = {0,}; obj = G_OBJECT (anObject); spec = g_object_class_find_property (G_OBJECT_GET_CLASS(obj), aProperty); @@ -635,7 +598,7 @@ container_get_child_property(GtkContainer *aParent, GtkWidget *aChild, const char *aProperty) { GParamSpec *spec; - GValue result; + GValue result = {0,}; g_return_val_if_fail (GTK_WIDGET (aParent) == gtk_widget_get_parent (GTK_WIDGET (aChild)), @@ -653,7 +616,7 @@ container_set_child_property(GtkContainer *aParent, GtkWidget *aChild, const char *aProperty, OOP aValue) { GParamSpec *spec; - GValue value; + GValue value = {0,}; g_return_if_fail (GTK_WIDGET (aParent) == gtk_widget_get_parent (GTK_WIDGET (aChild))); @@ -684,13 +647,61 @@ gtk_init (&argc, (gchar ***) &argv); } +/* MSA */ + +int +gtk_text_iter_sizeof () +{ + return(sizeof(GtkTextIter)); +} + +int +gtk_tree_iter_sizeof () +{ + return(sizeof(GtkTreeIter)); +} + +OOP +gtk_tree_model_get_oop(GtkTreeModel *model, GtkTreeIter *iter, int col) +{ + GValue gval = { 0, }; + OOP result; + + gtk_tree_model_get_value(model, iter, col, &gval); + result = convert_g_value_to_oop(&gval); + g_value_unset(&gval); /* Probably not necessary for most GValue types? */ + return(result); +} + +void +gtk_list_store_set_oop(GtkListStore *store, GtkTreeIter *iter, int col, OOP value) +{ + GValue gval = { 0, }; + g_value_init (&gval, gtk_tree_model_get_column_type(GTK_TREE_MODEL(store), col)); + fill_g_value_from_oop(&gval, value); + gtk_list_store_set_value (store, iter, col, &gval); + g_value_unset(&gval); /* Probably not necessary for most GValue types? */ +} + +void +gtk_tree_store_set_oop(GtkTreeStore *store, GtkTreeIter *iter, int col, OOP value) +{ + GValue gval = { 0, }; + g_value_init (&gval, gtk_tree_model_get_column_type(GTK_TREE_MODEL(store), col)); + fill_g_value_from_oop(&gval, value); + gtk_tree_store_set_value (store, iter, col, &gval); + g_value_unset(&gval); /* Probably not necessary for most GValue types? */ +} + +/* /MSA */ + void gst_initModule (proxy) VMProxy *proxy; { q_gst_object = g_quark_from_string ("gst_object"); g_type_init (); - h_callback = _blox_create_callback_hash (); + /*h_callback = _blox_create_callback_hash ();*/ _blox_vm_proxy = proxy; _blox_vm_proxy->defineCFunc ("bloxGtkInit", blox_gtk_init); @@ -709,6 +720,14 @@ _blox_vm_proxy->defineCFunc ("bloxGtkSetFlags", widget_set_flags); _blox_vm_proxy->defineCFunc ("bloxGtkUnsetFlags", widget_unset_flags); _blox_vm_proxy->defineCFunc ("bloxGtkGetWindow", widget_get_window); + + /* MSA */ + _blox_vm_proxy->defineCFunc ("gtk_text_iter_sizeof", gtk_text_iter_sizeof); + _blox_vm_proxy->defineCFunc ("gtk_tree_iter_sizeof", gtk_tree_iter_sizeof); + _blox_vm_proxy->defineCFunc ("gtk_tree_model_get_oop", gtk_tree_model_get_oop); + _blox_vm_proxy->defineCFunc ("gtk_list_store_set_oop", gtk_list_store_set_oop); + _blox_vm_proxy->defineCFunc ("gtk_tree_store_set_oop", gtk_tree_store_set_oop); + /* /MSA */ _blox_vm_proxy->defineCFunc ("gtk_placer_get_type", gtk_placer_get_type); _blox_vm_proxy->defineCFunc ("gtk_placer_new", gtk_placer_new);