From 6b411f4b47b59e809488351edca82ed42bc9529e Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Mon, 23 Mar 1998 03:31:11 +0000 Subject: [PATCH] leave container_class->add and container_class->remove untouched if we Mon Mar 23 01:08:30 1998 Tim Janik * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and container_class->remove untouched if we don't implement them. * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL initialization for the class method (*foreach). implement a default handler to output a warning for (*add) and (*remove). --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-0 | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-2 | 9 +++++++++ ChangeLog.pre-2-4 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ TODO | 5 ----- gtk/gtkclist.c | 4 ++-- gtk/gtkcontainer.c | 31 ++++++++++++++++++++++++++----- gtk/testgtk.c | 34 ++++++++++++++++++++++++++++++++-- tests/testgtk.c | 34 ++++++++++++++++++++++++++++++++-- 12 files changed, 155 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 0992a67e4f..792e2ac0fe 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +Mon Mar 23 01:08:30 1998 Tim Janik + + * gtk/gtkclist.c (gtk_clist_class_init): leave container_class->add and + container_class->remove untouched if we don't implement them. + + * gtk/gtkcontainer.c (gtk_container_class_init): add missing NULL + initialization for the class method (*foreach). implement a default + handler to output a warning for (*add) and (*remove). + Sun Mar 22 19:01:36 1998 Owen Taylor * gdk/gdkcolor.c: Fixes to allow GTK to work with colormaps diff --git a/TODO b/TODO index 1e84fd4ee1..66806ca3fd 100644 --- a/TODO +++ b/TODO @@ -9,11 +9,6 @@ Bugs: GtkLabels sometimes redraw without clearing up the underlying background on window resizes. - * GtkCList is derived from GtkContainer but doesn't implement the - need_resize, focus, add and remove methods from containers. - it should at least issue a warning upon invokation of not supported - member functions. - * GtkTree and GtkList should express in their *_add implementations, that they expect GtkListItems/GtkTreeItems as children. Similar things might apply to other containers. diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c index bc4ddeb8d0..64f8f8322b 100644 --- a/gtk/gtkclist.c +++ b/gtk/gtkclist.c @@ -355,8 +355,8 @@ gtk_clist_class_init (GtkCListClass * klass) widget_class->size_request = gtk_clist_size_request; widget_class->size_allocate = gtk_clist_size_allocate; - container_class->add = NULL; - container_class->remove = NULL; + /* container_class->add = NULL; use the default GtkContainerClass warning */ + /* container_class->remove = NULL; use the default GtkContainerClass warning */ container_class->foreach = gtk_clist_foreach; klass->select_row = real_select_row; diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 5cf5238e2b..3d2b8a1245 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -79,6 +79,10 @@ static void gtk_container_get_arg (GtkContainer *container, static void gtk_container_set_arg (GtkContainer *container, GtkArg *arg, guint arg_id); +static void gtk_container_add_unimplemented (GtkContainer *container, + GtkWidget *widget); +static void gtk_container_remove_unimplemented (GtkContainer *container, + GtkWidget *widget); static gint gtk_real_container_need_resize (GtkContainer *container); static gint gtk_real_container_focus (GtkContainer *container, GtkDirectionType direction); @@ -193,12 +197,29 @@ gtk_container_class_init (GtkContainerClass *class) * accessable through gtk_container_foreach. */ widget_class->show_all = gtk_container_show_all; - widget_class->hide_all = gtk_container_hide_all; - + widget_class->hide_all = gtk_container_hide_all; + + class->add = gtk_container_add_unimplemented; + class->remove = gtk_container_remove_unimplemented; class->need_resize = gtk_real_container_need_resize; + class->foreach = NULL; class->focus = gtk_real_container_focus; } +static void +gtk_container_add_unimplemented (GtkContainer *container, + GtkWidget *widget) +{ + g_warning ("GtkContainerClass::add not implemented for `%s'", gtk_type_name (GTK_OBJECT_TYPE (container))); +} + +static void +gtk_container_remove_unimplemented (GtkContainer *container, + GtkWidget *widget) +{ + g_warning ("GtkContainerClass::remove not implemented for `%s'", gtk_type_name (GTK_OBJECT_TYPE (container))); +} + static void gtk_container_init (GtkContainer *container) { @@ -325,12 +346,12 @@ gtk_container_remove (GtkContainer *container, g_return_if_fail (GTK_IS_CONTAINER (container)); g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GTK_CONTAINER (widget->parent) == container); + g_return_if_fail (widget->parent == GTK_WIDGET (container)); + gtk_signal_emit (GTK_OBJECT (container), container_signals[REMOVE], widget); + if (container->focus_child == widget) container->focus_child = NULL; - - gtk_signal_emit (GTK_OBJECT (container), container_signals[REMOVE], widget); } void diff --git a/gtk/testgtk.c b/gtk/testgtk.c index 3d6bd8f14d..c18bf26e6a 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -3019,7 +3019,7 @@ unselect_clist (GtkWidget *widget, clist_selected_row = row; } -void +static void insert_row_clist (GtkWidget *widget, gpointer data) { static char *text[] = @@ -3037,7 +3037,27 @@ insert_row_clist (GtkWidget *widget, gpointer data) clist_rows++; } -void +static void +clist_warning_test (GtkWidget *button, + GtkWidget *clist) +{ + GtkWidget *child; + static gboolean add_remove = FALSE; + + add_remove = !add_remove; + child = gtk_label_new ("Test"); + if (add_remove) + gtk_container_add (GTK_CONTAINER (clist), child); + else + { + child->parent = clist; + gtk_container_remove (GTK_CONTAINER (clist), child); + child->parent = NULL; + } + gtk_widget_destroy (child); +} + +static void create_clist () { gint i; @@ -3169,6 +3189,16 @@ create_clist () gtk_widget_show (button); + button = gtk_button_new_with_label ("Warning Test"); + gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); + + gtk_signal_connect (GTK_OBJECT (button), + "clicked", + (GtkSignalFunc) clist_warning_test, + (gpointer) clist); + + gtk_widget_show (button); + /* vbox for the list itself */ box2 = gtk_vbox_new (FALSE, 10); gtk_container_border_width (GTK_CONTAINER (box2), 10); diff --git a/tests/testgtk.c b/tests/testgtk.c index 3d6bd8f14d..c18bf26e6a 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -3019,7 +3019,7 @@ unselect_clist (GtkWidget *widget, clist_selected_row = row; } -void +static void insert_row_clist (GtkWidget *widget, gpointer data) { static char *text[] = @@ -3037,7 +3037,27 @@ insert_row_clist (GtkWidget *widget, gpointer data) clist_rows++; } -void +static void +clist_warning_test (GtkWidget *button, + GtkWidget *clist) +{ + GtkWidget *child; + static gboolean add_remove = FALSE; + + add_remove = !add_remove; + child = gtk_label_new ("Test"); + if (add_remove) + gtk_container_add (GTK_CONTAINER (clist), child); + else + { + child->parent = clist; + gtk_container_remove (GTK_CONTAINER (clist), child); + child->parent = NULL; + } + gtk_widget_destroy (child); +} + +static void create_clist () { gint i; @@ -3169,6 +3189,16 @@ create_clist () gtk_widget_show (button); + button = gtk_button_new_with_label ("Warning Test"); + gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); + + gtk_signal_connect (GTK_OBJECT (button), + "clicked", + (GtkSignalFunc) clist_warning_test, + (gpointer) clist); + + gtk_widget_show (button); + /* vbox for the list itself */ box2 = gtk_vbox_new (FALSE, 10); gtk_container_border_width (GTK_CONTAINER (box2), 10);