libegg r868 - in trunk: . libegg/toolpalette



Author: hasselmm
Date: Mon Mar 31 19:51:07 2008
New Revision: 868
URL: http://svn.gnome.org/viewvc/libegg?rev=868&view=rev

Log:
Implement "expand" child property for EggToolPalette.

Nothing is so firmly believed as that which we least know.
	-- Michel de Montaigne

* libegg/toolpalette/eggtoolitemgroup.c
 (egg_tool_item_group_real_size_allocate()): Change size allocation
  algorithm to utilize additional space horizontal item group get
  assigned get when expanded.

* libegg/toolpalette/eggtoolpalette.c (egg_tool_palette_get_expand(),
  egg_tool_palette_set_expand()): Implement the "expand" property.
* libegg/toolpalette/eggtoolpalette.c
 (egg_tool_palette_size_allocate()): Distribute unused space among
  item groups with expand child property set.


Modified:
   trunk/ChangeLog
   trunk/libegg/toolpalette/eggtoolitemgroup.c
   trunk/libegg/toolpalette/eggtoolpalette.c

Modified: trunk/libegg/toolpalette/eggtoolitemgroup.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolitemgroup.c	(original)
+++ trunk/libegg/toolpalette/eggtoolitemgroup.c	Mon Mar 31 19:51:07 2008
@@ -461,6 +461,13 @@
   orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
   style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
 
+  /* figure out header size */
+
+  if (GTK_WIDGET_VISIBLE (group->priv->header))
+    gtk_widget_size_request (group->priv->header, &child_requistion);
+  else
+    child_requistion.width = child_requistion.height = 0;
+
   /* figure out item size */
 
   egg_tool_item_group_get_item_size (group, &item_size);
@@ -486,14 +493,26 @@
 
       if (GTK_ORIENTATION_VERTICAL == orientation)
         {
-          n_columns = MAX (allocation->width / item_size.width, 1);
+          item_area.width = allocation->width - 2 * border_width;
+          n_columns = MAX (item_area.width / item_size.width, 1);
           n_rows = (n_visible_items + n_columns - 1) / n_columns;
         }
-      else
+      else if (inquery)
         {
-          n_rows = MAX (allocation->height / item_size.height, 1);
+          item_area.height = allocation->height - 2 * border_width;
+          n_rows = MAX (item_area.height / item_size.height, 1);
           n_columns = (n_visible_items + n_rows - 1) / n_rows;
         }
+      else
+        {
+          item_area.width = allocation->width - 2 * border_width;
+
+          if (child_requistion.width > 0)
+            item_area.width -= child_requistion.width;
+
+          n_columns = MAX (item_area.width / item_size.width, 1);
+          n_rows = (n_visible_items + n_columns - 1) / n_columns;
+        }
 
       item_area.width = item_size.width * n_columns;
       item_area.height = item_size.height * n_rows;
@@ -511,8 +530,6 @@
 
   if (GTK_WIDGET_VISIBLE (group->priv->header))
     {
-      gtk_widget_size_request (group->priv->header, &child_requistion);
-
       if (GTK_ORIENTATION_VERTICAL == orientation)
         {
           child_allocation.width = allocation->width;

Modified: trunk/libegg/toolpalette/eggtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpalette.c	(original)
+++ trunk/libegg/toolpalette/eggtoolpalette.c	Mon Mar 31 19:51:07 2008
@@ -301,14 +301,17 @@
   GtkAdjustment *adjustment = NULL;
   GtkAllocation child_allocation;
 
+  gint n_expand_groups = 0;
+  gint remaining_space = 0;
+  gint expand_space = 0;
+
   gint page_start, page_size = 0;
   gint offset = 0;
   guint i;
 
-  GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->size_allocate (widget, allocation);
+  gint *group_sizes = g_newa(gint, palette->priv->groups_length);
 
-  child_allocation.x = border_width;
-  child_allocation.y = border_width;
+  GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->size_allocate (widget, allocation);
 
   if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
     {
@@ -324,6 +327,9 @@
   if (adjustment)
     offset = gtk_adjustment_get_value (adjustment);
 
+  child_allocation.x = border_width;
+  child_allocation.y = border_width;
+
   if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
     {
       child_allocation.y -= offset;
@@ -335,6 +341,44 @@
       child_allocation.height = allocation->height - border_width * 2;
     }
 
+  if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+    remaining_space = allocation->height;
+  else
+    remaining_space = allocation->width;
+
+  for (i = 0; i < palette->priv->groups_length; ++i)
+    {
+      EggToolItemGroupInfo *group = &palette->priv->groups[i];
+      gint size;
+
+      if (!group->widget)
+        continue;
+
+      widget = GTK_WIDGET (group->widget);
+
+      if (egg_tool_item_group_get_n_items (group->widget))
+        {
+          if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+            size = _egg_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
+          else
+            size = _egg_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
+
+          if (group->expand && !egg_tool_item_group_get_collapsed (group->widget))
+            n_expand_groups += 1;
+        }
+      else
+        size = 0;
+
+      remaining_space -= size;
+      group_sizes[i] = size;
+    }
+
+  if (n_expand_groups > 0)
+    {
+      remaining_space = MAX (0, remaining_space);
+      expand_space = remaining_space / n_expand_groups;
+    }
+
   for (i = 0; i < palette->priv->groups_length; ++i)
     {
       EggToolItemGroupInfo *group = &palette->priv->groups[i];
@@ -347,10 +391,18 @@
 
       if (egg_tool_item_group_get_n_items (group->widget))
         {
+          gint size = group_sizes[i];
+
+          if (group->expand && !egg_tool_item_group_get_collapsed (group->widget))
+            {
+              size += MIN (expand_space, remaining_space);
+              remaining_space -= expand_space;
+            }
+
           if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
-            child_allocation.height = _egg_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
+            child_allocation.height = size;
           else
-            child_allocation.width = _egg_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
+            child_allocation.width = size;
 
           gtk_widget_size_allocate (widget, &child_allocation);
           gtk_widget_show (widget);
@@ -906,9 +958,23 @@
                              GtkWidget      *group,
                              gboolean        expand G_GNUC_UNUSED)
 {
+  EggToolItemGroupInfo *group_info;
+  gint position;
+
   g_return_if_fail (EGG_IS_TOOL_PALETTE (palette));
   g_return_if_fail (EGG_IS_TOOL_ITEM_GROUP (group));
-  g_return_if_reached ();
+
+  position = egg_tool_palette_get_group_position (palette, group);
+  g_return_if_fail (position >= 0);
+
+  group_info = &palette->priv->groups[position];
+
+  if (expand != group_info->expand)
+    {
+      group_info->expand = expand;
+      gtk_widget_queue_resize (GTK_WIDGET (palette));
+      gtk_widget_child_notify (group, "expand");
+    }
 }
 
 gint
@@ -946,9 +1012,15 @@
 egg_tool_palette_get_expand (EggToolPalette *palette,
                              GtkWidget      *group)
 {
+  gint position;
+
   g_return_val_if_fail (EGG_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
   g_return_val_if_fail (EGG_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
-  g_return_val_if_reached (DEFAULT_CHILD_EXPAND);
+
+  position = egg_tool_palette_get_group_position (palette, group);
+  g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
+
+  return palette->priv->groups[position].expand;
 }
 
 GtkToolItem*



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