libegg r862 - in trunk: . libegg/toolpalette



Author: hasselmm
Date: Fri Mar 28 18:40:48 2008
New Revision: 862
URL: http://svn.gnome.org/viewvc/libegg?rev=862&view=rev

Log:
Support horizontal orientation for icon-only style.

* libegg/toolpalette/eggtoolitemgroup.c,
  libegg/toolpalette/eggtoolpalette.c:
  Support horizontal orientation for icon-only style.
* libegg/toolpalette/eggtoolpaletteprivate.h:
  Add _egg_tool_item_group_palette_reconfigured() and
  _egg_tool_item_group_get_width_for_height().
* libegg/toolpalette/testtoolpalette.c:
  Set tooltip instead of label for items of advanced features group.
* libegg/toolpalette/TODO: Updated.


Modified:
   trunk/ChangeLog
   trunk/libegg/toolpalette/TODO
   trunk/libegg/toolpalette/eggtoolitemgroup.c
   trunk/libegg/toolpalette/eggtoolpalette.c
   trunk/libegg/toolpalette/eggtoolpaletteprivate.h
   trunk/libegg/toolpalette/testtoolpalette.c

Modified: trunk/libegg/toolpalette/TODO
==============================================================================
--- trunk/libegg/toolpalette/TODO	(original)
+++ trunk/libegg/toolpalette/TODO	Fri Mar 28 18:40:48 2008
@@ -2,11 +2,13 @@
 
  * implement natural-size interface
  * scroll to group, when expanding
- * support horizontal orientation
  * consider scrollbar size in size-request
  * install position child properties
+ * support ellipses in group headers again
+ * support horizontal orientation for other styles but icon only
 
 GtkToolShell:
 
 * ask tool items to apply ellipses to labels
 * left-align labels (and center icons) in both-horiz mode
+* enforce "expand" and "homogeneous" child property

Modified: trunk/libegg/toolpalette/eggtoolitemgroup.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolitemgroup.c	(original)
+++ trunk/libegg/toolpalette/eggtoolitemgroup.c	Fri Mar 28 18:40:48 2008
@@ -96,15 +96,34 @@
                                             gpointer        data)
 {
   EggToolItemGroup *group = EGG_TOOL_ITEM_GROUP (data);
+  GtkExpanderStyle expander_style;
+  GtkOrientation orientation;
+  gint x, y;
+
+  orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
+  expander_style = group->priv->expander_style;
+
+  if (GTK_ORIENTATION_VERTICAL == orientation)
+    {
+      x = widget->allocation.x + group->priv->expander_size / 2;
+      y = widget->allocation.y + widget->allocation.height / 2;
+    }
+  else
+    {
+      x = widget->allocation.x + widget->allocation.width / 2;
+      y = widget->allocation.y + group->priv->expander_size / 2;
 
-  gint x = widget->allocation.x + group->priv->expander_size / 2;
-  gint y = widget->allocation.y + widget->allocation.height / 2;
+      /* Unfortunatly gtk_paint_expander() doesn't support rotated drawing
+       * modes. Luckily the following shady arithmetics produce the desired
+       * result. */
+      expander_style = GTK_EXPANDER_EXPANDED - expander_style; /* XXX */
+    }
 
   gtk_paint_expander (widget->style, widget->window,
                       group->priv->header->state,
                       &event->area, GTK_WIDGET (group),
                       "tool-palette-header", x, y,
-                      group->priv->expander_style);
+                      expander_style);
 
   return FALSE;
 }
@@ -126,6 +145,113 @@
   egg_tool_item_group_set_expanded (group, !group->priv->expanded);
 }
 
+static GtkWidget*
+egg_tool_item_group_get_alignment (EggToolItemGroup *group)
+{
+  return gtk_bin_get_child (GTK_BIN (group->priv->header));
+}
+
+static GtkWidget*
+egg_tool_item_group_get_label (EggToolItemGroup *group)
+{
+  GtkWidget *alignment = egg_tool_item_group_get_alignment (group);
+  return gtk_bin_get_child (GTK_BIN (alignment));
+}
+
+#ifdef GTK_TOOL_SHELL
+
+static GtkIconSize
+egg_tool_item_group_get_icon_size (GtkToolShell *shell)
+{
+  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
+
+  if (EGG_IS_TOOL_PALETTE (parent))
+    return egg_tool_palette_get_icon_size (EGG_TOOL_PALETTE (parent));
+
+  return GTK_ICON_SIZE_SMALL_TOOLBAR;
+}
+
+static GtkOrientation
+egg_tool_item_group_get_orientation (GtkToolShell *shell)
+{
+  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
+
+  if (EGG_IS_TOOL_PALETTE (parent))
+    return egg_tool_palette_get_orientation (EGG_TOOL_PALETTE (parent));
+
+  return GTK_ORIENTATION_VERTICAL;
+}
+
+static GtkToolbarStyle
+egg_tool_item_group_get_style (GtkToolShell *shell)
+{
+  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
+
+  if (EGG_IS_TOOL_PALETTE (parent))
+    return egg_tool_palette_get_style (EGG_TOOL_PALETTE (parent));
+
+  return GTK_TOOLBAR_ICONS;
+}
+
+#else /* GTK_TOOL_SHELL */
+
+static GtkOrientation
+egg_tool_item_group_get_orientation (EggToolItemGroup *group)
+{
+  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (group));
+
+  if (EGG_IS_TOOL_PALETTE (parent))
+    return egg_tool_palette_get_orientation (EGG_TOOL_PALETTE (parent));
+
+  return GTK_ORIENTATION_VERTICAL;
+}
+
+static GtkToolbarStyle
+egg_tool_item_group_get_style (EggToolItemGroup *group)
+{
+  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (group));
+
+  if (EGG_IS_TOOL_PALETTE (parent))
+    return egg_tool_palette_get_style (EGG_TOOL_PALETTE (parent));
+
+  return GTK_TOOLBAR_ICONS;
+}
+
+#endif /* GTK_TOOL_SHELL */
+
+static void
+egg_tool_item_group_header_adjust_style (EggToolItemGroup *group)
+{
+  GtkWidget *alignment = egg_tool_item_group_get_alignment (group);
+  GtkWidget *label = gtk_bin_get_child (GTK_BIN (alignment));
+  GtkWidget *widget = GTK_WIDGET (group);
+  gint dx = 0, dy = 0;
+
+  gtk_widget_style_get (widget,
+                        "header-spacing", &group->priv->header_spacing,
+                        "expander-size", &group->priv->expander_size,
+                        NULL);
+
+#ifdef GTK_TOOL_SHELL
+  switch (gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group)))
+#else
+  switch (egg_tool_item_group_get_orientation (group))
+#endif
+    {
+      case GTK_ORIENTATION_HORIZONTAL:
+        dy = group->priv->header_spacing + group->priv->expander_size;
+        gtk_label_set_angle (GTK_LABEL (label), 90);
+        break;
+
+      case GTK_ORIENTATION_VERTICAL:
+        dx = group->priv->header_spacing + group->priv->expander_size;
+        gtk_label_set_angle (GTK_LABEL (label), 0);
+        break;
+    }
+
+  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), dy, 0, dx, 0);
+}
+
 static void
 egg_tool_item_group_init (EggToolItemGroup *group)
 {
@@ -135,8 +261,8 @@
   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (group), FALSE);
 
   group->priv = G_TYPE_INSTANCE_GET_PRIVATE (group,
-                                            EGG_TYPE_TOOL_ITEM_GROUP,
-                                            EggToolItemGroupPrivate);
+                                             EGG_TYPE_TOOL_ITEM_GROUP,
+                                             EggToolItemGroupPrivate);
 
   group->priv->items_length = 0;
   group->priv->items_size = 4;
@@ -147,14 +273,8 @@
   group->priv->expanded = TRUE;
 
   label = gtk_label_new (NULL);
-  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
-
-  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0,
-                             group->priv->header_spacing +
-                             group->priv->expander_size, 0);
-
   gtk_container_add (GTK_CONTAINER (alignment), label);
   gtk_widget_show_all (alignment);
 
@@ -168,6 +288,8 @@
   gtk_container_add (GTK_CONTAINER (group->priv->header), alignment);
   gtk_widget_set_parent (group->priv->header, GTK_WIDGET (group));
 
+  egg_tool_item_group_header_adjust_style (group);
+
   g_signal_connect_after (alignment, "expose-event",
                           G_CALLBACK (egg_tool_item_group_header_expose_event_cb),
                           group);
@@ -254,67 +376,6 @@
     _egg_tool_item_group_item_size_request (group, item_size);
 }
 
-#ifdef GTK_TOOL_SHELL
-
-static GtkIconSize
-egg_tool_item_group_get_icon_size (GtkToolShell *shell)
-{
-  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
-
-  if (EGG_IS_TOOL_PALETTE (parent))
-    return egg_tool_palette_get_icon_size (EGG_TOOL_PALETTE (parent));
-
-  return GTK_ICON_SIZE_SMALL_TOOLBAR;
-}
-
-static GtkOrientation
-egg_tool_item_group_get_orientation (GtkToolShell *shell)
-{
-  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
-
-  if (EGG_IS_TOOL_PALETTE (parent))
-    return egg_tool_palette_get_orientation (EGG_TOOL_PALETTE (parent));
-
-  return GTK_ORIENTATION_VERTICAL;
-}
-
-static GtkToolbarStyle
-egg_tool_item_group_get_style (GtkToolShell *shell)
-{
-  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
-
-  if (EGG_IS_TOOL_PALETTE (parent))
-    return egg_tool_palette_get_style (EGG_TOOL_PALETTE (parent));
-
-  return GTK_TOOLBAR_ICONS;
-}
-
-#else /* GTK_TOOL_SHELL */
-
-static GtkOrientation
-egg_tool_item_group_get_orientation (EggToolItemGroup *group)
-{
-  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (group));
-
-  if (EGG_IS_TOOL_PALETTE (parent))
-    return egg_tool_palette_get_orientation (EGG_TOOL_PALETTE (parent));
-
-  return GTK_ORIENTATION_VERTICAL;
-}
-
-static GtkToolbarStyle
-egg_tool_item_group_get_style (EggToolItemGroup *group)
-{
-  GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (group));
-
-  if (EGG_IS_TOOL_PALETTE (parent))
-    return egg_tool_palette_get_style (EGG_TOOL_PALETTE (parent));
-
-  return GTK_TOOLBAR_ICONS;
-}
-
-#endif /* GTK_TOOL_SHELL */
-
 static void
 egg_tool_item_group_size_request (GtkWidget      *widget,
                                   GtkRequisition *requisition)
@@ -374,14 +435,15 @@
   EggToolItemGroup *group = EGG_TOOL_ITEM_GROUP (widget);
   GtkRequisition child_requistion;
   GtkAllocation child_allocation;
-  GtkRequisition item_size;
 
-  gint width;
-  guint i;
+  GtkRequisition item_size;
+  GtkAllocation item_area;
 
   GtkOrientation orientation;
   GtkToolbarStyle style;
 
+  guint n_visible_items, i;
+
   GTK_WIDGET_CLASS (egg_tool_item_group_parent_class)->size_allocate (widget, allocation);
 
 #ifdef GTK_TOOL_SHELL
@@ -392,17 +454,50 @@
   style = egg_tool_item_group_get_style (group);
 #endif
 
+  /* figure out item size */
+
   egg_tool_item_group_get_item_size (group, &item_size);
 
-  item_size.width = MIN (item_size.width, allocation->width);
+  if (GTK_ORIENTATION_VERTICAL == orientation)
+    item_size.width = MIN (item_size.width, allocation->width);
+  else
+    item_size.height = MIN (item_size.height, allocation->height);
+
+  n_visible_items = 0;
 
-  if (style == GTK_TOOLBAR_ICONS)
+  for (i = 0; i < group->priv->items_length; ++i)
     {
-      guint n_columns = MAX (allocation->width / item_size.width, 1);
-      width = item_size.width * n_columns;
+      GtkToolItem *item = group->priv->items[i];
+
+      if (item && egg_tool_item_group_is_item_visible (item, orientation))
+        n_visible_items += 1;
+    }
+
+  if (GTK_TOOLBAR_ICONS == style)
+    {
+      guint n_columns, n_rows;
+
+      if (GTK_ORIENTATION_VERTICAL == orientation)
+        {
+          n_columns = MAX (allocation->width / item_size.width, 1);
+          n_rows = (n_visible_items + n_columns - 1) / n_columns;
+        }
+      else
+        {
+          n_rows = MAX (allocation->height / item_size.height, 1);
+          n_columns = (n_visible_items + n_rows - 1) / n_rows;
+        }
+
+      item_area.width = item_size.width * n_columns;
+      item_area.height = item_size.height * n_rows;
     }
   else
-    width = allocation->width;
+    {
+      item_area.width = allocation->width;
+      item_area.height = allocation->height;
+    }
+
+  /* place the header widget */
 
   child_allocation.x = border_width;
   child_allocation.y = border_width;
@@ -411,15 +506,31 @@
     {
       gtk_widget_size_request (group->priv->header, &child_requistion);
 
-      child_allocation.width = allocation->width;
-      child_allocation.height = child_requistion.height;
+      if (GTK_ORIENTATION_VERTICAL == orientation)
+        {
+          child_allocation.width = allocation->width;
+          child_allocation.height = child_requistion.height;
+        }
+      else
+        {
+          child_allocation.width = child_requistion.width;
+          child_allocation.height = allocation->height;
+        }
 
       if (!inquery)
         gtk_widget_size_allocate (group->priv->header, &child_allocation);
 
-      child_allocation.y += child_allocation.height;
+      if (GTK_ORIENTATION_VERTICAL == orientation)
+        child_allocation.y += child_allocation.height;
+      else
+        child_allocation.x += child_allocation.width;
     }
 
+  item_area.x = child_allocation.x;
+  item_area.y = child_allocation.y;
+
+  /* otherwise, when expanded or in transition, place the tool items */
+
   if (group->priv->expanded || group->priv->animation_timeout)
     {
       for (i = 0; i < group->priv->items_length; ++i)
@@ -431,20 +542,20 @@
 
           if (!egg_tool_item_group_is_item_visible (item, orientation))
             {
-              if (!inquery) /* in case of orientation preferences */
+              if (!inquery)
                 gtk_widget_set_child_visible (GTK_WIDGET (item), FALSE);
 
               continue;
             }
 
-          if (child_allocation.x + item_size.width > width)
+          if (child_allocation.x + item_size.width > item_area.x + item_area.width)
             {
               child_allocation.y += child_allocation.height;
-              child_allocation.x = border_width;
+              child_allocation.x = item_area.x;
             }
 
           if (style != GTK_TOOLBAR_ICONS || gtk_tool_item_get_expand (item))
-            child_allocation.width = width - child_allocation.x;
+            child_allocation.width = item_area.x + item_area.width - child_allocation.x;
           else
             child_allocation.width = item_size.width;
 
@@ -462,23 +573,22 @@
       child_allocation.y += item_size.height;
       child_allocation.x = border_width;
     }
+
+  /* or just hide all items, when collapsed */
+
   else if (!inquery)
     {
       for (i = 0; i < group->priv->items_length; ++i)
-        {
-          GtkToolItem *item = group->priv->items[i];
-
-          if (!item)
-            continue;
-
-          gtk_widget_set_child_visible (GTK_WIDGET (item), FALSE);
-        }
+        if (group->priv->items[i])
+          gtk_widget_set_child_visible (GTK_WIDGET (group->priv->items[i]), FALSE);
     }
 
+  /* report effective widget size */
+
   if (inquery)
     {
-      inquery->width = child_allocation.width;
-      inquery->height = child_allocation.y;
+      inquery->width = item_area.x + item_area.width + border_width;
+      inquery->height = child_allocation.y + border_width;
     }
 }
 
@@ -532,38 +642,11 @@
   gtk_widget_queue_resize_no_redraw (widget);
 }
 
-static GtkWidget*
-egg_tool_item_group_get_alignment (EggToolItemGroup *group)
-{
-  return gtk_bin_get_child (GTK_BIN (group->priv->header));
-}
-
-static GtkWidget*
-egg_tool_item_group_get_label (EggToolItemGroup *group)
-{
-  GtkWidget *alignment = egg_tool_item_group_get_alignment (group);
-  return gtk_bin_get_child (GTK_BIN (alignment));
-}
-
 static void
 egg_tool_item_group_style_set (GtkWidget *widget,
                                GtkStyle  *previous_style)
 {
-  EggToolItemGroup *group = EGG_TOOL_ITEM_GROUP (widget);
-  GtkWidget *alignment = NULL;
-
-  gtk_widget_style_get (widget,
-                        "header-spacing", &group->priv->header_spacing,
-                        "expander-size", &group->priv->expander_size,
-                        NULL);
-
-  alignment = egg_tool_item_group_get_alignment (group);
-
-  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
-                             0, 0,
-                             group->priv->header_spacing +
-                             group->priv->expander_size, 0);
-
+  egg_tool_item_group_header_adjust_style (EGG_TOOL_ITEM_GROUP (widget));
   GTK_WIDGET_CLASS (egg_tool_item_group_parent_class)->style_set (widget, previous_style);
 }
 
@@ -1057,23 +1140,40 @@
 
   if (group->priv->animation_timeout)
     {
+      GtkOrientation orientation = egg_tool_item_group_get_orientation (GTK_TOOL_SHELL (group));
       cairo_pattern_t *mask;
-      gdouble y0, y1;
+      gdouble v0, v1;
 
-      y0 = widget->allocation.height - 256;
-      y1 = widget->allocation.height;
+      if (GTK_ORIENTATION_VERTICAL == orientation)
+        v1 = widget->allocation.height;
+      else
+        v1 = widget->allocation.width;
 
-      if (GTK_WIDGET_VISIBLE (group->priv->header))
-        y0 = MAX (y0, group->priv->header->allocation.height);
+      v0 = v1 - 256;
+
+      if (!GTK_WIDGET_VISIBLE (group->priv->header))
+        v0 = MAX (v0, 0);
+      else if (GTK_ORIENTATION_VERTICAL == orientation)
+        v0 = MAX (v0, group->priv->header->allocation.height);
       else
-        y0 = MAX (y0, 0);
+        v0 = MAX (v0, group->priv->header->allocation.width);
 
-      y1 = MIN (y0 + 256, y1);
+      v1 = MIN (v0 + 256, v1);
 
-      y0 += widget->allocation.y;
-      y1 += widget->allocation.y;
+      if (GTK_ORIENTATION_VERTICAL == orientation)
+        {
+          v0 += widget->allocation.y;
+          v1 += widget->allocation.y;
 
-      mask = cairo_pattern_create_linear (0.0, y0, 0.0, y1);
+          mask = cairo_pattern_create_linear (0.0, v0, 0.0, v1);
+        }
+      else
+        {
+          v0 += widget->allocation.x;
+          v1 += widget->allocation.x;
+
+          mask = cairo_pattern_create_linear (v0, 0.0, v1, 0.0);
+        }
 
       cairo_pattern_add_color_stop_rgba (mask, 0.00, 0.0, 0.0, 0.0, 1.00);
       cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.25);
@@ -1088,9 +1188,10 @@
     cairo_paint (cr);
 }
 
-gint
-_egg_tool_item_group_get_height_for_width (EggToolItemGroup *group,
-                                           gint              width)
+static gint
+egg_tool_item_group_get_size_for_limit (EggToolItemGroup *group,
+                                        gint              limit,
+                                        gboolean          vertical)
 {
   GtkRequisition requisition;
 
@@ -1099,13 +1200,21 @@
 
   if (group->priv->expanded || group->priv->animation_timeout)
     {
-      GtkAllocation allocation = { 0, 0, width, requisition.height };
+      GtkAllocation allocation = { 0, 0, requisition.width, requisition.height };
       GtkRequisition inquery;
 
+      if (vertical)
+        allocation.width = limit;
+      else
+        allocation.height = limit;
+
       egg_tool_item_group_real_size_allocate (GTK_WIDGET (group),
                                               &allocation, &inquery);
 
-      inquery.height -= requisition.height;
+      if (vertical)
+        inquery.height -= requisition.height;
+      else
+        inquery.width -= requisition.width;
 
       if (group->priv->animation_timeout)
         {
@@ -1116,12 +1225,64 @@
           if (!group->priv->expanded)
             timestamp = ANIMATION_DURATION - timestamp;
 
-          inquery.height *= timestamp;
-          inquery.height /= ANIMATION_DURATION;
+          if (vertical)
+            {
+              inquery.height *= timestamp;
+              inquery.height /= ANIMATION_DURATION;
+            }
+          else
+            {
+              inquery.width *= timestamp;
+              inquery.width /= ANIMATION_DURATION;
+            }
         }
 
-      requisition.height += inquery.height;
+      if (vertical)
+        requisition.height += inquery.height;
+      else
+        requisition.width += inquery.width;
     }
 
-  return requisition.height;
+  return (vertical ? requisition.height : requisition.width);
+}
+
+gint
+_egg_tool_item_group_get_height_for_width (EggToolItemGroup *group,
+                                           gint              width)
+{
+  return egg_tool_item_group_get_size_for_limit (group, width, TRUE);
 }
+
+gint
+_egg_tool_item_group_get_width_for_height (EggToolItemGroup *group,
+                                           gint              height)
+{
+  return egg_tool_item_group_get_size_for_limit (group, height, FALSE);
+}
+
+#ifdef GTK_TOOL_SHELL
+
+static void
+egg_tool_palette_reconfigured_foreach_item (GtkWidget *child,
+                                            gpointer   data G_GNUC_UNUSED)
+{
+  if (GTK_IS_TOOL_ITEM (child))
+    gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (child));
+}
+
+#endif /* GTK_TOOL_SHELL */
+
+void
+_egg_tool_item_group_palette_reconfigured (EggToolItemGroup *group)
+{
+#ifdef GTK_TOOL_SHELL
+
+  gtk_container_foreach (GTK_CONTAINER (group),
+                         egg_tool_palette_reconfigured_foreach_item,
+                         NULL);
+
+#endif /* GTK_TOOL_SHELL */
+
+  egg_tool_item_group_header_adjust_style (group);
+}
+

Modified: trunk/libegg/toolpalette/eggtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpalette.c	(original)
+++ trunk/libegg/toolpalette/eggtoolpalette.c	Fri Mar 28 18:40:48 2008
@@ -96,17 +96,6 @@
   palette->priv->style = DEFAULT_TOOLBAR_STYLE;
 }
 
-#ifdef GTK_TOOL_SHELL
-
-static void
-egg_tool_palette_reconfigured_foreach_item (GtkWidget *child,
-                                            gpointer   data G_GNUC_UNUSED)
-{
-  if (GTK_IS_TOOL_ITEM (child))
-    gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (child));
-}
-
-
 static void
 egg_tool_palette_reconfigured (EggToolPalette *palette)
 {
@@ -114,29 +103,13 @@
 
   for (i = 0; i < palette->priv->groups_length; ++i)
     {
-      EggToolItemGroup *group = palette->priv->groups[i];
-
-      if (!group)
-        continue;
-
-      gtk_container_foreach (GTK_CONTAINER (group),
-                             egg_tool_palette_reconfigured_foreach_item,
-                             NULL);
+      if (palette->priv->groups[i])
+        _egg_tool_item_group_palette_reconfigured (palette->priv->groups[i]);
     }
 
   gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
 }
 
-#else /* GTK_TOOL_SHELL */
-
-static void
-egg_tool_palette_reconfigured (EggToolPalette *palette)
-{
-  gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
-}
-
-#endif /* GTK_TOOL_SHELL */
-
 static void
 egg_tool_palette_set_property (GObject      *object,
                                guint         prop_id,
@@ -293,18 +266,42 @@
 {
   const gint border_width = GTK_CONTAINER (widget)->border_width;
   EggToolPalette *palette = EGG_TOOL_PALETTE (widget);
+  GtkAdjustment *adjustment = NULL;
   GtkAllocation child_allocation;
+
+  gint page_start, page_size = 0;
   gint offset = 0;
   guint i;
 
   GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->size_allocate (widget, allocation);
 
-  if (palette->priv->vadjustment)
-    offset = gtk_adjustment_get_value (palette->priv->vadjustment);
-
   child_allocation.x = border_width;
-  child_allocation.y = border_width - offset;
-  child_allocation.width = allocation->width - border_width * 2;
+  child_allocation.y = border_width;
+
+  if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+    {
+      adjustment = palette->priv->vadjustment;
+      page_size = allocation->height;
+    }
+  else
+    {
+      adjustment = palette->priv->hadjustment;
+      page_size = allocation->width;
+    }
+
+  if (adjustment)
+    offset = gtk_adjustment_get_value (adjustment);
+
+  if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+    {
+      child_allocation.y -= offset;
+      child_allocation.width = allocation->width - border_width * 2;
+    }
+  else
+    {
+      child_allocation.x -= offset;
+      child_allocation.height = allocation->height - border_width * 2;
+    }
 
   for (i = 0; i < palette->priv->groups_length; ++i)
     {
@@ -312,34 +309,51 @@
 
       if (egg_tool_item_group_get_n_items (group))
         {
-          child_allocation.height = _egg_tool_item_group_get_height_for_width (group, child_allocation.width);
+          if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+            child_allocation.height = _egg_tool_item_group_get_height_for_width (group, child_allocation.width);
+          else
+            child_allocation.width = _egg_tool_item_group_get_width_for_height (group, child_allocation.height);
 
           gtk_widget_size_allocate (GTK_WIDGET (group), &child_allocation);
           gtk_widget_show (GTK_WIDGET (group));
 
-          child_allocation.y += child_allocation.height;
+          if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+            child_allocation.y += child_allocation.height;
+          else
+            child_allocation.x += child_allocation.width;
         }
       else
         gtk_widget_hide (GTK_WIDGET (group));
     }
 
-  child_allocation.y += border_width;
-  child_allocation.y += offset;
+  if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+    {
+      child_allocation.y += border_width;
+      child_allocation.y += offset;
 
-  if (palette->priv->vadjustment)
+      page_start = child_allocation.y;
+    }
+  else
     {
-      GtkAdjustment *vadj = palette->priv->vadjustment;
+      child_allocation.x += border_width;
+      child_allocation.x += offset;
+
+      page_start = child_allocation.x;
+    }
+
+  if (adjustment)
+    {
+      gdouble value;
+
+      adjustment->page_increment = page_size * 0.9;
+      adjustment->step_increment = page_size * 0.1;
+      adjustment->upper = MAX (0, page_start);
+      adjustment->page_size = page_size;
 
-      vadj->page_increment = allocation->height * 0.9;
-      vadj->step_increment = allocation->height * 0.1;
-      vadj->upper = MAX (0, child_allocation.y);
-      vadj->page_size = allocation->height;
-
-      gtk_adjustment_clamp_page (vadj,
-                                 MIN (offset, vadj->upper - vadj->page_size),
-                                 offset + allocation->height);
+      value = MIN (offset, adjustment->upper - adjustment->page_size);
+      gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
 
-      gtk_adjustment_changed (vadj);
+      gtk_adjustment_changed (adjustment);
     }
 }
 

Modified: trunk/libegg/toolpalette/eggtoolpaletteprivate.h
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpaletteprivate.h	(original)
+++ trunk/libegg/toolpalette/eggtoolpaletteprivate.h	Fri Mar 28 18:40:48 2008
@@ -30,10 +30,13 @@
 void _egg_tool_palette_child_set_drag_source   (GtkWidget        *widget,
                                                 gpointer          data);
 
+void _egg_tool_item_group_palette_reconfigured (EggToolItemGroup *group);
 void _egg_tool_item_group_item_size_request    (EggToolItemGroup *group,
                                                 GtkRequisition   *item_size);
 gint _egg_tool_item_group_get_height_for_width (EggToolItemGroup *group,
                                                 gint              width);
+gint _egg_tool_item_group_get_width_for_height (EggToolItemGroup *group,
+                                                gint              height);
 void _egg_tool_item_group_paint                (EggToolItemGroup *group,
                                                 cairo_t          *cr);
 

Modified: trunk/libegg/toolpalette/testtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/testtoolpalette.c	(original)
+++ trunk/libegg/toolpalette/testtoolpalette.c	Fri Mar 28 18:40:48 2008
@@ -427,32 +427,27 @@
   gtk_container_add (GTK_CONTAINER (palette), group);
 
   item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_UP);
-  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item),
-                             "Show on vertical palettes only");
-  gtk_tool_item_set_visible_horizontal (item, FALSE);
+  gtk_tool_item_set_tooltip_text (item, "Show on vertical palettes only");
   egg_tool_item_group_insert (EGG_TOOL_ITEM_GROUP (group), item, -1);
+  gtk_tool_item_set_visible_horizontal (item, FALSE);
 
   item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
-  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item),
-                             "Show on horizontal palettes only");
-  gtk_tool_item_set_visible_vertical (item, FALSE);
+  gtk_tool_item_set_tooltip_text (item, "Show on horizontal palettes only");
   egg_tool_item_group_insert (EGG_TOOL_ITEM_GROUP (group), item, -1);
+  gtk_tool_item_set_visible_vertical (item, FALSE);
 
   item = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE);
-  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item),
-                             "Do not show at all");
-  gtk_widget_set_no_show_all (GTK_WIDGET (item), TRUE);
+  gtk_tool_item_set_tooltip_text (item, "Do not show at all");
   egg_tool_item_group_insert (EGG_TOOL_ITEM_GROUP (group), item, -1);
+  gtk_widget_set_no_show_all (GTK_WIDGET (item), TRUE);
 
   item = gtk_tool_button_new_from_stock (GTK_STOCK_FULLSCREEN);
-  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item),
-                             "Expanded this item");
-  gtk_tool_item_set_expand (item, TRUE);
+  gtk_tool_item_set_tooltip_text (item, "Expanded this item");
   egg_tool_item_group_insert (EGG_TOOL_ITEM_GROUP (group), item, -1);
+  gtk_tool_item_set_expand (item, TRUE);
 
   item = gtk_tool_button_new_from_stock (GTK_STOCK_HELP);
-  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item),
-                             "A regular item");
+  gtk_tool_item_set_tooltip_text (item, "A regular item");
   egg_tool_item_group_insert (EGG_TOOL_ITEM_GROUP (group), item, -1);
 }
 
@@ -463,6 +458,40 @@
   return (enum_value->value != GTK_ICON_SIZE_INVALID);
 }
 
+static void
+palette_notify_orientation (GObject    *object,
+                            GParamSpec *pspec G_GNUC_UNUSED,
+                            gpointer    data  G_GNUC_UNUSED)
+{
+  GtkWidget *scroller = gtk_widget_get_parent (GTK_WIDGET (object));
+  GtkWidget *parent = gtk_widget_get_parent (scroller);
+
+  GtkWidget *hpaned = g_object_get_data (object, "hpaned");
+  GtkWidget *vpaned = g_object_get_data (object, "vpaned");
+
+  g_object_ref (scroller);
+
+  if (parent)
+    gtk_container_remove (GTK_CONTAINER (parent), scroller);
+
+  switch (egg_tool_palette_get_orientation (EGG_TOOL_PALETTE (object)))
+    {
+      case GTK_ORIENTATION_VERTICAL:
+        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller),
+                                        GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+        gtk_paned_pack1 (GTK_PANED (hpaned), scroller, FALSE, FALSE);
+        break;
+
+      case GTK_ORIENTATION_HORIZONTAL:
+        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller),
+                                        GTK_POLICY_ALWAYS, GTK_POLICY_NEVER);
+        gtk_paned_pack1 (GTK_PANED (vpaned), scroller, FALSE, FALSE);
+        break;
+    }
+
+  g_object_unref (scroller);
+}
+
 static GtkWidget*
 create_ui (void)
 {
@@ -522,8 +551,8 @@
   GError *error = NULL;
   GtkUIManager *ui;
 
-  GtkWidget *window, *vbox, *notebook;
-  GtkWidget *menubar, *toolbar, *hpaned;
+  GtkWidget *window, *vbox, *hpaned, *vpaned;
+  GtkWidget *menubar, *toolbar, *notebook;
   GtkWidget *palette, *palette_scroller;
   GtkWidget *contents, *contents_scroller;
   GtkAction *action;
@@ -566,11 +595,16 @@
   load_stock_items (EGG_TOOL_PALETTE (palette));
   load_special_items (EGG_TOOL_PALETTE (palette));
 
+  g_signal_connect (palette, "notify::orientation",
+                    G_CALLBACK (palette_notify_orientation),
+                    NULL);
+
   palette_scroller = gtk_scrolled_window_new (NULL, NULL);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (palette_scroller),
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
   gtk_container_set_border_width (GTK_CONTAINER (palette_scroller), 6);
   gtk_container_add (GTK_CONTAINER (palette_scroller), palette);
+  gtk_widget_show_all (palette_scroller);
 
   /* ===== notebook ===== */
 
@@ -642,15 +676,27 @@
   /* ===== hpaned ===== */
 
   hpaned = gtk_hpaned_new ();
-  gtk_paned_pack1 (GTK_PANED (hpaned), palette_scroller, FALSE, FALSE);
   gtk_paned_pack2 (GTK_PANED (hpaned), notebook, TRUE, FALSE);
 
+  g_object_set_data_full (G_OBJECT (palette), "hpaned",
+                          g_object_ref (hpaned),
+                          g_object_unref);
+
+  /* ===== vpaned ===== */
+
+  vpaned = gtk_vpaned_new ();
+  gtk_paned_pack2 (GTK_PANED (vpaned), hpaned, TRUE, FALSE);
+
+  g_object_set_data_full (G_OBJECT (palette), "vpaned",
+                          g_object_ref (vpaned),
+                          g_object_unref);
+
   /* ===== vbox ===== */
 
   vbox = gtk_vbox_new (FALSE, 0);
   gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
   gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), vpaned, TRUE, TRUE, 0);
   gtk_widget_show_all (vbox);
 
   /* ===== window ===== */
@@ -660,6 +706,8 @@
   gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (ui));
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
 
+  /* ===== final fixup ===== */
+
   g_object_unref (ui);
   return window;
 }



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