mirror of
https://github.com/php/php-gtk-src.git
synced 2026-04-28 11:33:20 +02:00
* Fixed constructor generation
* Overrode GtkButton() and GtkListItem() constructors so that a text label can be optionally passed in.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user