summaryrefslogtreecommitdiff
path: root/gtk/gtkcontainer.c
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>1998-11-29 06:29:40 +0000
committerTim Janik <timj@src.gnome.org>1998-11-29 06:29:40 +0000
commit60e5a2102235880e3095114b8e38e53ab0fd3f81 (patch)
tree3c71749c0f7e944756cfbacf42b950eef103269d /gtk/gtkcontainer.c
parent6edbb34d5495037a76ec3778849609eae74f5200 (diff)
downloadgtk+-60e5a2102235880e3095114b8e38e53ab0fd3f81.tar.gz
removed default initialization check, people must use gtk_type_init();
Sun Nov 29 06:12:01 1998 Tim Janik <timj@gtk.org> * gtk/gtktypeutils.c (gtk_type_unique): removed default initialization check, people must use gtk_type_init(); * gtk/gtkwidget.h: * gtk/gtkwidget.c: added gtk_widget_set_composite_name() which is meant for internal use by containers, that want to assign specific composite names to their composite children. added gtk_widget_get_composite_name() which will return a newly allocated string, containing the composite name of a widget. valid composite names can only be retrived from widgets that have a parent assigned and are flagged as GTK_COMPOSITE_CHILD. * gtk/gtkcontainer.h: * gtk/gtkcontainer.c: added a new function gtk_container_child_default_composite_name() which will return a newly allocated string, holding the composite name of a containers child. a default implementation is provided which will compose the composite name out of the widgets type and its sequential children id. this implementation can be overidden through a new class function *(composite_name)().
Diffstat (limited to 'gtk/gtkcontainer.c')
-rw-r--r--gtk/gtkcontainer.c83
1 files changed, 82 insertions, 1 deletions
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 52f1c4a30b..74bbaeca82 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -89,6 +89,9 @@ static void gtk_container_children_callback (GtkWidget *widget,
static void gtk_container_show_all (GtkWidget *widget);
static void gtk_container_hide_all (GtkWidget *widget);
+static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
+ GtkWidget *child);
+
static guint container_signals[LAST_SIGNAL] = { 0 };
@@ -212,6 +215,7 @@ gtk_container_class_init (GtkContainerClass *class)
class->focus = gtk_container_real_focus;
class->set_focus_child = gtk_container_real_set_focus_child;
class->child_type = NULL;
+ class->composite_name = gtk_container_child_default_composite_name;
}
GtkType
@@ -1254,7 +1258,7 @@ gtk_container_unregister_toplevel (GtkContainer *container)
gtk_widget_unref (GTK_WIDGET (container));
}
-GList *
+GList*
gtk_container_get_toplevels (void)
{
/* XXX: fixme we should ref all these widgets and duplicate
@@ -1263,6 +1267,83 @@ gtk_container_get_toplevels (void)
return toplevel_list;
}
+static void
+gtk_container_child_position_callback (GtkWidget *widget,
+ gpointer client_data)
+{
+ struct {
+ GtkWidget *child;
+ guint i;
+ guint index;
+ } *data = client_data;
+
+ data->i++;
+ if (data->child == widget)
+ data->index = data->i;
+}
+
+static gchar*
+gtk_container_child_default_composite_name (GtkContainer *container,
+ GtkWidget *child)
+{
+ struct {
+ GtkWidget *child;
+ guint i;
+ guint index;
+ } data;
+ gchar *name;
+
+ /* fallback implementation */
+ data.child = child;
+ data.i = 0;
+ data.index = 0;
+ gtk_container_forall (container,
+ gtk_container_child_position_callback,
+ &data);
+
+ name = g_strdup_printf ("%s-%u",
+ gtk_type_name (GTK_OBJECT_TYPE (child)),
+ data.index);
+
+ return name;
+}
+
+gchar*
+gtk_container_child_composite_name (GtkContainer *container,
+ GtkWidget *child)
+{
+ g_return_val_if_fail (container != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
+ g_return_val_if_fail (child != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
+ g_return_val_if_fail (child->parent == GTK_WIDGET (container), NULL);
+
+ if (GTK_WIDGET_COMPOSITE_CHILD (child))
+ {
+ static GQuark quark_composite_name = 0;
+ gchar *name;
+
+ if (!quark_composite_name)
+ quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
+
+ name = gtk_object_get_data_by_id (GTK_OBJECT (child), quark_composite_name);
+ if (!name)
+ {
+ GtkContainerClass *class;
+
+ class = GTK_CONTAINER_CLASS (GTK_OBJECT (container)->klass);
+ if (class->composite_name)
+ name = class->composite_name (container, child);
+ }
+ else
+ name = g_strdup (name);
+
+ return name;
+ }
+
+ return NULL;
+}
+
void
gtk_container_real_set_focus_child (GtkContainer *container,
GtkWidget *child)