libegg r873 - in trunk: . libegg/toolpalette



Author: jap
Date: Sun Jun  1 09:27:19 2008
New Revision: 873
URL: http://svn.gnome.org/viewvc/libegg?rev=873&view=rev

Log:
2008-06-01  Jan Arne Petersen  <jpetersen openismus com>

	Add support for scroll to group feature. Show the group's header and
	as many of its items as possible, when expanding (#535093).

	* libegg/toolpalette/TODO: remove entry

	* libegg/toolpalette/eggtoolitemgroup.c
	  (egg_tool_item_group_set_collapsed, _egg_tool_item_group_paint,
	  _egg_tool_item_group_get_size_for_limit,
	  _egg_tool_item_group_get_height_for_width,
	  _egg_tool_item_group_get_width_for_height): Add an additional
	  argument to _egg_tool_item_group_get_size_for_limit to allow to
	  query the non collapsed size.

	* libegg/toolpalette/eggtoolpalette.c (expanding_child,
	  egg_tool_palette_size_allocate,
	  egg_tool_palette_get_drag_target_group,
	  _egg_tool_palette_set_expanding_child): as long as a group is
	  expanding it is shown in view.

	* libegg/toolpalette/eggtoolpaletteprivate.h
	  (__EGG_TOOL_PALETTE_PRIVATE_H__): add function to set the expanding
	  group.



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

Modified: trunk/libegg/toolpalette/TODO
==============================================================================
--- trunk/libegg/toolpalette/TODO	(original)
+++ trunk/libegg/toolpalette/TODO	Sun Jun  1 09:27:19 2008
@@ -1,7 +1,6 @@
 EggToolPalette
 ==============
 
-* scroll to group to show as many of its items as possible, when expanding.
 * support horizontal orientation for other styles but icon only:
   - GTK_TOOLBAR_ICONS: done
   - GTK_TOOLBAR_TEXT: rotate the text labels. currently can be done

Modified: trunk/libegg/toolpalette/eggtoolitemgroup.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolitemgroup.c	(original)
+++ trunk/libegg/toolpalette/eggtoolitemgroup.c	Sun Jun  1 09:27:19 2008
@@ -1009,6 +1009,7 @@
   if (collapsed != group->priv->collapsed)
     {
       GTimeVal now;
+      GtkWidget *parent;
 
       g_get_current_time (&now);
 
@@ -1019,6 +1020,10 @@
       group->priv->animation_start = (now.tv_sec * G_USEC_PER_SEC + now.tv_usec);
       group->priv->animation_timeout = g_timeout_source_new (ANIMATION_TIMEOUT);
 
+      parent = gtk_widget_get_parent (GTK_WIDGET (group));
+      if (EGG_IS_TOOL_PALETTE (parent) && !collapsed)
+        _egg_tool_palette_set_expanding_child (EGG_TOOL_PALETTE (parent), GTK_WIDGET (group));
+
       g_source_set_callback (group->priv->animation_timeout,
                              egg_tool_item_group_animation_cb,
                              group, NULL);
@@ -1314,10 +1319,11 @@
     cairo_paint (cr);
 }
 
-static gint
-egg_tool_item_group_get_size_for_limit (EggToolItemGroup *group,
-                                        gint              limit,
-                                        gboolean          vertical)
+gint
+_egg_tool_item_group_get_size_for_limit (EggToolItemGroup *group,
+                                         gint              limit,
+                                         gboolean          vertical,
+                                         gboolean          animation)
 {
   GtkRequisition requisition;
 
@@ -1342,7 +1348,7 @@
       else
         inquery.width -= requisition.width;
 
-      if (group->priv->animation_timeout)
+      if (group->priv->animation_timeout && animation)
         {
           gint64 timestamp = egg_tool_item_group_get_animation_timestamp (group);
 
@@ -1376,14 +1382,14 @@
 _egg_tool_item_group_get_height_for_width (EggToolItemGroup *group,
                                            gint              width)
 {
-  return egg_tool_item_group_get_size_for_limit (group, width, TRUE);
+  return _egg_tool_item_group_get_size_for_limit (group, width, TRUE, 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);
+  return _egg_tool_item_group_get_size_for_limit (group, height, FALSE, TRUE);
 }
 
 #ifdef GTK_TYPE_TOOL_SHELL

Modified: trunk/libegg/toolpalette/eggtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpalette.c	(original)
+++ trunk/libegg/toolpalette/eggtoolpalette.c	Sun Jun  1 09:27:19 2008
@@ -77,6 +77,8 @@
   GtkOrientation        orientation;
   GtkToolbarStyle       style;
 
+  GtkWidget            *expanding_child;
+
   guint                 sparse_groups : 1;
   guint                 drag_source : 1;
 };
@@ -309,6 +311,8 @@
   gint offset = 0;
   guint i;
 
+  gint min_offset = -1, max_offset = -1;
+
   gint *group_sizes = g_newa(gint, palette->priv->groups_length);
 
   GTK_WIDGET_CLASS (egg_tool_palette_parent_class)->size_allocate (widget, allocation);
@@ -331,15 +335,9 @@
   child_allocation.y = border_width;
 
   if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
-    {
-      child_allocation.y -= offset;
-      child_allocation.width = allocation->width - border_width * 2;
-    }
+    child_allocation.width = allocation->width - border_width * 2;
   else
-    {
-      child_allocation.x -= offset;
-      child_allocation.height = allocation->height - border_width * 2;
-    }
+    child_allocation.height = allocation->height - border_width * 2;
 
   if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
     remaining_space = allocation->height;
@@ -371,6 +369,26 @@
 
       remaining_space -= size;
       group_sizes[i] = size;
+
+      if (widget == palette->priv->expanding_child)
+        {
+          gint j, real_size;
+          gint limit = GTK_ORIENTATION_VERTICAL == palette->priv->orientation ? child_allocation.width : child_allocation.height;
+
+          min_offset = 0;
+          for (j = 0; j < i; ++j)
+            {
+              min_offset += group_sizes[j];
+            }
+          max_offset = min_offset + group_sizes[i];
+
+          real_size = _egg_tool_item_group_get_size_for_limit (EGG_TOOL_ITEM_GROUP (widget),
+                                                               limit,
+                                                               GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
+                                                               FALSE);
+          if (size == real_size)
+            palette->priv->expanding_child = NULL;
+        }
     }
 
   if (n_expand_groups > 0)
@@ -379,6 +397,19 @@
       expand_space = remaining_space / n_expand_groups;
     }
 
+  if (max_offset != -1)
+    {
+      gint limit = GTK_ORIENTATION_VERTICAL == palette->priv->orientation ? allocation->height : allocation->width;
+
+      offset = MIN(MAX (offset, max_offset - limit), min_offset);
+    }
+
+  if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
+    child_allocation.y -= offset;
+  else
+    child_allocation.x -= offset;
+
+
   for (i = 0; i < palette->priv->groups_length; ++i)
     {
       EggToolItemGroupInfo *group = &palette->priv->groups[i];
@@ -1259,3 +1290,11 @@
   return &dnd_targets[1];
 }
 
+void
+_egg_tool_palette_set_expanding_child (EggToolPalette   *palette,
+                                       GtkWidget        *widget)
+{
+  g_return_if_fail (EGG_IS_TOOL_PALETTE (palette));
+
+  palette->priv->expanding_child = widget;
+}

Modified: trunk/libegg/toolpalette/eggtoolpaletteprivate.h
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpaletteprivate.h	(original)
+++ trunk/libegg/toolpalette/eggtoolpaletteprivate.h	Sun Jun  1 09:27:19 2008
@@ -29,6 +29,8 @@
                                                 GtkRequisition   *item_size);
 void _egg_tool_palette_child_set_drag_source   (GtkWidget        *widget,
                                                 gpointer          data);
+void _egg_tool_palette_set_expanding_child     (EggToolPalette   *palette,
+                                                GtkWidget        *widget);
 
 void _egg_tool_item_group_palette_reconfigured (EggToolItemGroup *group);
 void _egg_tool_item_group_item_size_request    (EggToolItemGroup *group,
@@ -39,5 +41,9 @@
                                                 gint              height);
 void _egg_tool_item_group_paint                (EggToolItemGroup *group,
                                                 cairo_t          *cr);
+gint _egg_tool_item_group_get_size_for_limit   (EggToolItemGroup *group,
+                                                gint              limit,
+                                                gboolean          vertical,
+                                                gboolean          animation);
 
 #endif /* __EGG_TOOL_PALETTE_PRIVATE_H__ */



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