cvs: php-gtk / TODO /generator generator.php gtk.defs gtk.overrides override.php templates.php

From: Date: Fri, 09 Mar 2001 04:33:36 +0000
Subject: cvs: php-gtk / TODO /generator generator.php gtk.defs gtk.overrides override.php templates.php
Groups: php.gtk 
Request: Send a blank email to php-gtk+get-591@lists.php.net to get a copy of this message
andrei Thu Mar 8 20:33:36 2001 EDT Modified files: /php-gtk TODO /php-gtk/generator generator.php gtk.defs gtk.overrides override.php templates.php Log: * Modified generator to allow overriding object properties. * Added helper GtkBoxChild class. * Added properties for GtkMisc, GtkArrow, GtkBox, and GtkCalendar classes. * Modified GtkCalendar::get_date() to return an array of the results.

Index: php-gtk/TODO diff -u php-gtk/TODO:1.22 php-gtk/TODO:1.23 --- php-gtk/TODO:1.22 Thu Mar 8 14:08:36 2001 +++ php-gtk/TODO Thu Mar 8 20:33:35 2001 @@ -5,6 +5,8 @@ * Provide access to GTK version number. * Fix $dialog->vbox->show() crash. * See what other object definitions might have been missed by h2def.py. +* See if it's possible or needed to set GtkAdjustment properties (and similar + ones). * Add missing field defs to gtk.defs. In PHP Index: php-gtk/generator/generator.php diff -u php-gtk/generator/generator.php:1.15 php-gtk/generator/generator.php:1.16 --- php-gtk/generator/generator.php:1.15 Thu Mar 8 14:08:36 2001 +++ php-gtk/generator/generator.php Thu Mar 8 20:33:35 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: generator.php,v 1.15 2001/03/08 22:08:36 andrei Exp $ */ +/* $Id: generator.php,v 1.16 2001/03/09 04:33:35 andrei Exp $ */ /* * Significant portions of this generator are based on the pygtk code generator @@ -310,24 +310,28 @@ foreach ($object->fields as $field_def) { list($field_type, $field_name) = $field_def; - $var_list = new Var_List(); - $handler = &$matcher->get($field_type); - if ($handler === null) { - error_log("Could not write getter for $object->c_name '$field_name' field (field type $field_type)"); - continue; - } - - $prop_tpl = $handler->write_return($field_type, $var_list); - $prop_code = sprintf($prop_tpl, - $obj_cast . '(PHP_GTK_GET(object))->' . $field_name, ""); - $prop_code = str_replace("\n", "\n\t", $prop_code); + if ($this->overrides->have_get_prop($object->c_name, $field_name)) { + $prop_get_code = $this->overrides->get_prop($object->c_name, $field_name); + $prop_get_code = str_replace("\n", "\n\t", $prop_get_code); + } else { + $var_list = new Var_List(); + $handler = &$matcher->get($field_type); + if ($handler === null) { + error_log("Could not write getter for $object->c_name '$field_name' field (field type $field_type)"); + continue; + } - $var_list_code = $var_list->to_string(); + $prop_tpl = $handler->write_return($field_type, $var_list); + $prop_code = sprintf($prop_tpl, + $obj_cast . '(PHP_GTK_GET(object))->' . $field_name, ""); + $prop_code = str_replace("\n", "\n\t", $prop_code); + $var_list_code = $var_list->to_string(); + $prop_get_code = ($var_list_code ? $var_list_code . "\t" : '') . ' ' . $prop_code; + } $prop_checks .= sprintf($prop_check_tpl, $else_clause, $field_name, - $var_list_code ? $var_list_code . "\t" : '', - $prop_code); + $prop_get_code); $else_clause = ' else '; } @@ -454,10 +458,13 @@ fwrite($fp, "\n/* object Gtk */\n"); fwrite($fp, "static zend_class_entry *gdk_ce;\n"); fwrite($fp, "static zend_class_entry *gtk_ce;\n"); + fwrite($fp, "static zend_class_entry *gtk_box_child_ce;\n"); $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gdk\", php_gdk_functions);\n" . "\tgdk_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gtk\", php_gtk_functions);\n" . "\tgtk_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; + $this->register_classes .= "\n\tINIT_CLASS_ENTRY(ce, \"gtkboxchild\", NULL);\n" + . "\tgtk_box_child_ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n"; $function_entry["gdk"] = sprintf($this->function_entry, 'php_gdk'); $function_entry["gtk"] = sprintf($this->function_entry, $this->prefix); Index: php-gtk/generator/gtk.defs diff -u php-gtk/generator/gtk.defs:1.3 php-gtk/generator/gtk.defs:1.4 --- php-gtk/generator/gtk.defs:1.3 Wed Mar 7 18:35:50 2001 +++ php-gtk/generator/gtk.defs Thu Mar 8 20:33:35 2001 @@ -144,6 +144,10 @@ (in-module Gtk) (parent Widget (Gtk)) (c-name GtkMisc) + (field (type-and-name gfloat xalign)) + (field (type-and-name gfloat yalign)) + (field (type-and-name guint16 xpad)) + (field (type-and-name guint16 ypad)) ) (object Pixmap @@ -156,6 +160,8 @@ (in-module Gtk) (parent Misc (Gtk)) (c-name GtkArrow) + (field (type-and-name gint16 arrow_type)) + (field (type-and-name gint16 shadow_type)) ) (object Image @@ -447,6 +453,9 @@ (in-module Gtk) (parent Container (Gtk)) (c-name GtkBox) + (field (type-and-name GList* children)) + (field (type-and-name gint16 spacing)) + (field (type-and-name gboolean homogeneous)) ) (object VBox @@ -528,6 +537,11 @@ (in-module Gtk) (parent Widget (Gtk)) (c-name GtkCalendar) + (field (type-and-name gint month)) + (field (type-and-name gint year)) + (field (type-and-name gint selected_day)) + (field (type-and-name gint num_marked_dates)) + (field (type-and-name gint* marked_date)) ) (object Window Index: php-gtk/generator/gtk.overrides diff -u php-gtk/generator/gtk.overrides:1.28 php-gtk/generator/gtk.overrides:1.29 --- php-gtk/generator/gtk.overrides:1.28 Wed Mar 7 08:38:01 2001 +++ php-gtk/generator/gtk.overrides Thu Mar 8 20:33:35 2001 @@ -1017,3 +1017,85 @@ gtk_label_get(GTK_LABEL(PHP_GTK_GET(this_ptr)), &text); RETURN_STRING(text, 1); } +%% +getprop GtkBox children + GtkBoxChild *box_child; + zval *php_box_child; + GList *tmp; + GList *children = GTK_BOX(PHP_GTK_GET(object))->children; + zend_overloaded_element *property; + zend_llist_element *next = (*element)->next; + int prop_index; + + if (next) { + int i = 0; + property = (zend_overloaded_element *)next->data; + if (Z_TYPE_P(property) == OE_IS_ARRAY && Z_TYPE(property->element) == IS_LONG) { + *element = next; + prop_index = Z_LVAL(property->element); + for (tmp = children, i = 0; tmp; tmp = tmp->next, i++) { + if (i == prop_index) { + box_child = (GtkBoxChild *)tmp->data; + object_init_ex(return_value, gtk_box_child_ce); + + add_property_zval(return_value, "widget", php_gtk_new((GtkObject *)box_child->widget)); + add_property_long(return_value, "padding", box_child->padding); + add_property_bool(return_value, "expand", box_child->expand); + add_property_bool(return_value, "fill", box_child->fill); + add_property_long(return_value, "pack", box_child->pack); + } + } + } + } else { + array_init(return_value); + for (tmp = children; tmp; tmp = tmp->next) { + box_child = (GtkBoxChild *)tmp->data; + MAKE_STD_ZVAL(php_box_child); + object_init_ex(php_box_child, gtk_box_child_ce); + + add_property_zval(php_box_child, "widget", php_gtk_new((GtkObject *)box_child->widget)); + add_property_long(php_box_child, "padding", box_child->padding); + add_property_bool(php_box_child, "expand", box_child->expand); + add_property_bool(php_box_child, "fill", box_child->fill); + add_property_long(php_box_child, "pack", box_child->pack); + + add_next_index_zval(return_value, php_box_child); + } + } + + return; +%% +getprop GtkCalendar marked_date + GtkCalendar *cal = GTK_CALENDAR(PHP_GTK_GET(object)); + zend_overloaded_element *property; + zend_llist_element *next = (*element)->next; + int prop_index; + + if (next) { + property = (zend_overloaded_element *)next->data; + if (Z_TYPE_P(property) == OE_IS_ARRAY && Z_TYPE(property->element) == IS_LONG) { + *element = next; + prop_index = Z_LVAL(property->element); + if (prop_index > 0 && prop_index < 31) + ZVAL_LONG(return_value, cal->marked_date[prop_index]); + } + } else { + int i; + + array_init(return_value); + for (i = 0; i < 31; i++) + add_next_index_long(return_value, cal->marked_date[i]); + } + + return; +%% +override gtk_calendar_get_date +PHP_FUNCTION(wrap_gtk_calendar_get_date) +{ + guint year, month, day; + + NOT_STATIC_METHOD(); + + gtk_calendar_get_date(GTK_CALENDAR(PHP_GTK_GET(this_ptr)), &year, &month, &day); + *return_value = *php_gtk_build_value("(iii)", year, month, day); +} Index: php-gtk/generator/override.php diff -u php-gtk/generator/override.php:1.7 php-gtk/generator/override.php:1.8 --- php-gtk/generator/override.php:1.7 Sun Mar 4 16:21:42 2001 +++ php-gtk/generator/override.php Thu Mar 8 20:33:35 2001 @@ -19,13 +19,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: override.php,v 1.7 2001/03/05 00:21:42 andrei Exp $ */ +/* $Id: override.php,v 1.8 2001/03/09 04:33:35 andrei Exp $ */ class Overrides { var $ignores = array(); var $glob_ignores = array(); var $overrides = array(); var $extra_methods = array(); + var $getprops = array(); function Overrides($file_name = null) { @@ -81,6 +82,13 @@ else $this->overrides[$func_cname] = array($func_name, $rest); break; + + case 'getprop': + if (count($words) >= 2) { + list($class_name, $prop_name) = $words; + $this->getprops[$class_name][$prop_name] = $rest; + } + break; } } @@ -105,6 +113,16 @@ function get_override($name) { return $this->overrides[$name]; + } + + function have_get_prop($class_name, $prop_name) + { + return isset($this->getprops[$class_name][$prop_name]); + } + + function get_prop($class_name, $prop_name) + { + return $this->getprops[$class_name][$prop_name]; } } Index: php-gtk/generator/templates.php diff -u php-gtk/generator/templates.php:1.7 php-gtk/generator/templates.php:1.8 --- php-gtk/generator/templates.php:1.7 Sun Mar 4 16:21:42 2001 +++ php-gtk/generator/templates.php Thu Mar 8 20:33:35 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: templates.php,v 1.7 2001/03/05 00:21:42 andrei Exp $ */ +/* $Id: templates.php,v 1.8 2001/03/09 04:33:35 andrei Exp $ */ $function_tpl = " PHP_FUNCTION(wrap_%s) @@ -71,7 +71,6 @@ $prop_check_tpl = "%sif (!strcmp(prop_name, \"%s\")) { - %s *found = SUCCESS; %s }"; @@ -81,6 +80,7 @@ char *prop_name = Z_STRVAL(((zend_overloaded_element *)(*element)->data)->element); ZVAL_NULL(return_value); + *found = SUCCESS; %s
« previous php.gtk (#591) next »