[Xfce4-commits] <xfce4-indicator-plugin:andrzejr/tmp> Added "nrows-min" property. Sets a minimum number of icon rows/columns.

Andrzej noreply at xfce.org
Wed Mar 21 08:06:04 CET 2012


Updating branch refs/heads/andrzejr/tmp
         to 7cf3a0d89e28573cfec0f2e4fd3ba23584189b46 (commit)
       from 2b92a4b2a72ad1d2406cdf9375989723c1f63716 (commit)

commit 7cf3a0d89e28573cfec0f2e4fd3ba23584189b46
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Wed Mar 21 16:04:57 2012 +0900

    Added "nrows-min" property. Sets a minimum number of icon rows/columns.
    
    To be used in the gui/xconf setting later. Default value is set to 2.

 panel-plugin/indicator-box.c |  106 +++++++++++++++++++++++++++++++++++++++--
 panel-plugin/indicator-box.h |    1 +
 2 files changed, 101 insertions(+), 6 deletions(-)

diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 2d64269..8d84410 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -17,6 +17,7 @@
 
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <exo/exo.h>
 #include <libxfce4panel/libxfce4panel.h>
 #include <libindicator/indicator-object.h>
 
@@ -24,6 +25,14 @@
 #include "indicator-button.h"
 
 static void                 xfce_indicator_box_finalize       (GObject        *object);
+static void                 xfce_indicator_box_get_property   (GObject        *object,
+                                                               guint           prop_id,
+                                                               GValue         *value,
+                                                               GParamSpec     *pspec);
+static void                 xfce_indicator_box_set_property   (GObject        *object,
+                                                               guint           prop_id,
+                                                               const GValue   *value,
+                                                               GParamSpec     *pspec);
 static void                 xfce_indicator_box_add            (GtkContainer   *container,
                                                                GtkWidget      *child);
 static void                 xfce_indicator_box_remove         (GtkContainer   *container,
@@ -39,6 +48,12 @@ static void                 xfce_indicator_box_size_allocate  (GtkWidget     *wi
                                                                GtkAllocation *allocation);
 
 
+enum
+{
+  PROP_0,
+  PROP_NROWS_MIN
+};
+
 G_DEFINE_TYPE (XfceIndicatorBox, xfce_indicator_box, GTK_TYPE_CONTAINER)
 
 static void
@@ -50,6 +65,8 @@ xfce_indicator_box_class_init (XfceIndicatorBoxClass *klass)
 
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->finalize = xfce_indicator_box_finalize;
+  gobject_class->get_property = xfce_indicator_box_get_property;
+  gobject_class->set_property = xfce_indicator_box_set_property;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
   gtkwidget_class->size_request = xfce_indicator_box_size_request;
@@ -60,6 +77,15 @@ xfce_indicator_box_class_init (XfceIndicatorBoxClass *klass)
   gtkcontainer_class->remove = xfce_indicator_box_remove;
   gtkcontainer_class->forall = xfce_indicator_box_forall;
   gtkcontainer_class->child_type = xfce_indicator_box_child_type;
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_NROWS_MIN,
+                                   g_param_spec_uint ("nrows-min",
+                                                      NULL, NULL,
+                                                      1,
+                                                      20,
+                                                      2,
+                                                      EXO_PARAM_READWRITE));
 }
 
 
@@ -75,6 +101,7 @@ xfce_indicator_box_init (XfceIndicatorBox *box)
   box->children = NULL;
 
   box->nrows = 1;
+  box->nrows_min = 2;
   box->panel_size = 16;
   box->panel_orientation = GTK_ORIENTATION_HORIZONTAL;
   box->orientation = GTK_ORIENTATION_HORIZONTAL;
@@ -98,6 +125,66 @@ xfce_indicator_box_finalize (GObject *object)
 
 
 
+static void
+xfce_indicator_box_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  XfceIndicatorBox *box = XFCE_INDICATOR_BOX (object);
+  GPtrArray        *array;
+
+  switch (prop_id)
+    {
+    case PROP_NROWS_MIN:
+      g_value_set_uint (value, box->nrows_min);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+
+static void
+xfce_indicator_box_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  XfceIndicatorBox     *box = XFCE_INDICATOR_BOX (object);
+  gint                  val;
+  XfceIndicatorButton  *child;
+  GSList               *li;
+
+  switch (prop_id)
+    {
+    case PROP_NROWS_MIN:
+      val = g_value_get_uint (value);
+      if (box->nrows_min != val)
+        {
+          box->nrows_min = val;
+          val = MAX (box->nrows, box->nrows_min);
+          for (li = box->children; li != NULL; li = li->next)
+            {
+              child = XFCE_INDICATOR_BUTTON (li->data);
+              g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (child));
+              xfce_indicator_button_set_size (child, box->panel_size, box->panel_size / val);
+            }
+          gtk_widget_queue_resize (GTK_WIDGET (box));
+        }
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+
 void
 xfce_indicator_box_set_orientation (XfceIndicatorBox *box,
                                     GtkOrientation    panel_orientation,
@@ -160,6 +247,7 @@ xfce_indicator_box_set_size (XfceIndicatorBox *box,
 
   if (needs_update)
     {
+      nrows = MAX (box->nrows, box->nrows_min);
       for (li = box->children; li != NULL; li = li->next)
         {
           child = XFCE_INDICATOR_BUTTON (li->data);
@@ -187,6 +275,7 @@ xfce_indicator_box_add (GtkContainer *container,
 {
   XfceIndicatorBox    *box = XFCE_INDICATOR_BOX (container);
   XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (child);
+  gint                 nrows;
 
   g_return_if_fail (XFCE_IS_INDICATOR_BOX (box));
   g_return_if_fail (GTK_IS_WIDGET (child));
@@ -196,7 +285,8 @@ xfce_indicator_box_add (GtkContainer *container,
 
   gtk_widget_set_parent (child, GTK_WIDGET (box));
   xfce_indicator_button_set_orientation (button, box->panel_orientation, box->orientation);
-  xfce_indicator_button_set_size (button, box->panel_size, box->panel_size / box->nrows);
+  nrows = MAX (box->nrows, box->nrows_min);
+  xfce_indicator_button_set_size (button, box->panel_size, box->panel_size / nrows);
 
   gtk_widget_queue_resize (GTK_WIDGET (container));
 }
@@ -265,6 +355,7 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
   gint              panel_size;
   gint              length;
   gint              row;
+  gint              nrows;
   gint              x;
   gboolean          has_label;
 
@@ -272,6 +363,7 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
   row = 0;
   length = 0;
   x = 0;
+  nrows = MAX (box->nrows, box->nrows_min);
 
   for (li = box->children; li != NULL; li = li->next)
     {
@@ -282,7 +374,7 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
       has_label = (xfce_indicator_button_get_label (XFCE_INDICATOR_BUTTON (child)) != NULL);
 
       /* wrap rows if column is overflowing or a label is encountered */
-      if (row > 0 && (has_label || row >= box->nrows))
+      if (row > 0 && (has_label || row >= nrows))
         {
           x += length;
           row = 0;
@@ -292,7 +384,7 @@ xfce_indicator_box_size_request (GtkWidget      *widget,
       length =
         MAX (length, (box->panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
 
-      if (has_label || row >= box->nrows)
+      if (has_label || row >= nrows)
         {
           x += length;
           row = 0;
@@ -335,6 +427,7 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
   GSList           *li;
   gint              length, width;
   gint              row;
+  gint              nrows;
   gboolean          has_label;
 
   row = 0;
@@ -344,8 +437,9 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
   x0 = allocation->x;
   y0 = allocation->y;
 
+  nrows = MAX (box->nrows, box->nrows_min);
   panel_size = box->panel_size;
-  size = panel_size / box->nrows;
+  size = panel_size / nrows;
 
   for (li = box->children; li != NULL; li = li->next)
     {
@@ -357,7 +451,7 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
       has_label = (xfce_indicator_button_get_label (XFCE_INDICATOR_BUTTON (child)) != NULL);
 
       /* wrap rows if column is overflowing or a label is encountered */
-      if (row > 0 && (has_label || row >= box->nrows))
+      if (row > 0 && (has_label || row >= nrows))
         {
           x += length;
           y = 0;
@@ -389,7 +483,7 @@ xfce_indicator_box_size_allocate (GtkWidget     *widget,
 
       gtk_widget_size_allocate (child, &child_alloc);
 
-      if (has_label || row >= box->nrows)
+      if (has_label || row >= nrows)
         {
           x += length;
           y = 0;
diff --git a/panel-plugin/indicator-box.h b/panel-plugin/indicator-box.h
index fafaa37..b755fe6 100644
--- a/panel-plugin/indicator-box.h
+++ b/panel-plugin/indicator-box.h
@@ -40,6 +40,7 @@ struct _XfceIndicatorBox
 
   gint                  panel_size;
   gint                  nrows;
+  gint                  nrows_min;
 
   GtkOrientation        panel_orientation;
   GtkOrientation        orientation;


More information about the Xfce4-commits mailing list