GNOME Bugzilla – Bug 710471
Make gtk_scrolled_window_remove() smart
Last modified: 2016-06-08 08:35:42 UTC
Now that gtk_scrolled_window_add() is smart enough to automatically add a GtkViewport if necessary (bug 693015), it would be appropriate to make gtk_scrolled_window_remove() as smart. I'll attach a patch to show what I mean.
Created attachment 257654 [details] [review] patch: Make gtk_scrolled_window_remove() smart This patch makes it possible to execute code such as g_object_ref_sink(child_widget); gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); /* ...... */ gtk_container_remove(GTK_CONTAINER(scrolled_window), gtk_bin_get_child(GTK_BIN(scrolled_window))); /* ...... */ gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); even if child_widget does not implement the GtkScrollable interface. gtk_container_remove() first removes child_widget from the viewport, then the viewport from scrolled_window. It would perhaps have been nicer to accept code such as g_object_ref_sink(child_widget); gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); /* ...... */ gtk_container_remove(GTK_CONTAINER(scrolled_window), child_widget); /* ...... */ gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); but that would require a complication of a test in gtk_container_remove(), which is probably not wanted. The proposed patch also better suits gtkmm.
Created attachment 257656 [details] A test case
(In reply to Kjell Ahlstedt from comment #1) > It would perhaps have been nicer to accept code such as Yes, I think that would be much nicer.
Review of attachment 257654 [details] [review]: .
Created attachment 329266 [details] [review] patch: Make gtk_scrolled_window_remove() smart The test in gtk_container_remove() that worried me in comment 1 was removed by https://git.gnome.org/browse/gtk+/commit/?id=a3805333361fee37a3b1a974cfa6452a85169f08 With this patch both g_object_ref_sink(child_widget); gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); /* ...... */ gtk_container_remove(GTK_CONTAINER(scrolled_window), gtk_bin_get_child(GTK_BIN(scrolled_window))); /* ...... */ gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); and g_object_ref_sink(child_widget); gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); /* ...... */ gtk_container_remove(GTK_CONTAINER(scrolled_window), child_widget); /* ...... */ gtk_container_add(GTK_CONTAINER(scrolled_window), child_widget); can be used. The result is the same in both cases.
Created attachment 329267 [details] An updated test case
Review of attachment 329266 [details] [review]: alright then!