com gtk/php-gtk: GtkTreeView::set_search_equal_func () This one doesn't leak :): ext/gtk+/g tktreeview.overrides

[email protected] (David Soria Parra)
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    06ca65f72aa43a71711570e93657d8f94045af29
Author:    Christian Weiske <[email protected]>         Fri, 16 Jun 2006 15:28:42 +0000
Parents:   33e6a2c53b73dfea11ba183b2c23f3058031d108
Branches:  master

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

Log:
GtkTreeView::set_search_equal_func()
This one doesn't leak :)

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


Diff:
06ca65f72aa43a71711570e93657d8f94045af29
diff --git a/ext/gtk+/gtktreeview.overrides b/ext/gtk+/gtktreeview.overrides
index a9d8cba..de68657 100644
--- a/ext/gtk+/gtktreeview.overrides
+++ b/ext/gtk+/gtktreeview.overrides
@@ -15,6 +15,7 @@ static gint phpg_tree_iter_compare_func_marshal(GtkTreeModel *model, GtkTreeIter
 static gboolean phpg_tree_model_filter_visible_func_marshal(GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
 static gboolean phpg_tree_view_row_separator_func_marshal (GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
 static gboolean phpg_tree_view_column_drop_func_marshal (GtkTreeView *tree_view, GtkTreeViewColumn *column, GtkTreeViewColumn *prev_column, GtkTreeViewColumn *next_column, gpointer data);
+static gboolean phpg_tree_view_search_equal_func_marshal (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data);
 static void phpg_tree_selection_foreach_func_marshal (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
 static gboolean phpg_tree_selection_func_marshal (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data);
 
@@ -2184,6 +2185,107 @@ PHP_METHOD
 
 
 %%
+add-arginfo GtkTreeView set_search_equal_func
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_INFO(0, callback)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_tree_view_set_search_equal_func
+static gboolean phpg_tree_view_search_equal_func_marshal (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, 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_model = NULL, *php_column = NULL, *php_iter = NULL, *php_key;
+    gboolean matches = FALSE;
+    gchar *cp_key;
+    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 0;
+    }
+
+    phpg_gobject_new(&php_model,       (GObject*)model              TSRMLS_CC);
+    phpg_gboxed_new(&php_iter, GTK_TYPE_TREE_ITER, iter, TRUE, TRUE TSRMLS_CC);
+
+    MAKE_STD_ZVAL(php_column);
+    ZVAL_LONG(php_column, column);
+
+    cp_key = phpg_from_utf8(key, strlen(key), &cp_len, &free_result TSRMLS_CC);
+    if (!cp_key) {
+        php_error(E_WARNING, "Could not convert key from UTF-8");
+        return FALSE;
+    }
+    MAKE_STD_ZVAL(php_key);
+    ZVAL_STRINGL(php_key, (char*)cp_key, cp_len, 1);
+    if (free_result) {
+        g_free(cp_key);
+    }
+
+    args = php_gtk_hash_as_array_offset(cbd->user_args, 4, &n_args);
+    args[0] = &php_model;
+    args[1] = &php_column;
+    args[2] = &php_key;
+    args[3] = &php_iter;
+
+    call_user_function_ex(EG(function_table), NULL, cbd->callback, &retval, n_args, args, 0, NULL TSRMLS_CC);
+
+    zval_ptr_dtor(&php_model);
+    zval_ptr_dtor(&php_column);
+    zval_ptr_dtor(&php_key);
+    zval_ptr_dtor(&php_iter);
+
+    if (retval) {
+        matches = zend_is_true(retval);
+        zval_ptr_dtor(&retval);
+    } else {
+        matches = FALSE;
+    }
+
+    phpg_handle_marshaller_exception(TSRMLS_C);
+
+    efree(callback_name);
+    efree(args);
+
+    return matches;
+}
+
+PHP_METHOD
+{
+    zval *php_callback, *extra;
+    phpg_cb_data_t *cb_data;
+    GtkTreeViewSearchEqualFunc callback;
+
+    NOT_STATIC_METHOD();
+
+    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 = (GtkTreeViewSearchEqualFunc)phpg_tree_view_search_equal_func_marshal;
+        }
+    }
+
+    gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(PHPG_GOBJECT(this_ptr)),
+                                                           callback,
+                                                           cb_data, phpg_cb_data_destroy);
+}
+
+%%
 add-arginfo GtkTreeView tree_to_widget_coords
 static
 ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
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.