[gtk+/extended-layout-jhs: 47/64] Provide natural size information. Consider and provide natural size



commit 43fff978a26a818e541290ea6b8a7b2753109169
Author: Mathias Hasselmann <mathias hasselmann gmx de>
Date:   Wed Aug 1 15:53:34 2007 +0000

    Provide natural size information. Consider and provide natural size
    
    2007-08-01  Mathias Hasselmann  <mathias hasselmann gmx de>
    
    	* gtk/gtkcellrenderertext.c: Provide natural size information.
    	* gtk/gtkcellview.c: Consider and provide natural size information.
    	* tests/testextendedlayout.c: Change background of testing cell view.
    
    svn path=/branches/extended-layout/; revision=18567

 ChangeLog.gtk-extended-layout |    6 ++
 gtk/gtkcellrenderertext.c     |   41 ++++++++++++++-
 gtk/gtkcellview.c             |  117 +++++++++++++++++++++++++++++++++++++++--
 tests/testextendedlayout.c    |    4 ++
 4 files changed, 162 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog.gtk-extended-layout b/ChangeLog.gtk-extended-layout
index d3acab9..9b8843b 100644
--- a/ChangeLog.gtk-extended-layout
+++ b/ChangeLog.gtk-extended-layout
@@ -1,5 +1,11 @@
 2007-08-01  Mathias Hasselmann  <mathias hasselmann gmx de>
 
+	* gtk/gtkcellrenderertext.c: Provide natural size information.
+	* gtk/gtkcellview.c: Consider and provide natural size information.
+	* tests/testextendedlayout.c: Change background of testing cell view.
+
+2007-08-01  Mathias Hasselmann  <mathias hasselmann gmx de>
+
 	* gtk/gtkcellview.c: Seems there is no point in distinguishing between
 	GTK_PACK_START and GTK_PACK_END during size allocation. The loops only
 	differ in the packing check.
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c
index 4a08f1c..46132a1 100644
--- a/gtk/gtkcellrenderertext.c
+++ b/gtk/gtkcellrenderertext.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <stdlib.h>
 #include "gtkcellrenderertext.h"
+#include "gtkextendedlayout.h"
 #include "gtkeditable.h"
 #include "gtkentry.h"
 #include "gtkmarshalers.h"
@@ -61,6 +62,8 @@ static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer
 							      GdkRectangle         *cell_area,
 							      GtkCellRendererState  flags);
 
+static void       gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface);
+
 enum {
   EDITED,
   LAST_SIGNAL
@@ -148,9 +151,12 @@ struct _GtkCellRendererTextPrivate
   gint wrap_width;
   
   GtkWidget *entry;
+  GtkWidget *owner;
 };
 
-G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
+G_DEFINE_TYPE_WITH_CODE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
+						gtk_cell_renderer_text_extended_layout_init))
 
 static void
 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
@@ -1489,6 +1495,7 @@ get_size (GtkCellRenderer *cell,
   GtkCellRendererTextPrivate *priv;
 
   priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
+  priv->owner = widget;
 
   if (celltext->calc_fixed_height)
     {
@@ -1919,5 +1926,37 @@ gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer
     }
 }
 
+static GtkExtendedLayoutFeatures
+gtk_cell_renderer_text_extended_layout_get_features (GtkExtendedLayout *layout)
+{
+  return GTK_EXTENDED_LAYOUT_NATURAL_SIZE;
+}
+
+static void
+gtk_cell_renderer_text_extended_layout_get_natural_size (GtkExtendedLayout *layout,
+                                                         GtkRequisition    *requisition)
+{
+  GtkCellRendererTextPrivate *priv;
+  PangoEllipsizeMode ellipsize;
+
+  priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (layout);
+
+  ellipsize = priv->ellipsize;
+  priv->ellipsize = PANGO_ELLIPSIZE_NONE;
+
+  get_size (GTK_CELL_RENDERER (layout),
+            priv->owner, NULL, NULL, NULL, NULL,
+            &requisition->width, &requisition->height);
+
+  priv->ellipsize = ellipsize;
+}
+
+static void
+gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface)
+{
+  iface->get_features = gtk_cell_renderer_text_extended_layout_get_features;
+  iface->get_natural_size = gtk_cell_renderer_text_extended_layout_get_natural_size;
+}
+
 #define __GTK_CELL_RENDERER_TEXT_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c
index 500a152..4ac8f2c 100644
--- a/gtk/gtkcellview.c
+++ b/gtk/gtkcellview.c
@@ -20,10 +20,12 @@
 #include <config.h>
 #include "gtkcellview.h"
 #include "gtkcelllayout.h"
+#include "gtkextendedlayout.h"
 #include "gtkintl.h"
 #include "gtksignal.h"
 #include "gtkcellrenderertext.h"
 #include "gtkcellrendererpixbuf.h"
+#include "gtkextendedlayout.h"
 #include "gtkprivate.h"
 #include <gobject/gmarshal.h>
 #include "gtkalias.h"
@@ -34,6 +36,7 @@ struct _GtkCellViewCellInfo
   GtkCellRenderer *cell;
 
   gint requested_width;
+  gint natural_width;
   gint real_width;
   guint expand : 1;
   guint pack : 1;
@@ -105,6 +108,25 @@ static void       gtk_cell_view_cell_layout_reorder            (GtkCellLayout
                                                                 gint                   position);
 static GList *    gtk_cell_view_cell_layout_get_cells          (GtkCellLayout         *layout);
 
+/* buildable */
+static void       gtk_cell_view_buildable_init                 (GtkBuildableIface     *iface);
+static gboolean   gtk_cell_view_buildable_custom_tag_start     (GtkBuildable  	      *buildable,
+								GtkBuilder    	      *builder,
+								GObject       	      *child,
+								const gchar   	      *tagname,
+								GMarkupParser 	      *parser,
+								gpointer      	      *data);
+static void       gtk_cell_view_buildable_custom_tag_end       (GtkBuildable  	      *buildable,
+								GtkBuilder    	      *builder,
+								GObject       	      *child,
+								const gchar   	      *tagname,
+								gpointer      	      *data);
+
+/* extended layout */
+static void       gtk_cell_view_extended_layout_init           (GtkExtendedLayoutIface *iface);
+
+static GtkBuildableIface *parent_buildable_iface;
+
 #define GTK_CELL_VIEW_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_VIEW, GtkCellViewPrivate))
 
 enum
@@ -118,7 +140,11 @@ enum
 
 G_DEFINE_TYPE_WITH_CODE (GtkCellView, gtk_cell_view, GTK_TYPE_WIDGET, 
 			 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
-						gtk_cell_view_cell_layout_init))
+						gtk_cell_view_cell_layout_init)
+			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+						gtk_cell_view_buildable_init)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
+						gtk_cell_view_extended_layout_init))
 
 static void
 gtk_cell_view_class_init (GtkCellViewClass *klass)
@@ -288,6 +314,7 @@ gtk_cell_view_size_request (GtkWidget      *widget,
   GList *i;
   gboolean first_cell = TRUE;
   GtkCellView *cellview;
+  GtkRequisition natural_size;
 
   cellview = GTK_CELL_VIEW (widget);
 
@@ -312,6 +339,15 @@ gtk_cell_view_size_request (GtkWidget      *widget,
                                   &width, &height);
 
       info->requested_width = width;
+
+      if (GTK_EXTENDED_LAYOUT_HAS_NATURAL_SIZE (info->cell))
+        {
+          gtk_extended_layout_get_natural_size (GTK_EXTENDED_LAYOUT (info->cell), &natural_size);
+          info->natural_width = natural_size.width;
+        }
+      else
+        info->natural_width = info->requested_width;
+
       requisition->width += width;
       requisition->height = MAX (requisition->height, height);
 
@@ -327,8 +363,9 @@ gtk_cell_view_size_allocate (GtkWidget     *widget,
   GList *i;
 
   gint nexpand_cells = 0;
-  gint full_requested_width = 0;
-  gint available, extra;
+  gint requested_width = 0;
+  gint natural_width = 0;
+  gint available, natural, extra;
 
   widget->allocation = *allocation;
 
@@ -345,10 +382,13 @@ gtk_cell_view_size_allocate (GtkWidget     *widget,
       if (info->expand)
         nexpand_cells++;
 
-      full_requested_width += info->requested_width;
+      requested_width += info->requested_width;
+      natural_width += info->natural_width - info->requested_width;
     }
 
-  available = MAX (0, widget->allocation.width - full_requested_width);
+  available = MAX (0, widget->allocation.width - requested_width);
+  natural = MIN (available, natural_width);
+  available -= natural;
 
   if (nexpand_cells > 0)
     extra = available / nexpand_cells;
@@ -364,6 +404,9 @@ gtk_cell_view_size_allocate (GtkWidget     *widget,
 
       info->real_width = info->requested_width;
 
+      if (natural_width > 0)
+          info->real_width += natural * (info->natural_width - info->requested_width) / natural_width;
+
       if (info->expand)
         {
           if (1 == nexpand_cells)
@@ -1063,5 +1106,69 @@ gtk_cell_view_cell_layout_get_cells (GtkCellLayout *layout)
 }
 
 
+<<<<<<< HEAD:gtk/gtkcellview.c
+=======
+static gboolean
+gtk_cell_view_buildable_custom_tag_start (GtkBuildable  *buildable,
+					  GtkBuilder    *builder,
+					  GObject       *child,
+					  const gchar   *tagname,
+					  GMarkupParser *parser,
+					  gpointer      *data)
+{
+  if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
+						tagname, parser, data))
+    return TRUE;
+
+  return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
+						      tagname, parser, data);
+}
+
+static void
+gtk_cell_view_buildable_custom_tag_end (GtkBuildable *buildable,
+					GtkBuilder   *builder,
+					GObject      *child,
+					const gchar  *tagname,
+					gpointer     *data)
+{
+  if (strcmp (tagname, "attributes") == 0)
+    _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
+					       data);
+  else
+    parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
+					    data);
+}
+
+static GtkExtendedLayoutFeatures
+gtk_cell_view_extended_layout_get_features (GtkExtendedLayout *layout)
+{
+  return GTK_EXTENDED_LAYOUT_NATURAL_SIZE;
+}
+
+static void
+gtk_cell_view_extended_layout_get_natural_size (GtkExtendedLayout *layout,
+                                                GtkRequisition    *requisition)
+{
+  GList *i;
+
+  requisition->width = 0;
+  requisition->height = GTK_WIDGET (layout)->requisition.height;
+
+  for (i = GTK_CELL_VIEW (layout)->priv->cell_list; i; i = i->next)
+    {
+      GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
+
+      if (info->cell->visible)
+        requisition->width += info->natural_width;
+    }
+}
+
+static void
+gtk_cell_view_extended_layout_init (GtkExtendedLayoutIface *iface)
+{
+  iface->get_features = gtk_cell_view_extended_layout_get_features;
+  iface->get_natural_size = gtk_cell_view_extended_layout_get_natural_size;
+}
+
 #define __GTK_CELL_VIEW_C__
 #include "gtkaliasdef.c"
diff --git a/tests/testextendedlayout.c b/tests/testextendedlayout.c
index 6f51469..473474b 100644
--- a/tests/testextendedlayout.c
+++ b/tests/testextendedlayout.c
@@ -492,6 +492,7 @@ natural_size_test_misc_create_child (TestCase  *test,
   GError *error = NULL;
   gint child_stdout;
   char buffer[32];
+  GdkColor color;
 
   if (type >= 3)
     {
@@ -577,6 +578,9 @@ natural_size_test_misc_create_child (TestCase  *test,
           case 3:
             child = gtk_cell_view_new ();
 
+            if (gdk_color_parse ("#ffc", &color))
+              gtk_cell_view_set_background_color (GTK_CELL_VIEW (child), &color);
+
             cell = gtk_cell_renderer_pixbuf_new ();
             gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child), cell, FALSE);
             gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (child), cell,



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