com gtk/php-gtk: Adding GtkAboutDialog::set_email_hook (callback); GtkAboutDialog::set_url_hook(call back); after changing the code according to A ndrei's suggestions: - allow unsetting the hook by passing NULL as callback - add marshaller declaration in headers section: ext/gtk+/gtk.ove rrides

[email protected] (David Soria Parra)
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    b8a411612fe07aa79028892dd3b4dd625354a41b
Author:    Christian Weiske <[email protected]>         Fri, 9 Jun 2006 16:33:04 +0000
Parents:   6d22e0c50ae2d13ed96cc08d116f5e7c304de483
Branches:  master

Link:       http://git.php.net/?p=gtk/php-gtk.git;a=commitdiff;h=b8a411612fe07aa79028892dd3b4dd625354a41b

Log:
Adding
GtkAboutDialog::set_email_hook(callback);
GtkAboutDialog::set_url_hook(callback);
after changing the code according to Andrei's suggestions:
- allow unsetting the hook by passing NULL as callback
- add marshaller declaration in headers section

Changed paths:
  M  ext/gtk+/gtk.overrides


Diff:
b8a411612fe07aa79028892dd3b4dd625354a41b
diff --git a/ext/gtk+/gtk.overrides b/ext/gtk+/gtk.overrides
index 2280c84..1878cba 100644
--- a/ext/gtk+/gtk.overrides
+++ b/ext/gtk+/gtk.overrides
@@ -3,6 +3,7 @@
 headers
 #include "php_gtk_api.h"
 #include "ext/standard/file.h"
+static void phpg_about_dialog_activate_link_func_marshal (GtkAboutDialog *about, const gchar *link, gpointer data); 
 
 #undef GDK_DISPLAY
 #define GDK_DISPLAY(object) (GDK_DISPLAY_OBJECT(object))
@@ -839,6 +840,121 @@ PHP_METHOD
     efree(doccers);
 }
 
+%%
+add-arginfo GtkAboutDialog set_email_hook
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_INFO(0, callback)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_about_dialog_set_email_hook
+static void phpg_about_dialog_activate_link_func_marshal(GtkAboutDialog *about, const gchar *link, gpointer data)
+{
+    phpg_cb_data_t *cbd = (phpg_cb_data_t *) data;
+    zval *retval = NULL;
+    zval ***args = NULL;
+    int n_args = 0;
+    char *callback_name;
+    zval *php_about = NULL, *php_link = NULL;
+    gboolean show = TRUE;
+    gchar *cp_link;
+    gsize cp_len;
+    zend_bool free_result;
+
+    TSRMLS_FETCH();
+
+    if (!zend_is_callable(cbd->callback, 0, &callback_name)) {
+        php_error(E_WARNING, "Unable to invoke callback '%s' specified in %s on line %ld", callback_name, cbd->src_filename, cbd->src_lineno);
+        efree(callback_name);
+        return;
+    }
+
+    phpg_gobject_new(&php_about,       (GObject*)about       TSRMLS_CC);
+    cp_link = phpg_from_utf8(link, strlen(link), &cp_len, &free_result TSRMLS_CC);
+    if (!cp_link) {
+        php_error(E_WARNING, "Could not convert link from UTF-8");
+        return;
+    }
+    MAKE_STD_ZVAL(php_link);
+    ZVAL_STRINGL(php_link, (char*)cp_link, cp_len, 1);
+    if (free_result) {
+        g_free(cp_link);
+    }
+
+
+    args = php_gtk_hash_as_array_offset(cbd->user_args, 2, &n_args);
+    args[0] = &php_about;
+    args[1] = &php_link;
+
+    call_user_function_ex(EG(function_table), NULL, cbd->callback, &retval, n_args, args, 0, NULL TSRMLS_CC);
+
+    zval_ptr_dtor(&php_about);
+    zval_ptr_dtor(&php_link);
+
+    if (retval) {
+        zval_ptr_dtor(&retval);
+    }
+
+    phpg_handle_marshaller_exception(TSRMLS_C);
+
+    efree(callback_name);
+    efree(args);
+}
+
+PHP_METHOD
+{
+    zval *php_callback, *extra;
+    phpg_cb_data_t *cb_data;
+    GtkAboutDialogActivateLinkFunc callback;
+
+    if (!php_gtk_parse_varargs(ZEND_NUM_ARGS(), 1, &extra, "V", &php_callback))
+        return;
+
+    if (Z_TYPE_P(php_callback) == IS_NULL) {
+        cb_data  = NULL;
+        callback = NULL;
+    } else {
+        zval_add_ref(&php_callback);
+        cb_data  = phpg_cb_data_new(php_callback, extra TSRMLS_CC);
+        callback = (GtkAboutDialogActivateLinkFunc)phpg_about_dialog_activate_link_func_marshal;
+    }
+
+    gtk_about_dialog_set_email_hook(callback, cb_data, phpg_cb_data_destroy);
+}
+
+%%
+add-arginfo GtkAboutDialog set_url_hook
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_INFO(0, callback)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_about_dialog_set_url_hook
+PHP_METHOD
+{
+    zval *php_callback, *extra;
+    phpg_cb_data_t *cb_data;
+    GtkAboutDialogActivateLinkFunc callback;
+
+    if (!php_gtk_parse_varargs(ZEND_NUM_ARGS(), 1, &extra, "V", &php_callback))
+        return;
+
+    if (php_callback) {
+        if (Z_TYPE_P(php_callback) == IS_NULL) {
+            cb_data  = NULL;
+            callback = NULL;
+        } else {
+            zval_add_ref(&php_callback);
+            cb_data  = phpg_cb_data_new(php_callback, extra TSRMLS_CC);
+            callback = (GtkAboutDialogActivateLinkFunc)phpg_about_dialog_activate_link_func_marshal;
+        }
+    }
+
+    gtk_about_dialog_set_url_hook(callback, cb_data, phpg_cb_data_destroy);
+}
+
 %% }}}
 
 %% {{{ GtkAdjustment
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.