cvs: php-gtk /main php_gtk.c php_gtk.h php_gtk_object.c

From: Date: Thu, 21 Aug 2003 14:59:26 +0000
Subject: cvs: php-gtk /main php_gtk.c php_gtk.h php_gtk_object.c
Groups: php.gtk.cvs 
Request: Send a blank email to php-gtk-cvs+get-851@lists.php.net to get a copy of this message
alan_k Thu Aug 21 10:59:26 2003 EDT Modified files: /php-gtk/main php_gtk.c php_gtk.h php_gtk_object.c Log: register_callback code added - this needs to be applied to the ZE2 PORT.. - Its need for gtksheet, and probably removing a few warnings from gtk+ - most of it is a copy/paste from other parts.. - discussed with frank/steph, we will stick it in for the time being as we can test build gtksheet. - revert if necessary...

Index: php-gtk/main/php_gtk.c diff -u php-gtk/main/php_gtk.c:1.28 php-gtk/main/php_gtk.c:1.29 --- php-gtk/main/php_gtk.c:1.28 Wed Nov 27 15:13:34 2002 +++ php-gtk/main/php_gtk.c Thu Aug 21 10:59:26 2003 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk.c,v 1.28 2002/11/27 20:13:34 fmk Exp $: */ +/* $Id: php_gtk.c,v 1.29 2003/08/21 14:59:26 alan_k Exp $: */ #include "php_gtk.h" #include "SAPI.h" @@ -109,6 +109,7 @@ zend_hash_init_ex(&php_gtk_prop_setters, 20, NULL, NULL, 1, 0); zend_hash_init_ex(&php_gtk_rsrc_hash, 50, NULL, NULL, 1, 0); zend_hash_init_ex(&php_gtk_type_hash, 50, NULL, NULL, 1, 0); + zend_hash_init_ex(&php_gtk_callback_hash, 50, NULL, NULL, 1, 0); zend_unset_timeout(TSRMLS_C); zend_set_timeout(0); Index: php-gtk/main/php_gtk.h diff -u php-gtk/main/php_gtk.h:1.61 php-gtk/main/php_gtk.h:1.62 --- php-gtk/main/php_gtk.h:1.61 Wed Nov 27 15:13:34 2002 +++ php-gtk/main/php_gtk.h Thu Aug 21 10:59:26 2003 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk.h,v 1.61 2002/11/27 20:13:34 fmk Exp $: */ +/* $Id: php_gtk.h,v 1.62 2003/08/21 14:59:26 alan_k Exp $: */ #ifndef _PHP_GTK_H #define _PHP_GTK_H @@ -96,7 +96,7 @@ extern HashTable php_gtk_prop_getters; extern HashTable php_gtk_prop_setters; extern HashTable php_gtk_type_hash; - +extern HashTable php_gtk_callback_hash; /* Function declarations. */ int php_gtk_startup_all_extensions(int module_number); @@ -123,7 +123,7 @@ PHP_GTK_API void php_gtk_register_prop_getter(zend_class_entry *ce, prop_getter_t getter); PHP_GTK_API void php_gtk_register_prop_setter(zend_class_entry *ce, prop_setter_t setter); - +PHP_GTK_API void php_gtk_register_callback(char *class_and_method, GtkSignalFunc call_function); PHP_GTK_API void php_gtk_object_init(GtkObject *obj, zval *wrapper); /* Utility functions. */ @@ -140,6 +140,9 @@ PHP_GTK_API zval *php_gtk_func_args_as_hash(int argc, int start, int length); PHP_GTK_API zval *php_gtk_build_value(char *format, ...); char *php_gtk_zval_type_name(zval *arg); + +PHP_GTK_API void php_gtk_signal_connect_impl(INTERNAL_FUNCTION_PARAMETERS, int pass_object, int after); +PHP_GTK_API zval* php_gtk_simple_signal_callback(GtkObject *o, gpointer data, zval *gtk_args ); #define NOT_STATIC_METHOD() \ if (!this_ptr) { \ Index: php-gtk/main/php_gtk_object.c diff -u php-gtk/main/php_gtk_object.c:1.55 php-gtk/main/php_gtk_object.c:1.56 --- php-gtk/main/php_gtk_object.c:1.55 Mon Dec 9 23:39:15 2002 +++ php-gtk/main/php_gtk_object.c Thu Aug 21 10:59:26 2003 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk_object.c,v 1.55 2002/12/10 04:39:15 fmk Exp $ */ +/* $Id: php_gtk_object.c,v 1.56 2003/08/21 14:59:26 alan_k Exp $ */ #include "php_gtk.h" @@ -31,12 +31,15 @@ HashTable php_gtk_rsrc_hash; HashTable php_gtk_type_hash; +HashTable php_gtk_callback_hash; + static const char *php_gtk_wrapper_key = "php_gtk::wrapper"; PHP_GTK_API void php_gtk_object_init(GtkObject *obj, zval *wrapper) { gtk_object_ref(obj); gtk_object_sink(obj); + php_gtk_set_object(wrapper, obj, le_gtk_object); } @@ -488,8 +491,8 @@ break; case GTK_TYPE_POINTER: - php_error(E_NOTICE, "%s(): internal error: GTK_TYPE_POINTER unsupported", - get_active_function_name(TSRMLS_C)); + php_error(E_NOTICE, "%s(): internal error: %s GTK_TYPE_POINTER unsupported", + get_active_function_name(TSRMLS_C), arg->name ); MAKE_STD_ZVAL(value); ZVAL_NULL(value); break; @@ -1235,5 +1238,169 @@ sizeof(prop_setter_t), NULL); } +PHP_GTK_API void php_gtk_register_callback(char *class_and_method, GtkSignalFunc call_function) +{ + char *lcname; + + lcname = emalloc(strlen(class_and_method)+1); + + strncpy(lcname, class_and_method, strlen(class_and_method)); + zend_str_tolower(lcname, strlen(class_and_method)); + zend_hash_update(&php_gtk_callback_hash, lcname, strlen(class_and_method),(void**) &call_function, + sizeof(void*), NULL); +} + + +PHP_GTK_API void php_gtk_signal_connect_impl(INTERNAL_FUNCTION_PARAMETERS, int pass_object, int after) +{ + char *name = NULL; + zval *callback = NULL; + zval *extra; + zval *data; + char *callback_filename; + uint callback_lineno; + char *lookup; + zend_class_entry *ce; + GtkSignalFunc *callback_cfunction; + int lookup_len; + + NOT_STATIC_METHOD(); + + if (ZEND_NUM_ARGS() < 2) { + php_error(E_WARNING, "%s() requires at least 2 arguments, %d given", + get_active_function_name(TSRMLS_C), ZEND_NUM_ARGS()); + return; + } + + if (!php_gtk_parse_args(2, "sV", &name, &callback)) + return; + + callback_filename = zend_get_executed_filename(TSRMLS_C); + callback_lineno = zend_get_executed_lineno(TSRMLS_C); + extra = php_gtk_func_args_as_hash(ZEND_NUM_ARGS(), 2, ZEND_NUM_ARGS()); + data = php_gtk_build_value("(VNisi)", callback, extra, pass_object, callback_filename, callback_lineno); + ce = Z_OBJCE_P(this_ptr); + lookup_len = ce->name_length + strlen(name) + 2; + lookup = emalloc(lookup_len + 1); + sprintf(lookup, "%s::%s", ce->name, name); + + lookup[lookup_len] = '\0'; + zend_str_tolower(lookup,lookup_len); + + /* now see if it's a manually handled object::callback.. */ + if (zend_hash_find(&php_gtk_callback_hash, lookup, lookup_len , (void **) &callback_cfunction) == SUCCESS) { + + switch (after) { + case 0: + RETURN_LONG( gtk_signal_connect(PHP_GTK_GET(this_ptr), + name, + (GtkSignalFunc) *callback_cfunction, + data)); + case 1: + RETURN_LONG( gtk_signal_connect_after(PHP_GTK_GET(this_ptr), + name, + (GtkSignalFunc) *callback_cfunction, + data)); + } + + } + + + RETURN_LONG(gtk_signal_connect_full(PHP_GTK_GET(this_ptr), name, NULL, + (GtkCallbackMarshal)php_gtk_callback_marshal, + data, php_gtk_destroy_notify, FALSE, after)); +} + +PHP_GTK_API zval* php_gtk_simple_signal_callback(GtkObject *o, gpointer data, zval *gtk_args ) +{ + guint nargs; + GtkArg *args; + zval *callback_data = (zval *)data; + zval **callback, **extra = NULL, **pass_object = NULL; + zval **callback_filename = NULL, **callback_lineno = NULL; + zval *wrapper = NULL; + zval *params; + zval *retval = NULL; + zval ***signal_args; + char *callback_name; + TSRMLS_FETCH(); + + /* Callback is always passed as the first element. */ + zend_hash_index_find(Z_ARRVAL_P(callback_data), 0, (void **)&callback); + + /* + * If there is more than one element, it will be an array of: + * [1] an array of extra arguments + * [2] a flag indidicating whether the object should be passed to the + * callback + * [3] the filename where the callback was specified + * [4] the line number where the callback was specified + */ + if (zend_hash_num_elements(Z_ARRVAL_P(callback_data)) > 1) { + zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&extra); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&pass_object); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 3, (void **)&callback_filename); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 4, (void **)&callback_lineno); + } + + if (!php_gtk_is_callable(*callback, 0, &callback_name)) { + if (callback_filename) + php_error(E_WARNING, "Unable to call signal callback '%s' specified in %s on line %d", callback_name, Z_STRVAL_PP(callback_filename), Z_LVAL_PP(callback_lineno)); + else + php_error(E_WARNING, "Unable to call callback '%s'", callback_name); + efree(callback_name); + return NULL; + } + + /* not needed: - you have to provide this! + gtk_args = php_gtk_args_as_hash(nargs, args); + */ + + /* + * If pass_object flag is not specified, or it's specified and true, and we + * have the actual object, construct the wrapper around it. + */ + if ((!pass_object || Z_LVAL_PP(pass_object)) && o) + wrapper = php_gtk_new(o); + + /* + * If there is a wrapper, construct array of parameters, set wrapper as + * the first parameter, and append the array of GTK signal arguments to it. + */ + if (wrapper) { + MAKE_STD_ZVAL(params); + array_init(params); + zend_hash_next_index_insert(Z_ARRVAL_P(params), &wrapper, sizeof(zval *), NULL); + php_array_merge(Z_ARRVAL_P(params), Z_ARRVAL_P(gtk_args), 0 TSRMLS_CC); + zval_ptr_dtor(&gtk_args); + } else + /* Otherwise, the only parameters will be GTK signal arguments. */ + params = gtk_args; + + /* + * If there are extra arguments specified by user, add them to the parameter + * array. + */ + if (extra) + php_array_merge(Z_ARRVAL_P(params), Z_ARRVAL_PP(extra), 0 TSRMLS_CC); + + signal_args = php_gtk_hash_as_array(params); + + call_user_function_ex(EG(function_table), NULL, *callback, &retval, zend_hash_num_elements(Z_ARRVAL_P(params)), signal_args, 0, NULL TSRMLS_CC); + + efree(signal_args); + zval_ptr_dtor(&params); + + return retval; + /* + if (retval) { + if (args) + php_gtk_ret_from_value(&args[nargs], retval); + zval_ptr_dtor(&retval); + } + */ + + +} #endif /* HAVE_PHP_GTK */
« previous php.gtk.cvs (#851) next »