mirror of
https://github.com/php/php-gtk-src.git
synced 2026-04-26 02:08:03 +02:00
Implement gtk::timeout_add();
This commit is contained in:
@@ -174,6 +174,96 @@ ignore
|
||||
GtkPrivateFlags
|
||||
%% }}}
|
||||
|
||||
%% {{{ main loop
|
||||
%%
|
||||
override gtk_timeout_add
|
||||
|
||||
static gboolean phpg_handler_marshal(gpointer user_data)
|
||||
{
|
||||
zval *callback_data = (zval *) user_data;
|
||||
zval **callback, **extra = NULL;
|
||||
zval **callback_filename = NULL, **callback_lineno = NULL;
|
||||
zval ***handler_args = NULL;
|
||||
int num_handler_args = 0;
|
||||
zval *retval = NULL;
|
||||
char *callback_name;
|
||||
gboolean result;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
/* Callback is always passed as the first element. */
|
||||
zend_hash_index_find(Z_ARRVAL_P(callback_data), 0, (void **)&callback);
|
||||
zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&extra);
|
||||
zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&callback_filename);
|
||||
zend_hash_index_find(Z_ARRVAL_P(callback_data), 3, (void **)&callback_lineno);
|
||||
|
||||
if (!zend_is_callable(*callback, 0, &callback_name)) {
|
||||
php_error(E_WARNING, "Unable to invoke handler callback '%s' specified in %s on line %ld", callback_name, Z_STRVAL_PP(callback_filename), Z_LVAL_PP(callback_lineno));
|
||||
efree(callback_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
handler_args = php_gtk_hash_as_array(*extra);
|
||||
num_handler_args = zend_hash_num_elements(Z_ARRVAL_PP(extra));
|
||||
|
||||
call_user_function_ex(EG(function_table), NULL, *callback, &retval, num_handler_args, handler_args, 0, NULL TSRMLS_CC);
|
||||
|
||||
result = FALSE;
|
||||
if (retval) {
|
||||
result = zval_is_true(retval);
|
||||
zval_ptr_dtor(&retval);
|
||||
}
|
||||
|
||||
if (handler_args)
|
||||
efree(handler_args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void phpg_gtk_timeout_add_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool with_priority)
|
||||
{
|
||||
guint interval;
|
||||
gint priority = G_PRIORITY_DEFAULT;
|
||||
zval *callback = NULL;
|
||||
zval *extra;
|
||||
zval *data = NULL;
|
||||
char *callback_filename;
|
||||
uint callback_lineno;
|
||||
guint handler_id;
|
||||
int req_args = with_priority ? 3 : 2;
|
||||
|
||||
if (ZEND_NUM_ARGS() < req_args) {
|
||||
php_error(E_WARNING, "%s() requires at least %d arguments, %d given",
|
||||
get_active_function_name(TSRMLS_C), req_args, ZEND_NUM_ARGS());
|
||||
return;
|
||||
}
|
||||
|
||||
if (with_priority) {
|
||||
if (!php_gtk_parse_args(3, "iiV", &interval, &priority, &callback))
|
||||
return;
|
||||
} else {
|
||||
if (!php_gtk_parse_args(2, "iV", &interval, &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());
|
||||
if (!extra) {
|
||||
MAKE_STD_ZVAL(extra);
|
||||
array_init(extra);
|
||||
}
|
||||
php_gtk_build_value(&data, "(VNsi)", callback, extra, callback_filename, callback_lineno);
|
||||
|
||||
handler_id = g_timeout_add_full(priority, interval, phpg_handler_marshal, data, phpg_destroy_notify);
|
||||
RETURN_LONG(handler_id);
|
||||
}
|
||||
|
||||
static PHP_METHOD(gtk, timeout_add)
|
||||
{
|
||||
phpg_gtk_timeout_add_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
||||
}
|
||||
%% }}}
|
||||
|
||||
%% {{{ GtkButton
|
||||
%%
|
||||
override gtk_button_new
|
||||
|
||||
+1
-1
@@ -234,7 +234,6 @@ PHP_GTK_API void phpg_get_properties_helper(zval *object, HashTable *ht TSRMLS_D
|
||||
PHP_GTK_API void *php_gtk_get_object(zval *wrapper);
|
||||
PHP_GTK_API int php_gtk_get_simple_enum_value(zval *enum_val, int *result);
|
||||
PHP_GTK_API int php_gtk_get_enum_value(GType enum_type, zval *enum_val, int *result);
|
||||
PHP_GTK_API void php_gtk_destroy_notify(gpointer user_data);
|
||||
PHP_GTK_API void php_gtk_callback_marshal(GtkObject *o, gpointer data, guint nargs, GtkArg *args);
|
||||
void php_gtk_handler_marshal(gpointer a, gpointer data, int nargs, GtkArg *args);
|
||||
zval *php_gtk_args_as_hash(int nargs, GtkArg *args);
|
||||
@@ -260,6 +259,7 @@ PHP_GTK_API void php_gtk_register_callback(char *class_and_method, GtkSignalFunc
|
||||
PHP_GTK_API void php_gtk_object_init(GtkObject *obj, zval *wrapper);
|
||||
|
||||
/* Utility functions. */
|
||||
PHP_GTK_API void phpg_destroy_notify(gpointer user_data);
|
||||
PHP_GTK_API int php_gtk_parse_args(int argc, char *format, ...);
|
||||
int php_gtk_parse_args_quiet(int argc, char *format, ...);
|
||||
int php_gtk_parse_args_hash(zval *hash, char *format, ...);
|
||||
|
||||
Reference in New Issue
Block a user