[gtk+/gtk-3-0] Revert "Added GTK_SIZE_REQUEST_CONSTANT_SIZE to GtkSizeRequestMode"



commit c7f02139bfd6a90d2499b4c3e94fbf8db137d352
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Apr 2 11:13:16 2011 -0400

    Revert "Added GTK_SIZE_REQUEST_CONSTANT_SIZE to GtkSizeRequestMode"
    
    This reverts commit bb39638c4f9fadca4a9254d1f6d3f18b72ee3d06.

 gtk/gtkbin.c         |   14 +++++++++++++
 gtk/gtkbox.c         |   12 +++++++++++
 gtk/gtkcellview.c    |   11 ----------
 gtk/gtkcontainer.c   |   54 --------------------------------------------------
 gtk/gtkenums.h       |    4 +--
 gtk/gtkgrid.c        |   21 +++++++++++++++---
 gtk/gtklabel.c       |    8 ++----
 gtk/gtksizerequest.c |   40 +++++++-----------------------------
 gtk/gtkwidget.c      |    4 +-
 gtk/gtkwidget.h      |   15 +++++--------
 10 files changed, 63 insertions(+), 120 deletions(-)
---
diff --git a/gtk/gtkbin.c b/gtk/gtkbin.c
index 331ae53..af3efea 100644
--- a/gtk/gtkbin.c
+++ b/gtk/gtkbin.c
@@ -59,6 +59,7 @@ static void gtk_bin_forall      (GtkContainer   *container,
 static GType gtk_bin_child_type (GtkContainer   *container);
 
 
+static GtkSizeRequestMode gtk_bin_get_request_mode                (GtkWidget           *widget);
 static void               gtk_bin_get_preferred_width_for_height  (GtkWidget           *widget,
                                                                    gint                 height,
                                                                    gint                *minimum_width,
@@ -76,6 +77,7 @@ gtk_bin_class_init (GtkBinClass *class)
   GtkWidgetClass *widget_class = (GtkWidgetClass*) class;
   GtkContainerClass *container_class = (GtkContainerClass*) class;
 
+  widget_class->get_request_mode               = gtk_bin_get_request_mode;
   widget_class->get_preferred_width_for_height = gtk_bin_get_preferred_width_for_height;
   widget_class->get_preferred_height_for_width = gtk_bin_get_preferred_height_for_width;
 
@@ -182,6 +184,18 @@ gtk_bin_forall (GtkContainer *container,
  * deduce a common code path for the get_width_for_height()/get_height_for_width()
  * cases by using the delta of the base size requsts.
  */
+static GtkSizeRequestMode
+gtk_bin_get_request_mode (GtkWidget           *widget)
+{
+  GtkBin *bin = GTK_BIN (widget);
+  GtkBinPrivate *priv = bin->priv;
+
+  if (priv->child)
+    return gtk_widget_get_request_mode (priv->child);
+
+  return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
 static void
 get_child_padding_delta (GtkBin *bin,
 			 gint   *delta_h,
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index bc9693d..f508173 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -185,6 +185,7 @@ static void gtk_box_get_child_property (GtkContainer   *container,
 static GType gtk_box_child_type        (GtkContainer   *container);
 
 
+static GtkSizeRequestMode gtk_box_get_request_mode               (GtkWidget           *widget);
 static void               gtk_box_get_preferred_width            (GtkWidget           *widget,
                                                                   gint                *minimum_size,
                                                                   gint                *natural_size);
@@ -215,6 +216,7 @@ gtk_box_class_init (GtkBoxClass *class)
   object_class->get_property = gtk_box_get_property;
 
   widget_class->size_allocate                  = gtk_box_size_allocate;
+  widget_class->get_request_mode               = gtk_box_get_request_mode;
   widget_class->get_preferred_width            = gtk_box_get_preferred_width;
   widget_class->get_preferred_height           = gtk_box_get_preferred_height;
   widget_class->get_preferred_height_for_width = gtk_box_get_preferred_height_for_width;
@@ -868,6 +870,16 @@ gtk_box_pack (GtkBox      *box,
   gtk_widget_thaw_child_notify (child);
 }
 
+
+static GtkSizeRequestMode
+gtk_box_get_request_mode  (GtkWidget       *widget)
+{
+  GtkBoxPrivate *private = GTK_BOX (widget)->priv;
+
+  return (private->orientation == GTK_ORIENTATION_VERTICAL) ?
+    GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH : GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
+
 static void
 gtk_box_get_size (GtkWidget      *widget,
 		  GtkOrientation  orientation,
diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c
index 051bae5..d6a87af 100644
--- a/gtk/gtkcellview.c
+++ b/gtk/gtkcellview.c
@@ -93,7 +93,6 @@ static void       gtk_cell_view_buildable_custom_tag_end       (GtkBuildable
 								const gchar   	      *tagname,
 								gpointer      	      *data);
 
-static GtkSizeRequestMode gtk_cell_view_get_request_mode       (GtkWidget             *widget);
 static void       gtk_cell_view_get_preferred_width            (GtkWidget             *widget,
 								gint                  *minimum_size,
 								gint                  *natural_size);
@@ -176,7 +175,6 @@ gtk_cell_view_class_init (GtkCellViewClass *klass)
 
   widget_class->draw                           = gtk_cell_view_draw;
   widget_class->size_allocate                  = gtk_cell_view_size_allocate;
-  widget_class->get_request_mode               = gtk_cell_view_get_request_mode;
   widget_class->get_preferred_width            = gtk_cell_view_get_preferred_width;
   widget_class->get_preferred_height           = gtk_cell_view_get_preferred_height;
   widget_class->get_preferred_width_for_height = gtk_cell_view_get_preferred_width_for_height;
@@ -639,15 +637,6 @@ gtk_cell_view_request_model (GtkCellView        *cellview,
     }
 }
 
-static GtkSizeRequestMode 
-gtk_cell_view_get_request_mode (GtkWidget *widget)
-{
-  GtkCellView        *cellview = GTK_CELL_VIEW (widget);
-  GtkCellViewPrivate *priv = cellview->priv;
-
-  return gtk_cell_area_get_request_mode (priv->area);
-}
-
 static void
 gtk_cell_view_get_preferred_width  (GtkWidget *widget,
                                     gint      *minimum_size,
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 4f0d72c..61ed85a 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -239,7 +239,6 @@ struct _GtkContainerPrivate
   guint need_resize        : 1;
   guint reallocate_redraws : 1;
   guint resize_mode        : 2;
-  guint request_mode       : 2;
 };
 
 enum {
@@ -308,7 +307,6 @@ static void     gtk_container_adjust_size_allocation (GtkWidget       *widget,
                                                       gint            *natural_size,
                                                       gint            *allocated_pos,
                                                       gint            *allocated_size);
-static GtkSizeRequestMode gtk_container_get_request_mode (GtkWidget   *widget);
 
 static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
                                                           GtkWidget    *child);
@@ -439,7 +437,6 @@ gtk_container_class_init (GtkContainerClass *class)
 
   widget_class->adjust_size_request = gtk_container_adjust_size_request;
   widget_class->adjust_size_allocation = gtk_container_adjust_size_allocation;
-  widget_class->get_request_mode = gtk_container_get_request_mode;
 
   class->add = gtk_container_add_unimplemented;
   class->remove = gtk_container_remove_unimplemented;
@@ -1854,57 +1851,6 @@ gtk_container_adjust_size_allocation (GtkWidget         *widget,
                                         allocated_size);
 }
 
-typedef struct {
-  gint hfw;
-  gint wfh;
-} RequestModeCount;
-
-static void
-count_request_modes (GtkWidget        *widget,
-		     RequestModeCount *count)
-{
-  GtkSizeRequestMode mode = gtk_widget_get_request_mode (widget);
-
-  switch (mode)
-    {
-    case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
-      count->hfw++;
-      break;
-    case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
-      count->wfh++;
-      break;
-    case GTK_SIZE_REQUEST_CONSTANT_SIZE:
-    default:
-      break;
-    }
-}
-
-static GtkSizeRequestMode 
-gtk_container_get_request_mode (GtkWidget *widget)
-{
-  GtkContainer        *container = GTK_CONTAINER (widget);
-  GtkContainerPrivate *priv      = container->priv;
-
-  /* Recalculate the request mode of the children by majority
-   * vote whenever the internal content changes */
-  if (_gtk_widget_get_width_request_needed (widget) ||
-      _gtk_widget_get_height_request_needed (widget))
-    {
-      RequestModeCount count = { 0, 0 };
-
-      gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
-
-      if (!count.hfw && !count.wfh)
-	priv->request_mode = GTK_SIZE_REQUEST_CONSTANT_SIZE;
-      else
-	priv->request_mode = count.wfh > count.hfw ? 
-	  GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
-	  GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
-    }
-
-  return priv->request_mode;
-}
-
 /**
  * gtk_container_class_handle_border_width:
  * @klass: the class struct of a #GtkContainer subclass
diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h
index 95cfb29..07b034c 100644
--- a/gtk/gtkenums.h
+++ b/gtk/gtkenums.h
@@ -793,7 +793,6 @@ typedef enum
  * GtkSizeRequestMode:
  * @GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: Prefer height-for-width geometry management
  * @GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: Prefer width-for-height geometry management
- * @GTK_SIZE_REQUEST_CONSTANT_SIZE: Dont trade height-for-width or width-for-height
  * 
  * Specifies a preference for height-for-width or
  * width-for-height geometry management.
@@ -801,8 +800,7 @@ typedef enum
 typedef enum
 {
   GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH = 0,
-  GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT,
-  GTK_SIZE_REQUEST_CONSTANT_SIZE
+  GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT
 } GtkSizeRequestMode;
 
 /**
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index 4719857..bd305f6 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -458,6 +458,17 @@ gtk_grid_child_type (GtkContainer *container)
   return GTK_TYPE_WIDGET;
 }
 
+static GtkSizeRequestMode
+gtk_grid_get_request_mode (GtkWidget *widget)
+{
+  GtkGridPrivate *priv = GTK_GRID (widget)->priv;
+
+  if (priv->orientation == GTK_ORIENTATION_VERTICAL)
+    return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+  else
+    return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
+
 /* Calculates the min and max numbers for both orientations.
  */
 static void
@@ -1093,7 +1104,8 @@ gtk_grid_get_preferred_width (GtkWidget *widget,
 {
   GtkGrid *grid = GTK_GRID (widget);
 
-  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
+  if (gtk_grid_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
+
     gtk_grid_get_size_for_size (grid, GTK_ORIENTATION_HORIZONTAL, 0, minimum, natural);
   else
     gtk_grid_get_size (grid, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
@@ -1106,7 +1118,7 @@ gtk_grid_get_preferred_height (GtkWidget *widget,
 {
   GtkGrid *grid = GTK_GRID (widget);
 
-  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+  if (gtk_grid_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
     gtk_grid_get_size_for_size (grid, GTK_ORIENTATION_VERTICAL, 0, minimum, natural);
   else
     gtk_grid_get_size (grid, GTK_ORIENTATION_VERTICAL, minimum, natural);
@@ -1120,7 +1132,7 @@ gtk_grid_get_preferred_width_for_height (GtkWidget *widget,
 {
   GtkGrid *grid = GTK_GRID (widget);
 
-  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
+  if (gtk_grid_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
     gtk_grid_get_size_for_size (grid, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
   else
     gtk_grid_get_size (grid, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
@@ -1134,7 +1146,7 @@ gtk_grid_get_preferred_height_for_width (GtkWidget *widget,
 {
   GtkGrid *grid = GTK_GRID (widget);
 
-  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+  if (gtk_grid_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
     gtk_grid_get_size_for_size (grid, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
   else
     gtk_grid_get_size (grid, GTK_ORIENTATION_VERTICAL, minimum, natural);
@@ -1246,6 +1258,7 @@ gtk_grid_class_init (GtkGridClass *class)
   widget_class->size_allocate = gtk_grid_size_allocate;
   widget_class->get_preferred_width = gtk_grid_get_preferred_width;
   widget_class->get_preferred_height = gtk_grid_get_preferred_height;
+  widget_class->get_request_mode = gtk_grid_get_request_mode;
   widget_class->get_preferred_width_for_height = gtk_grid_get_preferred_width_for_height;
   widget_class->get_preferred_height_for_width = gtk_grid_get_preferred_height_for_width;
 
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 922e2f5..9f7c7ad 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3381,12 +3381,10 @@ gtk_label_get_request_mode (GtkWidget *widget)
   GtkLabel *label = GTK_LABEL (widget);
   gdouble   angle = gtk_label_get_angle (label);
 
-  if (label->priv->wrap)
-    return (angle == 90 || angle == 270) ?
-      GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT : 
-      GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+  if (angle == 90 || angle == 270)
+    return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
 
-    return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+  return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
 }
 
 static void
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index 8526d59..6d3daad 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -156,11 +156,6 @@ pop_recursion_check (GtkWidget       *widget,
 #endif
 }
 
-/* This is the main function that checks for a cached size and
- * possibly queries the widget class to compute the size if it's
- * not cached. If the for_size here is -1, then get_preferred_width()
- * or get_preferred_height() will be used.
- */
 static void
 compute_size_for_orientation (GtkWidget         *widget,
                               GtkSizeGroupMode   orientation,
@@ -173,6 +168,9 @@ compute_size_for_orientation (GtkWidget         *widget,
   gboolean          found_in_cache = FALSE;
   int adjusted_min, adjusted_natural;
 
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (minimum_size != NULL || natural_size != NULL);
+
   cache  = _gtk_widget_peek_request_cache (widget);
 
   if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
@@ -403,9 +401,6 @@ gtk_widget_get_preferred_width (GtkWidget *widget,
                                 gint      *minimum_width,
                                 gint      *natural_width)
 {
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (minimum_width != NULL || natural_width != NULL);
-
   compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
                                 -1, minimum_width, natural_width);
 }
@@ -434,9 +429,6 @@ gtk_widget_get_preferred_height (GtkWidget *widget,
                                  gint      *minimum_height,
                                  gint      *natural_height)
 {
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (minimum_height != NULL || natural_height != NULL);
-
   compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
                                 -1, minimum_height, natural_height);
 }
@@ -467,16 +459,8 @@ gtk_widget_get_preferred_width_for_height (GtkWidget *widget,
                                            gint      *minimum_width,
                                            gint      *natural_width)
 {
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (minimum_width != NULL || natural_width != NULL);
-  g_return_if_fail (height >= 0);
-
-  if (GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
-    compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
-				  -1, minimum_width, natural_width);
-  else
-    compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
-				  height, minimum_width, natural_width);
+  compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
+                                height, minimum_width, natural_width);
 }
 
 /**
@@ -503,16 +487,8 @@ gtk_widget_get_preferred_height_for_width (GtkWidget *widget,
                                            gint      *minimum_height,
                                            gint      *natural_height)
 {
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (minimum_height != NULL || natural_height != NULL);
-  g_return_if_fail (width >= 0);
-
-  if (GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
-    compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
-				  -1, minimum_height, natural_height);
-  else
-    compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
-				  width, minimum_height, natural_height);
+  compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
+                                width, minimum_height, natural_height);
 }
 
 /**
@@ -564,7 +540,7 @@ gtk_widget_get_preferred_size (GtkWidget      *widget,
                                                      NULL, &natural_size->height);
 	}
     }
-  else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT or CONSTANT_SIZE */
+  else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
     {
       gtk_widget_get_preferred_height (widget, &min_height, &nat_height);
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 8f361b2..783aea2 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -12980,8 +12980,8 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
 static GtkSizeRequestMode 
 gtk_widget_real_get_request_mode (GtkWidget *widget)
 { 
-  /* By default widgets dont trade size at all. */
-  return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+  /* By default widgets are height-for-width. */
+  return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
 }
 
 static void
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index ce40385..c391b22 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -139,15 +139,12 @@ struct _GtkWidget
  *   %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT mode.
  *   %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH means the widget prefers to have
  *   #GtkWidgetClass.get_preferred_width() called and then
- *   #GtkWidgetClass.get_preferred_height_for_width().
- *   %GTK_SIZE_REQUEST_CONSTANT_SIZE disables any height-for-width or
- *   width-for-height geometry management for a said widget and is the
- *   default return.
- *   It's important to note (as described below) that any widget
- *   which trades height-for-width or width-for-height must respond properly 
- *   to both of the virtual methods #GtkWidgetClass.get_preferred_height_for_width()
- *   and #GtkWidgetClass.get_preferred_width_for_height() since it might be 
- *   queried in either #GtkSizeRequestMode by its parent container.
+ *   #GtkWidgetClass.get_preferred_height_for_width() and is the default
+ *   return for unimplemented cases.
+ *   However it's important to note (as described below) that any widget
+ *   which trades height-for-width must respond properly to both
+ *   #GtkSizeRequestModes since it might be queried in either orientation
+ *   by its parent container.
  * @get_preferred_height: This is called by containers to obtain the minimum
  *   and natural height of a widget. A widget that does not actually trade
  *   any height for width or width for height only has to implement these



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