[gdl] Allow pixbuf icon for dock item



commit ce486deee0c77c50f0380243025bab588873f4ee
Author: Alex Valavanis <a valavanis leeds ac uk>
Date:   Thu Dec 29 00:09:44 2011 +0000

    Allow pixbuf icon for dock item

 gdl/gdl-dock-bar.c       |    6 +++++-
 gdl/gdl-dock-item-grip.c |    8 ++++++++
 gdl/gdl-dock-item.c      |   21 +++++++++++++++++++++
 gdl/gdl-dock-item.h      |    5 +++++
 gdl/gdl-dock-notebook.c  |    5 +++--
 gdl/gdl-dock-object.c    |   14 ++++++++++++++
 gdl/gdl-dock-object.h    |    1 +
 gdl/gdl-switcher.c       |   21 ++++++++++++++++-----
 gdl/gdl-switcher.h       |    1 +
 9 files changed, 74 insertions(+), 8 deletions(-)
---
diff --git a/gdl/gdl-dock-bar.c b/gdl/gdl-dock-bar.c
index a9448c7..95ae251 100644
--- a/gdl/gdl-dock-bar.c
+++ b/gdl/gdl-dock-bar.c
@@ -266,6 +266,7 @@ gdl_dock_bar_add_item (GdlDockBar  *dockbar,
     GtkWidget *button;
     gchar *stock_id;
     gchar *name;
+    GdkPixbuf *pixbuf_icon;
     GtkWidget *image, *box, *label;
 
     g_return_if_fail (GDL_IS_DOCK_BAR (dockbar));
@@ -289,7 +290,8 @@ gdl_dock_bar_add_item (GdlDockBar  *dockbar,
     else
         box = gtk_vbox_new (FALSE, 0);
     
-    g_object_get (item, "stock-id", &stock_id, "long-name", &name, NULL);
+    g_object_get (item, "stock-id", &stock_id, "pixbuf-icon", &pixbuf_icon,
+                  "long-name", &name, NULL);
 
     if (dockbar->priv->dockbar_style == GDL_DOCK_BAR_TEXT ||
         dockbar->priv->dockbar_style == GDL_DOCK_BAR_BOTH) {
@@ -308,6 +310,8 @@ gdl_dock_bar_add_item (GdlDockBar  *dockbar,
             image = gtk_image_new_from_stock (stock_id,
                                               GTK_ICON_SIZE_SMALL_TOOLBAR);
             g_free (stock_id);
+        } else if (pixbuf_icon) {
+            image = gtk_image_new_from_pixbuf (pixbuf_icon);
         } else {
             image = gtk_image_new_from_stock (GTK_STOCK_NEW,
                                               GTK_ICON_SIZE_SMALL_TOOLBAR);
diff --git a/gdl/gdl-dock-item-grip.c b/gdl/gdl-dock-item-grip.c
index e1bc013..b127152 100644
--- a/gdl/gdl-dock-item-grip.c
+++ b/gdl/gdl-dock-item-grip.c
@@ -67,10 +67,12 @@ gdl_dock_item_create_label_widget(GdlDockItemGrip *grip)
     GtkLabel *label;
     gchar *stock_id = NULL;
     gchar *title = NULL;
+    GdkPixbuf *pixbuf;
   
     label_box = (GtkBox*)gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
     
     g_object_get (G_OBJECT (grip->item), "stock-id", &stock_id, NULL);
+    g_object_get (G_OBJECT (grip->item), "pixbuf-icon", &pixbuf, NULL);
     if(stock_id) {   
         image = GTK_IMAGE(gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU));
         
@@ -79,6 +81,12 @@ gdl_dock_item_create_label_widget(GdlDockItemGrip *grip)
             
         g_free (stock_id);
     }
+    else if (pixbuf) {
+        image = GTK_IMAGE(gtk_image_new_from_pixbuf (pixbuf));
+	    
+        gtk_widget_show (GTK_WIDGET(image));
+        gtk_box_pack_start(GTK_BOX(label_box), GTK_WIDGET(image), FALSE, TRUE, 0);
+    }
         
     g_object_get (G_OBJECT (grip->item), "long-name", &title, NULL);
     if (title) {
diff --git a/gdl/gdl-dock-item.c b/gdl/gdl-dock-item.c
index c628a55..47730e8 100644
--- a/gdl/gdl-dock-item.c
+++ b/gdl/gdl-dock-item.c
@@ -1747,6 +1747,27 @@ gdl_dock_item_new_with_stock (const gchar         *name,
     return GTK_WIDGET (item);
 }
 
+GtkWidget *
+gdl_dock_item_new_with_pixbuf_icon (const gchar         *name,
+                                    const gchar         *long_name,
+                                    const GdkPixbuf     *pixbuf_icon,
+                                    GdlDockItemBehavior  behavior)
+{
+    GdlDockItem *item;
+
+    item = GDL_DOCK_ITEM (g_object_new (GDL_TYPE_DOCK_ITEM, 
+                                        "name", name, 
+                                        "long-name", long_name,
+                                        "pixbuf-icon", pixbuf_icon,
+                                        "behavior", behavior,
+                                        NULL));
+
+    GDL_DOCK_OBJECT_UNSET_FLAGS (item, GDL_DOCK_AUTOMATIC);
+    gdl_dock_item_set_tablabel (item, gtk_label_new (long_name));
+
+    return GTK_WIDGET (item);
+}
+
 /* convenient function (and to preserve source compat) */
 /**
  * gdl_dock_item_dock_to:
diff --git a/gdl/gdl-dock-item.h b/gdl/gdl-dock-item.h
index a2f0b93..33ad7e9 100644
--- a/gdl/gdl-dock-item.h
+++ b/gdl/gdl-dock-item.h
@@ -172,6 +172,11 @@ GtkWidget     *gdl_dock_item_new_with_stock    (const gchar         *name,
                                                 const gchar         *stock_id,
                                                 GdlDockItemBehavior  behavior);
 
+GtkWidget     *gdl_dock_item_new_with_pixbuf_icon (const gchar         *name,
+                                                   const gchar         *long_name,
+                                                   const GdkPixbuf     *pixbuf_icon,
+                                                   GdlDockItemBehavior  behavior);
+
 GType          gdl_dock_item_get_type          (void);
 
 void           gdl_dock_item_dock_to           (GdlDockItem      *item,
diff --git a/gdl/gdl-dock-notebook.c b/gdl/gdl-dock-notebook.c
index 6f1c56b..3a654e1 100644
--- a/gdl/gdl-dock-notebook.c
+++ b/gdl/gdl-dock-notebook.c
@@ -393,11 +393,12 @@ gdl_dock_notebook_dock (GdlDockObject    *object,
             GdlDockItem *item = GDL_DOCK_ITEM (object);
             GdlDockItem *requestor_item = GDL_DOCK_ITEM (requestor);
             gchar       *long_name, *stock_id;
+            GdkPixbuf   *pixbuf_icon;
             GtkWidget   *label;
             gint         position = -1;
             
             g_object_get (requestor_item, "long-name", &long_name,
-                          "stock-id", &stock_id, NULL);
+                          "stock-id", &stock_id, "pixbuf-icon", &pixbuf_icon, NULL);
             label = gdl_dock_item_get_tablabel (requestor_item);
             if (!label) {
                 label = gtk_label_new (long_name);
@@ -417,7 +418,7 @@ gdl_dock_notebook_dock (GdlDockObject    *object,
             position = gdl_switcher_insert_page (GDL_SWITCHER (item->child), 
                                                  GTK_WIDGET (requestor), label,
                                                  long_name, long_name,
-                                                 stock_id, position);
+                                                 stock_id, pixbuf_icon, position);
             
             GDL_DOCK_OBJECT_SET_FLAGS (requestor, GDL_DOCK_ATTACHED);
             
diff --git a/gdl/gdl-dock-object.c b/gdl/gdl-dock-object.c
index 60d6fa9..984388e 100644
--- a/gdl/gdl-dock-object.c
+++ b/gdl/gdl-dock-object.c
@@ -79,6 +79,7 @@ enum {
     PROP_NAME,
     PROP_LONG_NAME,
     PROP_STOCK_ID,
+    PROP_PIXBUF_ICON,
     PROP_MASTER,
     PROP_EXPORT_PROPERTIES
 };
@@ -133,6 +134,12 @@ gdl_dock_object_class_init (GdlDockObjectClass *klass)
                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
     g_object_class_install_property (
+        g_object_class, PROP_PIXBUF_ICON,
+        g_param_spec_pointer ("pixbuf-icon", _("Pixbuf Icon"),
+                              _("Pixbuf icon for the dock object"),
+                              G_PARAM_READWRITE));
+
+    g_object_class_install_property (
         g_object_class, PROP_MASTER,
         g_param_spec_object ("master", _("Dock master"),
                              _("Dock master this dock object is bound to"),
@@ -209,6 +216,9 @@ gdl_dock_object_set_property  (GObject      *g_object,
         g_free (object->stock_id);
         object->stock_id = g_value_dup_string (value);
         break;
+    case PROP_PIXBUF_ICON:
+        object->pixbuf_icon = g_value_get_pointer (value);
+        break;
     case PROP_MASTER:
         if (g_value_get_object (value)) 
             gdl_dock_object_bind (object, g_value_get_object (value));
@@ -239,6 +249,9 @@ gdl_dock_object_get_property  (GObject      *g_object,
     case PROP_STOCK_ID:
         g_value_set_string (value, object->stock_id);
         break;
+    case PROP_PIXBUF_ICON:
+        g_value_set_pointer (value, object->pixbuf_icon);
+        break;
     case PROP_MASTER:
         g_value_set_object (value, object->master);
         break;
@@ -258,6 +271,7 @@ gdl_dock_object_finalize (GObject *g_object)
     g_free (object->name);
     g_free (object->long_name);
     g_free (object->stock_id);
+    g_free (object->pixbuf_icon);
 
     G_OBJECT_CLASS (gdl_dock_object_parent_class)->finalize (g_object);
 }
diff --git a/gdl/gdl-dock-object.h b/gdl/gdl-dock-object.h
index bc61f07..09d912b 100644
--- a/gdl/gdl-dock-object.h
+++ b/gdl/gdl-dock-object.h
@@ -88,6 +88,7 @@ struct _GdlDockObject {
     gchar              *name;
     gchar              *long_name;
     gchar              *stock_id;
+    GdkPixbuf          *pixbuf_icon;
     
     gboolean            reduce_pending;
 };
diff --git a/gdl/gdl-switcher.c b/gdl/gdl-switcher.c
index cad2efe..2b085a6 100644
--- a/gdl/gdl-switcher.c
+++ b/gdl/gdl-switcher.c
@@ -50,6 +50,7 @@ static void gdl_switcher_add_button  (GdlSwitcher *switcher,
                                       const gchar *label,
                                       const gchar *tooltips,
                                       const gchar *stock_id,
+                                      const GdkPixbuf *pixbuf_icon,
                                       gint switcher_id,
                                       GtkWidget *page);
 /* static void gdl_switcher_remove_button (GdlSwitcher *switcher, gint switcher_id); */
@@ -707,10 +708,12 @@ gdl_switcher_page_added_cb (GtkNotebook *nb, GtkWidget *page,
                             gint page_num, GdlSwitcher *switcher)
 {
     gint         switcher_id;
- 
+
+    (void)nb;
+    (void)page_num;
     switcher_id = gdl_switcher_get_page_id (page);
     
-    gdl_switcher_add_button (GDL_SWITCHER (switcher), NULL, NULL, NULL,
+    gdl_switcher_add_button (GDL_SWITCHER (switcher), NULL, NULL, NULL, NULL,
                              switcher_id, page);
     gdl_switcher_select_button (GDL_SWITCHER (switcher), switcher_id);
 }
@@ -828,6 +831,7 @@ gdl_switcher_new (void)
 void
 gdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
                          const gchar *tooltips, const gchar *stock_id,
+			 const GdkPixbuf *pixbuf_icon,
                          gint switcher_id, GtkWidget* page)
 {
     GtkWidget *event_box;
@@ -849,7 +853,14 @@ gdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
     gtk_container_add (GTK_CONTAINER (button_widget), hbox);
     gtk_widget_show (hbox);
 
-    icon_widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
+    if (stock_id) {
+        icon_widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
+    } else if (pixbuf_icon) {
+        icon_widget = gtk_image_new_from_pixbuf (pixbuf_icon);
+    } else {
+        icon_widget = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
+    }
+
     gtk_widget_show (icon_widget);
     
     if (!label) {
@@ -927,7 +938,7 @@ gint
 gdl_switcher_insert_page (GdlSwitcher *switcher, GtkWidget *page,
                           GtkWidget *tab_widget, const gchar *label,
                           const gchar *tooltips, const gchar *stock_id,
-                          gint position)
+                          const GdkPixbuf *pixbuf_icon, gint position)
 {
     gint ret_position;
     gint switcher_id;
@@ -940,7 +951,7 @@ gdl_switcher_insert_page (GdlSwitcher *switcher, GtkWidget *page,
         gtk_widget_show (tab_widget);
     }
     switcher_id = gdl_switcher_get_page_id (page);
-    gdl_switcher_add_button (switcher, label, tooltips, stock_id, switcher_id, page);
+    gdl_switcher_add_button (switcher, label, tooltips, stock_id, pixbuf_icon, switcher_id, page);
     
     ret_position = gtk_notebook_insert_page (GTK_NOTEBOOK (switcher), page,
                                              tab_widget, position);
diff --git a/gdl/gdl-switcher.h b/gdl/gdl-switcher.h
index 3924d5d..89d8d54 100644
--- a/gdl/gdl-switcher.h
+++ b/gdl/gdl-switcher.h
@@ -63,6 +63,7 @@ gint       gdl_switcher_insert_page  (GdlSwitcher *switcher,
                                       const gchar *label,
                                       const gchar *tooltips,
                                       const gchar *stock_id,
+                                      const GdkPixbuf *pixbuf_icon,
                                       gint position);
 G_END_DECLS
 



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