[libgd] GdHeaderBar: add get/set for title



commit d7f49c4907210cfaf06e2cfa2528cdd1d23c5433
Author: William Jon McCann <jmccann redhat com>
Date:   Sun Feb 17 12:01:10 2013 -0500

    GdHeaderBar: add get/set for title

 libgd/gd-header-bar.c |   61 ++++++++++++++++++++++++++++++++++++++++++------
 libgd/gd-header-bar.h |   17 ++++++++-----
 test-header-bar.c     |    3 +-
 3 files changed, 65 insertions(+), 16 deletions(-)
---
diff --git a/libgd/gd-header-bar.c b/libgd/gd-header-bar.c
index 48c0b8a..15a4a50 100644
--- a/libgd/gd-header-bar.c
+++ b/libgd/gd-header-bar.c
@@ -79,7 +79,7 @@ gd_header_bar_init (GdHeaderBar *bar)
   GtkStyleContext *context;
   GdHeaderBarPrivate *priv;
 
-  priv = G_TYPE_INSTANCE_GET_PRIVATE (bar, GTK_TYPE_HEADER_BAR, GdHeaderBarPrivate);
+  priv = G_TYPE_INSTANCE_GET_PRIVATE (bar, GD_TYPE_HEADER_BAR, GdHeaderBarPrivate);
   bar->priv = priv;
 
   gtk_widget_set_has_window (GTK_WIDGET (bar), FALSE);
@@ -497,6 +497,55 @@ gd_header_bar_size_allocate (GtkWidget     *widget,
   gtk_widget_size_allocate (priv->label, &child_allocation);
 }
 
+/**
+ * gd_header_bar_set_title:
+ * @bar: a #GdHeaderBar
+ * @title: a title
+ *
+ * Sets the title of the #GdHeaderBar. The title should help a user
+ * identify the current view. A good title should not include the
+ * application name.
+ *
+ **/
+void
+gd_header_bar_set_title (GdHeaderBar *bar,
+                         const gchar *title)
+{
+  GdHeaderBarPrivate *priv;
+  char *new_title;
+
+  g_return_if_fail (GD_IS_HEADER_BAR (bar));
+
+  priv = bar->priv;
+
+  new_title = g_strdup (title);
+  g_free (priv->title);
+  priv->title = new_title;
+
+  gtk_label_set_label (GTK_LABEL (priv->label), priv->title);
+  gtk_widget_queue_resize (GTK_WIDGET (bar));
+
+  g_object_notify (G_OBJECT (bar), "title");
+}
+
+/**
+ * gd_header_bar_get_title:
+ * @bar: a #GdHeaderBar
+ *
+ * Retrieves the title of the header. See gd_header_bar_set_title().
+ *
+ * Return value: the title of the header, or %NULL if none has
+ *    been set explicitely. The returned string is owned by the widget
+ *    and must not be modified or freed.
+ **/
+const gchar *
+gd_header_bar_get_title (GdHeaderBar *bar)
+{
+  g_return_val_if_fail (GD_IS_HEADER_BAR (bar), NULL);
+
+  return bar->priv->title;
+}
+
 static void
 gd_header_bar_get_property (GObject      *object,
                             guint         prop_id,
@@ -530,7 +579,6 @@ gd_header_bar_get_property (GObject      *object,
     }
 }
 
-
 static void
 gd_header_bar_set_property (GObject      *object,
                             guint         prop_id,
@@ -543,10 +591,7 @@ gd_header_bar_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_TITLE:
-      g_free (priv->title);
-      priv->title = g_value_dup_string (value);
-      gtk_label_set_label (GTK_LABEL (priv->label), priv->title);
-      gtk_widget_queue_resize (GTK_WIDGET (bar));
+      gd_header_bar_set_title (bar, g_value_get_string (value));
       break;
 
     case PROP_SPACING:
@@ -952,7 +997,7 @@ gd_header_bar_pack_end (GdHeaderBar *bar,
 }
 
 GtkWidget *
-gd_header_bar_new (const gchar *title)
+gd_header_bar_new (void)
 {
-  return GTK_WIDGET (g_object_new (GTK_TYPE_HEADER_BAR, "title", title, NULL));
+  return GTK_WIDGET (g_object_new (GD_TYPE_HEADER_BAR, NULL));
 }
diff --git a/libgd/gd-header-bar.h b/libgd/gd-header-bar.h
index 685d56a..e9e9b7e 100644
--- a/libgd/gd-header-bar.h
+++ b/libgd/gd-header-bar.h
@@ -24,12 +24,12 @@
 
 G_BEGIN_DECLS
 
-#define GTK_TYPE_HEADER_BAR            (gd_header_bar_get_type ())
-#define GD_HEADER_BAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_HEADER_BAR, GdHeaderBar))
-#define GD_HEADER_BAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_HEADER_BAR, 
GdHeaderBarClass))
-#define GTK_IS_HEADER_BAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_HEADER_BAR))
-#define GTK_IS_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HEADER_BAR))
-#define GD_HEADER_BAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_HEADER_BAR, 
GdHeaderBarClass))
+#define GD_TYPE_HEADER_BAR            (gd_header_bar_get_type ())
+#define GD_HEADER_BAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GD_TYPE_HEADER_BAR, GdHeaderBar))
+#define GD_HEADER_BAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GD_TYPE_HEADER_BAR, 
GdHeaderBarClass))
+#define GD_IS_HEADER_BAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GD_TYPE_HEADER_BAR))
+#define GD_IS_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GD_TYPE_HEADER_BAR))
+#define GD_HEADER_BAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GD_TYPE_HEADER_BAR, 
GdHeaderBarClass))
 
 typedef struct _GdHeaderBar              GdHeaderBar;
 typedef struct _GdHeaderBarPrivate       GdHeaderBarPrivate;
@@ -55,7 +55,10 @@ struct _GdHeaderBarClass
 };
 
 GType        gd_header_bar_get_type   (void) G_GNUC_CONST;
-GtkWidget   *gd_header_bar_new        (const gchar *title);
+GtkWidget   *gd_header_bar_new        (void);
+void         gd_header_bar_set_title  (GdHeaderBar *bar,
+                                       const char  *title);
+const char * gd_header_bar_get_title  (GdHeaderBar *bar);
 void         gd_header_bar_pack_start (GdHeaderBar *bar,
                                        GtkWidget   *child);
 void         gd_header_bar_pack_end   (GdHeaderBar *bar,
diff --git a/test-header-bar.c b/test-header-bar.c
index cce29a9..2e0eb1c 100644
--- a/test-header-bar.c
+++ b/test-header-bar.c
@@ -20,9 +20,10 @@ main (gint argc,
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), box);
 
-  bar = gd_header_bar_new ("Shells Shells Shells Shells Shells");
+  bar = gd_header_bar_new ();
   gtk_box_pack_start (GTK_BOX (box), bar, FALSE, TRUE, 0);
 
+  gd_header_bar_set_title (GD_HEADER_BAR (bar), "Title Title Title Title Title Title");
   button = gtk_button_new_with_label ("Forget");
   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
   gtk_style_context_add_class (gtk_widget_get_style_context (button), GTK_STYLE_CLASS_RAISED);


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