summaryrefslogtreecommitdiff
path: root/gtk/gtkinfobar.c
diff options
context:
space:
mode:
authorWilliam Jon McCann <william.jon.mccann@gmail.com>2013-07-15 15:04:56 -0400
committerWilliam Jon McCann <william.jon.mccann@gmail.com>2013-07-24 17:01:42 -0400
commit88771f7b1b056dd0a76d3eec9ee0e5e81fc43fef (patch)
treebab6d1d7019daeff14b630cd88765843d5960b6f /gtk/gtkinfobar.c
parent16e43733b96163c6365a6c04f5097722360ec5b2 (diff)
downloadgtk+-88771f7b1b056dd0a76d3eec9ee0e5e81fc43fef.tar.gz
Add an optional close button to the info bar
This adds gtk_info_bar_{get,set}_show_close_button. Similar to the one for the search bar. This can replace Cancel buttons. https://bugzilla.gnome.org/show_bug.cgi?id=704274
Diffstat (limited to 'gtk/gtkinfobar.c')
-rw-r--r--gtk/gtkinfobar.c85
1 files changed, 83 insertions, 2 deletions
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index bd805b64a6..e55f6403fc 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -118,14 +118,17 @@
enum
{
PROP_0,
- PROP_MESSAGE_TYPE
+ PROP_MESSAGE_TYPE,
+ PROP_SHOW_CLOSE_BUTTON
};
struct _GtkInfoBarPrivate
{
GtkWidget *content_area;
GtkWidget *action_area;
+ GtkWidget *close_button;
+ gboolean show_close_button;
GtkMessageType message_type;
};
@@ -198,6 +201,9 @@ gtk_info_bar_set_property (GObject *object,
case PROP_MESSAGE_TYPE:
gtk_info_bar_set_message_type (info_bar, g_value_get_enum (value));
break;
+ case PROP_SHOW_CLOSE_BUTTON:
+ gtk_info_bar_set_show_close_button (info_bar, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -217,6 +223,9 @@ gtk_info_bar_get_property (GObject *object,
case PROP_MESSAGE_TYPE:
g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
break;
+ case PROP_SHOW_CLOSE_BUTTON:
+ g_value_set_boolean (value, gtk_info_bar_get_show_close_button (info_bar));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -283,7 +292,8 @@ find_button (GtkInfoBar *info_bar,
static void
gtk_info_bar_close (GtkInfoBar *info_bar)
{
- if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
+ if (!gtk_widget_get_visible (info_bar->priv->close_button)
+ && !find_button (info_bar, GTK_RESPONSE_CANCEL))
return;
gtk_info_bar_response (GTK_INFO_BAR (info_bar),
@@ -404,6 +414,21 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
GTK_TYPE_MESSAGE_TYPE,
GTK_MESSAGE_INFO,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+ /**
+ * GtkInfoBar:show-close-button:
+ *
+ * Whether to include a standard close button.
+ *
+ * Since: 3.10
+ */
+ g_object_class_install_property (object_class,
+ PROP_SHOW_CLOSE_BUTTON,
+ g_param_spec_boolean ("show-close-button",
+ P_("Show Close Button"),
+ P_("Whether to include a standard close button"),
+ FALSE,
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* GtkInfoBar::response:
* @info_bar: the object on which the signal is emitted
@@ -523,6 +548,15 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkinfobar.ui");
gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, content_area);
gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, action_area);
+ gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, close_button);
+}
+
+static void
+close_button_clicked_cb (GtkWidget *button,
+ GtkInfoBar *info_bar)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (info_bar),
+ GTK_RESPONSE_CLOSE);
}
static void
@@ -540,6 +574,10 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
info_bar->priv->message_type = GTK_MESSAGE_OTHER;
gtk_widget_init_template (GTK_WIDGET (info_bar));
+
+ gtk_widget_set_no_show_all (info_bar->priv->close_button, TRUE);
+ g_signal_connect (info_bar->priv->close_button, "clicked",
+ G_CALLBACK (close_button_clicked_cb), info_bar);
}
static GtkBuildableIface *parent_buildable_iface;
@@ -1169,3 +1207,46 @@ gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
return info_bar->priv->message_type;
}
+
+
+/**
+ * gtk_info_bar_set_show_close_button:
+ * @info_bar: a #GtkInfoBar
+ * @setting: %TRUE to include a close button
+ *
+ * If true, a standard close button is shown. When clicked it emits
+ * the response %GTK_RESPONSE_CLOSE.
+ *
+ * Since: 3.10
+ */
+void
+gtk_info_bar_set_show_close_button (GtkInfoBar *info_bar,
+ gboolean setting)
+{
+ g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
+
+ if (setting != info_bar->priv->show_close_button)
+ {
+ info_bar->priv->show_close_button = setting;
+ gtk_widget_set_visible (info_bar->priv->close_button, setting);
+ g_object_notify (G_OBJECT (info_bar), "show-close-button");
+ }
+}
+
+/**
+ * gtk_info_bar_get_show_close_button:
+ * @info_bar: a #GtkInfoBar
+ *
+ * Returns whether the widget will display a standard close button.
+ *
+ * Returns: %TRUE if the widget displays standard close button
+ *
+ * Since: 3.10
+ */
+gboolean
+gtk_info_bar_get_show_close_button (GtkInfoBar *info_bar)
+{
+ g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), FALSE);
+
+ return info_bar->priv->show_close_button;
+}