summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-05-07 12:49:15 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-05-11 22:21:39 -0400
commit12ca08c3820ef5b375b2de2fa30b5fad71b4ec2b (patch)
treeb4133fd95a5db8f06a84e3194d628d94d57f6a9a
parent78d20b9301dde74b7fe4c4d6899fcf35937658da (diff)
downloadgtk+-12ca08c3820ef5b375b2de2fa30b5fad71b4ec2b.tar.gz
infobar: Add gtk_info_bar_add/remove_child
This is a replacement for container api that is going away.
-rw-r--r--docs/reference/gtk/gtk4-sections.txt2
-rw-r--r--gtk/gtkinfobar.c53
-rw-r--r--gtk/gtkinfobar.h7
3 files changed, 53 insertions, 9 deletions
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index ba5d96cd7b..f5af282172 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1755,6 +1755,8 @@ gtk_info_bar_get_show_close_button
gtk_info_bar_set_show_close_button
gtk_info_bar_get_revealed
gtk_info_bar_set_revealed
+gtk_info_bar_add_child
+gtk_info_bar_remove_child
<SUBSECTION Standard>
GTK_TYPE_INFO_BAR
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index a8baa91f1c..75deead08e 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -68,8 +68,9 @@
* to add buttons to the action area with gtk_info_bar_add_button() or
* gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
* can be controlled with gtk_info_bar_set_response_sensitive().
+ *
* To add widgets to the main content area of a #GtkInfoBar, use
- * gtk_info_bar_get_content_area() and add your widgets to the container.
+ * gtk_info_bar_add_child().
*
* Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
* classified as error message, warning, informational message, etc,
@@ -78,7 +79,8 @@
*
* A simple example for using a #GtkInfoBar:
* |[<!-- language="C" -->
- * GtkWidget *widget, *message_label, *content_area;
+ * GtkWidget *message_label;
+ * GtkWidget *widget;
* GtkWidget *grid;
* GtkInfoBar *bar;
*
@@ -88,9 +90,7 @@
* grid = gtk_grid_new ();
*
* message_label = gtk_label_new ("");
- * content_area = gtk_info_bar_get_content_area (bar);
- * gtk_container_add (GTK_CONTAINER (content_area),
- * message_label);
+ * gtk_info_bar_add_child (bar, message_label);
* gtk_info_bar_add_button (bar,
* _("_OK"),
* GTK_RESPONSE_OK);
@@ -106,8 +106,7 @@
*
* // show an error message
* gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!");
- * gtk_info_bar_set_message_type (bar,
- * GTK_MESSAGE_ERROR);
+ * gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR);
* gtk_widget_show (bar);
* ]|
*
@@ -1095,8 +1094,8 @@ gtk_info_bar_buildable_add_child (GtkBuildable *buildable,
{
GtkInfoBar *info_bar = GTK_INFO_BAR (buildable);
- if (!type)
- gtk_container_add (GTK_CONTAINER (info_bar->content_area), GTK_WIDGET (child));
+ if (!type && GTK_IS_WIDGET (child))
+ gtk_info_bar_add_child (GTK_INFO_BAR (info_bar), GTK_WIDGET (child));
else if (g_strcmp0 (type, "action") == 0)
gtk_container_add (GTK_CONTAINER (info_bar->action_area), GTK_WIDGET (child));
else
@@ -1273,3 +1272,39 @@ gtk_info_bar_get_revealed (GtkInfoBar *info_bar)
return gtk_revealer_get_reveal_child (GTK_REVEALER (info_bar->revealer));
}
+
+/**
+ * gtk_info_bar_add_child:
+ * @info_bar: a #GtkInfoBar
+ * @widget: the child to be added
+ *
+ * Adds a widget to the content area of the info bar.
+ */
+void
+gtk_info_bar_add_child (GtkInfoBar *info_bar,
+ GtkWidget *widget)
+{
+ g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ gtk_container_add (GTK_CONTAINER (info_bar->content_area), widget);
+}
+
+/**
+ * gtk_info_bar_remove_child:
+ * @info_bar: a #GtkInfoBar
+ * @widget: a child that has been added to the content area
+ *
+ * Removes a widget from the content area of the info bar,
+ * after it has been added with gtk_info_bar_add_child().
+ */
+void
+gtk_info_bar_remove_child (GtkInfoBar *info_bar,
+ GtkWidget *widget)
+{
+ g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ gtk_container_remove (GTK_CONTAINER (info_bar->content_area), widget);
+}
+
diff --git a/gtk/gtkinfobar.h b/gtk/gtkinfobar.h
index 3a2997d927..834ec197b9 100644
--- a/gtk/gtkinfobar.h
+++ b/gtk/gtkinfobar.h
@@ -69,6 +69,13 @@ void gtk_info_bar_add_buttons (GtkInfoBar *info_bar,
const gchar *first_button_text,
...);
GDK_AVAILABLE_IN_ALL
+void gtk_info_bar_add_child (GtkInfoBar *info_bar,
+ GtkWidget *widget);
+GDK_AVAILABLE_IN_ALL
+void gtk_info_bar_remove_child (GtkInfoBar *info_bar,
+ GtkWidget *widget);
+
+GDK_AVAILABLE_IN_ALL
void gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
gint response_id,
gboolean setting);