[gtk+] cellrenderer: Merge GtkCellSizeRequest into GtkCellRenderer



commit e66129015de47d21006ff03f82964a77fdf7ca3d
Author: Benjamin Otte <otte redhat com>
Date:   Tue Sep 21 16:52:59 2010 +0200

    cellrenderer: Merge GtkCellSizeRequest into GtkCellRenderer
    
    This mostly goes to keep consistency with the changes to GtkSizeRequest
    in the last patch, as GtkCellSizeRequest requires GtkCellRenderer and
    GtkCellRenderer implements GtkCellSizeRequest there's no use in keeping
    them separate.
    
    This patch renames the functions:
    gtk_cell_size_request_get_request_mode()
      => gtk_cell_renderer_get_request_mode()
    gtk_cell_size_request_get_width()
      => gtk_cell_renderer_get_preferred_width()
    gtk_cell_size_request_get_height()
      => gtk_cell_renderer_get_preferred_height()
    gtk_cell_size_request_get_size()
      => gtk_cell_renderer_get_preferred_size()
    gtk_cell_size_request_get_width_for_height()
      => gtk_cell_renderer_get_preferred_width_for_height()
    gtk_cell_size_request_get_height_for_width()
      => gtk_cell_renderer_get_preferred_height_for_width()
    ... and moves the corresponding vfuncs to GtkCellRenderer.
    
    The patch also renames the implementations of these functions in cell
    renderers to include the word "preferrred".

 gtk/Makefile.am                   |    2 -
 gtk/gtk.h                         |    1 -
 gtk/gtk.symbols                   |   18 +-
 gtk/gtkcellrenderer.c             |  448 ++++++++++++++++++++++++++++---------
 gtk/gtkcellrenderer.h             |  100 ++++++---
 gtk/gtkcellrenderertext.c         |   79 +++----
 gtk/gtkcellsizerequest.c          |  327 ---------------------------
 gtk/gtkcellsizerequest.h          |   92 --------
 gtk/gtkcellview.c                 |   19 +-
 gtk/gtkiconview.c                 |   19 +-
 gtk/gtktreeviewcolumn.c           |   19 +-
 modules/other/gail/gailtextcell.c |   12 +-
 12 files changed, 489 insertions(+), 647 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 15397d3..60057e5 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -179,7 +179,6 @@ gtk_public_h_sources =          \
 	gtkcellrendererspinner.h\
 	gtkcellrenderertext.h	\
 	gtkcellrenderertoggle.h	\
-	gtkcellsizerequest.h	\
 	gtkcellview.h		\
 	gtkcheckbutton.h	\
 	gtkcheckmenuitem.h	\
@@ -440,7 +439,6 @@ gtk_base_c_sources =            \
 	gtkcellrendererspinner.c\
 	gtkcellrenderertext.c	\
 	gtkcellrenderertoggle.c	\
-	gtkcellsizerequest.c	\
 	gtkcellview.c		\
 	gtkcheckbutton.c	\
 	gtkcheckmenuitem.c	\
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 71a0fa5..4484ae7 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -63,7 +63,6 @@
 #include <gtk/gtkcellrendererspinner.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtkcellrenderertoggle.h>
-#include <gtk/gtkcellsizerequest.h>
 #include <gtk/gtkcellview.h>
 #include <gtk/gtkcheckbutton.h>
 #include <gtk/gtkcheckmenuitem.h>
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index f97eae6..6730ce9 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -586,6 +586,12 @@ gtk_cell_renderer_activate
 gtk_cell_renderer_get_alignment
 gtk_cell_renderer_get_fixed_size
 gtk_cell_renderer_get_padding
+gtk_cell_renderer_get_preferred_height
+gtk_cell_renderer_get_preferred_height_for_width
+gtk_cell_renderer_get_preferred_size
+gtk_cell_renderer_get_preferred_width
+gtk_cell_renderer_get_preferred_width_for_height
+gtk_cell_renderer_get_request_mode
 gtk_cell_renderer_get_sensitive
 #ifndef GTK_DISABLE_DEPRECATED
 gtk_cell_renderer_get_size
@@ -666,18 +672,6 @@ gtk_cell_renderer_toggle_set_radio
 #endif
 #endif
 
-#if IN_HEADER(__GTK_CELL_SIZE_REQUEST_H__)
-#if IN_FILE(__GTK_CELL_SIZE_REQUEST_C__)
-gtk_cell_size_request_get_height
-gtk_cell_size_request_get_height_for_width
-gtk_cell_size_request_get_request_mode
-gtk_cell_size_request_get_size
-gtk_cell_size_request_get_type G_GNUC_CONST
-gtk_cell_size_request_get_width
-gtk_cell_size_request_get_width_for_height
-#endif
-#endif
-
 #if IN_HEADER(__GTK_CELL_VIEW_H__)
 #if IN_FILE(__GTK_CELL_VIEW_C__)
 gtk_cell_view_get_desired_height_for_width_of_row
diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c
index 486ff14..e0d6839 100644
--- a/gtk/gtkcellrenderer.c
+++ b/gtk/gtkcellrenderer.c
@@ -19,12 +19,12 @@
 
 #include "config.h"
 #include "gtkcellrenderer.h"
-#include "gtkcellsizerequest.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
 #include "gtktreeprivate.h"
 
+#define DEBUG_CELL_SIZE_REQUEST 0
 
 static void gtk_cell_renderer_init          (GtkCellRenderer      *cell);
 static void gtk_cell_renderer_class_init    (GtkCellRendererClass *class);
@@ -39,26 +39,25 @@ static void gtk_cell_renderer_set_property  (GObject              *object,
 static void set_cell_bg_color               (GtkCellRenderer      *cell,
 					     GdkColor             *color);
 
-/* Fallback GtkCellSizeRequest implementation to use remaining ->get_size() implementations */
-static void gtk_cell_renderer_cell_size_request_init   (GtkCellSizeRequestIface *iface);
-static void gtk_cell_renderer_get_width                (GtkCellSizeRequest      *cell,
-							GtkWidget               *widget,
-							gint                    *minimum_size,
-							gint                    *natural_size);
-static void gtk_cell_renderer_get_height               (GtkCellSizeRequest      *cell,
-							GtkWidget               *widget,
-							gint                    *minimum_size,
-							gint                    *natural_size);
-static void gtk_cell_renderer_get_height_for_width     (GtkCellSizeRequest      *cell,
-							GtkWidget               *widget,
-							gint                     width,
-							gint                    *minimum_height,
-							gint                    *natural_height);
-static void gtk_cell_renderer_get_width_for_height     (GtkCellSizeRequest      *cell,
-							GtkWidget               *widget,
-							gint                     height,
-							gint                    *minimum_width,
-							gint                    *natural_width);
+/* Fallback GtkCellRenderer    implementation to use remaining ->get_size() implementations */
+static void gtk_cell_renderer_real_get_preferred_width           (GtkCellRenderer         *cell,
+                                                                  GtkWidget               *widget,
+                                                                  gint                    *minimum_size,
+                                                                  gint                    *natural_size);
+static void gtk_cell_renderer_real_get_preferred_height          (GtkCellRenderer         *cell,
+                                                                  GtkWidget               *widget,
+                                                                  gint                    *minimum_size,
+                                                                  gint                    *natural_size);
+static void gtk_cell_renderer_real_get_preferred_height_for_width(GtkCellRenderer         *cell,
+                                                                  GtkWidget               *widget,
+                                                                  gint                     width,
+                                                                  gint                    *minimum_height,
+                                                                  gint                    *natural_height);
+static void gtk_cell_renderer_real_get_preferred_width_for_height(GtkCellRenderer         *cell,
+                                                                  GtkWidget               *widget,
+                                                                  gint                     height,
+                                                                  gint                    *minimum_width,
+                                                                  gint                    *natural_width);
 
 
 
@@ -114,47 +113,7 @@ enum {
 static guint  cell_renderer_signals[LAST_SIGNAL] = { 0 };
 
 
-/* Do a manual _get_type() here to avoid a deadlock implementing
- * the interface which we are a prerequisite of.
- */
-GType
-gtk_cell_renderer_get_type (void)
-{
-  static GType cell_renderer_type = 0;
-
-  if (G_UNLIKELY (cell_renderer_type == 0))
-    {
-      const GTypeInfo cell_renderer_info =
-      {
-	sizeof (GtkCellRendererClass),
-	NULL,		/* base_init */
-	NULL,           /* base_finalize */
-	(GClassInitFunc) gtk_cell_renderer_class_init,
-	NULL,		/* class_finalize */
-	NULL,		/* class_init */
-	sizeof (GtkCellRenderer),
-	0,		/* n_preallocs */
-	(GInstanceInitFunc) gtk_cell_renderer_init,
-	NULL,		/* value_table */
-      };
-
-      const GInterfaceInfo cell_size_request_info =
-      {
-	(GInterfaceInitFunc) gtk_cell_renderer_cell_size_request_init,
-	(GInterfaceFinalizeFunc) NULL,
-	NULL /* interface data */
-      };
-
-      cell_renderer_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer",
-						   &cell_renderer_info, G_TYPE_FLAG_ABSTRACT);
-
-      g_type_add_interface_static (cell_renderer_type, GTK_TYPE_CELL_SIZE_REQUEST,
-                                   &cell_size_request_info) ;
-    }
-
-  return cell_renderer_type;
-}
-
+G_DEFINE_ABSTRACT_TYPE(GtkCellRenderer, gtk_cell_renderer, GTK_TYPE_OBJECT)
 
 static void
 gtk_cell_renderer_init (GtkCellRenderer *cell)
@@ -190,6 +149,10 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
 
   class->render = NULL;
   class->get_size = NULL;
+  class->get_preferred_width            = gtk_cell_renderer_real_get_preferred_width;
+  class->get_preferred_height           = gtk_cell_renderer_real_get_preferred_height;
+  class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
+  class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
 
   /**
    * GtkCellRenderer::editing-canceled:
@@ -582,7 +545,7 @@ set_cell_bg_color (GtkCellRenderer *cell,
  * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
  *
  *
- * Deprecated: 3.0: Use gtk_cell_size_request_get_size() instead.
+ * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
  **/
 void
 gtk_cell_renderer_get_size (GtkCellRenderer    *cell,
@@ -597,8 +560,7 @@ gtk_cell_renderer_get_size (GtkCellRenderer    *cell,
 
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
-  gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (cell),
-				  widget, &request, NULL);
+  gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
 
   if (width)
     *width = request.width;
@@ -1093,21 +1055,11 @@ gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
 }
 
 static void
-gtk_cell_renderer_cell_size_request_init (GtkCellSizeRequestIface *iface)
-{
-  iface->get_width     = gtk_cell_renderer_get_width;
-  iface->get_height    = gtk_cell_renderer_get_height;
-
-  iface->get_width_for_height  = gtk_cell_renderer_get_width_for_height;
-  iface->get_height_for_width  = gtk_cell_renderer_get_height_for_width;
-}
-
-static void
-gtk_cell_renderer_get_desired_size (GtkCellSizeRequest   *cell,
-				    GtkWidget         *widget,
-				    GtkOrientation     orientation,
-				    gint              *minimum_size,
-				    gint              *natural_size)
+gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer   *cell,
+                                           GtkWidget         *widget,
+                                           GtkOrientation     orientation,
+                                           gint              *minimum_size,
+                                           gint              *natural_size)
 {
   GtkRequisition min_req;
 
@@ -1140,46 +1092,46 @@ gtk_cell_renderer_get_desired_size (GtkCellSizeRequest   *cell,
 }
 
 static void
-gtk_cell_renderer_get_width (GtkCellSizeRequest   *cell,
-			     GtkWidget         *widget,
-			     gint              *minimum_size,
-			     gint              *natural_size)
+gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
+                                            GtkWidget       *widget,
+                                            gint            *minimum_size,
+                                            gint            *natural_size)
 {
-  gtk_cell_renderer_get_desired_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, 
-				      minimum_size, natural_size);
+  gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, 
+                                             minimum_size, natural_size);
 }
 
 static void
-gtk_cell_renderer_get_height (GtkCellSizeRequest   *cell,
-			      GtkWidget         *widget,
-			      gint              *minimum_size,
-			      gint              *natural_size)
+gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
+                                             GtkWidget       *widget,
+                                             gint            *minimum_size,
+                                             gint            *natural_size)
 {
-  gtk_cell_renderer_get_desired_size (cell, widget, GTK_ORIENTATION_VERTICAL, 
-				      minimum_size, natural_size);
+  gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL, 
+                                             minimum_size, natural_size);
 }
 
 
 static void
-gtk_cell_renderer_get_height_for_width (GtkCellSizeRequest *cell,
-					GtkWidget       *widget,
-					gint             width,
-					gint            *minimum_height,
-					gint            *natural_height)
+gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
+                                                       GtkWidget       *widget,
+                                                       gint             width,
+                                                       gint            *minimum_height,
+                                                       gint            *natural_height)
 {
   /* Fall back on the height reported from ->get_size() */
-  gtk_cell_size_request_get_height (cell, widget, minimum_height, natural_height);
+  gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
 }
 
 static void
-gtk_cell_renderer_get_width_for_height (GtkCellSizeRequest *cell,
-					GtkWidget       *widget,
-					gint             height,
-					gint            *minimum_width,
-					gint            *natural_width)
+gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
+                                                       GtkWidget       *widget,
+                                                       gint             height,
+                                                       gint            *minimum_width,
+                                                       gint            *natural_width)
 {
   /* Fall back on the width reported from ->get_size() */
-  gtk_cell_size_request_get_width (cell, widget, minimum_width, natural_width);
+  gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
 }
 
 /* An internal convenience function for some containers to peek at the
@@ -1219,3 +1171,291 @@ _gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
       *y_offset = MAX (*y_offset, 0);
     }
 }
+
+/**
+ * gtk_cell_renderer_get_request_mode:
+ * @cell: a #GtkCellRenderer    instance
+ *
+ * Gets whether the cell renderer prefers a height-for-width layout
+ * or a width-for-height layout.
+ *
+ * Returns: The #GtkSizeRequestMode preferred by this renderer.
+ *
+ * Since: 3.0
+ */
+GtkSizeRequestMode
+gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
+{
+  GtkCellRendererClass *klass;
+
+  g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
+
+  klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+  if (klass->get_request_mode)
+    return klass->get_request_mode (cell);
+
+  /* By default cell renderers are height-for-width. */
+  return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
+/**
+ * gtk_cell_renderer_get_preferred_width:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @minimum_size: location to store the minimum size, or %NULL
+ * @natural_size: location to store the natural size, or %NULL
+ *
+ * Retreives a renderer's natural size when rendered to @widget.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
+                                       GtkWidget       *widget,
+                                       gint            *minimum_size,
+                                       gint            *natural_size)
+{
+  GtkCellRendererClass *klass;
+  gint width;
+
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (NULL != minimum_size || NULL != natural_size);
+
+  gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
+
+  if (width < 0)
+    {
+      klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+      klass->get_preferred_width (cell, widget, minimum_size, natural_size);
+    }
+  else
+    {
+      if (minimum_size)
+	*minimum_size = width;
+      if (natural_size)
+	*natural_size = width;
+    }
+
+#if DEBUG_CELL_SIZE_REQUEST
+  g_message ("%s returning minimum width: %d and natural width: %d",
+	     G_OBJECT_TYPE_NAME (cell), 
+	     minimum_size ? *minimum_size : 20000, 
+	     natural_size ? *natural_size : 20000);
+#endif
+}
+
+
+/**
+ * gtk_cell_renderer_get_preferred_height:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @minimum_size: location to store the minimum size, or %NULL
+ * @natural_size: location to store the natural size, or %NULL
+ *
+ * Retreives a renderer's natural size when rendered to @widget.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
+                                        GtkWidget       *widget,
+                                        gint            *minimum_size,
+                                        gint            *natural_size)
+{
+  GtkCellRendererClass *klass;
+  gint height;
+
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (NULL != minimum_size || NULL != natural_size);
+
+  gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
+
+  if (height < 0)
+    {
+      klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+      klass->get_preferred_height (cell, widget, minimum_size, natural_size);
+    }
+  else
+    {
+      if (minimum_size)
+	*minimum_size = height;
+      if (natural_size)
+	*natural_size = height;
+    }
+
+#if DEBUG_CELL_SIZE_REQUEST
+  g_message ("%s returning minimum height: %d and natural height: %d",
+	     G_OBJECT_TYPE_NAME (cell), 
+	     minimum_size ? *minimum_size : 20000, 
+	     natural_size ? *natural_size : 20000);
+#endif
+}
+
+
+/**
+ * gtk_cell_renderer_get_preferred_width_for_height:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @height: the size which is available for allocation
+ * @minimum_width: location for storing the minimum size, or %NULL
+ * @natural_width: location for storing the preferred size, or %NULL
+ *
+ * Retreives a cell renderers's minimum and natural width if it were rendered to 
+ * @widget with the specified @height.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
+                                                  GtkWidget       *widget,
+                                                  gint             height,
+                                                  gint            *minimum_width,
+                                                  gint            *natural_width)
+{
+  GtkCellRendererClass *klass;
+  gint width;
+
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (NULL != minimum_width || NULL != natural_width);
+
+  gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
+
+  if (width < 0)
+    {
+      klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+      klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
+    }
+  else
+    {
+      if (minimum_width)
+	*minimum_width = width;
+      if (natural_width)
+	*natural_width = width;
+    }
+
+#if DEBUG_CELL_SIZE_REQUEST
+  g_message ("%s width for height: %d is minimum %d and natural: %d",
+	     G_OBJECT_TYPE_NAME (cell), height,
+	     minimum_width ? *minimum_width : 20000, 
+	     natural_width ? *natural_width : 20000);
+#endif
+}
+
+/**
+ * gtk_cell_renderer_get_preferred_height_for_width:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @width: the size which is available for allocation
+ * @minimum_height: location for storing the minimum size, or %NULL
+ * @natural_height: location for storing the preferred size, or %NULL
+ *
+ * Retreives a cell renderers's minimum and natural height if it were rendered to 
+ * @widget with the specified @width.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
+                                                  GtkWidget       *widget,
+                                                  gint             width,
+                                                  gint            *minimum_height,
+                                                  gint            *natural_height)
+{
+  GtkCellRendererClass *klass;
+  gint height;
+
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (NULL != minimum_height || NULL != natural_height);
+
+  gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
+
+  if (height < 0)
+    {
+      klass = GTK_CELL_RENDERER_GET_CLASS (cell);
+      klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
+    }
+  else
+    {
+      if (minimum_height)
+	*minimum_height = height;
+      if (natural_height)
+	*natural_height = height;
+    }
+
+#if DEBUG_CELL_SIZE_REQUEST
+  g_message ("%s height for width: %d is minimum %d and natural: %d",
+	     G_OBJECT_TYPE_NAME (cell), width,
+	     minimum_height ? *minimum_height : 20000, 
+	     natural_height ? *natural_height : 20000);
+#endif
+}
+
+/**
+ * gtk_cell_renderer_get_preferred_size:
+ * @cell: a #GtkCellRenderer instance
+ * @widget: the #GtkWidget this cell will be rendering to
+ * @request_natural: Whether to base the contextual request off of the
+ *     base natural or the base minimum
+ * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
+ * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
+ *
+ * Retrieves the minimum and natural size of a cell taking
+ * into account the widget's preference for height-for-width management.
+ *
+ * If request_natural is specified, the non-contextual natural value will
+ * be used to make the contextual request; otherwise the minimum will be used.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
+                                      GtkWidget       *widget,
+                                      GtkRequisition  *minimum_size,
+                                      GtkRequisition  *natural_size)
+{
+  gint min_width, nat_width;
+  gint min_height, nat_height;
+
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+
+  if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+    {
+      gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
+
+      if (minimum_size)
+	{
+	  minimum_size->width = min_width;
+	  gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
+                                                            &minimum_size->height, NULL);
+	}
+
+      if (natural_size)
+	{
+	  natural_size->width = nat_width;
+	  gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
+                                                            NULL, &natural_size->height);
+	}
+    }
+  else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
+    {
+      gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
+
+      if (minimum_size)
+	{
+	  minimum_size->height = min_height;
+	  gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
+                                                            &minimum_size->width, NULL);
+	}
+
+      if (natural_size)
+	{
+	  natural_size->height = nat_height;
+	  gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
+                                                            NULL, &natural_size->width);
+	}
+    }
+}
diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h
index 29fda86..934406b 100644
--- a/gtk/gtkcellrenderer.h
+++ b/gtk/gtkcellrenderer.h
@@ -69,33 +69,52 @@ struct _GtkCellRendererClass
   GtkObjectClass parent_class;
 
   /* vtable - not signals */
-  void             (* get_size)      (GtkCellRenderer      *cell,
-				      GtkWidget            *widget,
-				      GdkRectangle         *cell_area,
-				      gint                 *x_offset,
-				      gint                 *y_offset,
-				      gint                 *width,
-				      gint                 *height);
-  void             (* render)        (GtkCellRenderer      *cell,
-                                      cairo_t              *cr,
-				      GtkWidget            *widget,
-				      const GdkRectangle   *background_area,
-				      const GdkRectangle   *cell_area,
-				      GtkCellRendererState  flags);
-  gboolean         (* activate)      (GtkCellRenderer      *cell,
-				      GdkEvent             *event,
-				      GtkWidget            *widget,
-				      const gchar          *path,
-				      GdkRectangle         *background_area,
-				      GdkRectangle         *cell_area,
-				      GtkCellRendererState  flags);
-  GtkCellEditable *(* start_editing) (GtkCellRenderer      *cell,
-				      GdkEvent             *event,
-				      GtkWidget            *widget,
-				      const gchar          *path,
-				      GdkRectangle         *background_area,
-				      GdkRectangle         *cell_area,
-				      GtkCellRendererState  flags);
+  GtkSizeRequestMode (* get_request_mode)                (GtkCellRenderer      *cell);
+  void               (* get_preferred_width)             (GtkCellRenderer      *cell,
+                                                          GtkWidget            *widget,
+                                                          gint                 *minimum_size,
+                                                          gint                 *natural_size);
+  void               (* get_preferred_height_for_width)  (GtkCellRenderer      *cell,
+                                                          GtkWidget            *widget,
+                                                          gint                  width,
+                                                          gint                 *minimum_height,
+                                                          gint                 *natural_height);
+  void               (* get_preferred_height)            (GtkCellRenderer      *cell,
+                                                          GtkWidget            *widget,
+                                                          gint                 *minimum_size,
+                                                          gint                 *natural_size);
+  void               (* get_preferred_width_for_height)  (GtkCellRenderer      *cell,
+                                                          GtkWidget            *widget,
+                                                          gint                  height,
+                                                          gint                 *minimum_width,
+                                                          gint                 *natural_width);
+  void               (* get_size)                        (GtkCellRenderer      *cell,
+                                                          GtkWidget            *widget,
+                                                          GdkRectangle         *cell_area,
+                                                          gint                 *x_offset,
+                                                          gint                 *y_offset,
+                                                          gint                 *width,
+                                                          gint                 *height);
+  void               (* render)                          (GtkCellRenderer      *cell,
+                                                          cairo_t              *cr,
+                                                          GtkWidget            *widget,
+                                                          const GdkRectangle   *background_area,
+                                                          const GdkRectangle   *cell_area,
+                                                          GtkCellRendererState  flags);
+  gboolean           (* activate)                        (GtkCellRenderer      *cell,
+                                                          GdkEvent             *event,
+                                                          GtkWidget            *widget,
+                                                          const gchar          *path,
+                                                          GdkRectangle         *background_area,
+                                                          GdkRectangle         *cell_area,
+                                                          GtkCellRendererState  flags);
+  GtkCellEditable *  (* start_editing)                   (GtkCellRenderer      *cell,
+                                                          GdkEvent             *event,
+                                                          GtkWidget            *widget,
+                                                          const gchar          *path,
+                                                          GdkRectangle         *background_area,
+                                                          GdkRectangle         *cell_area,
+                                                          GtkCellRendererState  flags);
 
   /* Signals */
   void (* editing_canceled) (GtkCellRenderer *cell);
@@ -108,8 +127,31 @@ struct _GtkCellRendererClass
   void (*_gtk_reserved2) (void);
 };
 
-GType            gtk_cell_renderer_get_type       (void) G_GNUC_CONST;
-
+GType              gtk_cell_renderer_get_type       (void) G_GNUC_CONST;
+
+GtkSizeRequestMode gtk_cell_renderer_get_request_mode               (GtkCellRenderer    *cell);
+void               gtk_cell_renderer_get_preferred_width            (GtkCellRenderer    *cell,
+                                                                     GtkWidget          *widget,
+                                                                     gint               *minimum_size,
+                                                                     gint               *natural_size);
+void               gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer    *cell,
+                                                                     GtkWidget          *widget,
+                                                                     gint                width,
+                                                                     gint               *minimum_height,
+                                                                     gint               *natural_height);
+void               gtk_cell_renderer_get_preferred_height           (GtkCellRenderer    *cell,
+                                                                     GtkWidget          *widget,
+                                                                     gint               *minimum_size,
+                                                                     gint               *natural_size);
+void               gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer    *cell,
+                                                                     GtkWidget          *widget,
+                                                                     gint                height,
+                                                                     gint               *minimum_width,
+                                                                     gint               *natural_width);
+void               gtk_cell_renderer_get_preferred_size             (GtkCellRenderer    *cell,
+                                                                     GtkWidget          *widget,
+                                                                     GtkRequisition     *minimum_size,
+                                                                     GtkRequisition     *natural_size);
 #ifndef GTK_DISABLE_DEPRECATED
 void             gtk_cell_renderer_get_size       (GtkCellRenderer      *cell,
 						   GtkWidget            *widget,
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c
index d4531ee..4cf85d9 100644
--- a/gtk/gtkcellrenderertext.c
+++ b/gtk/gtkcellrenderertext.c
@@ -24,7 +24,6 @@
 #include <stdlib.h>
 
 #include "gtkeditable.h"
-#include "gtkcellsizerequest.h"
 #include "gtkentry.h"
 #include "gtksizerequest.h"
 #include "gtkmarshalers.h"
@@ -58,20 +57,19 @@ static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer
 							      GdkRectangle         *cell_area,
 							      GtkCellRendererState  flags);
 
-static void       gtk_cell_renderer_text_cell_size_request_init (GtkCellSizeRequestIface  *iface);
-static void       gtk_cell_renderer_text_get_width              (GtkCellSizeRequest       *cell,
-							        GtkWidget                 *widget,
-							        gint                      *minimal_size,
-							        gint                      *natural_size);
-static void       gtk_cell_renderer_text_get_height            (GtkCellSizeRequest        *cell,
-							        GtkWidget                 *widget,
-							        gint                      *minimal_size,
-							        gint                      *natural_size);
-static void       gtk_cell_renderer_text_get_height_for_width  (GtkCellSizeRequest        *cell,
-								GtkWidget                 *widget,
-								gint                       width,
-								gint                      *minimum_height,
-								gint                      *natural_height);
+static void       gtk_cell_renderer_text_get_preferred_width            (GtkCellRenderer       *cell,
+                                                                         GtkWidget             *widget,
+                                                                         gint                  *minimal_size,
+                                                                         gint                  *natural_size);
+static void       gtk_cell_renderer_text_get_preferred_height           (GtkCellRenderer       *cell,
+                                                                         GtkWidget             *widget,
+                                                                         gint                  *minimal_size,
+                                                                         gint                  *natural_size);
+static void       gtk_cell_renderer_text_get_preferred_height_for_width (GtkCellRenderer       *cell,
+                                                                         GtkWidget             *widget,
+                                                                         gint                   width,
+                                                                         gint                  *minimum_height,
+                                                                         gint                  *natural_height);
 
 enum {
   EDITED,
@@ -183,9 +181,7 @@ struct _GtkCellRendererTextPrivate
   gulong entry_menu_popdown_timeout;
 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER,
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_SIZE_REQUEST,
-                                                gtk_cell_renderer_text_cell_size_request_init))
+G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
 
 static void
 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
@@ -225,6 +221,9 @@ gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
 
   cell_class->render = gtk_cell_renderer_text_render;
   cell_class->start_editing = gtk_cell_renderer_text_start_editing;
+  cell_class->get_preferred_width = gtk_cell_renderer_text_get_preferred_width;
+  cell_class->get_preferred_height = gtk_cell_renderer_text_get_preferred_height;
+  cell_class->get_preferred_height_for_width = gtk_cell_renderer_text_get_preferred_height_for_width;
 
   g_object_class_install_property (object_class,
                                    PROP_TEXT,
@@ -2012,18 +2011,10 @@ gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer
 }
 
 static void
-gtk_cell_renderer_text_cell_size_request_init (GtkCellSizeRequestIface *iface)
-{
-  iface->get_width            = gtk_cell_renderer_text_get_width;
-  iface->get_height           = gtk_cell_renderer_text_get_height;
-  iface->get_height_for_width = gtk_cell_renderer_text_get_height_for_width;
-}
-
-static void
-gtk_cell_renderer_text_get_width (GtkCellSizeRequest *cell,
-				  GtkWidget          *widget,
-				  gint               *minimum_size,
-				  gint               *natural_size)
+gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
+                                            GtkWidget       *widget,
+                                            gint            *minimum_size,
+                                            gint            *natural_size)
 {
   GtkCellRendererTextPrivate    *priv;
   GtkCellRendererText        *celltext;
@@ -2049,7 +2040,7 @@ gtk_cell_renderer_text_get_width (GtkCellSizeRequest *cell,
 
   style = gtk_widget_get_style (widget);
 
-  gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, NULL);
+  gtk_cell_renderer_get_padding (cell, &xpad, NULL);
 
   layout = get_layout (celltext, widget, NULL, 0);
 
@@ -2114,11 +2105,11 @@ gtk_cell_renderer_text_get_width (GtkCellSizeRequest *cell,
 }
 
 static void
-gtk_cell_renderer_text_get_height_for_width (GtkCellSizeRequest *cell,
-					     GtkWidget          *widget,
-					     gint                width,
-					     gint               *minimum_height,
-					     gint               *natural_height)
+gtk_cell_renderer_text_get_preferred_height_for_width (GtkCellRenderer *cell,
+                                                       GtkWidget       *widget,
+                                                       gint             width,
+                                                       gint            *minimum_height,
+                                                       gint            *natural_height)
 {
   GtkCellRendererTextPrivate    *priv;
   GtkCellRendererText        *celltext;
@@ -2129,7 +2120,7 @@ gtk_cell_renderer_text_get_height_for_width (GtkCellSizeRequest *cell,
   celltext = GTK_CELL_RENDERER_TEXT (cell);
   priv = celltext->priv;
 
-  gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, &ypad);
+  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
 
   layout = get_layout (celltext, widget, NULL, 0);
 
@@ -2146,10 +2137,10 @@ gtk_cell_renderer_text_get_height_for_width (GtkCellSizeRequest *cell,
 }
 
 static void
-gtk_cell_renderer_text_get_height (GtkCellSizeRequest *cell,
-				   GtkWidget          *widget,
-				   gint               *minimum_size,
-				   gint               *natural_size)
+gtk_cell_renderer_text_get_preferred_height (GtkCellRenderer *cell,
+                                             GtkWidget       *widget,
+                                             gint            *minimum_size,
+                                             gint            *natural_size)
 {
   gint min_width;
 
@@ -2160,8 +2151,8 @@ gtk_cell_renderer_text_get_height (GtkCellSizeRequest *cell,
    * Note this code path wont be followed by GtkTreeView which is
    * height-for-width specifically.
    */
-  gtk_cell_size_request_get_width (cell, widget, &min_width, NULL);
-  gtk_cell_renderer_text_get_height_for_width (cell, widget, min_width,
-					       minimum_size, natural_size);
+  gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, NULL);
+  gtk_cell_renderer_text_get_preferred_height_for_width (cell, widget, min_width,
+                                                         minimum_size, natural_size);
 }
 
diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c
index 9fbcd30..258aeeb 100644
--- a/gtk/gtkcellview.c
+++ b/gtk/gtkcellview.c
@@ -24,7 +24,6 @@
 #include "gtkintl.h"
 #include "gtkcellrenderertext.h"
 #include "gtkcellrendererpixbuf.h"
-#include "gtkcellsizerequest.h"
 #include "gtkprivate.h"
 #include "gtksizerequest.h"
 #include <gobject/gmarshal.h>
@@ -1218,8 +1217,8 @@ gtk_cell_view_get_preferred_width  (GtkWidget *widget,
 	      natural += cellview->priv->spacing;
 	    }
 
-	  gtk_cell_size_request_get_width (GTK_CELL_SIZE_REQUEST (info->cell),
-                                           GTK_WIDGET (cellview), &cell_min, &cell_nat);
+	  gtk_cell_renderer_get_preferred_width (info->cell,
+                                                 GTK_WIDGET (cellview), &cell_min, &cell_nat);
 	  
 	  info->requested_width = cell_min;
 	  info->natural_width   = cell_nat;
@@ -1294,10 +1293,10 @@ gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
         {
 	  GtkRequestedSize requested;
 
-	  gtk_cell_size_request_get_width (GTK_CELL_SIZE_REQUEST (info->cell),
-                                           GTK_WIDGET (cellview), 
-                                           &requested.minimum_size, 
-                                           &requested.natural_size);
+	  gtk_cell_renderer_get_preferred_width (GTK_CELL_RENDERER (info->cell),
+                                                 GTK_WIDGET (cellview), 
+                                                 &requested.minimum_size, 
+                                                 &requested.natural_size);
 
 	  requested.data = info;
 	  g_array_append_val (array, requested);
@@ -1350,9 +1349,9 @@ gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
 	    }
 
 	  /* Get the height for the real width of this cell */
-	  gtk_cell_size_request_get_height_for_width (GTK_CELL_SIZE_REQUEST (info->cell),
-                                                      GTK_WIDGET (widget),
-                                                      cell_width, &cell_minimum, &cell_natural);
+	  gtk_cell_renderer_get_preferred_height_for_width (GTK_CELL_RENDERER (info->cell),
+                                                            GTK_WIDGET (widget),
+                                                            cell_width, &cell_minimum, &cell_natural);
 
 	  minimum = MAX (minimum, cell_minimum);
 	  natural = MAX (natural, cell_natural);
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index ffd0b50..fc67a30 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -29,7 +29,6 @@
 #include "gtkcellrenderer.h"
 #include "gtkcellrenderertext.h"
 #include "gtkcellrendererpixbuf.h"
-#include "gtkcellsizerequest.h"
 #include "gtkmarshalers.h"
 #include "gtkbindings.h"
 #include "gtkdnd.h"
@@ -2969,9 +2968,9 @@ adjust_wrap_width (GtkIconView     *icon_view,
       pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
 				     icon_view->priv->pixbuf_cell);
 
-      gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (pixbuf_info->cell),
-                                      GTK_WIDGET (icon_view),
-                                      &min_size, NULL);
+      gtk_cell_renderer_get_preferred_size (pixbuf_info->cell,
+                                            GTK_WIDGET (icon_view),
+                                            &min_size, NULL);
 
       if (icon_view->priv->item_width > 0)
 	item_width = icon_view->priv->item_width;
@@ -3031,9 +3030,9 @@ gtk_icon_view_calculate_item_size (GtkIconView     *icon_view,
       if (!gtk_cell_renderer_get_visible (info->cell))
 	continue;
 
-      gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
-                                      GTK_WIDGET (icon_view),
-                                      &min_size, NULL);
+      gtk_cell_renderer_get_preferred_size (info->cell,
+                                            GTK_WIDGET (icon_view),
+                                            &min_size, NULL);
       item->box[info->position].width = min_size.width;
       item->box[info->position].height = min_size.height;
 
@@ -3113,9 +3112,9 @@ gtk_icon_view_calculate_item_size2 (GtkIconView     *icon_view,
 	    cell_area.height = max_height[i];
 	  }
 
-        gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
-                                        GTK_WIDGET (icon_view),
-                                        &min_size, NULL);
+        gtk_cell_renderer_get_preferred_size (info->cell,
+                                              GTK_WIDGET (icon_view),
+                                              &min_size, NULL);
         item->box[info->position].width  = min_size.width;
         item->box[info->position].height = min_size.height;
 
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index 9a14311..16c376d 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -23,7 +23,6 @@
 
 #include <string.h>
 
-#include "gtkcellsizerequest.h"
 #include "gtktreeview.h"
 #include "gtktreeprivate.h"
 #include "gtkcelllayout.h"
@@ -2641,9 +2640,9 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn  *tree_column,
       if (first_cell == FALSE && width)
 	*width += tree_column->spacing;
 
-      gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
-                                      GTK_WIDGET (tree_column->tree_view),
-                                      &min_size, NULL);
+      gtk_cell_renderer_get_preferred_size (info->cell,
+                                            GTK_WIDGET (tree_column->tree_view),
+                                            &min_size, NULL);
 
       if (height)
 	* height = MAX (*height, min_size.height + focus_line_width * 2);
@@ -2838,9 +2837,9 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
           gint x_offset, y_offset;
           GtkRequisition min_size;
 
-          gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
-                                          tree_column->tree_view,
-                                          &min_size, NULL);
+          gtk_cell_renderer_get_preferred_size (info->cell,
+                                                tree_column->tree_view,
+                                                &min_size, NULL);
 
           _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
                                           gtk_widget_get_direction (tree_column->tree_view),
@@ -3006,9 +3005,9 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
           gint x_offset, y_offset;
           GtkRequisition min_size;
 
-          gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
-                                          tree_column->tree_view,
-                                          &min_size, NULL);
+          gtk_cell_renderer_get_preferred_size (info->cell,
+                                                tree_column->tree_view,
+                                                &min_size, NULL);
 
           _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
                                           gtk_widget_get_direction (tree_column->tree_view),
diff --git a/modules/other/gail/gailtextcell.c b/modules/other/gail/gailtextcell.c
index 6258137..2cbf5bf 100644
--- a/modules/other/gail/gailtextcell.c
+++ b/modules/other/gail/gailtextcell.c
@@ -605,9 +605,9 @@ gail_text_cell_get_character_extents (AtkText          *text,
   gail_cell_parent_get_cell_area (GAIL_CELL_PARENT (parent), GAIL_CELL (text),
                                   &rendered_rect);
 
-  gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (gtk_renderer),
-                                  widget,
-                                  &min_size, NULL);
+  gtk_cell_renderer_get_preferred_size (GTK_CELL_RENDERER (gtk_renderer),
+                                        widget,
+                                        &min_size, NULL);
 
   _gtk_cell_renderer_calc_offset (GTK_CELL_RENDERER (gtk_renderer), &rendered_rect,
                                   gtk_widget_get_direction (widget),
@@ -672,9 +672,9 @@ gail_text_cell_get_offset_at_point (AtkText          *text,
   gail_cell_parent_get_cell_area (GAIL_CELL_PARENT (parent), GAIL_CELL (text),
                                   &rendered_rect);
 
-  gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (gtk_renderer),
-                                  widget,
-                                  &min_size, NULL);
+  gtk_cell_renderer_get_preferred_size (GTK_CELL_RENDERER (gtk_renderer),
+                                        widget,
+                                        &min_size, NULL);
   _gtk_cell_renderer_calc_offset (GTK_CELL_RENDERER (gtk_renderer), &rendered_rect,
                                   gtk_widget_get_direction (widget),
                                   min_size.width, min_size.height,



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