[gtk+/refactor: 1/145] Add _gtk_widget_set_requisition() internal function



commit cfd663abd2481e5ad74f6f473409791450e34239
Author: Javier Jardón <jjardon gnome org>
Date:   Mon Aug 9 18:39:29 2010 +0200

    Add _gtk_widget_set_requisition() internal function
    
    It's needed by gtkarrow, gtkimage, gtkmisc and gtkpathbar

 gtk/gtkarrow.c   |    7 +++++--
 gtk/gtkimage.c   |   12 ++++++++----
 gtk/gtkmisc.c    |   13 +++++++------
 gtk/gtkpathbar.c |    2 +-
 gtk/gtkwidget.c  |    7 +++++++
 gtk/gtkwidget.h  |    2 ++
 6 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkarrow.c b/gtk/gtkarrow.c
index 7da60bf..ce556d1 100644
--- a/gtk/gtkarrow.c
+++ b/gtk/gtkarrow.c
@@ -176,6 +176,7 @@ static void
 gtk_arrow_init (GtkArrow *arrow)
 {
   GtkArrowPriv *priv;
+  GtkRequisition requisition;
   gint xpad, ypad;
 
   arrow->priv = G_TYPE_INSTANCE_GET_PRIVATE (arrow,
@@ -186,8 +187,10 @@ gtk_arrow_init (GtkArrow *arrow)
   gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
 
   gtk_misc_get_padding (GTK_MISC (arrow), &xpad, &ypad);
-  GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + xpad * 2;
-  GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + ypad * 2;
+
+  requisition.width = MIN_ARROW_SIZE + xpad * 2;
+  requisition.height = MIN_ARROW_SIZE + ypad * 2;
+  _gtk_widget_set_requisition (GTK_WIDGET (arrow), &requisition);
 
   priv->arrow_type = GTK_ARROW_RIGHT;
   priv->shadow_type = GTK_SHADOW_OUT;
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 2a41329..fbd21ba 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -2268,12 +2268,14 @@ gtk_image_calc_size (GtkImage *image)
 
   if (pixbuf)
     {
+      GtkRequisition requisition;
       gint xpad, ypad;
 
       gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
 
-      widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
-      widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
+      requisition.width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
+      requisition.height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
+      _gtk_widget_set_requisition (widget, &requisition);
 
       g_object_unref (pixbuf);
     }
@@ -2326,13 +2328,15 @@ gtk_image_update_size (GtkImage *image,
                        gint      image_width,
                        gint      image_height)
 {
+  GtkRequisition requisition;
   GtkWidget *widget = GTK_WIDGET (image);
   gint xpad, ypad;
 
   gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
 
-  widget->requisition.width = image_width + xpad * 2;
-  widget->requisition.height = image_height + ypad * 2;
+  requisition.width = image_width + xpad * 2;
+  requisition.height = image_height + ypad * 2;
+  _gtk_widget_set_requisition (widget, &requisition);
 
   if (gtk_widget_get_visible (widget))
     gtk_widget_queue_resize (widget);
diff --git a/gtk/gtkmisc.c b/gtk/gtkmisc.c
index fc711aa..67bae4b 100644
--- a/gtk/gtkmisc.c
+++ b/gtk/gtkmisc.c
@@ -268,7 +268,7 @@ gtk_misc_set_padding (GtkMisc *misc,
 		      gint     ypad)
 {
   GtkMiscPriv *priv;
-  GtkRequisition *requisition;
+  GtkRequisition requisition;
 
   g_return_if_fail (GTK_IS_MISC (misc));
 
@@ -288,15 +288,16 @@ gtk_misc_set_padding (GtkMisc *misc,
       if (ypad != priv->ypad)
 	g_object_notify (G_OBJECT (misc), "ypad");
 
-      requisition = &(GTK_WIDGET (misc)->requisition);
-      requisition->width -= priv->xpad * 2;
-      requisition->height -= priv->ypad * 2;
+      gtk_widget_get_requisition (GTK_WIDGET (misc), &requisition);
+      requisition.width -= priv->xpad * 2;
+      requisition.height -= priv->ypad * 2;
 
       priv->xpad = xpad;
       priv->ypad = ypad;
 
-      requisition->width += priv->xpad * 2;
-      requisition->height += priv->ypad * 2;
+      requisition.width += priv->xpad * 2;
+      requisition.height += priv->ypad * 2;
+      _gtk_widget_set_requisition (GTK_WIDGET (misc), &requisition);
 
       if (gtk_widget_is_drawable (GTK_WIDGET (misc)))
 	gtk_widget_queue_resize (GTK_WIDGET (misc));
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 3c36f38..be44855 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -356,7 +356,7 @@ gtk_path_bar_size_request (GtkWidget      *widget,
   requisition->width += border_width * 2;
   requisition->height += border_width * 2;
 
-  widget->requisition = *requisition;
+  _gtk_widget_set_requisition (widget, requisition);
 }
 
 static void
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index a859bf2..8e062c0 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -11479,6 +11479,13 @@ gtk_widget_get_requisition (GtkWidget      *widget,
   *requisition = widget->requisition;
 }
 
+void
+_gtk_widget_set_requisition (GtkWidget            *widget,
+                             const GtkRequisition *requisition)
+{
+  widget->requisition = *requisition;
+}
+
 /**
  * gtk_widget_set_window:
  * @widget: a #GtkWidget
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 0bae2c6..c4318a2 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -964,6 +964,8 @@ void              _gtk_widget_set_has_grab                (GtkWidget    *widget,
                                                            gboolean      has_grab);
 void              _gtk_widget_set_is_toplevel             (GtkWidget    *widget,
                                                            gboolean      is_toplevel);
+void              _gtk_widget_set_requisition             (GtkWidget            *widget,
+                                                           const GtkRequisition *requisition);
 
 void              _gtk_widget_grab_notify                 (GtkWidget    *widget,
 						           gboolean	was_grabbed);



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