[PATCH] GtkTreePath stuff updated
| From: | Steph | Date: | Sun, 16 Oct 2005 14:41:47 +0000 |
| Subject: | [PATCH] GtkTreePath stuff updated | ||
| Groups: | php.gtk.dev | ||
| Request: | Send a blank email to php-gtk-dev+get-1835@lists.php.net to get a copy of this message | ||
Andrei,
I've now made it so that everything not an object is free'd as in the
original version. Can I go ahead and apply this please? - Pablo's waiting
for it...
Note that I fixed the existing get_iter() typo in CVS during the week.
Note also that my entire extended family have gone on holiday for two weeks
and I've some hope of actually achieving something during this bit of peace
and quiet :)
- Steph
----- Original Message -----
From: "Steph" <steph@zend.com>
To: <andrei@gravitonic.com>
Sent: Saturday, October 08, 2005 9:33 PM
Subject: Re: need response if I'm going to be useful this weekend
> Andrei, hi & thanks for breaking up a bit of Saturday :)
>
> > The reason for complexity was so that we could map easily between PHP
> > zvals and GtkTreePath. For example, by returning array(1, 2, 3) you
would
> > essentially be returning a tree path with those indices.
>
> Mm, I saw that, but of course all the treepath methods (some are useful)
> need full overrides if you go this route.
>
> How about a combination approach? Patch attached (nb your implementation
> was broken due to a typo). Note that I've removed the calls to
> gtk_tree_path_free(). This is because they cause a crash when a genuine
> GtkTreePath object's passed to get_iter(), but you already call
> gtk_tree_path_free() from phpg_gtk_tree_path_from_zval(), so I'm hoping
you
> don't actually need to call it again.
>
> It _appears_ to work with pretty much any form of data here, but if you
want
> me to stick a flag in there somewhere and only free what needs freeing
it's
> simple enough to do.
>
> > iter_next() and up() should return either FALSE or appropriate types.
>
> Yeah, found this. I spent some time trying to write overrides for
> $treepath->up() and $treepath->prev() - I'm a bit confused by the fact
that
> in either case when they don't exist they still return a GtkTreePath,
> whether overridden or not. If there's nothing there, up() returns an
object
> with a NULL path_string and prev() returns an object with a 0 path_string.
> When they _do_ exist they appear to work as anticipated, but when they
> don't, they never seem to be either == 0 or == FALSE. Which is odd....
but
> wtf, at least they do everything else you'd expect, e.g. iterate!
>
> - Steph
>
Index: ext/gtk+/gtk-types.defs =================================================================== RCS file: /repository/php-gtk/ext/gtk+/gtk-types.defs,v retrieving revision 1.3 diff -u -r1.3 gtk-types.defs --- ext/gtk+/gtk-types.defs 4 Apr 2005 04:07:30 -0000 1.3 +++ ext/gtk+/gtk-types.defs 16 Oct 2005 14:19:00 -0000 @@ -108,6 +108,14 @@ (release-func "gtk_tree_iter_free") ) +(define-boxed TreePath + (in-module "Gtk") + (c-name "GtkTreePath") + (gtype-id "GTK_TYPE_TREE_PATH") + (copy-func "gtk_tree_path_copy") + (release-func "gtk_tree_path_free") +) + (define-boxed TreeRowReference (in-module "Gtk") (c-name "GtkTreeRowReference") Index: ext/gtk+/gtktreeview.overrides =================================================================== RCS file: /repository/php-gtk/ext/gtk+/gtktreeview.overrides,v retrieving revision 1.19 diff -u -r1.19 gtktreeview.overrides --- ext/gtk+/gtktreeview.overrides 13 Oct 2005 05:26:49 -0000 1.19 +++ ext/gtk+/gtktreeview.overrides 16 Oct 2005 14:37:44 -0000 @@ -9,9 +9,6 @@ %% {{{ ignores %% -ignore-glob - gtk_tree_path_* -%% ignore gtk_list_store_newv gtk_list_store_set_valist @@ -417,27 +414,54 @@ zval *php_path = NULL; GtkTreeIter iter; GtkTreePath *path; + zend_bool is_obj = 0; NOT_STATIC_METHOD(); if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "V", &php_path)) return; - if (phpg_tree_path_from_zval(php_path, &path TSRMLS_CC) == FAILURE) { - php_error(E_WARNING, "%s::%s() expects path argument to be a valid tree path specification", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); - return; + if (php_path && IS_OBJECT == Z_TYPE_P(php_path)) { + path = (GtkTreePath *) PHPG_GBOXED(php_path); + is_obj = 1; + } else { + if (phpg_tree_path_from_zval(php_path, &path TSRMLS_CC) == FAILURE) { + php_error(E_WARNING, "%s::%s() expects path argument to be a valid tree path specification", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); + return; + } } if (gtk_tree_model_get_iter(GTK_TREE_MODEL(PHPG_GOBJECT(this_ptr)), &iter, path)) { - gtk_tree_path_free(path); + if (!is_obj) gtk_tree_path_free(path); phpg_gboxed_new(&return_value, GTK_TYPE_TREE_ITER, &iter, TRUE, TRUE TSRMLS_CC); } else { - gtk_tree_path_free(path); + if (!is_obj) gtk_tree_path_free(path); php_error(E_WARNING, "%s::%s(): invalid tree path", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); } } %% +override gtk_tree_model_iter_next +PHP_METHOD +{ + GtkTreeIter *iter; + zval *php_iter; + + NOT_STATIC_METHOD(); + + if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "O", &php_iter, gtktreeiter_ce)) + return; + + iter = (GtkTreeIter *) PHPG_GBOXED(php_iter); + + if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(PHPG_GOBJECT(this_ptr)), iter)) { + RETURN_FALSE; + } + + phpg_gboxed_new(&return_value, GTK_TYPE_TREE_ITER, &iter, TRUE, TRUE TSRMLS_CC); +} + +%% override gtk_tree_model_get_iter_first PHP_METHOD {
Index: ext/gtk+/gtk-types.defs =================================================================== RCS file: /repository/php-gtk/ext/gtk+/gtk-types.defs,v retrieving revision 1.3 diff -u -r1.3 gtk-types.defs --- ext/gtk+/gtk-types.defs 4 Apr 2005 04:07:30 -0000 1.3 +++ ext/gtk+/gtk-types.defs 16 Oct 2005 14:19:00 -0000 @@ -108,6 +108,14 @@ (release-func "gtk_tree_iter_free") ) +(define-boxed TreePath + (in-module "Gtk") + (c-name "GtkTreePath") + (gtype-id "GTK_TYPE_TREE_PATH") + (copy-func "gtk_tree_path_copy") + (release-func "gtk_tree_path_free") +) + (define-boxed TreeRowReference (in-module "Gtk") (c-name "GtkTreeRowReference") Index: ext/gtk+/gtktreeview.overrides =================================================================== RCS file: /repository/php-gtk/ext/gtk+/gtktreeview.overrides,v retrieving revision 1.19 diff -u -r1.19 gtktreeview.overrides --- ext/gtk+/gtktreeview.overrides 13 Oct 2005 05:26:49 -0000 1.19 +++ ext/gtk+/gtktreeview.overrides 16 Oct 2005 14:37:44 -0000 @@ -9,9 +9,6 @@ %% {{{ ignores %% -ignore-glob - gtk_tree_path_* -%% ignore gtk_list_store_newv gtk_list_store_set_valist @@ -417,27 +414,54 @@ zval *php_path = NULL; GtkTreeIter iter; GtkTreePath *path; + zend_bool is_obj = 0; NOT_STATIC_METHOD(); if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "V", &php_path)) return; - if (phpg_tree_path_from_zval(php_path, &path TSRMLS_CC) == FAILURE) { - php_error(E_WARNING, "%s::%s() expects path argument to be a valid tree path specification", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); - return; + if (php_path && IS_OBJECT == Z_TYPE_P(php_path)) { + path = (GtkTreePath *) PHPG_GBOXED(php_path); + is_obj = 1; + } else { + if (phpg_tree_path_from_zval(php_path, &path TSRMLS_CC) == FAILURE) { + php_error(E_WARNING, "%s::%s() expects path argument to be a valid tree path specification", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); + return; + } } if (gtk_tree_model_get_iter(GTK_TREE_MODEL(PHPG_GOBJECT(this_ptr)), &iter, path)) { - gtk_tree_path_free(path); + if (!is_obj) gtk_tree_path_free(path); phpg_gboxed_new(&return_value, GTK_TYPE_TREE_ITER, &iter, TRUE, TRUE TSRMLS_CC); } else { - gtk_tree_path_free(path); + if (!is_obj) gtk_tree_path_free(path); php_error(E_WARNING, "%s::%s(): invalid tree path", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); } } %% +override gtk_tree_model_iter_next +PHP_METHOD +{ + GtkTreeIter *iter; + zval *php_iter; + + NOT_STATIC_METHOD(); + + if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "O", &php_iter, gtktreeiter_ce)) + return; + + iter = (GtkTreeIter *) PHPG_GBOXED(php_iter); + + if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(PHPG_GOBJECT(this_ptr)), iter)) { + RETURN_FALSE; + } + + phpg_gboxed_new(&return_value, GTK_TYPE_TREE_ITER, &iter, TRUE, TRUE TSRMLS_CC); +} + +%% override gtk_tree_model_get_iter_first PHP_METHOD {