[gtk+] infobar: Add :revealed property



commit 1bb4f1e9d9c4fb54e1a4b4e05bf6c5d1302f00d3
Author: Timm Bäder <mail baedert org>
Date:   Thu Jan 12 09:09:22 2017 +0100

    infobar: Add :revealed property

 gtk/gtkinfobar.c     |   94 ++++++++++++++++++++++++++++++++-----------------
 gtk/gtkinfobar.h     |    6 +++
 gtk/ui/gtkinfobar.ui |    1 +
 3 files changed, 68 insertions(+), 33 deletions(-)
---
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index 91e2515..2a22938 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -132,6 +132,7 @@ enum
   PROP_0,
   PROP_MESSAGE_TYPE,
   PROP_SHOW_CLOSE_BUTTON,
+  PROP_REVEALED,
   LAST_PROP
 };
 
@@ -211,6 +212,9 @@ gtk_info_bar_set_property (GObject      *object,
     case PROP_SHOW_CLOSE_BUTTON:
       gtk_info_bar_set_show_close_button (info_bar, g_value_get_boolean (value));
       break;
+    case PROP_REVEALED:
+      gtk_info_bar_set_revealed (info_bar, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -233,6 +237,9 @@ gtk_info_bar_get_property (GObject    *object,
     case PROP_SHOW_CLOSE_BUTTON:
       g_value_set_boolean (value, gtk_info_bar_get_show_close_button (info_bar));
       break;
+    case PROP_REVEALED:
+      g_value_set_boolean (value, gtk_info_bar_get_revealed (info_bar));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -302,36 +309,6 @@ gtk_info_bar_close (GtkInfoBar *info_bar)
 }
 
 static void
-gtk_info_bar_show (GtkWidget *widget)
-{
-  GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
-
-  GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->show (widget);
-
-  gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), TRUE);
-}
-
-static void
-child_revealed (GObject *object, GParamSpec *pspec, gpointer data)
-{
-  GtkWidget *widget = data;
-
-  GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->hide (widget);
-  g_signal_handlers_disconnect_by_func (object, child_revealed, widget);
-  g_object_notify (G_OBJECT (widget), "visible");
-}
-
-static void
-gtk_info_bar_hide (GtkWidget *widget)
-{
-  GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
-
-  g_signal_connect_object (priv->revealer, "notify::child-revealed",
-                           G_CALLBACK (child_revealed), widget, 0);
-  gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), FALSE);
-}
-
-static void
 gtk_info_bar_class_init (GtkInfoBarClass *klass)
 {
   GtkWidgetClass *widget_class;
@@ -344,9 +321,6 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
   object_class->get_property = gtk_info_bar_get_property;
   object_class->set_property = gtk_info_bar_set_property;
 
-  widget_class->show = gtk_info_bar_show;
-  widget_class->hide = gtk_info_bar_hide;
-
   klass->close = gtk_info_bar_close;
 
   /**
@@ -380,6 +354,13 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
                           FALSE,
                           GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY);
 
+  props[PROP_REVEALED] =
+    g_param_spec_boolean ("revealed",
+                          P_("Reveal"),
+                          P_("Controls whether the action bar shows its contents or not"),
+                          TRUE,
+                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
   /**
@@ -1178,3 +1159,50 @@ gtk_info_bar_get_show_close_button (GtkInfoBar *info_bar)
 
   return info_bar->priv->show_close_button;
 }
+
+/**
+ * gtk_info_bar_set_revealed:
+ * @info_bar: a #GtkActionBar
+ * @revealed: The new value of the property
+ *
+ * Sets the GtkInfoBar:revealed property to @revealed. This will cause
+ * @info_bar to show up with a slide-in transition.
+ *
+ * Note that this settings does not automatically show @info_bar and thus won't
+ * have any effect if it is invisible.
+ *
+ * Since: 3.90
+ */
+void
+gtk_info_bar_set_revealed (GtkInfoBar *info_bar,
+                           gboolean    revealed)
+{
+  GtkInfoBarPrivate *priv = gtk_info_bar_get_instance_private (info_bar);
+
+  g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
+
+  revealed = !!revealed;
+  if (revealed != gtk_revealer_get_reveal_child (GTK_REVEALER (priv->revealer)))
+    {
+      gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), revealed);
+      g_object_notify_by_pspec (G_OBJECT (info_bar), props[PROP_REVEALED]);
+    }
+}
+
+/**
+ * gtk_info_bar_get_revealed:
+ * @info_bar: a #GtkInfoBar
+ *
+ * Returns:  the current value of the GtkInfoBar:revealed property.
+ *
+ * Since: 3.90
+ */
+gboolean
+gtk_info_bar_get_revealed (GtkInfoBar *info_bar)
+{
+  GtkInfoBarPrivate *priv = gtk_info_bar_get_instance_private (info_bar);
+
+  g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), FALSE);
+
+  return gtk_revealer_get_reveal_child (GTK_REVEALER (priv->revealer));
+}
diff --git a/gtk/gtkinfobar.h b/gtk/gtkinfobar.h
index a10c3a9..b4674f9 100644
--- a/gtk/gtkinfobar.h
+++ b/gtk/gtkinfobar.h
@@ -130,6 +130,12 @@ void           gtk_info_bar_set_show_close_button  (GtkInfoBar     *info_bar,
 GDK_AVAILABLE_IN_3_10
 gboolean       gtk_info_bar_get_show_close_button  (GtkInfoBar     *info_bar);
 
+GDK_AVAILABLE_IN_3_90
+void           gtk_info_bar_set_revealed           (GtkInfoBar     *info_bar,
+                                                    gboolean        revealed);
+GDK_AVAILABLE_IN_3_90
+gboolean       gtk_info_bar_get_revealed           (GtkInfoBar     *info_bar);
+
 G_END_DECLS
 
 #endif  /* __GTK_INFO_BAR_H__  */
diff --git a/gtk/ui/gtkinfobar.ui b/gtk/ui/gtkinfobar.ui
index 4fa4b9e..6bdc31b 100644
--- a/gtk/ui/gtkinfobar.ui
+++ b/gtk/ui/gtkinfobar.ui
@@ -5,6 +5,7 @@
     <child>
       <object class="GtkRevealer" id="revealer">
         <property name="visible">1</property>
+        <property name="reveal-child">1</property>
         <child>
           <object class="GtkBox" id="content">
             <property name="visible">1</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]