* Fixed constructor generation

* Overrode GtkButton() and GtkListItem() constructors so that a text
  label can be optionally passed in.
This commit is contained in:
Andrei Zmievski
2001-02-04 00:41:23 +00:00
parent 2052db1c02
commit 45f2823a2b
3 changed files with 66 additions and 16 deletions
+2 -2
View File
@@ -282,8 +282,8 @@ class Generator {
$this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, NULL, NULL);\n";
else {
$parent_obj = $this->parser->find_parent($object);
$this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, $parent_obj->ce, NULL);\n"
. "\tg_hash_table_insert(php_gtk_class_hash, g_strdup(\"Gtk$object->name\"), $object->ce);\n";
$this->register_classes .= "\t$object->ce = zend_register_internal_class_ex(&ce, $parent_obj->ce, NULL);\n" .
"\tg_hash_table_insert(php_gtk_class_hash, g_strdup(\"Gtk$object->name\"), $object->ce);\n";
}
$function_entry = sprintf($this->function_entry, $this->prefix . "_" . strtolower($object->name));
$constructor = $this->parser->find_constructor($object);
+58
View File
@@ -635,3 +635,61 @@ PHP_FUNCTION(wrap_gtk_list_append_items)
gtk_list_append_items(GTK_LIST(PHP_GTK_GET(this_ptr)), items);
}
%%
ignore gtk_list_item_new_with_label
%%
override gtk_list_item_new
PHP_FUNCTION(wrap_gtk_list_item_new)
{
GtkObject *wrapped_obj;
gchar *text = NULL;
NOT_STATIC_METHOD();
if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "|s", &text)) {
php_gtk_invalidate(this_ptr);
return;
}
if (text)
wrapped_obj = (GtkObject *)gtk_list_item_new_with_label(text);
else
wrapped_obj = (GtkObject *)gtk_list_item_new();
if (!wrapped_obj) {
php_error(E_WARNING, "%s(): could not create GtkListItem object",
get_active_function_name());
return;
}
php_gtk_object_init(wrapped_obj, this_ptr);
}
%%
ignore gtk_button_new_with_label
%%
override gtk_button_new
PHP_FUNCTION(wrap_gtk_button_new)
{
GtkObject *wrapped_obj;
gchar *text = NULL;
NOT_STATIC_METHOD();
if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "|s", &text)) {
php_gtk_invalidate(this_ptr);
return;
}
if (text)
wrapped_obj = (GtkObject *)gtk_button_new_with_label(text);
else
wrapped_obj = (GtkObject *)gtk_button_new();
if (!wrapped_obj) {
php_error(E_WARNING, "%s(): could not create GtkButton object",
get_active_function_name());
return;
}
php_gtk_object_init(wrapped_obj, this_ptr);
}
+6 -14
View File
@@ -49,7 +49,7 @@ class Defs_Parser {
var $file_name = null;
var $objects = array(); // objects
var $functions = array(); // module functions
var $constuctors = array(); // object constructors
var $constructors = array(); // object constructors
var $methods = array(); // object methods
var $enums = array(); // enums and flags
var $c_name = array(); // C names of entities
@@ -113,7 +113,7 @@ class Defs_Parser {
{
$function_def = &new Function_Def($arg);
if (isset($function_def->is_constructor_of))
$this->constuctors[] = &$function_def;
$this->constructors[] = &$function_def;
else
$this->functions[] = &$function_def;
$this->c_name[] = &$function_def->c_name;
@@ -161,26 +161,18 @@ class Defs_Parser {
function find_constructor($obj)
{
$obj_constructor = null;
foreach ($this->constuctors as $constructor) {
if ($constructor->is_constructor_of == $obj->name || $constructor->is_constructor_of == "Gtk$obj->name")
$obj_constructor = $constructor;
foreach ($this->constructors as $constructor) {
if ($constructor->is_constructor_of == $obj->c_name)
return $constructor;
}
return $obj_constructor;
}
function find_parent($obj)
{
$obj_parent = null;
foreach ($this->objects as $object) {
if ($object->name == $obj->parent)
$obj_parent = $object;
return $object;
}
return $obj_parent;
}
}