[gtk+/native-layout] Fixed internal native layout algorythm wrt size-request singals/implementations.



commit 5d83f5eba58a7266949c5e47fb5f3fefec10c107
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat Apr 3 20:43:39 2010 -0400

    Fixed internal native layout algorythm wrt size-request singals/implementations.
    
    Because "size-request" signal can be handled by signal connections as well
    as by third party derived classes it is necessary to always fire the
    "size-request" signal for every recalculation of the widget requisition,
    now gtksizegroup.c:do_size_request() fires the signal first and allows it
    to overflow the minimum/natural sizes returned by extended layout
    implementations.
    
    GtkWidget->get_natural_size() is now left assigning default -1 values to
    ensure they both get overridden by the size-request handling.

 gtk/gtksizegroup.c |   36 +++++++++++++++++++++++++++++++++---
 gtk/gtkwidget.c    |   19 ++++++++++++-------
 2 files changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtksizegroup.c b/gtk/gtksizegroup.c
index 7a2b9f4..2dcde99 100644
--- a/gtk/gtksizegroup.c
+++ b/gtk/gtksizegroup.c
@@ -659,16 +659,47 @@ do_size_request (GtkWidget *widget)
   if (GTK_WIDGET_REQUEST_NEEDED (widget))
     {
       GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+      GtkRequisition extended_minimum;
 
       gtk_widget_ensure_style (widget);      
       GTK_PRIVATE_UNSET_FLAG (widget, GTK_REQUEST_NEEDED);
 
+      /* First, allow client code to; extended classes or signal connections; to 
+       * modify the initial size request. 
+       *
+       * Note here that there is no convention of filling the argument or widget->requisition,
+       * so we have no choice but to fire size request with this pointer.
+       */
+      g_signal_emit_by_name (widget,
+			     "size-request",
+			     &widget->requisition);
+
+      /* Now get the extended layout minimum and natural size
+       */
       gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (widget),
-                                            &widget->requisition,
+                                            &extended_minimum,
                                             &aux_info->natural_size);
 
+      /* Base the base widget requisition on both the size-requst and the extended layout size
+       */
+      widget->requisition.width  = MAX (widget->requisition.width,  extended_minimum.width);
+      widget->requisition.height = MAX (widget->requisition.height, extended_minimum.height);
+
+      /* Additionally allow a "size-request" to overflow the natural size.
+       */
+      aux_info->natural_size.width  = MAX (aux_info->natural_size.width,  widget->requisition.width);
+      aux_info->natural_size.height = MAX (aux_info->natural_size.height, widget->requisition.height);
+
+      /* Assert that pure extended layout cases return initial minimum sizes smaller or equal
+       * to their possible natural size.
+       *
+       * Note that this only determines the return of gtk_widget_get_desired_size() and caches
+       * the initial hints. Height for width cases will further be addressed in containers
+       * using gtk_extended_layout_get_height_for_width().
+       */
       g_assert (widget->requisition.width <= aux_info->natural_size.width);
       g_assert (widget->requisition.height <= aux_info->natural_size.height);
+
     }
 }
 
@@ -682,7 +713,7 @@ compute_base_dimensions (GtkWidget        *widget,
   get_base_dimensions (widget, mode, minimum_size, natural_size);
 }
 
-static gint
+static void
 compute_dimension (GtkWidget        *widget,
 		   GtkSizeGroupMode  mode,
                    gint             *minimum_size,
@@ -691,7 +722,6 @@ compute_dimension (GtkWidget        *widget,
   GSList *widgets = NULL;
   GSList *groups = NULL;
   GSList *tmp_list;
-  gint result = 0;
 
   add_widget_to_closure (widget, mode, &groups, &widgets);
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index bea1259..0c7d12d 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -10720,15 +10720,20 @@ gtk_widget_real_get_desired_size (GtkExtendedLayout *layout,
                                   GtkRequisition    *minimum_size,
                                   GtkRequisition    *natural_size)
 {
-  GtkWidget *widget = GTK_WIDGET (layout);
-  GtkRequisition requisition = widget->requisition;
-
-  g_signal_emit (widget, widget_signals[SIZE_REQUEST], 0, &requisition);
-
+  /* Set the initial values so that unimplemented classes will fall back
+   * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
+   */
   if (minimum_size)
-    *minimum_size = requisition;
+    {
+      minimum_size->width  = -1;
+      minimum_size->height = -1;
+    }
+
   if (natural_size)
-    *natural_size = requisition;
+    {
+      natural_size->width  = -1;
+      natural_size->height = -1;
+    }
 }
 
 static void



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