[Xfce4-commits] <exo:stephan/icon-bar-improvements> Add auto_center

Stephan Arts noreply at xfce.org
Tue Jan 31 22:00:01 CET 2012


Updating branch refs/heads/stephan/icon-bar-improvements
         to 485dfd7bd609bcf7eb1e8fa20df651b62d9a4e6f (commit)
       from 7b8cb887373648f3166c4fbf637deda8cd3bc3f1 (commit)

commit 485dfd7bd609bcf7eb1e8fa20df651b62d9a4e6f
Author: Stephan Arts <stephan at xfce.org>
Date:   Tue Jan 31 21:58:42 2012 +0100

    Add auto_center

 exo/exo-icon-bar.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/exo/exo-icon-bar.c b/exo/exo-icon-bar.c
index 5327f08..ccebc74 100644
--- a/exo/exo-icon-bar.c
+++ b/exo/exo-icon-bar.c
@@ -215,6 +215,7 @@ struct _ExoIconBarPrivate
   ExoIconBarItem *active_item;
   ExoIconBarItem *single_click_item;
   ExoIconBarItem *cursor_item;
+
   GList          *items;
   gint            item_width;
   gint            item_height;
@@ -222,6 +223,8 @@ struct _ExoIconBarPrivate
   GtkAdjustment  *hadjustment;
   GtkAdjustment  *vadjustment;
 
+  gboolean        auto_center; /* automatically center */
+
   GtkOrientation  orientation;
 
   GtkTreeModel   *model;
@@ -457,6 +460,7 @@ exo_icon_bar_init (ExoIconBar *icon_bar)
   icon_bar->priv->pixbuf_column = -1;
   icon_bar->priv->text_column = -1;
   icon_bar->priv->show_text = TRUE;
+  icon_bar->priv->auto_center = TRUE;
 
   icon_bar->priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (icon_bar), NULL);
   pango_layout_set_width (icon_bar->priv->layout, -1);
@@ -715,6 +719,8 @@ exo_icon_bar_size_allocate (GtkWidget     *widget,
                             GtkAllocation *allocation)
 {
   ExoIconBar *icon_bar = EXO_ICON_BAR (widget);
+  gdouble value = 0.0;
+  gdouble page_size = 0.0;
 
   widget->allocation = *allocation;
 
@@ -750,6 +756,19 @@ exo_icon_bar_size_allocate (GtkWidget     *widget,
       icon_bar->priv->item_width = icon_bar->priv->width;
       icon_bar->priv->hadjustment->value = 0;
       gtk_adjustment_value_changed (icon_bar->priv->hadjustment);
+
+      /* If auto-center is true, center the selected item */
+      if (icon_bar->priv->auto_center == TRUE)
+        {
+          page_size = gtk_adjustment_get_page_size (icon_bar->priv->vadjustment);
+          value = icon_bar->priv->active_item->index * icon_bar->priv->item_width - ((page_size-icon_bar->priv->item_width)/2);
+
+          if (value > (gtk_adjustment_get_upper (icon_bar->priv->vadjustment)-page_size))
+            value = (gtk_adjustment_get_upper (icon_bar->priv->vadjustment)-page_size);
+
+          gtk_adjustment_set_value (icon_bar->priv->vadjustment, value);
+          gtk_adjustment_changed (icon_bar->priv->vadjustment);
+        }
     }
   else
     {
@@ -757,6 +776,19 @@ exo_icon_bar_size_allocate (GtkWidget     *widget,
       icon_bar->priv->item_height = icon_bar->priv->height;
       icon_bar->priv->vadjustment->value = 0;
       gtk_adjustment_value_changed (icon_bar->priv->vadjustment);
+
+      /* If auto-center is true, center the selected item */
+      if (icon_bar->priv->auto_center == TRUE)
+        {
+          page_size = gtk_adjustment_get_page_size (icon_bar->priv->hadjustment);
+          value = icon_bar->priv->active_item->index * icon_bar->priv->item_width - ((page_size-icon_bar->priv->item_width)/2);
+
+          if (value > (gtk_adjustment_get_upper (icon_bar->priv->hadjustment)-page_size))
+            value = (gtk_adjustment_get_upper (icon_bar->priv->hadjustment)-page_size);
+
+          gtk_adjustment_set_value (icon_bar->priv->hadjustment, value);
+          gtk_adjustment_changed (icon_bar->priv->hadjustment);
+        }
     }
 }
 
@@ -1882,6 +1914,10 @@ exo_icon_bar_set_orientation (ExoIconBar    *icon_bar,
     {
       icon_bar->priv->orientation = orientation;
       gtk_widget_queue_resize (GTK_WIDGET (icon_bar));
+      if (icon_bar->priv->auto_center == TRUE)
+        {
+          exo_icon_bar_show_active (icon_bar);
+        }
       g_object_notify (G_OBJECT (icon_bar), "orientation");
     }
 }


More information about the Xfce4-commits mailing list